import * as React from 'react'; import { cn } from '@/lib/utils'; /** * PromptChips — suggested prompts. * * Clicking a chip runs it immediately. A chip is already a complete question, so * making the user press Enter afterwards adds a step that buys nothing. * * Chips always wrap onto as many lines as they need. The earlier horizontal-scroll * variant is gone: a scroller can always leave a chip half-visible at the edge, * and a half-visible button is a bug no amount of fade masking fixes. Wrapping * makes clipping structurally impossible instead of merely unlikely. * * `max` caps how many are offered in a conversation, where vertical space belongs * to the thread rather than to suggestions. * * A chip is shrink-to-fit up to the panel's width, so a long suggestion spends the * whole row before it is allowed to take a second line. When it does take one, the * radius stays at the single-line pill's 14px rather than following the height: * `rounded-full` on a two-line chip resolves to half of 46px, and that corner is * what turns the same component into something that reads as a card. * * Arrow keys move between chips, so the whole set is one tab stop. */ /** @param {any} props */ export function PromptChips({ prompts = [], onSelect, max = 0, align = 'center', className = '' }) { const chipRefs = React.useRef([]); const visible = max ? prompts.slice(0, max) : prompts; const onKeyDown = (event, index) => { const delta = event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0; if (!delta) return; const next = chipRefs.current[index + delta]; if (!next) return; event.preventDefault(); next.focus(); }; if (!visible.length) return null; return (
{visible.map((prompt, i) => ( ))}
); }