feature/share-libs
tsx 58 lines 1.82 KB
Raw
1 "use client";
2
3 import * as React from 'react'
4 import { Slot } from '@radix-ui/react-slot'
5 import { cva, type VariantProps } from 'class-variance-authority'
6 import { cn } from '@/lib/utils'
7
8 const buttonVariants = cva(
9 'inline-flex items-center justify-center rounded-md text-sm font-medium shadow ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
10 {
11 variants: {
12 variant: {
13 default:
14 'bg-primary text-primary-foreground shadow-md hover:bg-primary/90',
15 destructive:
16 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
17 outline:
18 'border border-input hover:bg-accent hover:text-accent-foreground',
19 secondary:
20 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
21 ghost: 'shadow-none hover:bg-accent hover:text-accent-foreground',
22 link: 'text-primary underline-offset-4 shadow-none hover:underline'
23 },
24 size: {
25 default: 'h-8 px-4 py-2',
26 sm: 'h-8 rounded-md px-3',
27 lg: 'h-11 rounded-md px-8',
28 icon: 'size-8 p-0'
29 }
30 },
31 defaultVariants: {
32 variant: 'default',
33 size: 'default'
34 }
35 }
36 )
37
38 export interface ButtonProps
39 extends React.ButtonHTMLAttributes<HTMLButtonElement>,
40 VariantProps<typeof buttonVariants> {
41 asChild?: boolean
42 }
43
44 const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
45 ({ className, variant, size, asChild = false, ...props }, ref) => {
46 const Comp = asChild ? Slot : 'button'
47 return (
48 <Comp
49 className={cn(buttonVariants({ variant, size, className }))}
50 ref={ref}
51 {...props}
52 />
53 )
54 }
55 )
56 Button.displayName = 'Button'
57
58 export { Button, buttonVariants }