{
  "schemaVersion": 1,
  "target": "react",
  "name": "suggestion",
  "version": "0.1.0",
  "category": "ai-elements",
  "title": "Suggestion",
  "description": "Short prompt suggestions as hairline pills that send in one click, in a sideways scrolling row with edge fades or a wrapping layout.",
  "tags": [
    "ai",
    "chat",
    "prompt",
    "suggestions",
    "pills",
    "chips"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {},
  "registryDependencies": [],
  "docsPath": "/components/suggestion",
  "props": [
    {
      "name": "Suggestions variant",
      "type": "\"scroll\" | \"wrap\"",
      "default": "\"scroll\"",
      "description": "scroll keeps one line that scrolls sideways and fades the edges with more pills behind them; wrap flows onto more lines."
    },
    {
      "name": "Suggestions aria-label",
      "type": "string",
      "default": "\"Suggestions\"",
      "description": "Names the group."
    },
    {
      "name": "Suggestion suggestion",
      "type": "string",
      "description": "The prompt it sends, and the visible text unless children are passed."
    },
    {
      "name": "Suggestion onSelect",
      "type": "(suggestion) => void",
      "description": "Called with the prompt on press."
    },
    {
      "name": "Suggestion icon",
      "type": "ReactNode",
      "description": "A 16px icon before the text."
    }
  ],
  "accessibility": [
    "Pills are native buttons in a labeled group, reachable with Tab; the scrolling row scrolls focused pills into view.",
    "The scroller keeps padding inside its edges so focus rings are not clipped. The scrollbar is hidden, but touch, trackpad, and keyboard scrolling work.",
    "With reduced motion the press scale and the entry fade are off."
  ],
  "states": [],
  "files": [
    {
      "path": "agent/suggestion.tsx",
      "content": "\"use client\";\n\nimport { type ComponentProps, type CSSProperties, type ReactNode, useEffect, useRef, useState } from \"react\";\n\nfunction cx(...classes: Array<string | false | null | undefined>) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nexport interface SuggestionsProps extends Omit<ComponentProps<\"div\">, \"role\"> {\n  /**\n   * scroll keeps the pills on one line that scrolls sideways, with soft fades on the edges that\n   * have more pills behind them. wrap lets them flow onto as many lines as they need.\n   * @default \"scroll\"\n   */\n  variant?: \"scroll\" | \"wrap\";\n  /** Names the group for screen readers. @default \"Suggestions\" */\n  \"aria-label\"?: string;\n}\n\n/** A row of prompt suggestions. Put `Suggestion` pills inside it. */\nexport function Suggestions({ variant = \"scroll\", \"aria-label\": label = \"Suggestions\", className, style, children, ...props }: SuggestionsProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const [edges, setEdges] = useState({ start: false, end: false });\n\n  useEffect(() => {\n    const node = ref.current;\n    if (!node || variant !== \"scroll\") return;\n    const update = () => {\n      const max = node.scrollWidth - node.clientWidth;\n      // scrollLeft is negative in right-to-left layouts.\n      const left = Math.abs(node.scrollLeft);\n      setEdges({ start: left > 1, end: left < max - 1 });\n    };\n    update();\n    node.addEventListener(\"scroll\", update, { passive: true });\n    const observer = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(update);\n    observer?.observe(node);\n    for (const child of Array.from(node.children)) observer?.observe(child);\n    return () => {\n      node.removeEventListener(\"scroll\", update);\n      observer?.disconnect();\n    };\n  }, [variant, children]);\n\n  const fade = {\n    \"--fade-start\": edges.start ? \"2rem\" : \"0px\",\n    \"--fade-end\": edges.end ? \"2rem\" : \"0px\",\n  } as CSSProperties;\n\n  return (\n    <div\n      ref={ref}\n      role=\"group\"\n      aria-label={label}\n      data-variant={variant}\n      style={variant === \"scroll\" ? { ...fade, ...style } : style}\n      className={cx(\n        \"flex gap-2\",\n        variant === \"scroll\"\n          ? cx(\n              // Padding leaves room for focus rings inside the scroller; the negative margin keeps alignment.\n              \"-m-1 overflow-x-auto overscroll-x-contain p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\",\n              \"[mask-image:linear-gradient(to_right,transparent,black_var(--fade-start),black_calc(100%_-_var(--fade-end)),transparent)]\",\n            )\n          : \"flex-wrap\",\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </div>\n  );\n}\n\nexport interface SuggestionProps extends Omit<ComponentProps<\"button\">, \"onSelect\" | \"value\"> {\n  /** The prompt this pill sends. Also the visible text unless you pass children. */\n  suggestion: string;\n  /** Called with the prompt when the pill is pressed. Send it straight away; one click is the point. */\n  onSelect?: (suggestion: string) => void;\n  /** A 16px icon before the text. */\n  icon?: ReactNode;\n}\n\n/** One prompt suggestion: a hairline pill that sends its prompt in one click. */\nexport function Suggestion({ suggestion, onSelect, icon, className, children, onClick, type = \"button\", ...props }: SuggestionProps) {\n  return (\n    <button\n      type={type}\n      onClick={(event) => {\n        onClick?.(event);\n        if (!event.defaultPrevented) onSelect?.(suggestion);\n      }}\n      className={cx(\n        \"inline-flex h-8 shrink-0 cursor-pointer items-center gap-1.5 rounded-full border px-3.5 text-sm whitespace-nowrap select-none\",\n        \"border-zinc-950/10 bg-white text-zinc-700 shadow-[0_1px_2px_rgb(0_0_0/0.04)]\",\n        \"dark:border-white/10 dark:bg-black dark:text-zinc-300 dark:shadow-none\",\n        \"transition-[background-color,border-color,color,scale,opacity,translate] duration-150 ease-out active:duration-100 motion-safe:active:scale-[0.97] motion-reduce:transition-none\",\n        \"hover:border-zinc-950/20 hover:bg-zinc-950/[0.03] hover:text-zinc-950 dark:hover:border-white/20 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n        \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n        \"disabled:pointer-events-none disabled:opacity-45\",\n        // A new set of suggestions settles in from just below, once.\n        \"starting:translate-y-1 starting:opacity-0\",\n        \"[&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-zinc-400 dark:[&_svg]:text-zinc-500\",\n        icon ? \"pl-3\" : \"\",\n        className,\n      )}\n      {...props}\n    >\n      {icon}\n      {children ?? suggestion}\n    </button>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport { Suggestion, Suggestions } from \"@/components/shaken/agent/suggestion\";\n\nconst prompts = [\n  \"Summarize this pull request\",\n  \"Find flaky tests\",\n  \"Explain the failing build\",\n  \"Draft release notes\",\n  \"Which files changed most this week?\",\n];\n\nexport default function SuggestionExample() {\n  const [sent, setSent] = useState<string | null>(null);\n  return (\n    <div className=\"grid w-full max-w-md gap-3\">\n      <Suggestions>\n        {prompts.map((prompt) => (\n          <Suggestion key={prompt} suggestion={prompt} onSelect={setSent} />\n        ))}\n      </Suggestions>\n      <p aria-live=\"polite\" className=\"text-xs text-zinc-500\">\n        {sent ? `Sent: ${sent}` : \"Pick a suggestion to send it.\"}\n      </p>\n    </div>\n  );\n}\n"
  }
}
