{
  "name": "button",
  "type": "registry:ui",
  "framework": "react",
  "title": "Button",
  "description": "Displays a Discord-styled button with brand, secondary, success, danger, link and icon variants.",
  "dependencies": [
    "class-variance-authority"
  ],
  "files": [
    {
      "path": "ui/button.tsx",
      "content": "import { cva, type VariantProps } from \"class-variance-authority\"\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst buttonVariants = cva(\n  \"inline-flex cursor-pointer select-none items-center justify-center gap-2 whitespace-nowrap border-0 font-[family-name:var(--newt-font-sans)] font-medium leading-4 transition-[background-color,color,box-shadow] duration-fast ease-newt active:translate-y-[0.5px] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link disabled:cursor-not-allowed disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:cursor-not-allowed aria-disabled:opacity-50 no-underline\",\n  {\n    variants: {\n      variant: {\n        primary:\n          \"bg-newt-brand text-newt-on-accent hover:bg-newt-brand-hover active:bg-newt-brand-active\",\n        secondary:\n          \"bg-newt-bg-elevated text-newt-text-primary hover:bg-newt-bg-hover\",\n        danger: \"bg-newt-danger text-newt-on-accent hover:bg-newt-danger-hover\",\n        success: \"bg-newt-online text-newt-on-accent hover:brightness-90\",\n        link: \"bg-transparent text-newt-text-link hover:underline\",\n      },\n      size: {\n        default: \"rounded-[var(--newt-radius-sm)] px-4 py-2.5 text-sm\",\n        sm: \"rounded-[var(--newt-radius-sm)] px-3 py-1.5 text-[13px]\",\n        /*\n         * 32px, the height of a button in a message's action row. The height\n         * is fixed, so an emoji image, a leading icon or the link variant\n         * cannot make one button of the row taller or shorter.\n         */\n        message: \"h-8 rounded-[var(--newt-radius-sm)] px-4 py-0 text-sm\",\n        lg: \"rounded-[var(--newt-radius-sm)] px-6 py-3 text-base\",\n        icon: \"rounded-full p-2 text-sm\",\n      },\n    },\n    compoundVariants: [\n      { variant: \"link\", size: \"default\", class: \"px-0 py-1\" },\n      { variant: \"link\", size: \"sm\", class: \"px-0 py-1\" },\n      { variant: \"link\", size: \"message\", class: \"px-0\" },\n      { variant: \"link\", size: \"lg\", class: \"px-0 py-1\" },\n    ],\n    defaultVariants: {\n      variant: \"primary\",\n      size: \"default\",\n    },\n  }\n)\n\n/* The \"opens elsewhere\" glyph Discord puts on link buttons. */\nconst LaunchIcon = () => (\n  <svg\n    viewBox=\"0 0 24 24\"\n    aria-hidden=\"true\"\n    focusable=\"false\"\n    className=\"h-4 w-4 shrink-0\"\n  >\n    <path\n      fill=\"currentColor\"\n      d=\"M10 5a1 1 0 0 0 0 2h6.59L4.3 19.3a1 1 0 1 0 1.4 1.4L18 8.42V15a1 1 0 1 0 2 0V6a1 1 0 0 0-1-1h-9Z\"\n    />\n  </svg>\n)\n\nexport interface ButtonProps\n  extends\n    React.ButtonHTMLAttributes<HTMLButtonElement>,\n    VariantProps<typeof buttonVariants> {\n  /**\n   * The element or component to render. Defaults to `button`, or to `a` when\n   * `href` is set; pass a router link component to keep client navigation.\n   */\n  as?: React.ElementType\n  /** Render a link to this URL. */\n  href?: string\n  /** Link target, with `href`. */\n  target?: React.AnchorHTMLAttributes<HTMLAnchorElement>[\"target\"]\n  /** Link relationship, with `href`. */\n  rel?: string\n  /** Emoji image URL, rendered before the label. */\n  emoji?: string\n  /** Accessible name for `emoji`; empty (the default) hides it from readers. */\n  emojiAlt?: string\n  /**\n   * Content before the label, such as an icon component or a unicode emoji.\n   * It sits in its own box, so the button's gap separates it from the label.\n   */\n  leading?: React.ReactNode\n  /** Content after the label, before the link-out glyph. */\n  trailing?: React.ReactNode\n  /** Link-out glyph after the label. Defaults on for `variant=\"link\"`. */\n  launchIcon?: boolean\n}\n\n/*\n * No box without content: an empty box would still take a gap and push an\n * emoji-only button off centre. `toArray` drops `null`, `undefined` and\n * booleans, so `leading={cond && <Icon />}` leaves no box when `cond` is false.\n */\nfunction renders(node: React.ReactNode): boolean {\n  return React.Children.toArray(node).length > 0\n}\n\nconst Button = React.forwardRef<HTMLElement, ButtonProps>(\n  (\n    {\n      as,\n      className,\n      variant,\n      size,\n      type = \"button\",\n      href,\n      disabled,\n      emoji,\n      emojiAlt = \"\",\n      leading,\n      trailing,\n      launchIcon,\n      children,\n      ...props\n    },\n    ref\n  ) => {\n    const Tag: React.ElementType = as ?? (href === undefined ? \"button\" : \"a\")\n    const isButton = Tag === \"button\"\n    const showLaunch = launchIcon ?? variant === \"link\"\n    return (\n      <Tag\n        ref={ref}\n        type={isButton ? type : undefined}\n        /*\n         * A link has no `disabled`: it loses its `href` instead, which takes\n         * it out of the tab order, and says so with `aria-disabled`.\n         */\n        href={disabled ? undefined : href}\n        disabled={isButton ? disabled : undefined}\n        aria-disabled={!isButton && disabled ? true : undefined}\n        className={cn(buttonVariants({ variant, size }), className)}\n        {...props}\n      >\n        {emoji ? (\n          <img\n            src={emoji}\n            alt={emojiAlt}\n            aria-hidden={emojiAlt === \"\" ? true : undefined}\n            draggable={false}\n            className=\"h-[1.375em] w-[1.375em] shrink-0 object-contain align-bottom\"\n          />\n        ) : null}\n        {renders(leading) ? (\n          <span className=\"inline-flex shrink-0 items-center\">{leading}</span>\n        ) : null}\n        {renders(children) ? (\n          <span className=\"truncate\">{children}</span>\n        ) : null}\n        {renders(trailing) ? (\n          <span className=\"inline-flex shrink-0 items-center\">{trailing}</span>\n        ) : null}\n        {showLaunch ? <LaunchIcon /> : null}\n      </Tag>\n    )\n  }\n)\nButton.displayName = \"Button\"\n\nexport { Button, buttonVariants }\n",
      "type": "registry:ui"
    }
  ]
}