50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import { Button as ButtonPrimitive } from "@base-ui/react/button"
|
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
|
|
const buttonVariants = cva(
|
|
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-[background-color,border-color,color,box-shadow,transform] duration-150 ease-out outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:scale-[0.96] disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
{
|
|
variants: {
|
|
variant: {
|
|
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
outline: "border-border bg-background hover:bg-muted hover:text-foreground",
|
|
secondary: "bg-secondary text-secondary-foreground hover:bg-muted",
|
|
ghost: "hover:bg-muted hover:text-foreground",
|
|
destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20",
|
|
link: "text-primary underline-offset-4 hover:underline",
|
|
},
|
|
size: {
|
|
default: "h-11 gap-2 px-4",
|
|
sm: "h-11 gap-1.5 px-3 text-xs",
|
|
lg: "h-12 gap-2 px-5",
|
|
icon: "size-11",
|
|
"icon-sm": "size-11",
|
|
"icon-lg": "size-12",
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
variant: "default",
|
|
size: "default",
|
|
},
|
|
}
|
|
)
|
|
|
|
function Button({
|
|
className,
|
|
variant = "default",
|
|
size = "default",
|
|
...props
|
|
}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {
|
|
return (
|
|
<ButtonPrimitive
|
|
data-slot="button"
|
|
className={cn(buttonVariants({ variant, size, className }))}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export { Button, buttonVariants }
|