{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-group",
  "title": "Button Group",
  "description": "Buttons join into one strip, and a single highlight glides from segment to segment under the pointer or keyboard focus, taking each segment's corners as it goes.",
  "dependencies": [
    "@ui-sdk/core@0.1.0-beta.9",
    "@ui-sdk/react@0.1.0-beta.9"
  ],
  "registryDependencies": [
    "@keyframery/motion"
  ],
  "files": [
    {
      "path": "registry/components/keyframery/core/button-group-core.ts",
      "content": "/* A row (or column) of joined buttons, as a UI SDK primitive. UI SDK ships Button and Toolbar but no\n   button group, so it is defined here with `definePrimitive`.\n\n   It is a WAI-ARIA `group`: each control keeps its own tab stop, as in shadcn/ui. For one tab stop\n   and arrow keys, put the controls in a Toolbar instead.\n\n   The group follows the pointer and keyboard focus across its buttons and puts the one under them\n   in state, as a box (`--highlight-left`, `--highlight-top`, `--highlight-width`,\n   `--highlight-height`, `--highlight-radius` on the root), so one highlight can glide between\n   segments instead of each segment lighting up on its own. */\n\nimport { css, definePrimitive } from \"@ui-sdk/core\"\n\ntype ButtonGroupOptions = {\n  /** Lays the buttons out in a row or a column. */\n  orientation?: \"horizontal\" | \"vertical\"\n}\n\ntype Box = { left: number; top: number; width: number; height: number; radius: string }\n\ntype ButtonGroupState = {\n  orientation: \"horizontal\" | \"vertical\"\n  /** The box of the button under the pointer or keyboard focus. It stays at the last one while nothing is highlighted, so the highlight fades where it was. */\n  box: Box | null\n  /** Whether a button is highlighted now. */\n  highlighted: boolean\n  /** True while the highlight moves from one button to the next, false when it appears from nothing. */\n  gliding: boolean\n}\n\n/* What the highlight can rest on: buttons and links straight inside the group, not a nested\n   group, a field or a disabled control. */\nconst PRESSABLE = 'button, a[href], [role=\"button\"]'\n\nfunction itemFrom(root: HTMLElement, target: EventTarget | null): HTMLElement | null {\n  let node = target instanceof HTMLElement ? target : null\n  while (node && node.parentElement !== root) node = node.parentElement\n  if (!node || !node.matches(PRESSABLE)) return null\n  if (node.matches(':disabled, [data-disabled], [aria-disabled=\"true\"]')) return null\n  return node\n}\n\nconst boxOf = (el: HTMLElement): Box => ({\n  left: el.offsetLeft,\n  top: el.offsetTop,\n  width: el.offsetWidth,\n  height: el.offsetHeight,\n  radius: getComputedStyle(el).borderRadius,\n})\n\nconst buttonGroup = definePrimitive({\n  name: \"button-group\",\n  options: { orientation: \"string\" },\n  state: (options: ButtonGroupOptions): ButtonGroupState => ({\n    orientation: options.orientation ?? \"horizontal\",\n    box: null,\n    highlighted: false,\n    gliding: false,\n  }),\n  sync: (options) => ({ orientation: options.orientation ?? \"horizontal\" }),\n  controlled: [\"orientation\"],\n  api: (context) => {\n    const { store } = context\n    let pointerInside = false\n\n    const highlight = (item: HTMLElement | null) => {\n      const now = store.get()\n      if (!item) {\n        if (now.highlighted) store.set({ highlighted: false })\n        return\n      }\n      store.set({ box: boxOf(item), gliding: now.highlighted, highlighted: true })\n    }\n\n    return {\n      /** The pointer moved over the group. */\n      pointerOver(event: Event, root: HTMLElement) {\n        pointerInside = true\n        const item = itemFrom(root, event.target)\n        if (item) highlight(item)\n      },\n      /** The pointer left: the highlight goes back to a keyboard-focused button, or fades. */\n      pointerLeave(root: HTMLElement) {\n        pointerInside = false\n        const focused = root.querySelector(\":focus-visible\")\n        highlight(focused ? itemFrom(root, focused) : null)\n      },\n      focusIn(event: FocusEvent, root: HTMLElement) {\n        const target = event.target as HTMLElement\n        if (!pointerInside && target.matches(\":focus-visible\")) highlight(itemFrom(root, target))\n      },\n      focusOut(event: FocusEvent, root: HTMLElement) {\n        if (!pointerInside && !root.contains(event.relatedTarget as Node | null)) highlight(null)\n      },\n    }\n  },\n  slots: (slot) => ({\n    root: slot<{}, { orientation: \"horizontal\" | \"vertical\"; highlighted: boolean }>({\n      role: \"group\",\n      state: (state) => ({ orientation: state.orientation, highlighted: state.highlighted }),\n      attrs: (state) => ({\n        \"data-orientation\": state.orientation,\n        \"data-highlighted\": state.highlighted ? \"\" : undefined,\n        \"data-gliding\": state.highlighted && state.gliding ? \"\" : undefined,\n        style: state.box\n          ? css({\n              \"--highlight-left\": `${state.box.left}px`,\n              \"--highlight-top\": `${state.box.top}px`,\n              \"--highlight-width\": `${state.box.width}px`,\n              \"--highlight-height\": `${state.box.height}px`,\n              \"--highlight-radius\": state.box.radius,\n            })\n          : undefined,\n      }),\n      on: {\n        pointerover: (event, { el, api }) => el && api.pointerOver(event, el),\n        pointerleave: (_event, { el, api }) => el && api.pointerLeave(el),\n        focusin: (event, { el, api }) => el && api.focusIn(event as FocusEvent, el),\n        focusout: (event, { el, api }) => el && api.focusOut(event as FocusEvent, el),\n      },\n    }),\n    /* Words or an icon that belong to the group but don't press, like a unit or a label. */\n    text: slot({}),\n  }),\n  /* Expose the group's layout context; each button owns its actions. */\n  agent: { actions: [] },\n})\n\nexport { buttonGroup, type ButtonGroupOptions }\n",
      "type": "registry:component",
      "target": "components/keyframery/core/button-group-core.ts"
    },
    {
      "path": "registry/components/keyframery/primitives/button-group.tsx",
      "content": "\"use client\"\n\n/* Animated button group, on UI SDK's core. UI SDK ships no button group, so the behaviour is defined\n   in `@/components/core/button-group` with `definePrimitive` and rendered here. Put Keyframery's (or\n   UI SDK's) Button straight inside it. This file adds motion only. Colours, radii, shadows and\n   spacing stay yours.\n\n   - Glide: one highlight springs from segment to segment under the pointer or keyboard focus, and\n     takes each segment's corners as it goes. It is the group's `::after`, laid over the buttons so it\n     shows on solid keys; it follows the text colour unless you give it one with `after:` classes.\n   - It fades in where it lands the first time, and fades out where it was when the pointer leaves.\n   - `ButtonGroupSeparator` is UI SDK's Separator; the line draws in from its centre. */\n\nimport { createParts } from \"@ui-sdk/react/primitive\"\nimport { Separator as SeparatorPart } from \"@ui-sdk/react/separator\"\nimport * as React from \"react\"\n\nimport { buttonGroup } from \"@/components/keyframery/core/button-group-core\"\nimport { cn } from \"@/lib/utils\"\n\n/* UI SDK accepts a class name or a function of state; keep both working. */\nfunction withClass<S>(base: string, className: string | ((state: S) => string | undefined) | undefined) {\n  return typeof className === \"function\" ? (state: S) => cn(base, className(state)) : cn(base, className)\n}\n\nconst { Root: ButtonGroupRoot, Text: ButtonGroupTextPart } = createParts(buttonGroup, { root: \"div\", text: \"div\" })\n\nfunction ButtonGroup({ className, ...props }: React.ComponentProps<typeof ButtonGroupRoot>) {\n  return (\n    <ButtonGroupRoot\n      className={withClass(\n        cn(\n          \"relative isolate\",\n          \"after:pointer-events-none after:absolute after:z-20 after:content-['']\",\n          \"after:top-(--highlight-top,0) after:left-(--highlight-left,0) after:h-(--highlight-height,0) after:w-(--highlight-width,0) after:rounded-(--highlight-radius,0)\",\n          \"after:bg-[color-mix(in_oklch,currentColor_9%,transparent)] after:opacity-0 after:scale-[0.94]\",\n          \"after:[transition:opacity_calc(160ms*var(--kf-speed,1))_var(--ease-house),scale_calc(220ms*var(--kf-speed,1))_var(--ease-house)]\",\n          \"data-highlighted:after:opacity-100 data-highlighted:after:scale-100\",\n          \"data-gliding:after:[transition:left_calc(380ms*var(--kf-speed,1))_var(--ease-spring),top_calc(380ms*var(--kf-speed,1))_var(--ease-spring),width_calc(380ms*var(--kf-speed,1))_var(--ease-spring),height_calc(380ms*var(--kf-speed,1))_var(--ease-spring),border-radius_calc(380ms*var(--kf-speed,1))_var(--ease-spring),opacity_calc(160ms*var(--kf-speed,1))_var(--ease-house),scale_calc(220ms*var(--kf-speed,1))_var(--ease-house)]\",\n          \"motion-reduce:after:[transition:opacity_calc(160ms*var(--kf-speed,1))_var(--ease-house)]! motion-reduce:after:scale-100\",\n        ),\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction ButtonGroupText({ className, ...props }: React.ComponentProps<typeof ButtonGroupTextPart>) {\n  return <ButtonGroupTextPart className={withClass(\"relative\", className)} {...props} />\n}\n\nconst separatorKeyframes = \"@keyframes kf-button-group-sep-y{from{scale:1 0}}@keyframes kf-button-group-sep-x{from{scale:0 1}}\"\n\n/* A line between segments. It runs across the group, so it is vertical in a row and horizontal in a column. */\nfunction ButtonGroupSeparator({\n  className,\n  orientation = \"vertical\",\n  decorative = true,\n  ...props\n}: React.ComponentProps<typeof SeparatorPart>) {\n  return (\n    <>\n      <style href=\"kf-button-group-sep\" precedence=\"default\">\n        {separatorKeyframes}\n      </style>\n      <SeparatorPart\n        orientation={orientation}\n        decorative={decorative}\n        className={withClass(\n          cn(\n            \"relative z-10 shrink-0 self-stretch\",\n            \"data-[orientation=vertical]:animate-[kf-button-group-sep-y_calc(420ms*var(--kf-speed,1))_var(--ease-spring)_both]\",\n            \"data-[orientation=horizontal]:animate-[kf-button-group-sep-x_calc(420ms*var(--kf-speed,1))_var(--ease-spring)_both]\",\n            \"motion-reduce:animate-none!\",\n          ),\n          className,\n        )}\n        {...props}\n      />\n    </>\n  )\n}\n\nexport { ButtonGroup, ButtonGroupSeparator, ButtonGroupText }\n",
      "type": "registry:component",
      "target": "components/keyframery/primitives/button-group.tsx"
    },
    {
      "path": "registry/components/keyframery/button-group.tsx",
      "content": "\"use client\"\n\nexport * from \"@/components/keyframery/primitives/button-group\"\n\n/* Theming variables (set on a part or ancestor; absent values preserve the theme):\n   --button-group-face: Counter surface; default: bg-muted.\n   --button-group-ink: Counter text; default: text-muted-foreground.\n   --button-group-line: Separator; default: bg-border.\n   --button-group-radius: Counter corners; default: rounded-[9px].\n   --button-group-font: Counter size; default: text-[13px].\n   --button-group-gap: Nested group gap; default: 0.5rem.\n   --button-group-inset-x: Counter padding; default: px-3.\n*/\n\n/* Styled button group: the animated primitive plus the Keyframery look. Keyframery's Buttons (and\n   Inputs, NativeSelects, menu triggers) placed inside join into one strip: shared hairlines, square\n   inner corners, the outer corners kept. Groups inside a group sit apart with a gap. */\n\nimport * as React from \"react\"\n\nimport {\n  ButtonGroup as ButtonGroupPrimitive,\n  ButtonGroupSeparator as ButtonGroupSeparatorPrimitive,\n  ButtonGroupText as ButtonGroupTextPrimitive,\n} from \"@/components/keyframery/primitives/button-group\"\nimport { Speed, type SpeedProps } from \"@/lib/keyframery\"\nimport { cn } from \"@/lib/utils\"\n\n/* UI SDK accepts a class name or a function of state; keep both working. */\nfunction withClass<S>(base: string, className: string | ((state: S) => string | undefined) | undefined) {\n  return typeof className === \"function\" ? (state: S) => cn(base, className(state)) : cn(base, className)\n}\n\nfunction ButtonGroup({ speed, className, ...props }: React.ComponentProps<typeof ButtonGroupPrimitive> & SpeedProps) {\n  return (\n    <Speed speed={speed}>\n      <ButtonGroupPrimitive\n        className={withClass(\n          cn(\n            \"flex w-fit items-stretch\",\n            \"has-[>[data-slot=button-group]]:gap-[var(--button-group-gap,0.5rem)]\",\n            /* A focused or highlighted segment sits above its neighbours, so its ring is whole. */\n            \"[&>*]:focus-visible:z-10 [&>*:hover]:z-[5]\",\n            /* Joined segments keep one hairline between them, and only the outer corners. */\n            \"data-[orientation=horizontal]:[&>*:not([data-slot=button-group]):not(:first-child)]:-ms-px\",\n            \"data-[orientation=horizontal]:[&>*:not([data-slot=button-group]):not(:first-child)]:rounded-s-none\",\n            \"data-[orientation=horizontal]:[&>*:not([data-slot=button-group]):not(:last-child)]:rounded-e-none\",\n            \"data-[orientation=vertical]:flex-col data-[orientation=vertical]:[&>*:not([data-slot=button-group])]:w-auto!\",\n            \"data-[orientation=vertical]:[&>*:not([data-slot=button-group]):not(:first-child)]:-mt-px\",\n            \"data-[orientation=vertical]:[&>*:not([data-slot=button-group]):not(:first-child)]:rounded-t-none\",\n            \"data-[orientation=vertical]:[&>*:not([data-slot=button-group]):not(:last-child)]:rounded-b-none\",\n            /* A pressed segment sinks a little less than a lone button, so the strip stays joined. */\n            \"[&>[data-slot=button]:active]:scale-[0.975]!\",\n            \"*:data-[slot=input]:flex-1 *:data-[slot=native-select]:min-w-0\",\n          ),\n          className,\n        )}\n        {...props}\n      />\n    </Speed>\n  )\n}\n\n/* Words or an icon that belong to the group, on a well: a unit, a currency, a label. */\nfunction ButtonGroupText({ className, ...props }: React.ComponentProps<typeof ButtonGroupTextPrimitive>) {\n  return (\n    <ButtonGroupTextPrimitive\n      className={withClass(\n        cn(\n          \"flex shrink-0 items-center gap-[var(--button-group-gap,0.375rem)] rounded-[var(--button-group-radius,9px)] bg-[var(--button-group-face,var(--muted))] px-[var(--button-group-inset-x,0.75rem)] text-[length:var(--button-group-font,13px)] leading-none font-medium whitespace-nowrap text-[color:var(--button-group-ink,var(--muted-foreground))]\",\n          \"shadow-[inset_0_0_0_1px_rgb(0_0_0/0.06)] dark:shadow-[inset_0_0_0_1px_rgb(255_255_255/0.06)]\",\n          \"[&_svg]:pointer-events-none [&_svg]:shrink-0\",\n        ),\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/* A hairline between segments, for a split button whose two halves share one surface. */\nfunction ButtonGroupSeparator({ className, ...props }: React.ComponentProps<typeof ButtonGroupSeparatorPrimitive>) {\n  return (\n    <ButtonGroupSeparatorPrimitive\n      className={withClass(\n        cn(\n          \"bg-[var(--button-group-line,var(--border))]\",\n          \"data-[orientation=vertical]:my-2 data-[orientation=vertical]:w-px data-[orientation=horizontal]:mx-2 data-[orientation=horizontal]:h-px\",\n        ),\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nexport { ButtonGroup, ButtonGroupSeparator, ButtonGroupText }\n",
      "type": "registry:component",
      "target": "components/keyframery/button-group.tsx"
    }
  ],
  "type": "registry:component"
}