{
  "schemaVersion": 1,
  "target": "react",
  "name": "button-group",
  "version": "0.1.0",
  "category": "layout",
  "title": "Button Group",
  "description": "Joins buttons into one control with shared hairline borders, horizontally or vertically, with text segments and split buttons.",
  "tags": [
    "layout",
    "button",
    "group",
    "split-button",
    "toolbar"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {},
  "registryDependencies": [
    {
      "name": "button",
      "version": "0.2.1"
    },
    {
      "name": "dropdown-menu",
      "version": "0.2.1"
    }
  ],
  "docsPath": "/components/button-group",
  "props": [
    {
      "name": "orientation",
      "type": "\"horizontal\" | \"vertical\"",
      "default": "\"horizontal\"",
      "description": "Lays segments out in a row or a column."
    },
    {
      "name": "aria-label",
      "type": "string",
      "description": "Names the group, for example \"Artifact actions\"."
    },
    {
      "name": "ButtonGroupSeparator",
      "type": "ComponentProps<\"div\">",
      "description": "A hairline between filled segments, such as the two halves of a primary split button."
    },
    {
      "name": "ButtonGroupText",
      "type": "ComponentProps<\"div\">",
      "description": "A static segment for a label, unit, value, or prefix, bordered like a secondary button."
    }
  ],
  "accessibility": [
    "Renders role=\"group\"; give it an aria-label so screen readers announce what its buttons act on.",
    "Segments keep their own focus rings; the focused or hovered segment is raised above its neighbours so its full outline and border show.",
    "Icon-only segments need an aria-label (the example labels Zoom in, Zoom out, and Fit to view).",
    "In a split button the arrow is a separate menu button with its own name (\"Choose merge method\"), aria-haspopup, and aria-expanded.",
    "The press scale is turned off inside a group so a pressed segment never opens a gap in the shared edge; hover and press are shown with color."
  ],
  "states": [
    "default",
    "hover",
    "focus-visible",
    "disabled"
  ],
  "files": [
    {
      "path": "ui/button-group.tsx",
      "content": "import type { ComponentProps } from \"react\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\n// Every direct child joins the group: inner corners square off and each segment overlaps the\n// previous one by 1px, so neighbouring hairlines merge into one. The first and last segments are\n// counted with `nth-child(… of …)`, skipping the hidden focus guards a menu or popover inserts\n// beside its trigger while open. Class names are written out in full so Tailwind can find them.\nconst orientations = {\n  horizontal: cx(\n    \"flex-row [&>*]:rounded-none\",\n    \"[&>:nth-child(1_of_:not([data-base-ui-focus-guard],[aria-owns]))]:rounded-l-lg\",\n    \"[&>:nth-last-child(1_of_:not([data-base-ui-focus-guard],[aria-owns]))]:rounded-r-lg\",\n    \"[&>*:not(:first-child)]:-ml-px\",\n  ),\n  vertical: cx(\n    \"flex-col [&>*]:rounded-none\",\n    \"[&>:nth-child(1_of_:not([data-base-ui-focus-guard],[aria-owns]))]:rounded-t-lg\",\n    \"[&>:nth-last-child(1_of_:not([data-base-ui-focus-guard],[aria-owns]))]:rounded-b-lg\",\n    \"[&>*:not(:first-child)]:-mt-px\",\n  ),\n} as const;\n\nexport type ButtonGroupOrientation = keyof typeof orientations;\n\nexport interface ButtonGroupProps extends ComponentProps<\"div\"> {\n  /** Lays the segments out in a row or a column. */\n  orientation?: ButtonGroupOrientation;\n}\n\n/**\n * Joins buttons (and inputs or `ButtonGroupText`) into one control that shares its borders.\n * Name the group with `aria-label` so screen readers announce what the buttons act on.\n * Segments keep their own hover and focus styles; the hovered or focused one is lifted above its\n * neighbours so its full border and focus ring show. The press scale is turned off inside a group,\n * since shrinking one segment would open a gap in the shared edge.\n */\nexport function ButtonGroup({ orientation = \"horizontal\", className, ...props }: ButtonGroupProps) {\n  return (\n    <div\n      role=\"group\"\n      data-orientation={orientation}\n      className={cx(\n        \"inline-flex w-fit items-stretch isolate\",\n        orientations[orientation],\n        \"[&>*]:relative [&>*:hover]:z-10 [&>*:focus-visible]:z-20 [&>*:focus-within]:z-20 [&>*:active]:scale-100!\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/**\n * A hairline between two filled segments, such as the label and the arrow of a primary split\n * button. Bordered (secondary) segments already share an edge and do not need one.\n */\nexport function ButtonGroupSeparator({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      aria-hidden=\"true\"\n      data-slot=\"button-group-separator\"\n      className={cx(\n        \"z-30 shrink-0 self-stretch bg-white/25 dark:bg-black/20\",\n        \"in-data-[orientation=horizontal]:w-px in-data-[orientation=vertical]:h-px\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/**\n * A static segment for a label, unit, or prefix, such as \"https://\" before an input.\n * Matches the secondary button's hairline so it sits flush with bordered segments.\n */\nexport function ButtonGroupText({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      className={cx(\n        \"inline-flex items-center gap-2 border border-zinc-950/12 px-3 text-sm whitespace-nowrap text-zinc-500 select-none\",\n        \"dark:border-white/15 dark:text-zinc-400 [&_svg]:size-4 [&_svg]:shrink-0\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport { Button } from \"@/components/shaken/ui/button\";\nimport { ButtonGroup, ButtonGroupSeparator, ButtonGroupText } from \"@/components/shaken/ui/button-group\";\nimport { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from \"@/components/shaken/ui/dropdown-menu\";\n\nconst icon = { \"aria-hidden\": true, viewBox: \"0 0 16 16\", fill: \"none\" } as const;\nconst stroke = { stroke: \"currentColor\", strokeWidth: 1.5, strokeLinecap: \"round\", strokeLinejoin: \"round\" } as const;\n\nconst mergeMethods = [\"Squash and merge\", \"Rebase and merge\", \"Create a merge commit\"] as const;\n\nexport default function ButtonGroupExample() {\n  const [method, setMethod] = useState<(typeof mergeMethods)[number]>(\"Squash and merge\");\n  const [retries, setRetries] = useState(3);\n\n  return (\n    <div className=\"flex flex-wrap items-start justify-center gap-x-10 gap-y-8\">\n      <div className=\"flex flex-col items-start gap-6\">\n        <ButtonGroup aria-label=\"Artifact actions\">\n          <Button variant=\"secondary\">\n            <svg {...icon}>\n              <rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8\" rx=\"1.5\" {...stroke} />\n              <path d=\"M10.5 3.5v-.25a.75.75 0 0 0-.75-.75h-6.5a.75.75 0 0 0-.75.75v6.5c0 .41.34.75.75.75h.25\" {...stroke} />\n            </svg>\n            Copy\n          </Button>\n          <Button variant=\"secondary\">\n            <svg {...icon}>\n              <path d=\"M8 2.5v7.5M4.75 7 8 10.25 11.25 7M3 13.5h10\" {...stroke} />\n            </svg>\n            Download\n          </Button>\n          <Button variant=\"secondary\">\n            <svg {...icon}>\n              <path d=\"M9.5 2.5h4v4M13.5 2.5 8 8M11.5 9.5v3a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1h3\" {...stroke} />\n            </svg>\n            Open\n          </Button>\n        </ButtonGroup>\n\n        <ButtonGroup aria-label=\"Merge pull request\">\n          <Button>{method}</Button>\n          <ButtonGroupSeparator />\n          <DropdownMenu>\n            <DropdownMenuTrigger render={<Button aria-label=\"Choose merge method\" className=\"w-9 px-0!\" />}>\n              <svg {...icon}>\n                <path d=\"m4.5 6.25 3.5 3.5 3.5-3.5\" {...stroke} />\n              </svg>\n            </DropdownMenuTrigger>\n            <DropdownMenuContent align=\"end\">\n              {mergeMethods.map((option) => (\n                <DropdownMenuItem key={option} onClick={() => setMethod(option)}>\n                  <svg {...icon} className={option === method ? \"\" : \"invisible\"}>\n                    <path d=\"m3.75 8.25 2.75 2.75 5.75-6\" {...stroke} />\n                  </svg>\n                  {option}\n                </DropdownMenuItem>\n              ))}\n            </DropdownMenuContent>\n          </DropdownMenu>\n        </ButtonGroup>\n\n        <ButtonGroup aria-label=\"Retry limit\">\n          <Button variant=\"secondary\" aria-label=\"Fewer retries\" className=\"w-9 px-0!\" disabled={retries === 0} onClick={() => setRetries(retries - 1)}>\n            <svg {...icon}>\n              <path d=\"M3.5 8h9\" {...stroke} />\n            </svg>\n          </Button>\n          <ButtonGroupText aria-live=\"polite\" className=\"min-w-24 justify-center text-zinc-950 tabular-nums dark:text-white\">\n            {retries} {retries === 1 ? \"retry\" : \"retries\"}\n          </ButtonGroupText>\n          <Button variant=\"secondary\" aria-label=\"More retries\" className=\"w-9 px-0!\" disabled={retries === 5} onClick={() => setRetries(retries + 1)}>\n            <svg {...icon}>\n              <path d=\"M8 3.5v9M3.5 8h9\" {...stroke} />\n            </svg>\n          </Button>\n        </ButtonGroup>\n      </div>\n\n      <ButtonGroup orientation=\"vertical\" aria-label=\"Canvas zoom\">\n        <Button variant=\"secondary\" aria-label=\"Zoom in\" className=\"w-9 px-0!\">\n          <svg {...icon}>\n            <path d=\"M8 3.5v9M3.5 8h9\" {...stroke} />\n          </svg>\n        </Button>\n        <Button variant=\"secondary\" aria-label=\"Zoom out\" className=\"w-9 px-0!\">\n          <svg {...icon}>\n            <path d=\"M3.5 8h9\" {...stroke} />\n          </svg>\n        </Button>\n        <Button variant=\"secondary\" aria-label=\"Fit to view\" className=\"w-9 px-0!\">\n          <svg {...icon}>\n            <path d=\"M2.75 6V3.75a1 1 0 0 1 1-1H6M10 2.75h2.25a1 1 0 0 1 1 1V6M13.25 10v2.25a1 1 0 0 1-1 1H10M6 13.25H3.75a1 1 0 0 1-1-1V10\" {...stroke} />\n          </svg>\n        </Button>\n      </ButtonGroup>\n    </div>\n  );\n}\n"
  }
}
