{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "recall-card",
  "type": "registry:ui",
  "title": "Recall Card",
  "description": "A prompt the player answers in their head, then checks: they think of their answer, reveal the real one, and say honestly how they did. No typing and no multiple choice, so it fits anything with an answer longer than a word: a definition, a reply to a…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "games",
    "game"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/games/recall-card.tsx",
      "target": "components/ui/games/recall-card.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/recall-card v1.0.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/recall-card\n// What changed since: https://ds.interlace.tools/c/recall-card#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — RecallCard\n *\n * A prompt the player answers in their head, then checks: they think of\n * their answer, reveal the real one, and say honestly how they did. No\n * typing and no multiple choice, so it fits anything with an answer longer\n * than a word: a definition, a reply to a question, a step in a procedure.\n * It is the round of a flashcard deck or a daily self-check.\n *\n * For a pick from two to four answers, use `GuessReveal`.\n *\n * ## Anatomy\n *\n *   RecallCard                     (div — data-slot=\"recall-card\", data-state=asking|revealed|rated)\n *     ├─ p                         (data-slot=\"recall-card-prompt\", id ← labels the answer region)\n *     ├─ p                         (data-slot=\"recall-card-hint\": \"Think of your answer, then reveal it.\")\n *     ├─ button                    (data-slot=\"recall-card-reveal\", aria-expanded, aria-controls)\n *     ├─ div role=\"region\"         (data-slot=\"recall-card-answer\" — opens on reveal, inert while closed)\n *     ├─ div role=\"group\"          (data-slot=\"recall-card-ratings\", labelled by labels.rate)\n *     │   └─ button × 2–4          (data-slot=\"recall-card-rating\", aria-pressed)\n *     ├─ p aria-live=\"polite\"      (data-slot=\"recall-card-status\": the rating, in words)\n *     └─ details                   (data-slot=\"recall-card-fallback\" — only without JavaScript)\n *\n * ## The flow\n *\n * Reveal opens the answer and moves focus to it, so a screen reader reads\n * it next and a keyboard player tabs straight on to the ratings. The\n * ratings appear only once the answer is open: rating before looking is not\n * a rating. A rating can be changed until the parent moves on; `onRate`\n * fires on every change, `onReveal` once.\n *\n * Both steps are controlled or uncontrolled: `revealed` / `defaultRevealed`\n * and `rating` / `defaultRating`.\n *\n * ## Without JavaScript\n *\n * A `<details>` (shown only under `noscript:`) holds the answer, so it is\n * never locked behind a script.\n *\n * ## Reduced motion\n *\n * The answer opens by growing its row (`grid-template-rows` 0fr to 1fr,\n * 250ms). Under `prefers-reduced-motion` it opens at once.\n *\n * ## MIN_VIEWPORT — 320\n *\n * Ratings stack below 30rem and sit in a row above it.\n *\n * | Rule | Concept                   | Where in this file                                         |\n * | ---- | ------------------------- | ---------------------------------------------------------- |\n * | R4   | Extends native el         | `React.ComponentProps<'div'>`                              |\n * | R6   | data-slot per part        | recall-card / -prompt / -hint / -reveal / -answer / -ratings / -rating / -status / -fallback |\n * | R7   | cn + ...rest              | `cn(…, className)` + `{...props}`                          |\n * | R9   | Controlled + uncontrolled | `revealed` / `defaultRevealed`, `rating` / `defaultRating` |\n * | R14  | Declares min viewport     | `data-min-viewport` + exported const                       |\n * | R19  | Tokens only               | primary, border, card, muted-foreground, ring              |\n * | R26  | A11y                      | aria-expanded reveal; focus to the answer; pressed ratings; live status |\n */\n\nimport { cn } from '@/lib/utils';\n\nexport const MIN_VIEWPORT = 320 as const;\n\ninterface RecallCardRating {\n  /** Stable id, passed back through `onRate`. */\n  id: string;\n  label: React.ReactNode;\n  /** Said in the status line once picked. @default the label, when it is a string */\n  status?: string;\n}\n\ninterface RecallCardLabels {\n  /** @default 'Think of your answer, then reveal it.' */\n  hint?: string;\n  /** @default 'Show the answer' */\n  reveal?: string;\n  /** Names the answer region. @default 'The answer' */\n  answer?: string;\n  /** Names the ratings group. @default 'How did you do?' */\n  rate?: string;\n}\n\ntype RecallCardProps = Omit<React.ComponentProps<'div'>, 'children'> & {\n  /** What the player answers in their head. */\n  prompt: React.ReactNode;\n  /** The answer to check against, with its source. */\n  answer: React.ReactNode;\n  /** Two to four honest choices. @default \"I had it\" and \"Not yet\" */\n  ratings?: readonly RecallCardRating[];\n  /** Controlled: whether the answer is open. */\n  revealed?: boolean;\n  defaultRevealed?: boolean;\n  /** Called once, when the player opens the answer. */\n  onReveal?: () => void;\n  /** Controlled: the id of the picked rating, or null for none yet. */\n  rating?: string | null;\n  defaultRating?: string | null;\n  /** Called on every pick. */\n  onRate?: (id: string) => void;\n  labels?: RecallCardLabels;\n};\n\nconst DEFAULT_RATINGS: readonly RecallCardRating[] = [\n  { id: 'had-it', label: 'I had it', status: 'Marked as one you had.' },\n  { id: 'not-yet', label: 'Not yet', status: 'Marked to come back to.' },\n];\n\nconst CHOICE =\n  'border-border bg-card text-card-foreground focus-visible:outline-ring flex min-h-11 w-full items-center justify-center gap-2 rounded-lg border px-4 py-2.5 text-sm font-medium transition-colors duration-(--duration-fast) ease-enter focus-visible:outline-2 focus-visible:outline-offset-2';\n\nfunction RecallCard({\n  prompt,\n  answer,\n  ratings = DEFAULT_RATINGS,\n  revealed: revealedProp,\n  defaultRevealed = false,\n  onReveal,\n  rating: ratingProp,\n  defaultRating = null,\n  onRate,\n  labels,\n  className,\n  ...props\n}: RecallCardProps) {\n  const [revealedState, setRevealed] = React.useState(defaultRevealed);\n  const [ratingState, setRating] = React.useState<string | null>(defaultRating);\n  const revealed = revealedProp ?? revealedState;\n  const rating = ratingProp === undefined ? ratingState : ratingProp;\n  const promptId = React.useId();\n  const answerId = React.useId();\n  const ratingsId = React.useId();\n  const answerRef = React.useRef<HTMLDivElement>(null);\n  const focusOnOpen = React.useRef(false);\n  const words = {\n    hint: 'Think of your answer, then reveal it.',\n    reveal: 'Show the answer',\n    answer: 'The answer',\n    rate: 'How did you do?',\n    ...labels,\n  };\n  const picked = ratings.find((r) => r.id === rating);\n  const state = picked ? 'rated' : revealed ? 'revealed' : 'asking';\n\n  const reveal = () => {\n    if (revealed) return;\n    focusOnOpen.current = true;\n    if (revealedProp === undefined) setRevealed(true);\n    onReveal?.();\n  };\n\n  // Focus moves to the answer once it is in the tree and no longer inert.\n  React.useEffect(() => {\n    if (revealed && focusOnOpen.current) {\n      focusOnOpen.current = false;\n      answerRef.current?.focus();\n    }\n  }, [revealed]);\n\n  const rate = (id: string) => {\n    if (!revealed || id === rating) return;\n    if (ratingProp === undefined) setRating(id);\n    onRate?.(id);\n  };\n\n  const status = picked\n    ? (picked.status ?? (typeof picked.label === 'string' ? picked.label : ''))\n    : '';\n\n  return (\n    <div\n      data-slot=\"recall-card\"\n      data-min-viewport={String(MIN_VIEWPORT)}\n      data-state={state}\n      className={cn('grid gap-4', className)}\n      {...props}\n    >\n      <p\n        id={promptId}\n        data-slot=\"recall-card-prompt\"\n        className=\"font-heading text-h3 font-semibold text-balance\"\n      >\n        {prompt}\n      </p>\n      {revealed ? null : (\n        <>\n          <p data-slot=\"recall-card-hint\" className=\"text-muted-foreground text-sm noscript:hidden\">\n            {words.hint}\n          </p>\n          <div className=\"noscript:hidden\">\n            <button\n              type=\"button\"\n              data-slot=\"recall-card-reveal\"\n              aria-expanded={false}\n              aria-controls={answerId}\n              onClick={reveal}\n              className={cn(\n                CHOICE,\n                'bg-primary text-primary-foreground border-primary hover:bg-primary/90 w-auto cursor-pointer',\n              )}\n            >\n              {words.reveal}\n            </button>\n          </div>\n        </>\n      )}\n      <div\n        data-slot=\"recall-card-answer\"\n        className={cn(\n          'grid',\n          'motion-safe:transition-[grid-template-rows,opacity] motion-safe:duration-(--duration-medium) motion-safe:ease-enter',\n          revealed ? 'grid-rows-[1fr] opacity-100' : 'grid-rows-[0fr] opacity-0',\n        )}\n        // Closed, its links are out of the tab order and the accessibility tree.\n        inert={revealed ? undefined : true}\n      >\n        <div\n          ref={answerRef}\n          id={answerId}\n          role=\"region\"\n          aria-label={words.answer}\n          tabIndex={-1}\n          className=\"focus-visible:outline-ring -m-1 min-h-0 overflow-hidden rounded-md p-1 focus-visible:outline-2 focus-visible:outline-offset-2\"\n        >\n          {answer}\n        </div>\n      </div>\n      {revealed ? (\n        <div className=\"grid gap-2\">\n          <p id={ratingsId} className=\"text-sm font-semibold\">\n            {words.rate}\n          </p>\n          <div\n            role=\"group\"\n            aria-labelledby={ratingsId}\n            data-slot=\"recall-card-ratings\"\n            className=\"grid grid-cols-[repeat(auto-fit,minmax(min(100%,max(13rem,calc(50%_-_0.25rem))),1fr))] gap-2\"\n          >\n            {ratings.map((r) => {\n              const on = r.id === rating;\n              return (\n                <button\n                  key={r.id}\n                  type=\"button\"\n                  data-slot=\"recall-card-rating\"\n                  aria-pressed={on}\n                  onClick={() => rate(r.id)}\n                  className={cn(\n                    CHOICE,\n                    'hover:bg-muted cursor-pointer',\n                    on && 'border-primary bg-primary/10 text-foreground hover:bg-primary/10',\n                  )}\n                >\n                  {on ? <span aria-hidden>✓</span> : null}\n                  {r.label}\n                </button>\n              );\n            })}\n          </div>\n        </div>\n      ) : null}\n      <p data-slot=\"recall-card-status\" aria-live=\"polite\" className=\"text-muted-foreground text-sm empty:hidden\">\n        {status}\n      </p>\n      <details data-slot=\"recall-card-fallback\" className=\"hidden text-sm noscript:block\">\n        <summary className=\"text-primary cursor-pointer font-semibold\">{words.reveal}</summary>\n        <div className=\"mt-2\">{answer}</div>\n      </details>\n    </div>\n  );\n}\nRecallCard.displayName = 'RecallCard';\n\nexport { RecallCard };\nexport type { RecallCardProps, RecallCardRating, RecallCardLabels };\n"
    }
  ],
  "meta": {
    "tier": "game",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.0.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/recall-card\n\nInstalled to `components/ui/games/recall-card.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/games/recall-card';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/recall-card\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
