nook
Browse the docs

Components

Sources

Built on Base UI

Source links, a collapsible citation list and focusable inline citation previews.

See the prompt

Installation

npx nook-ui@latest add sources

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Sources" component to this project, exactly as Nook ships it.

Source links, a collapsible citation list and focusable inline citation previews.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add sources`. It writes `components/ui/sources.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/sources.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { Citation, Sources, type Source } from "@/components/ui/sources";
const sources: Source[] = [
  {
    id: 1,
    site: "Platform handbook",
    title: "Choosing a deployment region",
    href: "#deployment-region",
    snippet:
      "Place your application close to the database to reduce network latency.",
  },
  {
    id: 2,
    site: "Engineering notes",
    title: "Reading a request trace",
    href: "#request-trace",
    snippet:
      "A trace separates application time from database queries and network hops.",
  },
  {
    id: 3,
    site: "Operations guide",
    title: "Measure before changing regions",
    href: "#measure-latency",
    snippet:
      "Compare median and 95th percentile response times over the same window.",
  },
];
export default function SourcesDefault() {
  return (
    <article className="w-full max-w-xl text-sm leading-relaxed">
      <h3 className="mb-3 font-semibold">Keep the data close</h3>
      <p>
        Deploy the API in the same region as the database.
        <Citation source={sources[0]!} />
        Check a request trace before moving services: a slower query can look
        like a network problem.
        <Citation source={sources[1]!} />
        Compare the 95th percentile after the change.
        <Citation source={sources[2]!} />
      </p>
      <div className="mt-4 border-t border-border pt-2">
        <Sources sources={sources} />
      </div>
    </article>
  );
}
```

API
- `SourceChip`: A numbered source link with an optional hover preview.
  - `source` (`Source`): id, title, site, href and optional snippet.
- `Sources`: A list summarized as Used N sources.
  - `sources` (`Source[]`): Citation records.
  - `open` (`boolean`): Native disclosure state.
- `Citation`: An inline [N] button with a source popover.
  - `source` (`Source`): The same source record used in the list.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Native details collapses the list. Source links use HoverCard previews; inline Citation buttons open a Popover with a normal source link. Escape dismisses the popover and restores focus.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { Citation, Sources, type Source } from "@/components/ui/sources";
const sources: Source[] = [
  {
    id: 1,
    site: "Platform handbook",
    title: "Choosing a deployment region",
    href: "#deployment-region",
    snippet:
      "Place your application close to the database to reduce network latency.",
  },
  {
    id: 2,
    site: "Engineering notes",
    title: "Reading a request trace",
    href: "#request-trace",
    snippet:
      "A trace separates application time from database queries and network hops.",
  },
  {
    id: 3,
    site: "Operations guide",
    title: "Measure before changing regions",
    href: "#measure-latency",
    snippet:
      "Compare median and 95th percentile response times over the same window.",
  },
];
export default function SourcesDefault() {
  return (
    <article className="w-full max-w-xl text-sm leading-relaxed">
      <h3 className="mb-3 font-semibold">Keep the data close</h3>
      <p>
        Deploy the API in the same region as the database.
        <Citation source={sources[0]!} />
        Check a request trace before moving services: a slower query can look
        like a network problem.
        <Citation source={sources[1]!} />
        Compare the 95th percentile after the change.
        <Citation source={sources[2]!} />
      </p>
      <div className="mt-4 border-t border-border pt-2">
        <Sources sources={sources} />
      </div>
    </article>
  );
}

Examples

Source chips

The cheapest way to the airport after midnight is the N2 night bus. A taxi costs about three times as much.

Used 3 sources
  1. 1City transitNight bus timetable
  2. 2Airport guideGetting to the terminal
  3. 3Travel forumTaxi prices after midnight

One citation

Your next return is due on January 15.

Props

SourceChip

A numbered source link with an optional hover preview.

PropTypeDefaultDescription
sourceSource–id, title, site, href and optional snippet.

Sources

A list summarized as Used N sources.

PropTypeDefaultDescription
sourcesSource[]–Citation records.
openboolean–Native disclosure state.

Citation

An inline [N] button with a source popover.

PropTypeDefaultDescription
sourceSource–The same source record used in the list.

Accessibility

Native details collapses the list. Source links use HoverCard previews; inline Citation buttons open a Popover with a normal source link. Escape dismisses the popover and restores focus.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.