{
  "name": "spoiler",
  "type": "registry:ui",
  "framework": "react",
  "title": "Spoiler",
  "description": "Inline text hidden behind a solid block until the reader clicks to reveal it.",
  "files": [
    {
      "path": "ui/spoiler.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface SpoilerProps extends React.HTMLAttributes<HTMLSpanElement> {\n  /** Controlled revealed state. */\n  revealed?: boolean\n  /** Initial revealed state when uncontrolled. */\n  defaultRevealed?: boolean\n  /** Called with the next revealed state when toggled. */\n  onRevealedChange?: (revealed: boolean) => void\n  /**\n   * Accessible name while hidden, read in place of the content it hides.\n   * Defaults to `\"Spoiler, click to reveal\"`; pass a translated string.\n   */\n  label?: string\n}\n\nconst Spoiler = React.forwardRef<HTMLSpanElement, SpoilerProps>(\n  (\n    {\n      className,\n      revealed: revealedProp,\n      defaultRevealed = false,\n      onRevealedChange,\n      label = \"Spoiler, click to reveal\",\n      onClick,\n      onKeyDown,\n      children,\n      ...props\n    },\n    ref\n  ) => {\n    const [uncontrolled, setUncontrolled] = React.useState(defaultRevealed)\n    const isControlled = revealedProp !== undefined\n    const revealed = isControlled ? revealedProp : uncontrolled\n\n    const toggle = () => {\n      const next = !revealed\n      if (!isControlled) setUncontrolled(next)\n      onRevealedChange?.(next)\n    }\n\n    const handleClick = (event: React.MouseEvent<HTMLSpanElement>) => {\n      onClick?.(event)\n      if (event.defaultPrevented) return\n      toggle()\n    }\n\n    const handleKeyDown = (event: React.KeyboardEvent<HTMLSpanElement>) => {\n      onKeyDown?.(event)\n      if (event.defaultPrevented || revealed) return\n      if (event.key === \"Enter\" || event.key === \" \") {\n        event.preventDefault()\n        toggle()\n      }\n    }\n\n    return (\n      <span\n        ref={ref}\n        role={revealed ? undefined : \"button\"}\n        tabIndex={revealed ? undefined : 0}\n        aria-label={revealed ? undefined : label}\n        aria-expanded={revealed}\n        data-state={revealed ? \"revealed\" : \"hidden\"}\n        className={cn(\n          \"rounded-[var(--newt-radius-sm)] px-1 transition-[background-color] duration-fast ease-newt\",\n          revealed\n            ? \"cursor-text select-text bg-newt-bg-active text-newt-text-primary\"\n            : \"cursor-pointer select-none bg-newt-spoiler hover:bg-newt-spoiler-hover\",\n          className\n        )}\n        onClick={handleClick}\n        onKeyDown={handleKeyDown}\n        {...props}\n      >\n        {/* Hidden, the content is invisible and inert rather than painted in\n         * the background colour: a link, an image or a child with its own\n         * colour would otherwise show through, and a link could still be\n         * clicked or tabbed to. Both keep its box, so the chip keeps the size\n         * of what it hides. */}\n        <span inert={!revealed} className={revealed ? undefined : \"invisible\"}>\n          {children}\n        </span>\n      </span>\n    )\n  }\n)\nSpoiler.displayName = \"Spoiler\"\n\nexport { Spoiler }\n",
      "type": "registry:ui"
    }
  ]
}