{
  "schemaVersion": 1,
  "target": "react",
  "name": "toggle",
  "version": "0.1.0",
  "category": "forms",
  "title": "Toggle",
  "description": "A button that stays pressed, in ghost and outline styles, with text or a single icon.",
  "tags": [
    "toggle",
    "button",
    "pressed",
    "toolbar",
    "base-ui"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [],
  "docsPath": "/components/toggle",
  "props": [
    {
      "name": "pressed / defaultPressed",
      "type": "boolean",
      "description": "Controlled or initial state."
    },
    {
      "name": "onPressedChange",
      "type": "(pressed: boolean) => void",
      "description": "Called when the toggle is pressed or released."
    },
    {
      "name": "variant",
      "type": "\"ghost\" | \"outline\"",
      "default": "\"ghost\"",
      "description": "Toolbar style, or with an edge for standalone use."
    },
    {
      "name": "size",
      "type": "\"sm\" | \"md\"",
      "default": "\"md\"",
      "description": "32px or 36px tall."
    },
    {
      "name": "iconOnly",
      "type": "boolean",
      "default": "false",
      "description": "A square button for one icon; give it an aria-label."
    }
  ],
  "accessibility": [
    "Renders a native <button> with aria-pressed, so screen readers announce pressed or not pressed.",
    "Enter and Space toggle it; the focus ring shows on keyboard focus only.",
    "The pressed look combines a filled tint with the primary text color.",
    "The 100ms press scale is skipped under reduced motion."
  ],
  "states": [
    "off",
    "on",
    "hover",
    "focus-visible",
    "disabled"
  ],
  "files": [
    {
      "path": "ui/toggle.tsx",
      "content": "\"use client\";\n\nimport { Toggle as BaseToggle } from \"@base-ui/react/toggle\";\n\ntype ClassName<State> = string | ((state: State) => string | undefined) | undefined;\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\n/** Prepends base classes while keeping Base UI's state-function form of className working. */\nfunction withBase<State>(base: string, className: ClassName<State>) {\n  return typeof className === \"function\" ? (state: State) => cx(base, className(state)) : cx(base, className);\n}\n\nconst variants = {\n  ghost: cx(\n    \"text-zinc-600 hover:bg-zinc-950/[0.04] hover:text-zinc-950\",\n    \"dark:text-zinc-400 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n    \"data-[pressed]:bg-zinc-950/[0.07] data-[pressed]:text-zinc-950 dark:data-[pressed]:bg-white/[0.1] dark:data-[pressed]:text-white\",\n  ),\n  outline: cx(\n    \"border border-zinc-950/12 bg-white text-zinc-700 shadow-[0_1px_2px_rgb(0_0_0/0.04)] hover:border-zinc-950/20 hover:bg-zinc-950/[0.03] hover:text-zinc-950\",\n    \"dark:border-white/15 dark:bg-black dark:text-zinc-300 dark:shadow-none dark:hover:border-white/25 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n    \"data-[pressed]:border-zinc-950/25 data-[pressed]:bg-zinc-950/[0.06] data-[pressed]:text-zinc-950 data-[pressed]:shadow-[inset_0_1px_1px_rgb(0_0_0/0.06)]\",\n    \"dark:data-[pressed]:border-white/30 dark:data-[pressed]:bg-white/[0.1] dark:data-[pressed]:text-white\",\n  ),\n} as const;\n\nconst sizes = {\n  sm: { text: \"h-8 px-2.5 text-sm\", icon: \"size-8\" },\n  md: { text: \"h-9 px-3 text-sm\", icon: \"size-9\" },\n} as const;\n\nexport type ToggleVariant = keyof typeof variants;\nexport type ToggleSize = keyof typeof sizes;\n\nexport interface ToggleProps extends BaseToggle.Props {\n  /** `ghost` for toolbars; `outline` for a standalone toggle that needs an edge. */\n  variant?: ToggleVariant;\n  size?: ToggleSize;\n  /** A square button for a single icon. Give it an `aria-label`. */\n  iconOnly?: boolean;\n}\n\n/**\n * A button that stays pressed, such as Bold in an editor or Pin on a message. It sets\n * `aria-pressed`, so screen readers announce the state; the pressed look is a filled tint\n * plus the primary text color. Use `pressed` + `onPressedChange` to control it.\n */\nexport function Toggle({ variant = \"ghost\", size = \"md\", iconOnly = false, className, ...props }: ToggleProps) {\n  return (\n    <BaseToggle\n      className={withBase(\n        cx(\n          \"inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 rounded-lg font-medium whitespace-nowrap select-none\",\n          iconOnly ? sizes[size].icon : sizes[size].text,\n          variants[variant],\n          \"transition-[background-color,border-color,color,box-shadow,scale] duration-150 ease-out active:duration-100\",\n          \"motion-safe:active:scale-[0.97] motion-reduce:transition-none\",\n          \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n          \"data-[disabled]:pointer-events-none data-[disabled]:opacity-45\",\n          \"[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0\",\n        ),\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n"
    }
  ],
  "example": {
    "content": "import { Toggle } from \"@/components/shaken/ui/toggle\";\n\nfunction PinIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <path d=\"M9.5 2.25l4.25 4.25-2.5 1-2 2 .25 2.75-1 1-2.25-2.25L3 14l-.25-.25 3.25-3.25-2.25-2.25 1-1 2.75.25 2-2 1-2.5z\" />\n    </svg>\n  );\n}\n\nfunction WrapIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <path d=\"M2.5 4h11M2.5 8h9a2 2 0 0 1 0 4H8.5M2.5 12h3M10 10.5L8.5 12l1.5 1.5\" />\n    </svg>\n  );\n}\n\nfunction BoldIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinejoin=\"round\">\n      <path d=\"M4.5 2.75h4.25a2.6 2.6 0 0 1 0 5.25H4.5zM4.5 8h5a2.6 2.6 0 0 1 0 5.25h-5z\" />\n    </svg>\n  );\n}\n\nexport default function ToggleExample() {\n  return (\n    <div className=\"flex flex-wrap items-center gap-3\">\n      <Toggle aria-label=\"Bold\" iconOnly defaultPressed>\n        <BoldIcon />\n      </Toggle>\n      <Toggle variant=\"outline\" defaultPressed>\n        <PinIcon />\n        Pinned\n      </Toggle>\n      <Toggle variant=\"outline\">\n        <WrapIcon />\n        Wrap lines\n      </Toggle>\n      <Toggle size=\"sm\" disabled>\n        Read only\n      </Toggle>\n    </div>\n  );\n}\n"
  }
}
