Citation chips and grouped source lists for AI responses.
Citation chips and grouped source lists for AI responses.
import { ChatSource, ChatSources } from 'heroui-native-pro' ;
< ChatSource href = "..." title = "..." description = "..." >
< ChatSource.Trigger >
< ChatSource.Icon />
< ChatSource.Title />
</ ChatSource.Trigger >
< ChatSource.Preview />
</ ChatSource >
< ChatSources >
< ChatSources.Trigger >...</ ChatSources.Trigger >
< ChatSources.Content >
< ChatSources.List >
< ChatSource ... />
</ ChatSources.List >
</ ChatSources.Content >
</ ChatSources >
ChatSource : Root row. Owns the source data and how URLs open. Without children it renders the chip and, when enabled, the preview.
ChatSource.Trigger : The citation chip. URL chips open the source on press and the preview on long press. Screen readers open the preview through the longpress accessibility action. Document chips are static unless they receive onPress or onLongPress.
ChatSource.Icon : Favicon, or the first letter of the label when there is no favicon or it fails to load.
ChatSource.DocumentIcon : Document glyph used by document chips.
ChatSource.Title : Single-line, truncated chip label. Defaults to title, then the URL domain.
ChatSource.Preview : Card opened by a long press, built on heroui-native Popover. Shows the favicon, domain, title, and description. Pressing anywhere on the card opens the source.
ChatSources : Disclosure grouping several sources. Owns the expanded state.
ChatSources.Trigger : Pressable muted label followed by a chevron that rotates as the content expands.
ChatSources.Content : Collapsible panel with a top border.
ChatSources.List : Row of chips, wrapping or horizontally scrolling with heroui-native ScrollShadow edge fades. With maxVisible, it shows that many chips and a "+N more" / "Show less" chip. It also works on its own, without the disclosure.
Pass the source data to ChatSource. URL chips open href when pressed. When the source has a title or a description, a long press opens a preview card above the chip.
< ChatSource
href = "https://heroui.com"
title = "HeroUI Pro"
description = "Presentation-only AI chat compounds for React Native."
faviconUrl = "https://heroui.com/favicon.png"
/>
Without an href (or with sourceType="document"), the chip shows a document glyph. It is static unless the trigger receives onPress.
< ChatSource sourceType = "document" title = "Q3-launch-brief.pdf" />
< ChatSource sourceType = "document" title = "Q3-launch-brief.pdf" >
< ChatSource.Trigger onPress ={openAttachment} />
</ ChatSource >
URLs open with React Native Linking.openURL by default. Pass onOpenUrl to route them to an in-app browser instead.
import * as WebBrowser from 'expo-web-browser' ;
< ChatSource
href = "https://heroui.com"
title = "HeroUI"
onOpenUrl ={(href) => WebBrowser. openBrowserAsync (href)}
/>;
ChatSources collapses several chips behind a trigger. The content is collapsed by default.
< ChatSources >
< ChatSources.Trigger >3 sources</ ChatSources.Trigger >
< ChatSources.Content >
< ChatSources.List >
< ChatSource href = "https://heroui.com" title = "HeroUI" />
< ChatSource href = "https://tailwind-variants.org" title = "Tailwind Variants" />
< ChatSource sourceType = "document" title = "design-system-audit.pdf" />
</ ChatSources.List >
</ ChatSources.Content >
</ ChatSources >
Set orientation="horizontal" on ChatSources.List to keep long source lists on a single scrolling row. Its edges fade with heroui-native ScrollShadow. scrollShadowProps tunes its size (default 24), color (match the surface behind the list), and visibility.
< ChatSources.List orientation = "horizontal" >
{sources. map ((source) => (
< ChatSource key ={source.href} href ={source.href} title ={source.title} />
))}
</ ChatSources.List >
Set maxVisible on ChatSources.List to show that many sources, followed by a "+N more" chip that reveals the rest and turns into "Show less". Sources wrapped in fragments count one by one. Control it with showAll / onShowAllChange, or start expanded with defaultShowAll. Localize the chip with renderToggle.
< ChatSources.List
maxVisible ={ 3 }
renderToggle ={({ hiddenCount, showAll }) =>
showAll ? 'Show less' : `+ ${ hiddenCount } more`
}
>
{sources. map ((source) => (
< ChatSource key ={source.href} href ={source.href} title ={source.title} />
))}
</ ChatSources.List >
String children of ChatSources.Trigger get the trigger typography. Other nodes, such as stacked favicons, render as-is in the same row. Consecutive strings and numbers ({sources.length} sources) share a single Text.
import { cn } from 'heroui-native' ;
< ChatSources.Trigger >
< View className = "flex-row" >
{sources. map ((source, index) => (
< Image
key ={source.href}
source ={{ uri: source.faviconUrl }}
className ={ cn (
'size-5 rounded-full border border-border bg-background' ,
index > 0 && '-ms-1.5'
)}
/>
))}
</ View >
Sources
</ ChatSources.Trigger >
Style the preview through classNames. The title and description show two lines. A line-clamp-* class on their slot overrides it, since uniwind resolves it to the Text numberOfLines.
< ChatSource href = "..." title = "..." description = "..." >
< ChatSource.Trigger />
< ChatSource.Preview
classNames ={{ title: 'text-base' , description: 'line-clamp-4 text-xs' }}
/>
</ ChatSource >
Compose the chip and the preview from the parts. Set enablePreview to show a custom preview for a source without a title or description. extractSourceDomain returns the hostname of a URL without www..
import { ChatSource, extractSourceDomain } from 'heroui-native-pro' ;
< ChatSource enablePreview href = "https://react.dev" >
< ChatSource.Trigger >
< ChatSource.Icon faviconUrl ={faviconUrl} />
< ChatSource.Title >React docs</ ChatSource.Title >
</ ChatSource.Trigger >
< ChatSource.Preview >
< View className = "gap-2 p-3" >
< View className = "flex-row items-center gap-2" >
< ChatSource.Icon faviconUrl ={faviconUrl} />
< Text className = "text-sm font-medium text-foreground" >
{ extractSourceDomain ( 'https://react.dev' )}
</ Text >
</ View >
< Text className = "text-sm text-muted" >Official React documentation.</ Text >
</ View >
</ ChatSource.Preview >
</ ChatSource >;
ChatSources animates its height with a layout transition. Give views laid out after it the same transition, ChatSourcesLayoutTransition, so they move in sync with the panel. Inside ChatConversation.Content this is not needed: the panel changes height in one commit and fades in.
import Animated from 'react-native-reanimated' ;
import { ChatSourcesLayoutTransition } from 'heroui-native-pro' ;
< ChatSources >...</ ChatSources >
< Animated.View layout ={ChatSourcesLayoutTransition}>...</ Animated.View >
import { ChatMessage, ChatSource, ChatSources } from 'heroui-native-pro' ;
import { View } from 'react-native' ;
const getFaviconUrl = (href: string ) =>
`https://www.google.com/s2/favicons?domain_url= ${ encodeURIComponent (href) } &sz=64` ;
const SOURCES = [
{ href: 'https://heroui.com' , title: 'HeroUI' },
{
href: 'https://tailwind-variants.org' ,
title: 'Tailwind Variants' ,
description: 'Tailwind Variants powers slot-based styling in Pro components.' ,
},
];
export default function ChatSourceExample () {
return (
< View className = "flex-1 justify-center px-5" >
< ChatMessage.Assistant >
< ChatMessage.Avatar alt = "Assistant" fallback = "AI" />
< ChatMessage.Body >
< ChatMessage.Content >
Answer synthesized from multiple sources.
</ ChatMessage.Content >
< ChatSources >
< ChatSources.Trigger >{SOURCES.length + 1 } sources</ ChatSources.Trigger >
< ChatSources.Content >
< ChatSources.List >
{SOURCES. map ((source) => (
< ChatSource
key ={source.href}
href ={source.href}
title ={source.title}
description ={source.description}
faviconUrl ={ getFaviconUrl (source.href)}
/>
))}
< ChatSource sourceType = "document" title = "design-system-audit.pdf" />
</ ChatSources.List >
</ ChatSources.Content >
</ ChatSources >
</ ChatMessage.Body >
</ ChatMessage.Assistant >
</ View >
);
}
prop type default description childrenReactNode- Custom parts. Defaults to the chip and, when enabled, the preview hrefstring- URL of the source. Its domain is the label when there is no title titlestring- Chip label and preview heading descriptionstring- Summary shown in the preview faviconUrlstring- Favicon shown in the chip and the preview sourceType'url' | 'document''url' with href, else 'document'Kind of source enablePreviewbooleantrue for URL sources with a title or descriptionWhether a long press opens the preview. Always false for documents classNamestring- Additional CSS classes for the root row onOpenUrl(href: string) => voidLinking.openURLOpens the URL when the chip or the preview is pressed animationChatSourceRootAnimation- 'disable-all' disables the chip press feedback and the preview animations...ViewPropsViewProps- All React Native View props are supported
prop type default description childrenReactNode- Custom chip content. Text renders in a ChatSource.Title. Defaults to the favicon (or document glyph) and the title classNamestring- Additional CSS classes for the chip classNamesElementSlots<TriggerSlots>- Additional CSS classes for the slots styleStyleProp<ViewStyle>- Inline style of the chip stylesChatSourceTriggerStyles- Inline styles for the slots accessibilityLabelstringtitle, then the domainAccessible name of the chip onPress(event: GestureResponderEvent) => void- Called when the chip is pressed, before the URL opens onLongPress(event: GestureResponderEvent) => void- Called when the chip is long-pressed, before the preview opens animationChatSourceTriggerAnimation- Press feedback configuration ...PressableFeedbackPropsPressableFeedbackProps- heroui-native PressableFeedback props, except asChild and isAnimatedStyleActive
prop type description anchorstringPopover anchor wrapping the chip. Renders only with the preview enabled containerstringThe chip
prop type description anchorViewStyleStyles for the popover anchor containerViewStyleStyles for the chip
Animation configuration for the chip press feedback. Can be:
false or "disabled": Disable the press scale and the highlight
"disable-all": Disable all animations of the chip
true or undefined: Use default animations
object: Custom animation configuration
prop type default description state'disabled' | 'disable-all' | boolean- Disable animations while customizing properties scalePressableFeedbackScaleAnimation- Press scale of the chip. false keeps only the highlight highlightPressableFeedbackHighlightAnimation- Highlight overlay that fades in while pressed
prop type default description childrenReactNode- Custom icon, rendered inside the 16px image slot faviconUrlstring- Favicon URL. Overrides the root faviconUrl classNamestring- Additional CSS classes for the image, custom icon wrapper, or fallback classNamesElementSlots<IconSlots>- Additional CSS classes for the slots stylesChatSourceIconStyles- Inline styles for the slots
prop type description imagestringFavicon Image, or the wrapper of a custom icon fallbackstringCircle shown without a favicon fallbackTextstringInitial inside the fallback circle
prop type description imageImageStyleStyles for the favicon Image. Not applied to a custom icon fallbackViewStyleStyles for the fallback circle fallbackTextTextStyleStyles for the initial
prop type default description classNamestring- Additional CSS classes for the glyph wrapper iconPropsChatSourceDocumentIconIconProps- Props of the default glyph ...ViewPropsViewProps- All React Native View props are supported
prop type default description sizenumber16Size of the glyph, in pixels colorstringtheme muted Color of the glyph
prop type default description childrenReactNode- Label. Defaults to the root title, then the domain classNamestring- Additional CSS classes for the label ...TextPropsTextProps- All React Native Text props are supported
Renders only for URL sources with the preview enabled.
prop type default description childrenReactNode- Custom card content. Pressing anywhere on the card still opens the source titleReactNode- Preview heading. Overrides the root title descriptionReactNode- Preview summary. Overrides the root description widthnumber | 'trigger' | 'content-fit' | 'full'288Width of the card placement'top' | 'bottom' | 'left' | 'right''top'Placement of the card relative to the chip offsetnumber8Distance from the chip, in pixels classNamestring- Additional CSS classes for the card classNamesElementSlots<PreviewSlots>- Additional CSS classes for the slots stylesChatSourcePreviewStyles- Inline styles for the slots ...PopoverContentPropsPopoverContentProps- heroui-native Popover.Content props for the popover presentation
domain, title, and description apply to the default content only. A line-clamp-* class on title or description sets their line count (default 2).
prop type description contentstringThe Popover.Content card bodystringPressable filling the card, carries the padding headerstringFavicon and domain row domainstringSource domain titlestringPage title descriptionstringPage summary
prop type description bodyViewStyleStyles for the pressable body headerViewStyleStyles for the header row domainTextStyleStyles for the domain text titleTextStyleStyles for the title text descriptionTextStyleStyles for the description text
prop type default description childrenReactNode- Trigger and content isExpandedboolean- Controlled expanded state defaultExpandedbooleanfalseExpanded state on mount, for uncontrolled usage isDisabledbooleanfalseDisables the trigger. The content keeps its current state stateKeystring- Keeps the expanded state across row remounts in ChatConversation.Content classNamestring- Additional CSS classes for the root column onExpandedChange(isExpanded: boolean) => void- Called when the expanded state changes animationChatSourcesRootAnimation- Animation configuration ...ViewPropsViewProps- All React Native View props are supported
Animation configuration for the ChatSources root. Can be:
false or "disabled": Disable only the layout transition
"disable-all": Disable all animations including the chevron, the panel fade, and every chip
true or undefined: Use default animations
object: Custom animation configuration
prop type default description state'disabled' | 'disable-all' | boolean- Disable animations while customizing properties layout.valueLayoutTransitionLinearTransition.springify().damping(140).stiffness(1600).mass(4)Layout transition of the root and the panel. Exported as ChatSourcesLayoutTransition
prop type default description childrenReactNode- Label. Strings and numbers are wrapped in a Text; other nodes render as-is classNamestring- Additional CSS classes for the container classNamesElementSlots<SourcesTriggerSlots>- Additional CSS classes for the slots styleViewStyle- Inline style of the container stylesChatSourcesTriggerStyles- Inline styles for the slots iconPropsChatSourcesTriggerIconProps- Props of the default chevron onPress(event: GestureResponderEvent) => void- Called when the trigger is pressed, before the content toggles animationChatSourcesTriggerAnimation- Chevron rotation configuration isAnimatedStyleActivebooleantrueWhen false, the animated rotation is not applied to the indicator slot ...PressablePropsPressableProps- All React Native Pressable props except children and style
prop type description containerstringThe Pressable row labelstringRow wrapping the children textstringText wrapping each string or number runindicatorstringView hosting the chevron
prop type description labelViewStyleStyles for the label row textTextStyleStyles for each label Text indicatorViewStyleStyles for the chevron view
prop type default description sizenumber14Size of the chevron, in pixels colorstringtheme muted Color of the chevron
Animation configuration for the chevron. Can be:
false or "disabled": The chevron snaps between its two rotations
true or undefined: Use default animations
object: Custom animation configuration
prop type default description state'disabled' | boolean- Disable animations while customizing properties rotation.value[number, number][0, -180]Rotation values [collapsed, expanded], in degrees rotation.springConfigWithSpringConfig{ damping: 140, stiffness: 1000, mass: 4 }Spring configuration of the rotation
prop type default description childrenReactNode- Expanded content, usually ChatSources.List classNamestring- Additional CSS classes for the container classNamesElementSlots<SourcesContentSlots>- Additional CSS classes for the slots stylesPartial<Record<SourcesContentSlots, ViewStyle>>- Inline styles for the slots animationChatSourcesContentAnimation- Panel fade configuration ...ViewPropsViewProps- All React Native View props are supported
prop type description containerstringAlways-mounted clipping wrapper whose height animates bodystringBordered panel, mounted only while expanded
prop type description containerViewStyleStyles for the clipping wrapper bodyViewStyleStyles for the panel
Animation configuration for the panel. Can be:
false or "disabled": The panel appears and disappears instantly
true or undefined: Use default animations
object: Custom animation configuration
prop type default description state'disabled' | boolean- Disable animations while customizing properties entering.valueEntryOrExitLayoutTypeFadeIn.duration(150).easing(Easing.bezier(0, 0, 0.2, 1))Entering animation of the panel exiting.valueEntryOrExitLayoutTypeFadeOut.duration(150).easing(Easing.in(Easing.ease))Exiting animation of the panel
prop type default description childrenReactNode- ChatSource elements. Fragments are flattened before countingorientation'wrap' | 'horizontal''wrap'Wrapping rows, or a single horizontally scrolling strip maxVisiblenumber- Shows this many sources, then a "+N more" chip that reveals the rest. Rounded down showAllboolean- Whether every source is shown (controlled) defaultShowAllbooleanfalseWhether every source is shown on mount (uncontrolled) stateKeystring- Keeps the show-all state across row remounts in ChatConversation.Content classNamestring- Additional CSS classes for the container classNamesElementSlots<SourcesListSlots>- Additional CSS classes for the slots stylesChatSourcesListStyles- Inline styles for the slots scrollShadowPropsOmit<ScrollShadowProps, 'children' | 'LinearGradientComponent'>- Props of the horizontal ScrollShadow. size defaults to 24 renderToggle(state: ChatSourcesListToggleState) => ReactNode- Label of the more / less chip. A string is also its accessible name onShowAllChange(showAll: boolean) => void- Called when the more / less chip toggles the list ...ViewPropsViewProps- All React Native View props are supported
scrollShadow, scrollView, and content apply to the horizontal orientation only. To bleed the strip to the screen edges, pair a negative container margin with matching content padding.
prop type description containerstringOuter view scrollShadowstringScrollShadow of the horizontal stripscrollViewstringHorizontal ScrollView contentstringScrollView content rowtogglestringThe "+N more" / "Show less" chip toggleTextstringText of the more / less chip label
prop type description containerViewStyleStyles for the outer view scrollShadowViewStyleStyles for the ScrollShadow scrollViewViewStyleStyles for the ScrollView contentViewStyleStyles for the content row toggleViewStyleStyles for the more / less chip toggleTextTextStyleStyles for the more / less chip label
prop type description hiddenCountnumberSources hidden while collapsed showAllbooleanWhether every source is shown
Returns the source data and actions of the enclosing ChatSource.
property type description sourceType'url' | 'document'Kind of source hrefstring | undefinedURL of the source titlestring | undefinedTitle of the source descriptionstring | undefinedSummary of the source faviconUrlstring | undefinedFavicon URL domainstring | undefinedDomain extracted from href isUrlbooleanWhether the source is a URL with an href enablePreviewbooleanWhether a long press opens the preview previewTriggerRefRefObject<PopoverTriggerRef | null>Anchor the preview is positioned against openUrl() => voidOpens the source URL openPreview() => voidOpens the preview closePreview() => voidCloses the preview
Returns the disclosure state of the enclosing ChatSources.
property type description isExpandedbooleanWhether the content is expanded isDisabledbooleanWhether the trigger is disabled setIsExpanded(isExpanded: boolean) => voidExpands or collapses the content