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