Suggestions
Offer starting prompts and follow-up questions as chips or cards.
Installation & usage
npm i @youj/reactFor an app already set up with npx @youj/cli init, which installs the peers (@youj/core, @youj/motion, motion and Base UI) and wires the provider. New app? Start at Installation.
Use suggestions for ways into a new conversation, or follow-ups under an answer. Picking one hands its prompt to onSelect, typically to fill the Prompt Input and focus it, so people can edit it before sending. For a whole first-run screen with a greeting, use the Chat Empty State, which includes them.
import { ChatSuggestions } from '@youj/react'
<ChatSuggestions
suggestions={[{ label: 'Show the diff' }, { label: 'Is a rollback safe?', prompt: 'Is rolling back to dpl_7c1e0b2 safe?' }]}
onSelect={(prompt) => {
setDraft(prompt)
composer.current?.focus()
}}
/>Each suggestion has a label, and a prompt when what goes in the composer should differ from what the chip says. delay waits that many stagger steps before the first one arrives, to follow something else in.
Description
Four follow-up chips, where picking one fills the composer and focuses it.
Four starter prompts as cards, each with an icon and a description.
layout="cards" sets them in a two-column grid, with an icon and a line of description under each label. Chips wrap in a centered row and show only the label and icon.
Code
suggestions-demo.tsx, the Demo story. The component itself comes from the package.
Reference
Propssuggestions, onSelect, layout… (9)
Props
| Prop | Type | |
|---|---|---|
suggestionsRequired | ChatSuggestion[] | – |
onSelectRequired | (prompt: string, suggestion: ChatSuggestion) => void | – |
layout | 'chips' | 'cards''chips' wrap in a row; 'cards' form a two-column grid with descriptions. default 'chips' | 'chips' |
label | stringNames the group. default "Suggested prompts" | "Suggested prompts" |
delay | numberWait this many stagger steps before the first one arrives. default 0 | 0 |
Other props pass through: extends ComponentProps<'div'>. | ||
ChatSuggestion
Each entry in suggestions:
| Prop | Type | |
|---|---|---|
labelRequired | stringWhat the chip says. | – |
prompt | stringWhat it puts in the composer. Default: the label. | – |
description | stringA second line, shown in the cards layout. | – |
icon | ReactNodeSits before the label. | – |
MotionEach suggestion, step · reduced motion
Motion
| Moment | Tokens | ||
|---|---|---|---|
Each suggestionrises a few px and fades in (Stagger rise) | duration.slowease.enter340ms · cubic-bezier(0.16, 1, 0.3, 1) | 340mscubic-bezier(0.16, 1, 0.3, 1) | |
| Stepbetween one suggestion and the next | stagger.base40ms step | 40ms step |
Reduced motion
All of them appear at once, in place.
They arrive once, when they mount, and then hold still.
Reduced motion
Every suggestion is in place from the first frame, with no rise or fade.
Accessibilityfocus
Accessibility
- The suggestions are a
groupnamed bylabel(default "Suggested prompts"), and each one is a real button. - Picking one doesn't send it. Move focus to the composer in
onSelect, as the examples do, so the next keystroke edits the prompt.