{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button",
  "title": "Button",
  "description": "A button, or a link styled as one.",
  "dependencies": [
    "@base-ui/react@^1.8.0"
  ],
  "registryDependencies": [
    "@ouro/lib-announce",
    "@ouro/lib-appearance-hints",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-page-scroll-hold",
    "@ouro/lib-refs",
    "@ouro/lib-router-link",
    "@ouro/lib-tones",
    "@ouro/lib-touch-target",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/button/button.tsx",
      "content": "\"use client\";\n\nimport { Button as BaseButton } from \"@base-ui/react/button\";\nimport { useEffect, useRef } from \"react\";\nimport type {\n  AnchorHTMLAttributes,\n  ButtonHTMLAttributes,\n  ComponentType,\n  JSX,\n  KeyboardEvent,\n  MouseEvent,\n  PointerEvent,\n  ReactNode,\n  Ref,\n  SVGProps,\n} from \"react\";\nimport { announce } from \"@/registry/ouro/lib/ouro/announce\";\nimport { fontFor, radiusFor, sizeFor, toneFor } from \"@/registry/ouro/lib/ouro/appearance-hints\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { holdPageAtPress } from \"@/registry/ouro/lib/ouro/page-scroll-hold\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { RouterLink } from \"@/registry/ouro/lib/ouro/router-link\";\nimport { TouchTarget } from \"@/registry/ouro/lib/ouro/touch-target\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { toneWarning } from \"@/registry/ouro/lib/ouro/tones\";\n\n/** An icon component, such as one from `lucide-react` or `@heroicons/react`. */\nexport type ButtonIcon = ComponentType<SVGProps<SVGSVGElement>>;\n\n/** Props shared by both kinds of Button (`href` switches between them). */\nexport interface ButtonBaseProps {\n  /**\n   * Color role from the theme, named after its token: `primary` reads `--primary`.\n   * A solid primary button, the page's main action, reads `--ouro-action` and\n   * `--ouro-action-foreground` instead when the theme sets them, with `href` too, so a theme\n   * can give its actions their own colour. Only the solid look reads them: soft, outline and\n   * plain primary buttons keep `--primary`, as do `Link`, checkboxes, switches and the current tab.\n   * Optional `--ouro-action-hover` and `--ouro-action-active` set its state fills without\n   * changing the state layers. `--ouro-action-disabled`, `--ouro-action-disabled-foreground`\n   * and `--ouro-action-disabled-opacity` set its disabled look; opacity defaults to 0.5.\n   * shadcn's `variant=\"destructive\"` is `tone=\"destructive\"`, and its `variant=\"secondary\"` is `tone=\"secondary\"`.\n   * @claim \"Optional `--ouro-action-hover` and\" test/action-token.test.tsx verify:testExists(test/action-token.test.tsx::the action token > uses optional hover and active action fills for a button and a link, keeping the original state layers)\n   * @claim \"`--ouro-action-disabled`, `--ouro-action-disabled-foreground` and `--ouro-action-disabled-opacity` set its disabled look\" test/action-token.test.tsx verify:testExists(test/action-token.test.tsx::the action token > uses optional disabled action colours and opacity without changing other button looks or selections) verify:fileLine(registry/ouro/components/ouro/button/button.tsx, /disabled:opacity-\\(--ouro-action-disabled-opacity,0\\.5\\)/)\n   * @claim \"Only the solid look reads them\" test/action-token.test.tsx verify:testExists(test/action-token.test.tsx::the action token > repaints the solid primary Button, as a button and as a link, and leaves every selection on --primary)\n   * @claim \"A solid primary button, the\" test/action-token.test.tsx verify:testExists(test/action-token.test.tsx::the action token > repaints the solid primary Button, as a button and as a link, and leaves every selection on --primary)\n   * @default \"primary\"\n   */\n  tone?:\n    | \"primary\"\n    | \"secondary\"\n    | \"destructive\"\n    | \"success\"\n    | \"warning\"\n    | (string & { 'danger is \"destructive\"; accent is \"primary\"; neutral is \"secondary\"': never })\n    | undefined;\n  /**\n   * Visual weight: `solid` for the primary action, `soft` for secondary actions,\n   * `outline` for a quiet bordered control, `plain` for a borderless one.\n   * shadcn's `default` is `solid` (the default), `ghost` and `link` are `plain`, and\n   * `destructive` and `secondary` are tones: `tone=\"destructive\"`. Any other\n   * string is a type error whose message names the fix.\n   * Variant is visual only. For a toggle, pass `aria-pressed`; for the current\n   * nav item, `aria-current=\"page\"`.\n   * @default \"solid\"\n   */\n  variant?:\n    | \"solid\"\n    | \"soft\"\n    | \"outline\"\n    | \"plain\"\n    | (string & { 'From shadcn? Use tone=\"destructive\" or tone=\"secondary\". default is \"solid\"; ghost and link are \"plain\"': never })\n    | undefined;\n  /**\n   * Control size. `sm`, `md` and `lg` are taller on phones and step down to desktop\n   * density from the `sm` breakpoint (640px). `inline` is an action inside a line of text,\n   * such as Undo in a note: it takes the text's size, leaves the line's height as it was and\n   * keeps a target at least 24px tall and wide (44px on a coarse pointer). shadcn's `default`\n   * is `md`; for an icon-only button, pass the icon as children and an `aria-label`: Button sizes\n   * the icon as it sizes `startIcon`, unless the icon has a size class of its own. Any other\n   * string is a type error whose message names the fix. @default \"md\"\n   * @claim \"are taller on phones\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::appearance > orders sizes sm < md < lg)\n   * @claim \"are taller on phones\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::className > lets the app's height and padding win at desktop widths too)\n   * @claim \"it takes the text's size\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::inline size > sits in a line of text at the text's size without moving the line, and keeps a 24px target)\n   * @claim \"it takes the text's size\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::inline size > is at least 24px wide around a one-letter label)\n   * @claim \"it takes the text's size\" registry/ouro/components/ouro/button/button.touch.test.tsx verify:fileLine(registry/ouro/components/ouro/button/button.touch.test.tsx, /44px hit area on a coarse pointer/)\n   */\n  size?:\n    | \"sm\"\n    | \"md\"\n    | \"lg\"\n    | \"inline\"\n    | (string & { 'From shadcn? default is \"md\"; for icon, pass aria-label with the icon as children': never })\n    | undefined;\n  /** Stretches the button to the width of its container. */\n  fullWidth?: boolean | undefined;\n  /**\n   * Shows a centered spinner, keeps the width, sets `aria-busy` and disables\n   * the button. It stays focusable, so focus is not lost when a pressed button\n   * turns busy.\n   */\n  loading?: boolean | undefined;\n  /**\n   * What screen readers hear, politely, when `loading` turns on. It is spoken\n   * through a shared live region, so the button's name stays its label. Use the\n   * action in progress: `loadingLabel=\"Saving recipe\"`. @default \"Loading\"\n   */\n  loadingLabel?: string | undefined;\n  /** Icon before the label. Pass the component, not an element: `startIcon={PlusIcon}`. */\n  startIcon?: ButtonIcon | undefined;\n  /**\n   * Icon after the label. Pass the component, not an element: `endIcon={ArrowRightIcon}`. On a\n   * button wider than its label, such as one with `fullWidth`, it sits at the end and the label\n   * stays centred in the rest, or at the start with `className=\"justify-start\"`.\n   *\n   * @claim \"On a button wider than its label\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::button branch > puts an end icon at the inline end of a button wider than its label, %s)\n   * @claim \"On a button wider than its label\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::button branch > keeps an app's justify-start on a wide button %s an end icon)\n   */\n  endIcon?: ButtonIcon | undefined;\n  /** The label. For an icon-only button, also pass `aria-label`. */\n  children: ReactNode;\n  /**\n   * Layout only: margins, width, grid placement (`mt-4`, `col-span-2`). Your\n   * classes always win over Ouro UI's. Appearance classes warn in development;\n   * use `tone`, `variant` and `size` instead.\n   * @claim \"Your classes always win over Ouro\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::className > lets app layout classes win over library styles)\n   * @claim \"Your classes always win over Ouro\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::className > lets the app's height and padding win at desktop widths too)\n   */\n  className?: string | undefined;\n\n  /** Not a prop. Ouro UI uses `loading`: `<Button loading>`. */\n  isLoading?: { 'Use <Button loading>': never };\n  /** Not a prop. Ouro UI uses `tone`: `<Button tone=\"destructive\">`. */\n  color?: { 'Use <Button tone=\"destructive\">': never };\n  /** Not a prop. To render a link, pass `href`: `<Button href=\"/recipes\">`. For other elements, use parts. */\n  asChild?: { 'Use <Button href=\"/path\">': never };\n  /** Not a prop. Ouro UI uses `startIcon`: `<Button startIcon={PlusIcon}>`. */\n  leftIcon?: { 'Use <Button startIcon={Icon}>': never };\n  /** Not a prop. Ouro UI uses `endIcon`: `<Button endIcon={ArrowRightIcon}>`. */\n  rightIcon?: { 'Use <Button endIcon={Icon}>': never };\n}\n\n/** A Button with `href`: renders a link that looks like a button. */\nexport type ButtonLinkProps = ButtonBaseProps &\n  Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof ButtonBaseProps | \"type\"> & {\n    /**\n     * Where the link goes. Internal paths render through `OuroProvider`'s\n     * `linkComponent` (your router's link); `http(s)://`, `mailto:` and other\n     * absolute URLs render as a plain `<a>`. An absolute URL with\n     * `target=\"_blank\"` always gets `rel=\"noopener noreferrer\"`, merged with\n     * any `rel` you pass.\n     * @claim \"`, merged with any `rel` you pass.\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::link branch > merges an explicit rel with noopener noreferrer on an external _blank link)\n     */\n    href: string;\n    /**\n     * Loads the document instead of using the provider's router link, for a server sign-in\n     * or a resource route. A present `download` attribute does the same.\n     * @claim \"Loads the document instead of using\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::link branch > uses the document for reloadDocument and downloads, retaining router navigation otherwise)\n     */\n    reloadDocument?: boolean | undefined;\n    /**\n     * Links have no `type`. Remove `href` to make a submit button: `<Button type=\"submit\">`.\n     *\n     * @claim \"Links have no `type`\" registry/ouro/components/ouro/button/button.test-d.ts verify:fileLine(registry/ouro/components/ouro/button/button.test-d.ts, /\\{\\schildren:\\s\"Go\";\\shref:\\s\"\\/x\";\\stype:\\s\"submit\"\\s\\}>\\(\\)\\.not\\.toExtend<ButtonProps>/)\n     */\n    type?: never;\n    /** A link cannot be disabled. Remove `href` to render a disabled button, or don't render the link. */\n    disabled?: never;\n    /** A dialog's default action is a button. Remove `href`: `<Button default onClick={start}>`. */\n    default?: never;\n    ref?: Ref<HTMLAnchorElement> | undefined;\n  };\n\n/** A Button without `href`: renders a native `<button>`. */\nexport type ButtonButtonProps = ButtonBaseProps &\n  Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof ButtonBaseProps | \"type\"> & {\n    /** Not set: this is a `<button>`. Pass `href` to render a link instead. */\n    href?: never;\n    /** Document navigation needs a link: pass `href` with `reloadDocument`. */\n    reloadDocument?: never;\n    /**\n     * The button's role in a form: `submit` sends it, `reset` clears it.\n     * @default \"button\" (never submits a form by accident)\n     * @claim \"never submits a form by accident\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::button branch > renders a native button with type=button and data-ouro)\n     */\n    type?: \"button\" | \"submit\" | \"reset\" | (string & { 'Use \"button\", \"submit\" or \"reset\"; for looks use tone and variant': never }) | undefined;\n    /**\n     * The dialog's default action, as on a Mac: Return presses it from anywhere in the dialog\n     * around it, unless focus is in a multi-line field (where Command or Control Return presses\n     * it), on a control that takes Return itself (another button, a link, an option) or in a\n     * list that is open, or Shift or Option is held. Return calls `onClick` with the key's own\n     * `KeyboardEvent`, so an action that needs a person's gesture still gets one, and a submit\n     * button then sends its form once. It tells assistive technology so with\n     * `aria-keyshortcuts`. Give it to one button per dialog, the main action, and keep\n     * the solid look; outside a dialog it does nothing, since Return there belongs to the page.\n     * @claim \"The dialog's default action, as\" registry/ouro/components/ouro/button/button.default.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.default.test.tsx::Button default > is what Return presses from a field in its dialog, with the key's own trusted event)\n     * @claim \"Return presses it from anywhere\" registry/ouro/components/ouro/button/button.default.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.default.test.tsx::Button default > leaves Return to a multi-line field, and takes Command or Control Return from it)\n     * @claim \"Return presses it from anywhere\" registry/ouro/components/ouro/button/button.default.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.default.test.tsx::Button default > leaves Return to a control that takes it itself: another button, a link, a list's option and an open list)\n     * @claim \"Return presses it from anywhere\" registry/ouro/components/ouro/button/button.default.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.default.test.tsx::Button default > leaves Return alone with Shift or Option held, while an input method composes, or when the app took it)\n     * @claim \"Return calls `onClick` with the\" registry/ouro/components/ouro/button/button.default.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.default.test.tsx::Button default > is what Return presses from a field in its dialog, with the key's own trusted event)\n     * @claim \"and a submit button then\" registry/ouro/components/ouro/button/button.default.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.default.test.tsx::Button default > sends its form once as a submit button, and calls onClick alone without a form)\n     * @claim \"It tells assistive technology so\" registry/ouro/components/ouro/button/button.default.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.default.test.tsx::Button default > says so to assistive technology, and looks like the dialog's main action)\n     * @claim \"Give it to one button\" registry/ouro/components/ouro/button/button.default.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.default.test.tsx::Button default > does nothing outside a dialog, where Return belongs to the page)\n     */\n    default?: boolean | undefined;\n    ref?: Ref<HTMLButtonElement> | undefined;\n  };\n\n/** Props for {@link Button}. Passing `href` makes it a link; otherwise it is a `<button>`. */\nexport type ButtonProps = ButtonLinkProps | ButtonButtonProps;\n\n// Class strings are literal so the app's Tailwind finds them when it compiles.\nconst base =\n  \"press relative box-border inline-flex shrink-0 items-center justify-center align-middle \" +\n  \"rounded-ouro-lg border border-solid font-medium whitespace-nowrap \" +\n  \"no-underline select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  // A state layer in the text color: a light wash on hover, a deeper one while pressed.\n  \"before:pointer-events-none before:absolute before:-inset-px before:rounded-[inherit] before:[corner-shape:inherit] before:bg-current \" +\n  \"before:opacity-0 before:transition-opacity before:duration-(--ouro-duration-fast) before:ease-[ease] \" +\n  \"not-data-disabled:not-active:pointer-fine:hover:before:opacity-8 not-data-disabled:active:before:opacity-14 \" +\n  // Where corner-shape is missing, the surface slot paints the background, border and state layer instead (see ouro-base.css).\n  \"bg-(--ouro-bg) border-(--ouro-bd) [--ouro-sq-w:1px] [--ouro-sq-r:calc(var(--radius)*var(--ouro-radius-scale,1))] \" +\n  // Stryker disable next-line StringLiteral: a class string in a class position, which no test reads\n  \"not-data-disabled:not-active:pointer-fine:hover:[--ouro-state:0.08] not-data-disabled:active:[--ouro-state:0.14] \" +\n  // Press feedback: scale only when motion is allowed and the button is enabled.\n  \"motion-safe:not-data-disabled:active:scale-(--ouro-press-scale) \" +\n  \"disabled:cursor-not-allowed disabled:opacity-50 aria-busy:cursor-progress\";\n\n// Height and padding step down to desktop density at the `sm` breakpoint through two\n// variables, so the button has one unprefixed `h-*` and `px-*` class and the app's own\n// (`className=\"h-20\"`) replaces it at every width.\nconst density = \"h-(--ouro-button-h) px-(--ouro-button-px)\";\nconst sizes = {\n  sm:\n    `${density} gap-1.5 text-sm [--ouro-button-h:calc(var(--spacing)*9)] [--ouro-button-px:calc(var(--spacing)*3)] ` +\n    \"sm:[--ouro-button-h:calc(var(--spacing)*8)] sm:[--ouro-button-px:calc(var(--spacing)*2.5)]\",\n  md:\n    `${density} gap-2 text-base sm:text-sm [--ouro-button-h:calc(var(--spacing)*11)] [--ouro-button-px:calc(var(--spacing)*4)] ` +\n    \"sm:[--ouro-button-h:calc(var(--spacing)*9)] sm:[--ouro-button-px:calc(var(--spacing)*3.5)]\",\n  lg:\n    `${density} gap-2 text-base [--ouro-button-h:calc(var(--spacing)*12)] [--ouro-button-px:calc(var(--spacing)*5)] ` +\n    \"sm:[--ouro-button-h:calc(var(--spacing)*11)]\",\n  // In a line of text, at the text's own size: the padding takes the box to 24px and more, and the\n  // negative margin gives that back, so the line keeps its height and the label sits on its baseline.\n  inline: \"h-auto min-w-6 px-1 py-[3px] -my-1 gap-1 rounded-ouro-md align-baseline text-[length:inherit] leading-[inherit]\",\n} as const;\n\n// `soft` is the tone at low opacity behind text in the tone, the pattern shadcn uses for\n// destructive, with the text mixed 20% toward the foreground so it keeps 4.5:1 on the\n// tint under shadcn's stock values too (plain `text-destructive` there is 3.97:1). `secondary` is shadcn's: a quiet surface (`bg-secondary`) with its own\n// foreground, so its outline and plain text are the page's foreground. The primary outline's\n// text is the foreground too, as in shadcn, where --primary is a fill color: a theme whose primary\n// only just reaches 4.5:1 on its page loses it on any tinted surface around the button.\n// The solid primary is the page's main action: it reads --ouro-action and its foreground, which\n// fall back to --primary and --primary-foreground at the button itself (never in a :root rule,\n// so a theme scoped to part of the page still repaints it). A theme sets them to give the action\n// its own colour while selection (checkboxes, switches, the current tab) keeps --primary.\nconst looks = {\n  solid: {\n    primary:\n      \"[--ouro-bd:transparent] [--ouro-bg:var(--ouro-action,var(--primary))] text-(--ouro-action-foreground,var(--primary-foreground)) \" +\n      \"not-data-disabled:not-active:pointer-fine:hover:[--ouro-bg:var(--ouro-action-hover,var(--ouro-action,var(--primary)))] \" +\n      \"not-data-disabled:active:[--ouro-bg:var(--ouro-action-active,var(--ouro-action,var(--primary)))] \" +\n      \"data-disabled:[--ouro-bg:var(--ouro-action-disabled,var(--ouro-action,var(--primary)))] \" +\n      \"data-disabled:text-(--ouro-action-disabled-foreground,var(--ouro-action-foreground,var(--primary-foreground))) \" +\n      \"disabled:opacity-(--ouro-action-disabled-opacity,0.5)\",\n    secondary: \"[--ouro-bd:transparent] [--ouro-bg:var(--secondary)] text-secondary-foreground\",\n    destructive: \"[--ouro-bd:transparent] [--ouro-bg:var(--destructive)] text-destructive-foreground\",\n    success: \"[--ouro-bd:transparent] [--ouro-bg:var(--success)] text-success-foreground\",\n    warning: \"[--ouro-bd:transparent] [--ouro-bg:var(--warning)] text-warning-foreground\",\n  },\n  soft: {\n    primary: \"[--ouro-bd:transparent] [--ouro-bg:color-mix(in_oklab,var(--primary)_10%,transparent)] text-[color-mix(in_oklab,var(--primary)_80%,var(--foreground))] contrast-more:[--ouro-bd:currentColor]\",\n    secondary: \"[--ouro-bd:transparent] [--ouro-bg:color-mix(in_oklab,var(--secondary)_50%,transparent)] text-secondary-foreground contrast-more:[--ouro-bd:currentColor]\",\n    destructive: \"[--ouro-bd:transparent] [--ouro-bg:color-mix(in_oklab,var(--destructive)_10%,transparent)] text-[color-mix(in_oklab,var(--destructive)_80%,var(--foreground))] contrast-more:[--ouro-bd:currentColor]\",\n    success: \"[--ouro-bd:transparent] [--ouro-bg:color-mix(in_oklab,var(--success)_10%,transparent)] text-[color-mix(in_oklab,var(--success)_80%,var(--foreground))] contrast-more:[--ouro-bd:currentColor]\",\n    warning: \"[--ouro-bd:transparent] [--ouro-bg:color-mix(in_oklab,var(--warning)_10%,transparent)] text-[color-mix(in_oklab,var(--warning)_80%,var(--foreground))] contrast-more:[--ouro-bd:currentColor]\",\n  },\n  outline: {\n    primary: \"[--ouro-bd:color-mix(in_oklab,var(--primary)_45%,transparent)] [--ouro-bg:transparent] text-foreground\",\n    secondary: \"[--ouro-bd:var(--border)] [--ouro-bg:transparent] text-foreground\",\n    destructive: \"[--ouro-bd:color-mix(in_oklab,var(--destructive)_45%,transparent)] [--ouro-bg:transparent] text-destructive\",\n    success: \"[--ouro-bd:color-mix(in_oklab,var(--success)_45%,transparent)] [--ouro-bg:transparent] text-success\",\n    warning: \"[--ouro-bd:color-mix(in_oklab,var(--warning)_45%,transparent)] [--ouro-bg:transparent] text-warning\",\n  },\n  plain: {\n    primary: \"[--ouro-bd:transparent] [--ouro-bg:transparent] text-primary\",\n    secondary: \"[--ouro-bd:transparent] [--ouro-bg:transparent] text-foreground\",\n    destructive: \"[--ouro-bd:transparent] [--ouro-bg:transparent] text-destructive\",\n    success: \"[--ouro-bd:transparent] [--ouro-bg:transparent] text-success\",\n    warning: \"[--ouro-bd:transparent] [--ouro-bg:transparent] text-warning\",\n  },\n} as const;\n\nconst iconClass = \"size-[1.25em] shrink-0\";\n\n// An icon passed as children sizes like `startIcon`, unless it carries a size class of its own.\nconst iconChildClass =\n  \"[&>[data-ouro-label]>svg:not([class*='size-'])]:size-[1.25em] [&>[data-ouro-label]>svg]:shrink-0\";\n\nconst buttonTypes = [\"button\", \"submit\", \"reset\"] as const;\n\nfunction buttonHint(token: string): string {\n  const size = sizeFor(token, [\"sm\", \"sm\", \"md\", \"lg\", \"lg\", \"lg\", \"lg\"]);\n  if (size) return `size=\"${size}\"`;\n  if (token.startsWith(\"font-\")) return fontFor(\"Button\", token);\n  if (token.startsWith(\"rounded\")) return radiusFor(token);\n  if (/^(border|ring|shadow)/.test(token)) return 'variant=\"outline\"';\n  if (/^bg-(transparent|none)$/.test(token)) return 'variant=\"plain\"';\n  return `tone=\"${toneFor(token)}\"`;\n}\n\n/** shadcn's Button variants, with the Ouro UI props that do the same job. Development only. */\nconst shadcnVariants: Readonly<Record<string, string>> = {\n  default: \"<Button>\",\n  destructive: '<Button tone=\"destructive\">',\n  secondary: '<Button tone=\"secondary\">',\n  ghost: '<Button variant=\"plain\">',\n  link: '<Button variant=\"plain\" href=\"/path\">',\n};\n\n/** The dev message for a variant that is not one of Ouro UI's. */\nfunction variantWarning(variant: string): readonly [string, string] {\n  const fix = Object.hasOwn(shadcnVariants, variant) ? shadcnVariants[variant]! : '<Button variant=\"solid\">';\n  return [`variant=\"${variant}\" is not a variant`, fix];\n}\n\n/** The dev message for a size that is not one of Ouro UI's, such as shadcn's `default` and `icon`. */\nfunction sizeWarning(size: string): readonly [string, string] {\n  const fix = size === \"icon\" ? '<Button aria-label=\"Add\"><PlusIcon /></Button>' : '<Button size=\"md\">';\n  return [`size=\"${size}\" is not a size`, fix];\n}\n\nfunction Spinner(): JSX.Element {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"absolute inset-0 flex items-center justify-center transition-opacity duration-(--ouro-duration-base) ease-(--ouro-ease-out) starting:opacity-0\"\n    >\n      <svg\n        data-ouro-spinner=\"\"\n        viewBox=\"0 0 24 24\"\n        fill=\"none\"\n        className=\"size-[1.25em] animate-[ouro-spin_0.8s_linear_infinite] motion-reduce:animate-[ouro-pulse_1.6s_ease-in-out_infinite]\"\n      >\n        <circle cx=\"12\" cy=\"12\" r=\"9\" stroke=\"currentColor\" strokeWidth=\"2.5\" opacity=\"0.25\" />\n        <path d=\"M21 12a9 9 0 0 0-9-9\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" />\n      </svg>\n    </span>\n  );\n}\n\nconst preventDefault = (event: MouseEvent) => event.preventDefault();\n\n/** What takes Return itself, so a dialog's default action leaves it be: controls, links, options and an open list. */\nconst takesReturn =\n  \"button,a[href],select,[contenteditable]:not([contenteditable=false]),input:is([type=button],[type=submit],[type=reset],[type=checkbox],[type=radio],[type=file]),\" +\n  \"[role=button],[role=link],[role=menuitem],[role=menuitemcheckbox],[role=menuitemradio],[role=option],[role=checkbox],[role=radio],[role=switch],[role=tab],[role=treeitem],[aria-expanded=true]\";\n\n/** Whether this key press is Return for the default action of the dialog `root`. */\nfunction returnPresses(event: globalThis.KeyboardEvent, root: Element): boolean {\n  if (event.key !== \"Enter\" || event.defaultPrevented || event.isComposing || event.keyCode === 229 || event.shiftKey || event.altKey) return false;\n  const target = event.target as Element;\n  if (!root.contains(target)) return false;\n  if (target.matches(\"textarea\")) return event.metaKey || event.ctrlKey;\n  return !target.matches(takesReturn);\n}\n\n/**\n * A button, or a link styled as one. The obvious name for any action: pressing\n * it gives physical feedback, it has a 44px touch target on phones, and `loading`\n * handles the busy state without the layout jumping.\n *\n * Use `href` to navigate (it renders a link); use `type=\"submit\"` in a form.\n * Use `Text` with an `<a>` instead when a link sits inside running text.\n *\n * A button that opens a dialog says so with `aria-haspopup=\"dialog\"`; pressing it (or Enter or\n * Space on it) while the page smooth-scrolls then stops the page where it is until its click, so\n * the release lands on the button and the dialog opens.\n *\n * @group Actions\n * @see https://ui.ouroboros.bot/docs/button\n *\n * @example\n * <Button onClick={save} loading={saving}>Save</Button>\n * <Button href=\"/recipes/new\" startIcon={PlusIcon}>New recipe</Button>\n * <Button tone=\"destructive\" variant=\"soft\" type=\"submit\">Delete</Button>\n * @claim \"The obvious name for any action\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::press feedback > scales to --ouro-press-scale while pressed)\n * @claim \"then stops the page where it is until its click\" registry/ouro/components/ouro/button/button.test.tsx verify:fileLine(registry/ouro/components/ouro/button/button.test.tsx, /with aria-haspopup=\"dialog\", stops the scroll where/)\n * @claim \"then stops the page where it is until its click\" registry/ouro/components/ouro/dialog/dialog.test.tsx verify:fileLine(registry/ouro/components/ouro/dialog/dialog.test.tsx, /opens and leaves the page where the press found it, pressed mid-scroll/)\n * @claim \"The obvious name for any action\" registry/ouro/components/ouro/button/button.touch.test.tsx verify:fileLine(registry/ouro/components/ouro/button/button.touch.test.tsx, /44px hit area on a coarse pointer/)\n * @claim \"The obvious name for any action\" registry/ouro/components/ouro/button/button.test.tsx verify:testExists(registry/ouro/components/ouro/button/button.test.tsx::loading > sets aria-busy, disables without losing focus, and keeps the width within 1px)\n */\nexport function Button(props: ButtonProps): JSX.Element {\n  const {\n    tone: toneProp = \"primary\",\n    variant: variantProp = \"solid\",\n    size: sizeProp = \"md\",\n    fullWidth,\n    loading,\n    loadingLabel = \"Loading\",\n    startIcon: StartIcon,\n    endIcon: EndIcon,\n    children,\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    isLoading,\n    color,\n    asChild,\n    leftIcon,\n    rightIcon,\n    reloadDocument,\n    default: isDefault,\n    ...rest\n  } = props;\n  // A tone, variant or size that is not one of Ouro UI's (a type error) warns and renders the default.\n  const tone = Object.hasOwn(looks.solid, toneProp) ? (toneProp as keyof typeof looks.solid) : \"primary\";\n  const variant = Object.hasOwn(looks, variantProp) ? (variantProp as keyof typeof looks) : \"solid\";\n  const size = Object.hasOwn(sizes, sizeProp) ? (sizeProp as keyof typeof sizes) : \"md\";\n  useAppearanceClassNameCheck(\n    \"Button\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? buttonHint : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Button\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => {\n          const link = rest as { href?: string; type?: string; disabled?: boolean };\n          return [\n            tone !== toneProp && toneWarning(\"Button\", String(toneProp), Object.keys(looks.solid)),\n            variant !== variantProp && variantWarning(String(variantProp)),\n            size !== sizeProp && sizeWarning(String(sizeProp)),\n            isLoading !== undefined && [\"isLoading is not a prop\", \"<Button loading>\"],\n            color !== undefined && [\"color is not a prop\", `<Button tone=\"${toneFor(`bg-${String(color)}`)}\">`],\n            asChild !== undefined && [\"asChild is not a prop\", '<Button href=\"/path\">'],\n            leftIcon !== undefined && [\"leftIcon is not a prop\", \"<Button startIcon={Icon}>\"],\n            rightIcon !== undefined && [\"rightIcon is not a prop\", \"<Button endIcon={Icon}>\"],\n            link.href === undefined &&\n              link.type !== undefined &&\n              !buttonTypes.includes(link.type as (typeof buttonTypes)[number]) && [\n                `type=\"${link.type}\" is not a button type; use \"button\", \"submit\", \"reset\"`,\n                Object.hasOwn(looks.solid, link.type) ? `<Button tone=\"${link.type}\">` : '<Button type=\"button\">',\n              ],\n            link.href === undefined &&\n              reloadDocument !== undefined && [\"reloadDocument needs href\", '<Button href=\"/path\" reloadDocument>'],\n            link.href !== undefined &&\n              link.type !== undefined && [\n                `a link has no type, so type=\"${link.type}\" is ignored`,\n                `<Button type=\"${link.type}\"> without href`,\n              ],\n            link.href !== undefined &&\n              link.disabled !== undefined && [\"a link cannot be disabled\", \"<Button disabled> without href\"],\n          ];\n        }\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  // Speak the busy state when loading turns on. The shared region sits outside the\n  // button, so the button's accessible name stays exactly its label.\n  const wasLoading = useRef(loading);\n  useEffect(() => {\n    if (loading && !wasLoading.current) announce(loadingLabel);\n    wasLoading.current = loading;\n  }, [loading, loadingLabel]);\n\n  // The default action listens on the document, after React's own handlers, so a key the app took\n  // (an open list's Return) is seen as taken; the button's latest onClick gets the key's own event.\n  const own = useRef<HTMLElement | null>(null);\n  const press = useRef<((event: globalThis.KeyboardEvent) => void) | undefined>(undefined);\n  const onClick = (rest as unknown as { onClick?: (event: globalThis.KeyboardEvent) => void }).onClick;\n  useEffect(() => {\n    press.current = onClick;\n  });\n  const pressable = isDefault && rest.href === undefined && !(rest as { disabled?: boolean }).disabled && !loading;\n  useEffect(() => {\n    const root = pressable ? own.current!.closest(\"[role=dialog],[role=alertdialog]\") : null;\n    if (!root) return undefined;\n    const onKeyDown = (event: globalThis.KeyboardEvent) => {\n      if (!returnPresses(event, root)) return;\n      event.preventDefault();\n      press.current?.(event);\n      // A submit button sends its form, once: the browser's own submit on Return was prevented above.\n      const button = own.current as HTMLButtonElement;\n      if (button.type === \"submit\") button.form?.requestSubmit(button);\n    };\n    root.ownerDocument.addEventListener(\"keydown\", onKeyDown);\n    return () => root.ownerDocument.removeEventListener(\"keydown\", onKeyDown);\n  }, [pressable]);\n\n  const buttonRef = useMergedRef((rest as { ref?: Ref<HTMLElement> }).ref, own);\n  const classes = cn(base, iconChildClass, sizes[size], looks[variant][tone], fullWidth && \"w-full\", className);\n\n  // The touch target comes first and the label is positioned, so the label paints above\n  // the target: the target still enlarges the hit area, and nothing covers the text\n  // (axe can check its contrast).\n  const fade = cn(\"relative transition-opacity duration-(--ouro-duration-fast) ease-(--ouro-ease-out)\", loading && \"opacity-0\");\n  const content = (\n    <>\n      <TouchTarget />\n      <span data-ouro-surface=\"\" aria-hidden=\"true\" />\n      <span\n        data-ouro-label=\"\"\n        // The label takes the room a wider button has, aligned as the button aligns it (centred, or the app's\n        // justify-start), so an end icon after it sits at the end.\n        className={cn(\"inline-flex grow items-center gap-[inherit] [justify-content:inherit]\", fade)}\n      >\n        {StartIcon && <StartIcon aria-hidden=\"true\" className={cn(iconClass, \"-ms-0.5\")} />}\n        {children}\n      </span>\n      {EndIcon && <EndIcon aria-hidden=\"true\" className={cn(iconClass, fade, \"-me-0.5\")} />}\n      {loading && <Spinner />}\n    </>\n  );\n\n  if (rest.href !== undefined) {\n    // `type` and `disabled` are typed `never` on links; drop them if they arrive anyway.\n    const { onClick, type: _type, disabled: _disabled, ...anchorProps } = rest as Omit<ButtonLinkProps, keyof ButtonBaseProps>;\n    return (\n      <RouterLink\n        data-ouro-control=\"button\"\n        data-ouro-part=\"root\"\n        {...anchorProps}\n        reloadDocument={reloadDocument}\n        onClick={loading ? preventDefault : onClick}\n        onAuxClick={loading ? preventDefault : anchorProps.onAuxClick}\n        className={classes}\n        data-ouro=\"button\"\n        data-ouro-squircle=\"\"\n        data-variant={variant}\n        data-tone={tone}\n        data-loading={loading ? \"\" : undefined}\n        data-disabled={loading ? \"\" : undefined}\n        aria-busy={loading || anchorProps[\"aria-busy\"]}\n        aria-disabled={loading || anchorProps[\"aria-disabled\"]}\n      >\n        {content}\n      </RouterLink>\n    );\n  }\n\n  // Stryker disable next-line StringLiteral: a type that is not a button type renders \"button\", so \"\" does too.\n  const { ref: _ref, disabled, type: typeProp = \"button\", ...buttonProps } = rest as Omit<ButtonButtonProps, keyof ButtonBaseProps>;\n  // A button that opens a dialog (its own, or a component's trigger) holds the page from the press,\n  // so a release during a smooth scroll lands on it and its click opens the dialog.\n  const holdsPage =\n    buttonProps[\"aria-haspopup\"] === \"dialog\"\n      ? {\n          onPointerDown: (event: PointerEvent<HTMLButtonElement>) => {\n            buttonProps.onPointerDown?.(event);\n            holdPageAtPress.dialog.onPointerDown(event);\n          },\n          onKeyDown: (event: KeyboardEvent<HTMLButtonElement>) => {\n            buttonProps.onKeyDown?.(event);\n            holdPageAtPress.dialog.onKeyDown(event);\n          },\n        }\n      : {};\n  // A type that is not a button type would submit forms (the browser's default), so it renders \"button\".\n  const type = buttonTypes.includes(typeProp as (typeof buttonTypes)[number]) ? (typeProp as (typeof buttonTypes)[number]) : \"button\";\n  return (\n    <BaseButton\n      data-ouro-control=\"button\"\n      data-ouro-part=\"root\"\n      {...buttonProps}\n      {...holdsPage}\n      ref={buttonRef}\n      type={type}\n      disabled={Boolean(disabled || loading)}\n      focusableWhenDisabled={Boolean(loading && !disabled)}\n      className={classes}\n      data-ouro=\"button\"\n      data-ouro-squircle=\"\"\n      data-variant={variant}\n      data-tone={tone}\n      data-loading={loading ? \"\" : undefined}\n      data-default={isDefault ? \"\" : undefined}\n      aria-keyshortcuts={isDefault ? \"Enter\" : buttonProps[\"aria-keyshortcuts\"]}\n      aria-busy={loading || buttonProps[\"aria-busy\"]}\n    >\n      {content}\n    </BaseButton>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/button/button.tsx"
    }
  ],
  "docs": "A button, or a link styled as one. Import: import { Button } from \"@/components/ouro/button/button\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/button.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}