PeakUIPro

ChatSource

Citation chips and grouped source lists for answers

Usage

import {ChatSource, ChatSources} from "@peakui-pro/react";

Anatomy

import {ChatSource, ChatSources} from "@peakui-pro/react";

export default () => (
  <>
    {/* A URL source: a link with a hover card. Without children it renders Trigger and Preview. */}
    <ChatSource description="Guides and API reference." href="https://docs.example.com" title="Docs">
      <ChatSource.Trigger>
        <ChatSource.Icon />
        <ChatSource.Title />
      </ChatSource.Trigger>
      {/* Opens after 700ms of hover or keyboard focus, or on long press; closes 300ms after leaving, or on Escape. */}
      <ChatSource.Preview />
    </ChatSource>

    {/* The core Disclosure around a wrapping list of sources. */}
    <ChatSources defaultExpanded={false}>
      <ChatSources.Trigger>3 sources</ChatSources.Trigger>
      <ChatSources.Content>
        <ChatSources.List>
          <ChatSource href="https://docs.example.com" title="Docs" />
        </ChatSources.List>
      </ChatSources.Content>
    </ChatSources>
  </>
);

Examples

Document

sourceType="document" renders a pill with no link and no preview.

Grouped

Stacked Favicons

Put favicon avatars in ChatSources.Trigger for a compact source button.

Composable

Customization

Tailwind CSS

<ChatSource
  className="[--chat-source-bg:var(--color-accent-soft)] [--chat-source-max-width:12rem]"
  href="https://docs.example.com"
  title="Example Docs"
/>

Global CSS

@layer components {
  .chat-source {
    --chat-source-bg: var(--color-accent-soft);
    --chat-source-fg: var(--color-accent-soft-foreground);
    --chat-source-max-width: 12rem;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The ChatSource component uses these CSS classes (view source styles):

Base Classes

  • .chat-source - Source root
  • .chat-sources - Grouped source disclosure, beside the core .disclosure

Element Classes

  • .chat-source__trigger - Trigger wrapper
  • .chat-source__trigger-link - Link or document pill
  • .chat-source__icon - Favicon image or custom icon
  • .chat-source__icon-fallback - Initial shown when there is no favicon
  • .chat-source__document-icon - Document source glyph
  • .chat-source__title - Title, truncated
  • .chat-source__preview - Hover card
  • .chat-source__preview-link - Card body, a link to the source
  • .chat-source__preview-header - Favicon and domain row
  • .chat-source__preview-domain - Domain
  • .chat-source__preview-title - Card title
  • .chat-source__preview-description - Card description, clamped to two lines
  • .chat-sources__trigger - Group trigger, beside the core .disclosure__trigger
  • .chat-sources__trigger-label - Group trigger label
  • .chat-sources__indicator - Group trigger chevron
  • .chat-sources__content - Group panel, beside the core .disclosure__content
  • .chat-sources__list - Wrapping source list

Slots

  • [data-slot="chat-source"]
  • [data-slot="chat-source-trigger"]
  • [data-slot="chat-source-trigger-link"]
  • [data-slot="chat-source-icon"]
  • [data-slot="chat-source-icon-fallback"]
  • [data-slot="chat-source-document-icon"]
  • [data-slot="chat-source-title"]
  • [data-slot="chat-source-preview"]
  • [data-slot="chat-source-preview-link"]
  • [data-slot="chat-source-preview-header"]
  • [data-slot="chat-source-preview-domain"]
  • [data-slot="chat-source-preview-title"]
  • [data-slot="chat-source-preview-description"]
  • [data-slot="chat-sources"]
  • [data-slot="chat-sources-trigger"]
  • [data-slot="chat-sources-trigger-label"]
  • [data-slot="chat-sources-content"]
  • [data-slot="chat-sources-list"]

CSS Variables

VariablePurpose
--chat-source-heightPill height; defaults to 1.5rem
--chat-source-padding-inlinePill inline padding; defaults to 0.5rem
--chat-source-gapSpace between icon and title; defaults to 0.25rem
--chat-source-max-widthWidest pill before the title truncates; defaults to 8rem
--chat-source-icon-sizeFavicon and glyph size; defaults to 0.875rem
--chat-source-bgPill fill; defaults to var(--color-default)
--chat-source-bg-hoverLink pill fill on hover; defaults to var(--color-default-hover)
--chat-source-fgPill text; defaults to var(--color-muted)
--chat-source-fg-hoverLink pill text on hover; defaults to var(--color-default-foreground)
--chat-source-preview-widthHover card width; the card is portalled, so set it on .chat-source__preview; defaults to 20rem
--chat-sources-list-gapSpace between grouped sources; defaults to 0.375rem
--chat-sources-trigger-gapSpace between the group label and its chevron; defaults to 0.375rem

Interactive States

  • Hover: :hover or [data-hovered] on a link pill
  • Focus: :focus-visible or [data-focus-visible] on a link pill and on the card link
  • Entering / Exiting: [data-entering] / [data-exiting] on .chat-source__preview, stopped under reduced motion
  • Placement: [data-placement] on .chat-source__preview
  • Expanded: [data-expanded="true"] on .chat-sources
  • Forced colors: a link pill draws a LinkText border, a document pill a CanvasText border; the card a ButtonBorder boundary

API Reference

ChatSource

PropTypeDefaultDescription
hrefstring-URL of the source
titlestringdomainDisplay title; falls back to the domain of href, then to href
descriptionstring-Fills the hover card, and enables it
enablePreviewbooleanautoOn for a URL source with a title or description. true mounts a custom Preview; false turns the card off. A document has none
faviconUrlstring-Favicon shown in the trigger and the card; a failed load falls back to the initial
sourceType'url' | 'document'inferredurl when href is set, otherwise document
childrenReactNodeTrigger and PreviewCustom composition
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'div'
...restComponentProps<'div'>-Native attributes

ChatSource.Trigger

PropTypeDefaultDescription
hrefstringroot hrefLink target of a URL source
targetstring'_blank'Link target window
relstring'noopener noreferrer'Link relationship
childrenReactNodeIcon and TitlePill content
classNamestring | ((values: LinkRenderProps) => string)-Classes of the link or the document pill
...restLinkProps-React Aria Link props, applied to a URL source's link

ChatSource.Icon

PropTypeDefaultDescription
faviconUrlstringroot faviconUrlFavicon image URL
childrenReactNodeinitial or document glyphCustom glyph; decorative, hidden from assistive technology
...restComponentProps<'span'>-Native attributes

ChatSource.Title

PropTypeDefaultDescription
childrenReactNoderesolved titleTitle text
renderDOMRenderFunction<'span', undefined>-Replaces the rendered <span>
...restComponentProps<'span'>-Native attributes

ChatSource.Preview

PropTypeDefaultDescription
placementPlacement'bottom start'Card placement relative to the pill
offsetnumber8Distance from the pill
aria-labelstringresolved titleName of the card's dialog
childrenReactNodefavicon, domain, title, descriptionCustom card content
...restPopoverProps-React Aria Popover props, except isOpen, defaultOpen, onOpenChange and triggerRef

ChatSources

PropTypeDefaultDescription
defaultExpandedbooleanfalseOpen on first render
isExpandedboolean-Controlled expanded state
onExpandedChange(isExpanded: boolean) => void-Called when the state changes
isDisabledbooleanfalseDisables the trigger
...restComponentProps<typeof Disclosure>-Every other core Disclosure prop

ChatSources.Trigger

PropTypeDefaultDescription
level1 | 2 | 3 | 4 | 5 | 63Level of the heading that holds the trigger
childrenReactNode | ((values: ButtonRenderProps) => ReactNode)-Label
...restComponentProps<typeof Disclosure.Trigger>-Every other core Disclosure trigger prop

ChatSources.Content

PropTypeDefaultDescription
childrenReactNode-Panel body; nodes only
...restComponentProps<typeof Disclosure.Content>-Every other core panel prop

ChatSources.List

PropTypeDefaultDescription
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div>
...restComponentProps<'div'>-Native attributes

On this page