Sources
List the sources a response used, behind a compact count that opens into links.
Use sources under a response that searched the web or read documents, so readers can check where an answer came from. It shows "Used N sources", and opens into a link for each source with its site's icon, title and host name.
- Rate limits for the REST APIdocs.github.com
Primary rate limits cap how many requests you can make in an hour.
- Retry-After headerdeveloper.mozilla.org
How long to wait before making the next request.
- RFC 9110: HTTP Semanticsrfc-editor.org
Installation
npx shadcn@latest add @kind-ui/sourcesComposition
Sources
├── SourcesTrigger
└── SourcesContent
└── SourcesList
└── SourcesItem
├── SourcesLink
│ ├── SourcesIcon
│ ├── SourcesTitle
│ └── SourcesHost
└── SourcesSnippetSourcesTrigger is a native button that shows the label, else "Used N sources", and shows or hides SourcesContent. SourcesList renders a SourcesItem for each source, keyed by its id. SourcesLink links to the source's url and opens it in a new tab. SourcesIcon shows the source's favicon, and the first letter of its host name until the image loads or without one. SourcesHost shows the host name without www., and SourcesSnippet the snippet, up to two lines. To arrange the parts yourself, pass them as children of Sources.
Usage
Sources
Pass sources, each with an id and a title, and optionally a url, favicon and snippet. Links accept http, https, mailto and relative URLs. A source with any other URL, like javascript:, shows as text with no link and no host name.
<Sources
sources={[
{ id: "limits", title: "Rate limits for the REST API", url: "https://docs.github.com/en/rest" },
{ id: "notes", title: "Meeting notes" },
]}
/>Streaming Sources
Add sources as the agent finds them, keeping each id. A source added after the list first renders fades up once, and the count in the trigger updates without moving anything around it. A source whose title or URL changes updates in place, without fading in again. At full motion the list slides open; under prefers-reduced-motion, or with motion="reduced", it fades in over 120 ms, and with motion="none" it shows at once.
Opening
The list starts closed. Pass defaultOpen to start with it shown, or open with onOpenChange to control it; onOpenChange gets "trigger-press", "find-in-page" or "imperative". The list stays in the page while it's closed, so the browser's find in page reaches it and opens it.
API Reference
Prop
Type
Agent
An agent connected with createAgent finds the sources by the trigger's text and reads open. expand() is offered while the list is hidden and collapse() while it shows. Like any component with a button, it also has UI SDK's generic press.
Prop
Type
Runs in React and Web Components. On <kind-sources>, set sources as a property; the other props are kebab-case attributes, and onOpenChange is the openchange event. The element fills in its trigger, list and items, and keeps any <kind-sources-item value="…"> you write inside its <kind-sources-list>.