{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "segmented",
  "title": "Segmented control",
  "description": "Exclusive choice in one frame; the ink band stretches between cells.",
  "dependencies": [
    "@base-ui/react@1.9.0",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "utils",
    "@keyline-ui/keyline-motion",
    "@keyline-ui/scroll-edges",
    "@keyline-ui/keyline-scope",
    "@keyline-ui/keyline-render"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/segmented.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { RadioGroup } from \"@base-ui/react/radio-group\";\nimport { Radio } from \"@base-ui/react/radio\";\nimport { cva } from \"class-variance-authority\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useStretch } from \"../lib/keyline-motion\";\nimport { dataAttrs, resolveClassName } from \"../lib/keyline-render\";\nimport { useScrollEdges } from \"../lib/scroll-edges\";\nimport { useMergedRef } from \"../lib/keyline-scope\";\n\n/*\n * One control frame of cells and the ink band beneath them. The band and the covered labels are drawn by the\n * STRETCH engine (keyline-motion): it sizes the band and marks each item the band covers with data-kl-covered. In\n * flight it clones the row with every item covered and drops the clone's data-slot, so every style here sits on\n * the element it styles (no rule keys on a part's slot), and the clone reads the same.\n */\nconst segmentedVariants = cva(\n  \"kl-ctl kl-cells relative isolate inline-flex min-h-(--kl-ctl) max-w-full overflow-x-auto\",\n  {\n    variants: {\n      // a cell gives its background to the enclosing frame (the foundation's layout=\"cell\")\n      layout: { control: \"bg-kl-cell\", cell: \"\" },\n      size: { default: \"\", compact: \"min-h-[28px] [--kl-cut-size:var(--kl-cut-nested)]\" },\n    },\n    defaultVariants: { layout: \"control\", size: \"default\" },\n  },\n);\n\nconst itemVariants = cva(\n  [\n    \"kl-key inline-flex cursor-pointer items-center justify-center bg-transparent whitespace-nowrap text-kl-ink\",\n    \"text-(length:--kl-text-body) font-(--kl-weight-strong)\",\n    \"hover:not-data-checked: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-kl-covered:text-kl-dis\",\n    // covered by the band; a disabled choice that is still the chosen one keeps its label legible on it\n    \"data-kl-covered:text-kl-on-inverse\",\n    \"forced-colors:data-kl-covered:text-[HighlightText] forced-colors:data-kl-covered:forced-color-adjust-none\",\n  ],\n  {\n    variants: {\n      size: { default: \"px-3.5\", compact: \"px-2.5 text-(length:--kl-text-label)\" },\n    },\n    defaultVariants: { size: \"default\" },\n  },\n);\n\nconst SizeContext = React.createContext<\"default\" | \"compact\">(\"default\");\n\ntype SegmentedProps = Omit<React.ComponentProps<typeof RadioGroup>, \"value\" | \"defaultValue\" | \"onValueChange\"> & {\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  size?: \"default\" | \"compact\";\n  /** control: its own frame. cell: a cell of an enclosing frame. */\n  layout?: \"control\" | \"cell\";\n};\n\n/**\n * Exclusive choice inside one control frame. Radio-group semantics (arrows move and select).\n * The ink band STRETCHES between cells: leading edge first, trailing edge follows, zero bounce.\n */\nfunction Segmented({\n  value,\n  defaultValue,\n  onValueChange,\n  size = \"default\",\n  layout = \"control\",\n  className,\n  children,\n  ref: refProp,\n  ...props\n}: SegmentedProps): React.ReactElement {\n  const [inner, setInner] = React.useState(defaultValue);\n  const current = value ?? inner;\n  const ref = React.useRef<HTMLDivElement>(null);\n  const setRef = useMergedRef(ref, refProp);\n  const values = React.Children.toArray(children)\n    .filter(React.isValidElement)\n    .map((c) => (c.props as { value?: string }).value);\n  useStretch(ref, values.indexOf(current));\n  useScrollEdges(ref);\n  return (\n    <SizeContext.Provider value={size}>\n      <RadioGroup\n        ref={setRef}\n        data-kl-stretch=\"\"\n        data-kl-layout={layout}\n        {...dataAttrs({ size })}\n        // one Tab stop: Firefox makes an overflowing scroller a Tab stop of its own, even around focusable items\n        tabIndex={-1}\n        value={current}\n        onValueChange={(v) => {\n          setInner(v as string);\n          onValueChange?.(v as string);\n        }}\n        className={resolveClassName(cn(segmentedVariants({ layout, size })), className)}\n        {...props}\n        data-slot=\"segmented\"\n      >\n        <span\n          data-kl-band=\"\"\n          className=\"pointer-events-none absolute -z-1 bg-kl-inverse forced-colors:bg-[Highlight] forced-colors:forced-color-adjust-none\"\n          aria-hidden\n          hidden\n        />\n        {children}\n      </RadioGroup>\n    </SizeContext.Provider>\n  );\n}\n\ntype SegmentedItemProps = React.ComponentProps<typeof Radio.Root> & { value: string };\n\n/** One choice: Base UI's Radio. */\nfunction SegmentedItem({ className, children, ...props }: SegmentedItemProps): React.ReactElement {\n  const size = React.useContext(SizeContext);\n  return (\n    <Radio.Root\n      data-kl-item=\"\"\n      className={resolveClassName(cn(itemVariants({ size })), className)}\n      {...props}\n      data-slot=\"segmented-item\"\n    >\n      <span>{children}</span>\n    </Radio.Root>\n  );\n}\n\nexport { Segmented, SegmentedItem, type SegmentedProps, type SegmentedItemProps };\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/segmented.tsx"
    }
  ],
  "type": "registry:ui"
}