{
  "$comment": "Generated by scripts/build_slant_registry.mjs (npm run build:registry) from the Slant registries and sources; do not edit.",
  "name": "Button",
  "group": "primitives",
  "description": "A clickable control in three variants, five tones and three sizes. It defaults to type=\"button\", so it never submits a form by accident.",
  "since": "0.1.0",
  "status": "stable",
  "exports": [
    "Button"
  ],
  "import": "import { Button } from '@tuttn/slant'",
  "docs": {
    "slug": "button",
    "title": "Button",
    "url": "https://tuttn.io/lab/slant/docs/button",
    "description": "Primary, secondary and ghost buttons with sizes, icons and a loading state.",
    "markdown": "`loading` is not `disabled`: it keeps the button focused, so keyboard and screen reader users don't lose their place, and looks disabled through `aria-disabled`. Use `disabled` for a button that can't be used at all yet. The busy mark is a small, decorative [Spinner](https://tuttn.io/lab/slant/docs/spinner) in the button's text colour; the label stays the button's name, so change it (\"Saving…\") if the wait needs words."
  },
  "props": {
    "Button": [
      {
        "name": "variant",
        "type": "'primary' | 'secondary' | 'ghost'",
        "default": "'secondary', or the ButtonGroup's",
        "description": "Emphasis: a solid fill in the tone's colour, a raised surface, or no background."
      },
      {
        "name": "tone",
        "type": "Tone",
        "default": "'accent'",
        "description": "Semantic colour. `primary` fills with it, so `tone=\"danger\" variant=\"primary\"` is a destructive button; `secondary` and `ghost` take it as their text and border colour. With `accent` and `neutral` they keep their usual look."
      },
      {
        "name": "size",
        "type": "'sm' | 'md' | 'lg'",
        "default": "'md', or the ButtonGroup's",
        "description": "Height on the control scale: 28, 34 or 40px at regular density. `lg` also sets larger text and padding."
      },
      {
        "name": "icon",
        "type": "boolean",
        "description": "A square button holding only an icon; give it an aria-label."
      },
      {
        "name": "loading",
        "type": "boolean",
        "description": "Shows a small Spinner before the label, in the button's text colour, and sets aria-busy and aria-disabled. The button keeps focus, so a screen reader stays on it, but clicks are ignored until loading ends."
      },
      {
        "name": "fullWidth",
        "type": "boolean",
        "description": "Stretches the button to the width of its container."
      },
      {
        "name": "asChild",
        "type": "boolean",
        "description": "Renders the single child (a link, a router's Link) instead of a button, with the button's class, data attributes and handlers merged onto it. No `type` is added, and `disabled` becomes aria-disabled, which a link understands."
      }
    ]
  },
  "extraProps": [
    {
      "name": "type",
      "type": "'button' | 'submit' | 'reset'",
      "default": "'button'",
      "description": "Never submits a form by accident. Not added with asChild."
    },
    {
      "name": "disabled",
      "type": "boolean",
      "default": "false",
      "description": "The native attribute: the button leaves the tab order. With asChild it becomes aria-disabled."
    },
    {
      "name": "…rest",
      "type": "ButtonHTMLAttributes",
      "description": "onClick, aria-* and every other button attribute pass through; a ref reaches the button element, or the child with asChild."
    }
  ],
  "usage": "import { Button } from '@tuttn/slant'\n\n<Button variant=\"primary\">Deploy</Button>\n<Button>Secondary</Button>\n<Button variant=\"ghost\" size=\"sm\">Ghost</Button>\n<Button variant=\"primary\" size=\"lg\">Get started</Button>\n\n// tone is the colour: a danger fill is a destructive action.\n<Button variant=\"primary\" tone=\"danger\">Delete project</Button>\n<Button tone=\"danger\">Discard draft</Button>\n\n// Loading shows a small Spinner and sets aria-busy and aria-disabled. The\n// button keeps focus, and clicks are ignored until it finishes.\n<Button variant=\"primary\" loading={saving} onClick={save}>{saving ? 'Saving…' : 'Save'}</Button>\n\n// Icon-only buttons are square; give them a label.\n<Button icon aria-label=\"Add\"><PlusIcon /></Button>\n\n// asChild renders your link (or a router's Link) with the button's look.\n<Button asChild variant=\"primary\"><a href=\"/docs\">Read the docs</a></Button>\n\n<Button fullWidth type=\"submit\">Continue</Button>",
  "keyboard": [
    {
      "keys": "Tab",
      "does": "moves between buttons"
    },
    {
      "keys": "Enter / Space",
      "does": "presses the focused button"
    }
  ],
  "accessibility": [
    "Pressed counts announce through a live region.",
    "Icons are hidden from assistive technology; the text carries the meaning."
  ],
  "related": [],
  "recipes": [
    "buttons-and-badges"
  ],
  "usedIn": [
    "buttons-and-badges",
    "verification-code",
    "alerts",
    "sign-up-form",
    "filter-bar",
    "schedule",
    "entry-editor",
    "checkpoint-timeline",
    "meters",
    "plan-picker",
    "presence",
    "toasts",
    "progress-steps",
    "file-browser",
    "buddy-editor",
    "loading-and-empty-states",
    "before-after",
    "code-review",
    "app-shell",
    "ticket-panel",
    "review-checks",
    "appearance",
    "dialog",
    "feedback"
  ],
  "classes": [
    "sl-btn"
  ],
  "tokens": [
    "--sl-accent",
    "--sl-accent-text",
    "--sl-control-lg",
    "--sl-control-md",
    "--sl-control-sm",
    "--sl-disabled-opacity",
    "--sl-duration-base",
    "--sl-duration-fast",
    "--sl-duration-slow",
    "--sl-font-sans",
    "--sl-font-size-lg",
    "--sl-font-size-md",
    "--sl-font-size-sm",
    "--sl-line-strong",
    "--sl-muted",
    "--sl-radius-small",
    "--sl-space-2xs",
    "--sl-space-lg",
    "--sl-space-sm",
    "--sl-space-xs",
    "--sl-surface-2",
    "--sl-text",
    "--sl-tone",
    "--sl-tone-soft",
    "--sl-tone-text"
  ],
  "source": {
    "path": "react/src/primitives/Button.tsx",
    "url": "https://github.com/nirtuttnauer/tuttn-portfolio/blob/main/slant/react/src/primitives/Button.tsx",
    "code": "import { Children, cloneElement, forwardRef, isValidElement, type ButtonHTMLAttributes, type MouseEvent, type ReactElement, type ReactNode } from 'react'\nimport { cx } from '../cx'\nimport { Slot, useButtonGroup } from '../internal'\n// Straight from its file, not the feedback index, so the two groups' index\n// modules never import each other.\nimport { Spinner } from '../feedback/Spinner'\nimport type { Tone } from '../theme'\n\nexport type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {\n  /**\n   * Emphasis: a solid fill in the tone's colour, a raised surface, or no background.\n   * @default 'secondary', or the ButtonGroup's\n   */\n  variant?: 'primary' | 'secondary' | 'ghost'\n  /**\n   * Semantic colour. `primary` fills with it, so `tone=\"danger\" variant=\"primary\"`\n   * is a destructive button; `secondary` and `ghost` take it as their text and\n   * border colour. With `accent` and `neutral` they keep their usual look.\n   */\n  tone?: Tone\n  /**\n   * Height on the control scale: 28, 34 or 40px at regular density. `lg` also sets larger text and padding.\n   * @default 'md', or the ButtonGroup's\n   */\n  size?: 'sm' | 'md' | 'lg'\n  /** A square button holding only an icon; give it an aria-label. */\n  icon?: boolean\n  /**\n   * Shows a small Spinner before the label, in the button's text colour, and\n   * sets aria-busy and aria-disabled. The button keeps focus, so a screen reader stays on it, but\n   * clicks are ignored until loading ends.\n   */\n  loading?: boolean\n  /** Stretches the button to the width of its container. */\n  fullWidth?: boolean\n  /**\n   * Renders the single child (a link, a router's Link) instead of a button,\n   * with the button's class, data attributes and handlers merged onto it. No\n   * `type` is added, and `disabled` becomes aria-disabled, which a link\n   * understands.\n   */\n  asChild?: boolean\n}\n\nconst preventDefault = (event: MouseEvent) => event.preventDefault()\n\n// A clickable control in three variants, five tones and three sizes. It\n// defaults to type=\"button\", so it never submits a form by accident.\nexport const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(\n  { variant, tone = 'accent', size, icon, loading, fullWidth, asChild, className, children, disabled, type = 'button', onClick, ...rest }, ref,\n) {\n  // Inside a ButtonGroup (or a ToggleGroup), the group's size and variant are\n  // the defaults, and an attached group joins its buttons into one bar.\n  const group = useButtonGroup()\n  // A loading button, or a disabled one rendered as a link, keeps its focus\n  // and says it is unavailable; its clicks go nowhere.\n  const inert = Boolean(loading || (asChild && disabled))\n  const props = {\n    className: cx('sl-btn', className),\n    'data-variant': variant ?? group?.variant ?? 'secondary',\n    'data-tone': tone,\n    'data-size': size ?? group?.size ?? 'md',\n    'data-attached': group?.attached ? group.orientation : undefined,\n    'data-icon': icon ? '' : undefined,\n    'data-full': fullWidth ? '' : undefined,\n    'aria-busy': loading || undefined,\n    'aria-disabled': inert || undefined,\n    onClick: (event: MouseEvent<HTMLButtonElement>) => {\n      if (inert) event.preventDefault()\n      else onClick?.(event)\n    },\n    ...rest,\n  }\n  if (asChild) return <Slot ref={ref} {...props}>{slotted(children, loading, inert)}</Slot>\n  return <button ref={ref} type={type} disabled={disabled} {...props}>\n    {loading && <Spinner size=\"sm\" />}{children}\n  </button>\n})\n\n// asChild: the spinner goes inside the child, before its own content, and\n// while the button is inert the child's own click handler is held back too.\nfunction slotted(children: ReactNode, loading: boolean | undefined, inert: boolean) {\n  if (!loading && !inert) return children\n  const child = Children.only(children)\n  if (!isValidElement(child)) return child\n  const element = child as ReactElement<{ children?: ReactNode; onClick?: (event: MouseEvent) => void }>\n  const props = inert ? { onClick: preventDefault } : undefined\n  return loading ? cloneElement(element, props, <Spinner size=\"sm\" />, element.props.children) : cloneElement(element, props)\n}\n"
  }
}
