{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-group",
  "title": "Button group",
  "description": "Buttons joined in a row or a column, each divided from the next. One highlight glides from button to button under the pointer and takes the shape of each.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/highlight.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/button-group.tsx",
      "content": "'use client'\n\nimport {\n  followPointer,\n  type HighlightTarget,\n  highlightClassName,\n} from '@/registry/lib/highlight'\nimport { mergeProps, type PartProps, renderElement } from '@ui-sdk/react/primitive'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport { type ReactNode, useEffect, useRef, useState } from 'react'\n\nimport { cn } from '@/lib/utils'\n\nconst buttonGroupVariants = cva(\n  [\n    'group/button-group relative isolate flex w-fit items-stretch has-[>[role=group]]:gap-2 [&>*]:focus-visible:z-10',\n    // A segment takes the group's corner at every size, whatever the group renders as.\n    '[--control-radius-sm:var(--control-radius)] [--control-radius-xs:var(--control-radius)]',\n    // A segment never shrinks on a press: the row's edges stay put.\n    '[&>*]:active:scale-100!',\n    // A filled segment paints under its clear border, so its border can be the divider.\n    '[&>.bg-primary]:bg-clip-border [&>.bg-secondary]:bg-clip-border [&>[data-variant=destructive]]:bg-clip-border',\n    // Each segment's own hover would snap from one to the next; the highlight shows it instead.\n    // Under forced colours a segment keeps its own system colours.\n    'not-forced-colors:[&>.border-border]:hover:bg-background! not-forced-colors:dark:[&>.border-border]:hover:bg-input/30! not-forced-colors:[&>.bg-primary]:hover:bg-primary! not-forced-colors:[&>.bg-secondary]:hover:bg-secondary! not-forced-colors:[&>[data-variant=destructive]]:hover:bg-destructive/10! not-forced-colors:dark:[&>[data-variant=destructive]]:hover:bg-destructive/20!',\n  ],\n  {\n    variants: {\n      // An open popup (ui-sdk's `[popover]`) sits beside its trigger, a Copy\n      // button puts its status region beside itself, and the\n      // highlight is the group's last child, so the first and last segment are\n      // counted without them (2026-11-15: a toolbar's grouped buttons with\n      // tooltips lost their end corners). Every segment but the\n      // first keeps its start border as the divider, and every one but the last\n      // drops its end border, so a segment is the same size in any variant: a\n      // toggle that fills when pressed doesn't move its neighbours.\n      orientation: {\n        horizontal: [\n          'flex-row [&>*:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:rounded-s-none [&>*:not(:nth-last-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:rounded-e-none [&>*:not(:nth-last-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-e-0',\n          '[&>.bg-primary:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-s [&>.bg-primary:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-s-[color-mix(in_oklch,var(--primary),var(--primary-foreground)_30%)] [&>.bg-secondary:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-s [&>.bg-secondary:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-s-[color-mix(in_oklch,var(--secondary),var(--foreground)_12%)] [&>[data-variant=destructive]:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-s-destructive/30 dark:[&>[data-variant=destructive]:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-s-destructive/40',\n        ],\n        // A column grows past one line, so its corners are a box's, never a\n        // pill's: a pill's corner would curve across a segment's whole width.\n        vertical: [\n          'flex-col [--control-radius:var(--control-radius-capped)] [&>*:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:rounded-t-none [&>*:not(:nth-last-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:rounded-b-none [&>*:not(:nth-last-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-b-0',\n          '[&>.bg-primary:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-t [&>.bg-primary:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-t-[color-mix(in_oklch,var(--primary),var(--primary-foreground)_30%)] [&>.bg-secondary:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-t [&>.bg-secondary:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-t-[color-mix(in_oklch,var(--secondary),var(--foreground)_12%)] [&>[data-variant=destructive]:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-t-destructive/30 dark:[&>[data-variant=destructive]:not(:nth-child(1_of_:not([aria-owns],[hidden],[role=status],[popover],[data-slot=button-group-highlight])))]:border-t-destructive/40',\n        ],\n      },\n    },\n    defaultVariants: {\n      orientation: 'horizontal',\n    },\n  },\n)\n\n/** The segment `node` is in: a button or a link the highlight lands on, or something it doesn't. */\nfunction segmentOf(group: HTMLElement, node: EventTarget | null): HighlightTarget {\n  let segment = node instanceof Element ? node : null\n  while (segment && segment.parentElement !== group) segment = segment.parentElement\n  if (!(segment instanceof HTMLElement)) return 'gap'\n  return segment.matches('button, a') &&\n    !segment.matches('[data-disabled], :disabled, [aria-disabled=\"true\"]')\n    ? segment\n    : 'none'\n}\n\nfunction ButtonGroup({\n  className,\n  orientation,\n  children,\n  render,\n  ...props\n}: Omit<PartProps<'div'>, 'className' | 'children'> &\n  VariantProps<typeof buttonGroupVariants> & {\n    className?: string\n    children?: ReactNode\n  }) {\n  const [group, setGroup] = useState<HTMLDivElement | null>(null)\n  const layerRef = useRef<HTMLSpanElement>(null)\n\n  // One highlight for the whole row, so it glides from segment to segment.\n  useEffect(() => {\n    if (!group || !layerRef.current) return\n    return followPointer(group, layerRef.current, {\n      itemOf: (node) => segmentOf(group, node),\n    })\n  }, [group])\n\n  // What the caller passes wins, so a ui-sdk group rendered as this one keeps\n  // its own slot; its ref joins ours, the same function each render.\n  return renderElement(\n    'div',\n    mergeProps(\n      {\n        ref: setGroup,\n        role: 'group',\n        'data-slot': 'button-group',\n        'data-orientation': orientation ?? 'horizontal',\n        className: cn(buttonGroupVariants({ orientation }), className),\n        children: (\n          <>\n            {children}\n            <span\n              ref={layerRef}\n              aria-hidden\n              data-slot='button-group-highlight'\n              className={cn(\n                highlightClassName,\n                'bg-foreground/7 z-20 group-has-[>:active]/button-group:bg-foreground/12 [@media(hover:hover)]:group-has-[>.bg-primary:hover]/button-group:bg-primary-foreground/15 [@media(hover:hover)]:group-has-[>.bg-primary:active]/button-group:bg-primary-foreground/22! [@media(hover:hover)]:group-has-[>[data-variant=destructive]:hover]/button-group:bg-destructive/10',\n              )}\n            />\n          </>\n        ),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\nfunction ButtonGroupText({\n  className,\n  render,\n  ...props\n}: Omit<PartProps<'div'>, 'className'> & { className?: string }) {\n  return renderElement(\n    'div',\n    mergeProps(\n      {\n        'data-slot': 'button-group-text',\n        className: cn(\n          \"flex items-center gap-1.5 rounded-(--control-radius) border bg-muted/60 px-(--control-padding) text-sm whitespace-nowrap text-muted-foreground tabular-nums [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4\",\n          className,\n        ),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\nexport { ButtonGroup, ButtonGroupText, buttonGroupVariants }\n",
      "type": "registry:component",
      "target": "@components/kino/button-group.tsx"
    }
  ],
  "type": "registry:component"
}