Button
Dark, glass, crimson and ghost variants in four sizes.
npx shadcn@latest add https://ui.thjsecurity.tech/r/button.jsonPulls the component into components/ui/button.tsx and its token dependencies. The app owns the copy from then on.
@radix-ui/react-slotclass-variance-authority
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
/** The console's buttons: `default` is the white `.btn-dark`, `outline` and
* `secondary` the glass `.btn`, `destructive` the crimson `.btn-signal`.
* The button owns its icon: 16px at the default size (14 small, 18 large)
* with one gap, so an icon inside never needs a size or a margin. */
const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-xl border text-[13px] font-semibold leading-none transition-colors [&_svg]:size-[16px] [&_svg]:shrink-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-signal focus-visible:ring-offset-2 focus-visible:ring-offset-ink disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
default: "border-paper-strong bg-paper-strong text-ink hover:border-paper-dim hover:bg-paper-dim",
destructive: "border-signal bg-signal text-white hover:border-authority-strong hover:bg-authority-strong",
outline:
"border-glass-border bg-glass text-paper hover:border-rule-hot hover:bg-glass-hover hover:text-paper-strong",
secondary:
"border-glass-border bg-glass-strong text-paper hover:border-rule-hot hover:bg-glass-strong hover:text-paper-strong",
ghost: "border-transparent text-paper-dim hover:bg-glass-hover hover:text-paper-strong",
link: "border-transparent text-signal underline-offset-4 hover:underline",
},
size: {
default: "h-9 px-3.5",
sm: "h-[30px] gap-1.5 rounded-[10px] px-3 text-[12px] [&_svg]:size-[14px]",
lg: "h-11 px-6 text-[14px] [&_svg]:size-[18px]",
icon: "h-9 w-9 [&_svg]:size-[17px]",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button"
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
)
}
)
Button.displayName = "Button"
export { Button, buttonVariants }