{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button",
  "title": "Button",
  "description": "Framed button with affix cells, key travel and pending/done/failed signals.",
  "dependencies": [
    "@base-ui/react@1.9.0",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "@keyline-ui/keyline-render",
    "utils"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/button.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Button as ButtonPrimitive } from \"@base-ui/react/button\";\nimport { mergeProps } from \"@base-ui/react/merge-props\";\nimport { useRender } from \"@base-ui/react/use-render\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nimport { cn } from \"@/lib/utils\";\nimport { dataAttrs, resolveClassName, resolveStyle, type PartProps } from \"../lib/keyline-render\";\n\n/*\n * The frame and its look. The button has no padding of its own, so its signal cells (! and the done mark) sit\n * on its edges; a container that wants a roomier button widens the label with --kl-button-px, never the\n * button's padding. Sizes use the (--kl-…) forms, which cn() recognises, so a consumer's h-10 or text-sm\n * replaces Keyline's instead of fighting it in the cascade.\n */\nconst buttonVariants = cva(\n  [\n    \"kl-key group/button inline-flex max-w-full cursor-pointer items-stretch p-0 select-none\",\n    \"bg-kl-cell text-kl-ink [-webkit-tap-highlight-color:transparent]\",\n    \"font-(family-name:--kl-font) text-(length:--kl-text-body)/none font-(--kl-weight-strong)\",\n    \"hover:bg-kl-tint active:not-data-disabled:bg-kl-press [&_svg]:flex-none\",\n    // KEY, refined: the frame and every cell in it stay put; only ink travels 1px. The theme's Key moves each\n    // child, and a button's children are cells that paint (the ! and done cells, the affix through the label's\n    // padding): moving them opened a hairline under the frame's top edge on every press. The label's text moves\n    // by its padding, and each cell moves its own glyph (theme: KEY), so no edge or seam moves.\n    \"[&:is(:active,[data-kl-pressed]):not(:disabled,[data-disabled])>*]:translate-none\",\n    \"aria-busy:cursor-progress\",\n    \"data-disabled:not-aria-busy:cursor-not-allowed data-disabled:not-aria-busy:bg-kl-cell\",\n    \"data-disabled:not-aria-busy:bg-(image:--kl-hatch) data-disabled:not-aria-busy:text-kl-dis\",\n  ],\n  {\n    variants: {\n      /** control: its own 2px frame. cell: fills a cell of an enclosing frame (no frame, no cut). A cell sets no\n       * border at all: its edges are the seams the enclosing row draws (one edge, one owner), and a border utility\n       * here would beat them. */\n      layout: {\n        control: [\n          \"kl-ctl min-h-(--kl-ctl)\",\n          \"data-disabled:not-aria-busy:border-kl-dis-line data-disabled:not-aria-busy:[--kl-cut-line:var(--kl-dis-line)]\",\n          // failed turns the frame red; a cell has no frame of its own, so its ! cell alone says it\n          \"data-[signal=failed]:data-[kl-layout=control]:border-kl-red\",\n          \"data-[signal=failed]:data-[kl-layout=control]:[--kl-cut-line:var(--kl-red)]\",\n        ],\n        cell: \"relative min-h-[48px] justify-center [--kl-bw:0px] focus-visible:outline-offset-(--kl-ring-in)\",\n      },\n      variant: {\n        secondary: \"\",\n        primary: [\n          \"bg-kl-cobalt text-kl-on-cobalt hover:bg-kl-cobalt-hi\",\n          // pressed: the same colour, deeper (it turned ink, so a press read as a different button)\n          \"active:not-data-disabled:bg-kl-cobalt-lo\",\n        ],\n        destructive: \"bg-kl-red text-kl-on-red hover:bg-kl-red-hi active:not-data-disabled:bg-kl-red-lo\",\n        quiet: \"bg-transparent data-disabled:not-aria-busy:bg-transparent data-disabled:not-aria-busy:bg-none\",\n      },\n      size: {\n        default: \"\",\n        compact:\n          \"min-h-[28px] text-(length:--kl-text-label)/none [--kl-button-px:10px] [--kl-cut-size:var(--kl-cut-nested)]\",\n        icon: \"w-(--kl-ctl)\",\n      },\n    },\n    compoundVariants: [\n      // the frame takes the fill's colour (control only: a cell's edges belong to its row)\n      {\n        layout: \"control\",\n        variant: \"primary\",\n        className: [\n          \"border-kl-cobalt [--kl-cut-line:var(--kl-cobalt)] hover:border-kl-cobalt-hi\",\n          \"active:not-data-disabled:border-kl-cobalt-lo forced-colors:border-[ButtonText]\",\n        ],\n      },\n      {\n        layout: \"control\",\n        variant: \"destructive\",\n        className: [\n          \"border-kl-red [--kl-cut-line:var(--kl-red)] hover:border-kl-red-hi\",\n          \"active:not-data-disabled:border-kl-red-lo forced-colors:border-[ButtonText]\",\n        ],\n      },\n      {\n        layout: \"control\",\n        variant: \"quiet\",\n        className: \"border-transparent [--kl-cut-line:transparent] data-disabled:not-aria-busy:border-transparent\",\n      },\n      { layout: \"cell\", variant: [\"primary\", \"destructive\"], className: \"focus-visible:outline-current\" },\n    ],\n    defaultVariants: { layout: \"control\", variant: \"secondary\", size: \"default\" },\n  },\n);\n\n/* The label cell: the text, centred, with the key travel in its padding. */\nconst labelVariants = cva(\n  [\n    \"inline-flex min-w-0 flex-1 items-center justify-center gap-2 leading-[1.2] whitespace-nowrap\",\n    \"px-(--kl-button-px,14px) pt-[calc(6px+var(--kl-key-y))] pb-[calc(6px-var(--kl-key-y))]\",\n  ],\n  {\n    variants: {\n      // a label longer than its container wraps inside the frame; the affix cell keeps the full height\n      layout: { control: \"text-start text-balance whitespace-normal\", cell: \"\" },\n      variant: {\n        secondary: \"\",\n        primary: \"\",\n        destructive: \"\",\n        quiet: \"underline decoration-1 underline-offset-4 group-hover/button:decoration-2\",\n      },\n      size: { default: \"\", compact: \"\", icon: \"p-0\" },\n    },\n    defaultVariants: { layout: \"control\", variant: \"secondary\", size: \"default\" },\n  },\n);\n\n/* a signal cell: the ! or the done mark, inserted at an edge of the frame (it unfolds through kl-slot) */\nconst signalCell = cn(\n  \"grid h-full w-[calc(var(--kl-ctl)-2*var(--kl-bw))] place-items-center\",\n  \"forced-colors:bg-[Highlight] forced-colors:text-[HighlightText] forced-colors:forced-color-adjust-none\",\n);\n\ntype Signal = \"idle\" | \"pending\" | \"done\" | \"failed\";\n\ntype ButtonProps = ButtonPrimitive.Props &\n  VariantProps<typeof buttonVariants> & {\n    /** pending: a segment runs along the bottom keyline and the button is busy.\n     *  done: a ✓ cell is inserted for a moment. failed: a ! cell is inserted at the start. */\n    signal?: Signal;\n  };\n\nfunction Button({\n  className,\n  layout = \"control\",\n  variant = \"secondary\",\n  size = \"default\",\n  signal = \"idle\",\n  children,\n  disabled,\n  ...props\n}: ButtonProps): React.ReactElement {\n  const pending = signal === \"pending\";\n  return (\n    <ButtonPrimitive\n      data-kl-layout={layout ?? \"control\"}\n      {...dataAttrs({ variant, size, signal: signal === \"idle\" ? undefined : signal })}\n      aria-busy={pending || undefined}\n      disabled={disabled || pending}\n      focusableWhenDisabled={pending}\n      className={resolveClassName(buttonVariants({ layout, variant, size }), className)}\n      {...props}\n      // after the props: rendered through another part (a trigger's render={<Button />}), the element is still a\n      // button, and its styles and its container's rules key on this slot\n      data-slot=\"button\"\n    >\n      <span className=\"kl-slot\" data-slot=\"button-fail\" data-open={signal === \"failed\" ? \"\" : undefined} aria-hidden>\n        <span className=\"flex\">\n          <span\n            className={cn(\n              signalCell,\n              \"border-e-(length:--kl-k1) border-e-kl-seam bg-kl-red text-[15px] font-(--kl-weight-display) text-kl-on-red\",\n            )}\n          >\n            !\n          </span>\n        </span>\n      </span>\n      <span className={cn(labelVariants({ layout, variant, size }))} data-slot=\"button-label\">\n        {children}\n      </span>\n      <span className=\"kl-slot\" data-slot=\"button-done\" data-open={signal === \"done\" ? \"\" : undefined} aria-hidden>\n        <span className=\"flex\">\n          <span\n            className={cn(\n              signalCell,\n              \"border-s-(length:--kl-k1) bg-kl-yellow text-kl-on-yellow\",\n              variant === \"primary\" ? \"border-s-kl-on-cobalt\" : \"border-s-current\",\n            )}\n          >\n            <svg\n              className=\"kl-tick\"\n              viewBox=\"0 0 16 16\"\n              width=\"14\"\n              height=\"14\"\n              fill=\"none\"\n              stroke=\"currentColor\"\n              strokeWidth=\"2.25\"\n              strokeLinecap=\"square\"\n            >\n              <path pathLength={1} d=\"m3.5 8.5 3 3 6-7\" />\n            </svg>\n          </span>\n        </span>\n      </span>\n      {pending ? (\n        <span className={cn(\"kl-pending\", layout === \"cell\" && \"[inset-block-end:0] [--kl-bw:3px]\")} aria-hidden />\n      ) : null}\n    </ButtonPrimitive>\n  );\n}\n\nconst affix = cn(\n  \"inline-flex min-w-[calc(var(--kl-ctl)-2*var(--kl-bw))] items-center justify-center self-stretch px-2\",\n  \"ms-1 me-[calc(-1*var(--kl-button-px,14px))] group-data-[size=compact]/button:min-w-[26px]\",\n  \"mt-[calc(-6px-var(--kl-key-y))] mb-[calc(-6px+var(--kl-key-y))] pt-[calc(2*var(--kl-key-y))]\",\n  \"border-s-(length:--kl-k1) border-s-current font-(--kl-weight-display) tabular-nums\",\n  \"has-[kbd]:font-(family-name:--kl-font-mono) has-[kbd]:text-(length:--kl-text-code)/[inherit] has-[kbd]:font-medium\",\n  \"[&.kl-code]:font-(family-name:--kl-font-mono) [&.kl-code]:text-(length:--kl-text-code)/[inherit] [&.kl-code]:font-medium\",\n);\n\ntype ButtonAffixState = Record<string, never>;\nconst AFFIX_STATE: ButtonAffixState = {};\n\n/** A cell inside the button frame, divided by a keyline: counts, shortcuts, units. Its keyline runs through the\n * label's block padding, so it meets the frame in T-junctions. */\nfunction ButtonAffix({ render, className, style, ...props }: PartProps<\"span\", ButtonAffixState>): React.ReactElement {\n  const own = {\n    \"data-slot\": \"button-affix\",\n    className: resolveClassName(affix, className)(AFFIX_STATE),\n    style: resolveStyle(undefined, style)(AFFIX_STATE),\n  };\n  return useRender({ defaultTagName: \"span\", render, state: AFFIX_STATE, props: mergeProps<\"span\">(props, own) });\n}\n\nexport { Button, ButtonAffix, buttonVariants };\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/button.tsx"
    }
  ],
  "type": "registry:ui"
}