{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"prompt-suggestions","type":"registry:ui","title":"PromptSuggestions","description":"Row of prompt pills that cascade in after a reply lands, offering the user a next turn without composing one","author":"fancy-ui <https://fancy-ui.rama.app>","categories":["ai-chat"],"registryDependencies":["https://fancy-ui.rama.app/r/internals-dom.json","https://fancy-ui.rama.app/r/sound.json","https://fancy-ui.rama.app/r/utils.json"],"files":[{"path":"react/src/components/prompt-suggestions/PromptSuggestions.tsx","content":"\"use client\";\n\nimport { forwardRef, useLayoutEffect, useRef, useState, type ReactNode } from \"react\";\nimport { cn } from \"../../utils\";\nimport { useSoundCue } from \"../../sound/use-sound\";\nimport \"./prompt-suggestions.css\";\n\nexport interface PromptSuggestionsProps {\n\t/** Prompt texts offered to the user, in display order */\n\tsuggestions: string[];\n\t/** Called with the chosen prompt and its index when a pill is activated */\n\tonSelect?: (suggestion: string, index: number) => void;\n\t/** Whether the pills are shown; flipping this to true replays the entrance */\n\tvisible?: boolean;\n\t/** Delay between two consecutive pills entering, in milliseconds. Defaults to\n\t * 60ms via a CSS fallback — omit this prop to let an ancestor's\n\t * `--ft-suggestions-stagger` theme the whole subtree instead. */\n\tstaggerMs?: number;\n\t/** Accessible name of the group wrapping the pills */\n\tlabel?: string;\n\t/** Custom pill content, receiving the suggestion and its index */\n\titem?: (suggestion: string, index: number) => ReactNode;\n\t/** Additional CSS classes */\n\tclassName?: string;\n\t/**\n\t * Plays the matching interface cue through the sound controller. Off\n\t * by default; only audible once the user has enabled sound.\n\t */\n\tsound?: boolean;\n}\n\n/** Mirrors the CSS fallback on `--ft-suggestions-delay` below. */\nconst DEFAULT_STAGGER_MS = 60;\n/** Past this the last pill of a long row would still be waiting long after the reply landed. */\nconst MAX_STAGGER_MS = 400;\n\nexport const PromptSuggestions = forwardRef<HTMLDivElement, PromptSuggestionsProps>(\n\tfunction PromptSuggestions(\n\t\t{\n\t\t\tsuggestions,\n\t\t\tonSelect,\n\t\t\tvisible = true,\n\t\t\tstaggerMs,\n\t\t\tlabel = \"Suggestions\",\n\t\t\titem,\n\t\t\tclassName,\n\t\t\tsound = false,\n\t\t},\n\t\tref\n\t) {\n\t\tconst playCue = useSoundCue(sound);\n\t\t// A negative stagger would drop later pills in mid-entrance rather than\n\t\t// delaying them, which reads as a glitch instead of a cascade. `undefined`\n\t\t// is left alone: the inline custom property is only ever written when the\n\t\t// caller actually passed a value, so an ancestor's `--ft-suggestions-stagger`\n\t\t// is free to theme the subtree otherwise.\n\t\tconst stagger = staggerMs === undefined ? undefined : Math.min(Math.max(staggerMs, 0), MAX_STAGGER_MS);\n\n\t\t// Recreating the pills is what restarts their CSS animation, so the keyed\n\t\t// list hangs off a counter that only moves when `visible` flips false →\n\t\t// true. The effect reads `visible` and writes `generation` — never the\n\t\t// other way round; the counter's source and the previous value are plain\n\t\t// refs so nothing it touches can schedule it again.\n\t\tconst [generation, setGeneration] = useState(0);\n\t\tconst generationSource = useRef(0);\n\t\tconst wasVisible = useRef<boolean | null>(null);\n\n\t\t// Runs synchronously before paint, so the re-key and the unhiding land in\n\t\t// the same DOM update: a post-paint bump would show the previous pills\n\t\t// for a frame at full opacity before replacing them with ones animating\n\t\t// up from zero.\n\t\tuseLayoutEffect(() => {\n\t\t\tconst isVisible = visible;\n\t\t\t// The first run only adopts the mounted value — a component that starts\n\t\t\t// out visible has not transitioned, and re-keying it would throw away the\n\t\t\t// pills the browser is already animating.\n\t\t\tif (wasVisible.current !== null && isVisible && !wasVisible.current) {\n\t\t\t\tgenerationSource.current += 1;\n\t\t\t\tsetGeneration(generationSource.current);\n\t\t\t}\n\t\t\twasVisible.current = isVisible;\n\t\t}, [visible]);\n\n\t\tconst rootStyle: React.CSSProperties = {\n\t\t\t...(stagger === undefined ? {} : { \"--ft-suggestions-stagger\": `${stagger}ms` }),\n\t\t\t...(visible ? {} : { display: \"none\" }),\n\t\t} as React.CSSProperties;\n\n\t\t// A pick is an activation, not a change of a selected value — no\n\t\t// changed-only guard.\n\t\tfunction pick(suggestion: string, index: number) {\n\t\t\tplayCue(\"select\");\n\t\t\tonSelect?.(suggestion, index);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName={cn(\"flex flex-wrap items-center gap-2\", className)}\n\t\t\t\tstyle={rootStyle}\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={label}\n\t\t\t>\n\t\t\t\t{suggestions.map((suggestion, i) => (\n\t\t\t\t\t<button\n\t\t\t\t\t\tkey={`${generation}:${i}`}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName=\"ft-suggestion border-border text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:bg-muted focus-visible:text-foreground focus-visible:ring-ring cursor-pointer rounded-full border px-3 py-1.5 text-sm transition-colors focus-visible:ring-1 focus-visible:outline-none\"\n\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\"--ft-suggestions-delay\": `calc(var(--ft-suggestions-stagger, ${DEFAULT_STAGGER_MS}ms) * ${i})`,\n\t\t\t\t\t\t\t} as React.CSSProperties\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonClick={() => pick(suggestion, i)}\n\t\t\t\t\t>\n\t\t\t\t\t\t{item ? item(suggestion, i) : suggestion}\n\t\t\t\t\t</button>\n\t\t\t\t))}\n\t\t\t</div>\n\t\t);\n\t}\n);\n","type":"registry:ui","target":"@ui/fancy/components/prompt-suggestions/PromptSuggestions.tsx"},{"path":"react/src/components/prompt-suggestions/index.ts","content":"\"use client\";\n\nexport { PromptSuggestions } from \"./PromptSuggestions\";\nexport type { PromptSuggestionsProps } from \"./PromptSuggestions\";\n","type":"registry:ui","target":"@ui/fancy/components/prompt-suggestions/index.ts"},{"path":"react/src/components/prompt-suggestions/prompt-suggestions.css","content":"@media (prefers-reduced-motion: no-preference) {\n\t.ft-suggestion {\n\t\t/*\n\t\t * `backwards` holds the pill at the keyframe's starting opacity through\n\t\t * its delay. Without it every pill would paint fully opaque first and\n\t\t * then drop out to fade back in, one at a time.\n\t\t */\n\t\tanimation: ft-suggestions-enter var(--ft-suggestions-duration, 220ms) ease-out backwards;\n\t\tanimation-delay: var(--ft-suggestions-delay, 0ms);\n\t}\n\n\t@keyframes ft-suggestions-enter {\n\t\tfrom {\n\t\t\topacity: 0;\n\t\t\ttransform: translateY(4px);\n\t\t}\n\t\tto {\n\t\t\topacity: 1;\n\t\t\ttransform: none;\n\t\t}\n\t}\n}\n\n/*\n * Reduced motion leaves the pills exactly where they land. The entrance is the\n * only motion in the component, so there is nothing here to override.\n */\n","type":"registry:ui","target":"@ui/fancy/components/prompt-suggestions/prompt-suggestions.css"}],"meta":{"license":"MIT","package":"fancy-ui-react","version":"0.7.0","source":"https://fancy-ui.rama.app/docs/components/prompt-suggestions?framework=react"}}