Files
Minikura/apps/web/components/ui/button.tsx
T

61 lines
2.2 KiB
TypeScript
Raw Normal View History

2026-02-13 15:52:13 +07:00
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
2026-02-17 18:12:02 +07:00
import type * as React from "react";
2026-02-13 15:52:13 +07:00
2026-02-17 18:12:02 +07:00
import { cn } from "@/lib/cn";
2026-02-13 15:52:13 +07:00
const buttonVariants = cva(
2026-08-13 01:58:09 +07:00
"inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-sm border border-transparent text-sm font-bold tracking-[-0.01em] transition-[background-color,color,border-color,transform,box-shadow] disabled:pointer-events-none disabled:opacity-50 active:translate-y-px [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 outline-none focus-visible:ring-ring/40 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 aria-invalid:border-destructive",
2026-02-13 15:52:13 +07:00
{
variants: {
variant: {
2026-08-13 01:58:09 +07:00
default:
"border-foreground bg-primary text-primary-foreground shadow-[3px_3px_0_var(--foreground)] hover:-translate-y-0.5 hover:shadow-[4px_4px_0_var(--foreground)]",
2026-02-13 15:52:13 +07:00
destructive:
2026-08-13 01:58:09 +07:00
"border-destructive bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20",
outline: "border-border bg-card text-foreground hover:border-foreground hover:bg-accent",
secondary: "border-border bg-secondary text-secondary-foreground hover:border-foreground",
ghost: "text-current hover:bg-accent hover:text-accent-foreground",
2026-02-13 15:52:13 +07:00
link: "text-primary underline-offset-4 hover:underline",
},
size: {
2026-08-13 01:58:09 +07:00
default: "h-10 px-4 py-2 has-[>svg]:px-3",
sm: "h-8 gap-1.5 px-3 has-[>svg]:px-2.5",
lg: "h-12 px-6 has-[>svg]:px-4",
icon: "size-10",
2026-02-13 15:52:13 +07:00
"icon-sm": "size-8",
"icon-lg": "size-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
);
function Button({
className,
variant = "default",
size = "default",
asChild = false,
...props
}: React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean;
}) {
const Comp = asChild ? Slot : "button";
return (
<Comp
data-slot="button"
data-variant={variant}
data-size={size}
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
);
}
export { Button, buttonVariants };