{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "feedback-dialog",
  "title": "Feedback Dialog",
  "description": "Response feedback with copy, thumbs up and thumbs down actions that expands into a reason picker and an optional note.",
  "dependencies": [
    "@solar-icons/react@^2.2.0",
    "cn@^0.3.0",
    "motion@^13.4.0"
  ],
  "registryDependencies": [
    "button",
    "https://pastaui.com/r/pastaui-styles.json",
    "textarea"
  ],
  "files": [
    {
      "path": "src/components/ai/feedback-dialog.tsx",
      "content": "import { ChatSquareIcon as MessageSquareIcon } from '@solar-icons/react/linear/chat-square'\nimport { CheckCircleIcon as CheckIcon } from '@solar-icons/react/linear/check-circle'\nimport { CopyIcon } from '@solar-icons/react/linear/copy'\nimport { DislikeIcon } from '@solar-icons/react/linear/dislike'\nimport { LikeIcon } from '@solar-icons/react/linear/like'\nimport { AnimatePresence, MotionConfig, motion } from 'motion/react'\nimport * as React from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Textarea } from '@/components/ui/textarea'\nimport { cn } from 'cn'\n\ninterface FeedbackFormProps extends Omit<React.ComponentProps<'form'>, 'onSubmit'> {\n  comment?: string\n  onCancel?: () => void\n  onCommentChange?: (comment: string) => void\n  onReasonChange?: (reason: string) => void\n  onSubmit?: () => void\n  reason?: string\n  reasons: string[]\n  title?: string\n}\n\nfunction FeedbackForm({\n  className,\n  comment = '',\n  onCancel,\n  onCommentChange,\n  onReasonChange,\n  onSubmit,\n  reason,\n  reasons,\n  title = 'What could be better?',\n  ...props\n}: FeedbackFormProps) {\n  const commentId = React.useId()\n  const [error, setError] = React.useState('')\n  const [sent, setSent] = React.useState(false)\n\n  if (sent) {\n    return (\n      <output\n        data-slot=\"feedback-dialog\"\n        className={cn(\n          'flex items-center gap-3 rounded-[16px] bg-card p-5 font-sans text-sm font-[450] tracking-[-0.05px] text-muted-foreground shadow-card transition-opacity duration-200 ease-[cubic-bezier(0.23,1,0.32,1)] starting:opacity-0',\n          className,\n        )}\n      >\n        <span className=\"flex size-9 shrink-0 items-center justify-center rounded-[10px] bg-foreground/6\">\n          <svg\n            aria-hidden=\"true\"\n            className=\"size-4 text-emerald-600 dark:text-emerald-500\"\n            fill=\"none\"\n            stroke=\"currentColor\"\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            strokeWidth=\"1.75\"\n            viewBox=\"0 0 16 16\"\n          >\n            <path d=\"m3.5 8.5 3 3 6-7\" />\n          </svg>\n        </span>\n        <span className=\"text-[15px] leading-6 text-foreground\">\n          Thanks, your feedback was sent.\n        </span>\n      </output>\n    )\n  }\n\n  return (\n    <form\n      data-slot=\"feedback-dialog\"\n      className={cn(\n        'rounded-[16px] bg-card p-5 font-sans text-sm font-[450] tracking-[-0.05px] text-muted-foreground shadow-card transition-[opacity,translate] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)] starting:translate-y-1 starting:opacity-0 motion-reduce:starting:translate-y-0',\n        className,\n      )}\n      onSubmit={(event) => {\n        event.preventDefault()\n        if (!reason && !comment.trim()) {\n          setError('Pick a reason or add a note.')\n          return\n        }\n        setError('')\n        onSubmit?.()\n        setSent(true)\n      }}\n      {...props}\n    >\n      <header className=\"flex items-start gap-3\">\n        <span className=\"flex size-9 shrink-0 items-center justify-center rounded-[10px] bg-foreground/6 text-muted-foreground\">\n          <MessageSquareIcon className=\"size-4\" />\n        </span>\n        <div>\n          <h3 className=\"text-[15px] leading-6 font-medium text-foreground\">{title}</h3>\n          <p className=\"mt-0.5 text-[13px] leading-5 text-muted-foreground\">\n            Your feedback helps improve the next response.\n          </p>\n        </div>\n      </header>\n\n      <fieldset className=\"mt-5\">\n        <legend className=\"sr-only\">Feedback reason</legend>\n        <div className=\"flex flex-wrap gap-1.5\">\n          {reasons.map((item) => {\n            const selected = reason === item\n\n            return (\n              <button\n                aria-pressed={selected}\n                className={cn(\n                  'inline-flex h-7 items-center gap-1.5 rounded-full px-3 text-[13px] leading-4 font-[450] transition-[background-color,color,scale] duration-150 ease-out outline-none focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.97] motion-reduce:active:scale-100',\n                  selected\n                    ? 'bg-primary text-primary-foreground'\n                    : 'bg-foreground/6 text-foreground/80 hover:bg-foreground/10',\n                )}\n                key={item}\n                onClick={() => {\n                  setError('')\n                  onReasonChange?.(item)\n                }}\n                type=\"button\"\n              >\n                {selected && (\n                  <svg\n                    aria-hidden=\"true\"\n                    className=\"-ml-0.5 size-3.5\"\n                    fill=\"none\"\n                    stroke=\"currentColor\"\n                    strokeLinecap=\"round\"\n                    strokeLinejoin=\"round\"\n                    strokeWidth=\"2\"\n                    viewBox=\"0 0 16 16\"\n                  >\n                    <path d=\"m3.5 8.5 3 3 6-7\" />\n                  </svg>\n                )}\n                {item}\n              </button>\n            )\n          })}\n        </div>\n      </fieldset>\n\n      <label\n        className=\"mt-5 block text-sm leading-5 font-medium text-foreground/85\"\n        htmlFor={commentId}\n      >\n        Add a note <span className=\"font-[450] text-muted-foreground/70\">· Optional</span>\n      </label>\n      <Textarea\n        className=\"mt-2 min-h-20 resize-none rounded-[12px] border-0 bg-foreground/4 px-3 py-2.5 text-sm font-[450] tracking-[-0.05px] text-foreground shadow-none placeholder:text-muted-foreground/60 focus-visible:ring-2 focus-visible:ring-ring/40 md:text-sm dark:bg-foreground/4\"\n        id={commentId}\n        onChange={(event) => {\n          setError('')\n          onCommentChange?.(event.target.value)\n        }}\n        placeholder=\"What should be different?\"\n        value={comment}\n      />\n\n      <div className=\"mt-4 flex items-center justify-end gap-2\">\n        <p aria-live=\"polite\" className=\"mr-auto text-[13px] leading-5 text-destructive\">\n          {error}\n        </p>\n        {onCancel && (\n          <Button\n            className=\"h-7 rounded-full px-3 text-sm font-[450] tracking-[-0.05px] text-muted-foreground hover:bg-foreground/8 hover:text-foreground\"\n            onClick={onCancel}\n            size=\"sm\"\n            type=\"button\"\n            variant=\"ghost\"\n          >\n            Cancel\n          </Button>\n        )}\n        <Button\n          className=\"h-7 rounded-full border-0 bg-primary bg-linear-to-b from-[color-mix(in_oklch,var(--primary),var(--primary-foreground)_30%)] to-primary px-3 text-sm font-[450] tracking-[-0.05px] text-primary-foreground shadow-[inset_0_1px_0_rgba(255,255,255,0.14),0_1px_2px_rgba(0,0,0,0.18)] shadow-none hover:brightness-110 dark:bg-none\"\n          size=\"sm\"\n          type=\"submit\"\n          variant=\"default\"\n        >\n          Send feedback\n        </Button>\n      </div>\n    </form>\n  )\n}\n\ntype FeedbackRating = 'down' | 'up' | null\n\ninterface FeedbackDialogProps extends Omit<FeedbackFormProps, 'onSubmit'> {\n  defaultRating?: FeedbackRating\n  onCopy?: () => void\n  onRatingChange?: (rating: FeedbackRating) => void\n  onSubmit?: (feedback: { comment: string; rating: 'down'; reason?: string }) => void\n  rating?: FeedbackRating\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const\n\nfunction FeedbackDialog({\n  className,\n  comment,\n  defaultRating = null,\n  onCancel,\n  onCommentChange,\n  onCopy,\n  onRatingChange,\n  onReasonChange,\n  onSubmit,\n  rating,\n  reason,\n  ...props\n}: FeedbackDialogProps) {\n  const [internalRating, setInternalRating] = React.useState<FeedbackRating>(defaultRating)\n  const [internalReason, setInternalReason] = React.useState<string>()\n  const [internalComment, setInternalComment] = React.useState('')\n  const [copied, setCopied] = React.useState(false)\n  const current = rating === undefined ? internalRating : rating\n  const currentReason = reason ?? internalReason\n  const currentComment = comment ?? internalComment\n\n  React.useEffect(() => {\n    if (!copied) return\n    const timer = setTimeout(() => setCopied(false), 1400)\n    return () => clearTimeout(timer)\n  }, [copied])\n\n  function rate(next: FeedbackRating) {\n    const value = current === next ? null : next\n    if (rating === undefined) setInternalRating(value)\n    onRatingChange?.(value)\n  }\n\n  const actionClass =\n    'text-muted-foreground hover:text-muted-foreground aria-pressed:bg-muted aria-pressed:text-foreground'\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div\n        data-slot=\"feedback-dialog\"\n        className={cn('w-full font-sans text-sm tracking-[-0.05px]', className)}\n      >\n        <div\n          aria-label=\"Rate this response\"\n          className=\"flex items-center gap-0.5 text-muted-foreground\"\n          role=\"toolbar\"\n        >\n          <Button\n            aria-label={copied ? 'Copied' : 'Copy response'}\n            className={actionClass}\n            onClick={() => {\n              setCopied(true)\n              onCopy?.()\n            }}\n            size=\"icon-sm\"\n            type=\"button\"\n            variant=\"ghost\"\n          >\n            <span className=\"grid *:col-start-1 *:row-start-1 *:transition-[opacity,scale] *:duration-150 motion-reduce:*:transition-opacity\">\n              <CopyIcon className={cn('size-4', copied && 'scale-75 opacity-0')} />\n              <CheckIcon className={cn('size-4', !copied && 'scale-75 opacity-0')} />\n            </span>\n          </Button>\n          <Button\n            aria-label=\"Good response\"\n            aria-pressed={current === 'up'}\n            className={actionClass}\n            onClick={() => rate('up')}\n            size=\"icon-sm\"\n            type=\"button\"\n            variant=\"ghost\"\n          >\n            <motion.span\n              animate={\n                current === 'up'\n                  ? { scale: [1, 1.25, 1], rotate: [0, -12, 0] }\n                  : { scale: 1, rotate: 0 }\n              }\n              className=\"flex\"\n              transition={{ duration: 0.35, ease }}\n            >\n              <LikeIcon className=\"size-4\" />\n            </motion.span>\n          </Button>\n          <Button\n            aria-label=\"Bad response\"\n            aria-pressed={current === 'down'}\n            className={actionClass}\n            onClick={() => rate('down')}\n            size=\"icon-sm\"\n            type=\"button\"\n            variant=\"ghost\"\n          >\n            <motion.span\n              animate={\n                current === 'down'\n                  ? { scale: [1, 1.25, 1], rotate: [0, 12, 0] }\n                  : { scale: 1, rotate: 0 }\n              }\n              className=\"flex\"\n              transition={{ duration: 0.35, ease }}\n            >\n              <DislikeIcon className=\"size-4\" />\n            </motion.span>\n          </Button>\n          <AnimatePresence initial={false}>\n            {current === 'up' && (\n              <motion.span\n                animate={{ opacity: 1, x: 0 }}\n                aria-live=\"polite\"\n                className=\"ml-2 text-[13px] leading-5 font-[450]\"\n                exit={{ opacity: 0, x: -4 }}\n                initial={{ opacity: 0, x: -4 }}\n                transition={{ duration: 0.2, ease }}\n              >\n                Thanks for the feedback\n              </motion.span>\n            )}\n          </AnimatePresence>\n        </div>\n        <AnimatePresence initial={false}>\n          {current === 'down' && (\n            <motion.div\n              animate={{ height: 'auto', opacity: 1 }}\n              className=\"overflow-hidden\"\n              exit={{ height: 0, opacity: 0 }}\n              initial={{ height: 0, opacity: 0 }}\n              transition={{ duration: 0.25, ease }}\n            >\n              <div className=\"p-px pt-3\">\n                <FeedbackForm\n                  comment={currentComment}\n                  onCancel={() => {\n                    rate('down')\n                    onCancel?.()\n                  }}\n                  onCommentChange={(value) => {\n                    if (comment === undefined) setInternalComment(value)\n                    onCommentChange?.(value)\n                  }}\n                  onReasonChange={(value) => {\n                    if (reason === undefined) setInternalReason(value)\n                    onReasonChange?.(value)\n                  }}\n                  onSubmit={() =>\n                    onSubmit?.({ comment: currentComment, rating: 'down', reason: currentReason })\n                  }\n                  reason={currentReason}\n                  {...props}\n                />\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </MotionConfig>\n  )\n}\n\nexport { FeedbackDialog }\nexport type { FeedbackDialogProps, FeedbackRating }\n",
      "type": "registry:component",
      "target": "@components/ai/feedback-dialog.tsx"
    }
  ],
  "type": "registry:component"
}