---
title: "Inline Citation"
description: "An inline source reference with a hover and focus card."
---

# Inline Citation

An inline source reference with a hover and focus card.

## Usage

Hover, focus or activate an inline citation to inspect its source. Follow its link to open the original documentation.

## Example

```contract
use FontWeights from "@rightui/ui"
use uiFontFamily from "@rightui/ui"
shape CitationSource
  id: string
  host: string
  url: string
  title: string
  description: string

component Demo
  props
    width: number
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
    rightuiDemoTime: number
    rightuiRunDemo: action
  state active = 0
  state hideAt = 0
  state popupFocused = false
  derive sources = [CitationSource(id="ai-inline-citation-0", host="github.com", url="https://github.com/expo/exact", title="Exact runtime", description="One interface, rendered by the web, iOS and macOS hosts."), CitationSource(id="ai-inline-citation-1", host="github.com", url="https://github.com/expo/exact/blob/main/docs/contract-for-agents.md", title="Contract language", description="Declare views, state and actions in a typed interface language."), CitationSource(id="ai-inline-citation-2", host="github.com", url="https://github.com/expo/exact#how-it-works", title="TypeScript and Rust data sources", description="Keep data logic behind the typed boundary used by Contract."), CitationSource(id="ai-inline-citation-3", host="github.com", url="https://github.com/expo/exact/blob/main/docs/recipes/fetch-loading-error.md", title="Loading, errors and retry", description="Use resource states to display progress, failures and a retry action."), CitationSource(id="ai-inline-citation-4", host="github.com", url="https://github.com/expo/exact/blob/main/docs/recipes/tamber.md", title="Tamber themes", description="Share named color tokens and switch between theme modes.")]
  derive source = match sources.at(active) { case some(item) => item, case none => CitationSource(id="ai-inline-citation-0", host="github.com", url="https://github.com/expo/exact", title="Exact runtime", description="One interface, rendered by the web, iOS and macOS hosts.") }
  action show(index: number)
    active = index
    hideAt = 0
    showPopover("ai-inline-citation-content", source="ai-inline-citation-" + index.toString())
  action hover(index: number, inside: bool)
    if inside
      show(index)
    else
      hideAt = rightuiDemoTime + 100
      rightuiRunDemo(100)
  action popupHover(inside: bool)
    if inside
      hideAt = 0
    else if not popupFocused
      hideAt = rightuiDemoTime + 100
      rightuiRunDemo(100)
  action enter
    popupFocused = true
    hideAt = 0
  action leave
    popupFocused = false
    hideAt = rightuiDemoTime + 100
    rightuiRunDemo(100)
  action triggerKeys(index: number, k: string)
    if k == "Enter" or k == " "
      preventDefault()
      show(index)
    else
      closeTip(k)
  action closeTip(k: string)
    if k == "Escape"
      hidePopover("ai-inline-citation-content")
      focus(source.id)
  view
    column max-width="24rem" gap="ui.space-12" padding="ui.space-24 ui.space-0" font-size="ui.text-sm" line-height="ui.leading-relaxed"
      text "" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text "Exact renders the same interface on the web, iOS and macOS using each platform's host." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-0" testId="ai-inline-citation-0" role="button" tabindex=0 aria-haspopup="dialog" press=show(0) hover=hover(0) focusin=show(0) focusout=leave key=triggerKeys(0) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      text "" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text "Contract describes the view, its state and the actions behind each interaction." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-1" testId="ai-inline-citation-1" role="button" tabindex=0 aria-haspopup="dialog" press=show(1) hover=hover(1) focusin=show(1) focusout=leave key=triggerKeys(1) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " TypeScript or Rust supplies the data through a typed boundary, keeping data logic separate from the interface." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-2" testId="ai-inline-citation-2" role="button" tabindex=0 aria-haspopup="dialog" press=show(2) hover=hover(2) focusin=show(2) focusout=leave key=triggerKeys(2) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      text "" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text "Resources expose loading and error states, so the view can show progress or offer a retry." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-3" testId="ai-inline-citation-3" role="button" tabindex=0 aria-haspopup="dialog" press=show(3) hover=hover(3) focusin=show(3) focusout=leave key=triggerKeys(3) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " Tamber keeps named colors and theme modes together in app.tamber." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-4" testId="ai-inline-citation-4" role="button" tabindex=0 aria-haspopup="dialog" press=show(4) hover=hover(4) focusin=show(4) focusout=leave key=triggerKeys(4) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      if hideAt == 0 or rightuiDemoTime < hideAt or popupFocused
        column id="ai-inline-citation-content" testId="ai-inline-citation-content" popover="auto" role="dialog" aria-label=source.title position-area="bottom" position-try-fallbacks="flip-block, flip-inline" margin="ui.space-8" width="16rem" padding="ui.space-16" gap="ui.space-4" border-width="ui.border-width" border-style="solid" border-color="ui.border" border-radius="ui.ai-radius-popover" background-color="ui.surface" color="ui.foreground" box-shadow="ui.shadow-menu" hover=popupHover focusin=enter focusout=leave key=closeTip
          text source.title font-weight=uiWeights.medium font-family=uiFontFamily(uiFont) data-rightui-font="body"
          text source.description color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
          link id="ai-inline-citation-source-link" href=source.url target="_blank" rel="noreferrer" aria-label=(source.host + " (opens in a new tab)")
            text source.host font-size="ui.text-xs" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```

## Keyboard

Tab opens the citation card; Escape closes it. Tab to the source link and Enter to follow.

## Demo runtime

Timed examples use an injected clock. Add these members to your root component. Replace the scripted state with events from your TypeScript or Rust data source when connecting a model.

```contract
use defaultFontWeights from "@rightui/ui"
  state demoTime = 0
  state demoUntil = 0
  provide
    uiFont = "theme"
    uiWeights = defaultFontWeights()
    rightuiDemoTime = demoTime
    rightuiRunDemo = runDemo
  action runDemo(duration: number)
    demoUntil = max(demoUntil, demoTime + duration)
  action tickDemo
    demoTime = min(demoUntil, demoTime + 32)
  task demoClock when demoTime < demoUntil
    every(32, tickDemo)
```

## Source

File: patterns/ai-elements/inline-citation.contract

```contract
use FontWeights from "@rightui/ui"
use uiFontFamily from "@rightui/ui"
shape CitationSource
  id: string
  host: string
  url: string
  title: string
  description: string

component Demo
  props
    width: number
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
    rightuiDemoTime: number
    rightuiRunDemo: action
  state active = 0
  state hideAt = 0
  state popupFocused = false
  derive sources = [CitationSource(id="ai-inline-citation-0", host="github.com", url="https://github.com/expo/exact", title="Exact runtime", description="One interface, rendered by the web, iOS and macOS hosts."), CitationSource(id="ai-inline-citation-1", host="github.com", url="https://github.com/expo/exact/blob/main/docs/contract-for-agents.md", title="Contract language", description="Declare views, state and actions in a typed interface language."), CitationSource(id="ai-inline-citation-2", host="github.com", url="https://github.com/expo/exact#how-it-works", title="TypeScript and Rust data sources", description="Keep data logic behind the typed boundary used by Contract."), CitationSource(id="ai-inline-citation-3", host="github.com", url="https://github.com/expo/exact/blob/main/docs/recipes/fetch-loading-error.md", title="Loading, errors and retry", description="Use resource states to display progress, failures and a retry action."), CitationSource(id="ai-inline-citation-4", host="github.com", url="https://github.com/expo/exact/blob/main/docs/recipes/tamber.md", title="Tamber themes", description="Share named color tokens and switch between theme modes.")]
  derive source = match sources.at(active) { case some(item) => item, case none => CitationSource(id="ai-inline-citation-0", host="github.com", url="https://github.com/expo/exact", title="Exact runtime", description="One interface, rendered by the web, iOS and macOS hosts.") }
  action show(index: number)
    active = index
    hideAt = 0
    showPopover("ai-inline-citation-content", source="ai-inline-citation-" + index.toString())
  action hover(index: number, inside: bool)
    if inside
      show(index)
    else
      hideAt = rightuiDemoTime + 100
      rightuiRunDemo(100)
  action popupHover(inside: bool)
    if inside
      hideAt = 0
    else if not popupFocused
      hideAt = rightuiDemoTime + 100
      rightuiRunDemo(100)
  action enter
    popupFocused = true
    hideAt = 0
  action leave
    popupFocused = false
    hideAt = rightuiDemoTime + 100
    rightuiRunDemo(100)
  action triggerKeys(index: number, k: string)
    if k == "Enter" or k == " "
      preventDefault()
      show(index)
    else
      closeTip(k)
  action closeTip(k: string)
    if k == "Escape"
      hidePopover("ai-inline-citation-content")
      focus(source.id)
  view
    column max-width="24rem" gap="ui.space-12" padding="ui.space-24 ui.space-0" font-size="ui.text-sm" line-height="ui.leading-relaxed"
      text "" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text "Exact renders the same interface on the web, iOS and macOS using each platform's host." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-0" testId="ai-inline-citation-0" role="button" tabindex=0 aria-haspopup="dialog" press=show(0) hover=hover(0) focusin=show(0) focusout=leave key=triggerKeys(0) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      text "" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text "Contract describes the view, its state and the actions behind each interaction." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-1" testId="ai-inline-citation-1" role="button" tabindex=0 aria-haspopup="dialog" press=show(1) hover=hover(1) focusin=show(1) focusout=leave key=triggerKeys(1) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " TypeScript or Rust supplies the data through a typed boundary, keeping data logic separate from the interface." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-2" testId="ai-inline-citation-2" role="button" tabindex=0 aria-haspopup="dialog" press=show(2) hover=hover(2) focusin=show(2) focusout=leave key=triggerKeys(2) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      text "" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text "Resources expose loading and error states, so the view can show progress or offer a retry." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-3" testId="ai-inline-citation-3" role="button" tabindex=0 aria-haspopup="dialog" press=show(3) hover=hover(3) focusin=show(3) focusout=leave key=triggerKeys(3) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " Tamber keeps named colors and theme modes together in app.tamber." font-family=uiFontFamily(uiFont) data-rightui-font="body"
        text " github.com " id="ai-inline-citation-4" testId="ai-inline-citation-4" role="button" tabindex=0 aria-haspopup="dialog" press=show(4) hover=hover(4) focusin=show(4) focusout=leave key=triggerKeys(4) background-color="ui.muted" color="ui.foreground" font-size="ui.text-xs" font-weight=uiWeights.medium border-radius="ui.ai-radius-control" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      if hideAt == 0 or rightuiDemoTime < hideAt or popupFocused
        column id="ai-inline-citation-content" testId="ai-inline-citation-content" popover="auto" role="dialog" aria-label=source.title position-area="bottom" position-try-fallbacks="flip-block, flip-inline" margin="ui.space-8" width="16rem" padding="ui.space-16" gap="ui.space-4" border-width="ui.border-width" border-style="solid" border-color="ui.border" border-radius="ui.ai-radius-popover" background-color="ui.surface" color="ui.foreground" box-shadow="ui.shadow-menu" hover=popupHover focusin=enter focusout=leave key=closeTip
          text source.title font-weight=uiWeights.medium font-family=uiFontFamily(uiFont) data-rightui-font="body"
          text source.description color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
          link id="ai-inline-citation-source-link" href=source.url target="_blank" rel="noreferrer" aria-label=(source.host + " (opens in a new tab)")
            text source.host font-size="ui.text-xs" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```
