{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toggle",
  "title": "Toggle",
  "description": "One on/off button (Base UI Toggle, aria-pressed): pressed floods yellow and fills the lamp; icon toggles show a floor keyline. Control or cell, alone or as a cell of a field frame. ToggleGroup composes its cells.",
  "dependencies": [
    "@base-ui/react@1.9.0",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "utils",
    "@keyline-ui/keyline-motion",
    "@keyline-ui/keyline-render"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/toggle.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Toggle as TogglePrimitive } from \"@base-ui/react/toggle\";\nimport { cva } from \"class-variance-authority\";\n\nimport { cn } from \"@/lib/utils\";\nimport { floodHandlers } from \"../lib/keyline-motion\";\nimport { resolveClassName } from \"../lib/keyline-render\";\n\n/*\n * A toggle is a key cell that FLOODS yellow when pressed (kl-flood, the foundation's flood) and carries a lamp, the\n * state's shape. The flood paints the pressed cell's fill and text from the foundation, so this file sets the\n * cell's own background and colour only while it is off (`not-data-pressed:`): a utility would beat the flood.\n * ToggleGroupItem uses the same cell (toggleVariants with no layout) and the same contents (toggleContents).\n */\nconst toggleVariants = cva(\n  [\n    \"kl-flood kl-key group/toggle inline-flex cursor-pointer items-stretch p-0 whitespace-nowrap\",\n    \"text-(length:--kl-text-body) font-(--kl-weight-strong)\",\n    \"not-data-pressed:bg-transparent not-data-pressed:text-kl-ink\",\n    \"hover:not-data-pressed:not-data-disabled:bg-kl-tint focus-visible:outline-offset-(--kl-ring-in)\",\n    \"data-disabled:cursor-not-allowed data-disabled:bg-(image:--kl-hatch) data-disabled:not-data-pressed:text-kl-dis\",\n    // disabled and on: the state keeps its shape (a full lamp) but the flood goes out of service\n    \"data-disabled:data-pressed:[--kl-fc:var(--kl-press)] data-disabled:data-pressed:[--kl-fg:var(--kl-dis)]\",\n  ],\n  {\n    variants: {\n      /** Toggle alone: control is its own frame (kl-ctl: border, cut), cell fills a cell of an enclosing frame.\n       * Unset: a cell of a ToggleGroup, whose frame and background are the group's. */\n      layout: {\n        control: [\n          \"kl-ctl box-border min-h-(--kl-ctl) align-middle not-data-pressed:bg-kl-cell\",\n          \"data-disabled:border-kl-dis-line data-disabled:[--kl-cut-line:var(--kl-dis-line)]\",\n        ],\n        cell: \"box-border min-h-(--kl-row) align-middle not-data-pressed:bg-kl-cell\",\n      },\n      /** Icon only: a square cell; pressed draws a floor keyline in the flood's ink (the lamp's job). */\n      icon: {\n        true: [\n          \"min-w-(--kl-ctl) justify-center [&_svg]:size-4 [&_svg]:flex-none\",\n          \"data-pressed:shadow-[inset_0_-3px_0_currentColor]\",\n          \"forced-colors:data-pressed:shadow-none forced-colors:data-pressed:outline-3 forced-colors:data-pressed:outline-solid\",\n          \"forced-colors:data-pressed:outline-offset-[-4px] forced-colors:data-pressed:outline-[Highlight]\",\n        ],\n        false: \"\",\n      },\n    },\n    defaultVariants: { icon: false },\n  },\n);\n\nconst labelVariants = cva(\"inline-flex items-center gap-2 px-3\", {\n  variants: {\n    layout: { control: \"\", cell: \"\" },\n    icon: { true: \"flex-1 justify-center px-0\", false: \"\" },\n  },\n  compoundVariants: [\n    // a control's label clears the cut in its top-start corner\n    { layout: \"control\", icon: false, className: \"ps-[calc(12px+var(--kl-c,0px)*0.35)]\" },\n  ],\n  defaultVariants: { icon: false },\n});\n\n/** The inside of a toggle cell: the lamp (the state's shape), the label, an optional count. Shared with\n *  ToggleGroupItem, so a toggle reads the same alone and in a group. */\nfunction toggleContents(\n  children: React.ReactNode,\n  { count, icon, layout }: { count?: React.ReactNode; icon?: boolean; layout?: \"control\" | \"cell\" },\n): React.ReactElement {\n  return (\n    <span data-slot=\"toggle-label\" className={cn(labelVariants({ layout, icon: !!icon }))}>\n      {/* the lamp sits in the label, so the theme's direct-child rule never reaches it */}\n      {icon ? null : (\n        <span data-slot=\"toggle-lamp\" className=\"kl-lamp group-data-pressed/toggle:border-[5px]\" aria-hidden />\n      )}\n      {children}\n      {count != null ? (\n        <span\n          data-slot=\"toggle-count\"\n          className=\"font-medium text-kl-ink-2 tabular-nums group-data-pressed/toggle:text-inherit\"\n        >\n          {count}\n        </span>\n      ) : null}\n    </span>\n  );\n}\n\ntype ToggleProps = TogglePrimitive.Props & {\n  /** control: its own frame. cell: a cell of an enclosing frame (a panel header, a field frame). */\n  layout?: \"control\" | \"cell\";\n  /** Icon only: a square cell; pass `aria-label`. Pressed shows a floor keyline instead of the lamp. */\n  icon?: boolean;\n  count?: React.ReactNode;\n};\n\n/**\n * Toggle: one on/off button on Base UI Toggle (`aria-pressed`). Pressed FLOODS yellow from the\n * press point (the working set) and fills the lamp, so the state has a shape as well as a colour; the\n * label never changes with the state. Controlled (`pressed` + `onPressedChange`) or uncontrolled\n * (`defaultPressed`). For several related toggles use ToggleGroup; for one of many use Segmented.\n */\nfunction Toggle({\n  className,\n  layout = \"control\",\n  icon = false,\n  count,\n  children,\n  ...props\n}: ToggleProps): React.ReactElement {\n  return (\n    <TogglePrimitive\n      data-kl-layout={layout}\n      data-kl-icon={icon || undefined}\n      className={resolveClassName(cn(toggleVariants({ layout, icon })), className)}\n      {...floodHandlers}\n      {...props}\n      data-slot=\"toggle\"\n    >\n      {toggleContents(children, { count, icon, layout })}\n    </TogglePrimitive>\n  );\n}\n\nexport { Toggle, toggleVariants, toggleContents, type ToggleProps };\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/toggle.tsx"
    }
  ],
  "type": "registry:ui"
}