tasko/components/ui/button.tsx

61 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-02-16 01:49:19 +00:00
import * as React from 'react';
import { Slot } from '@radix-ui/react-slot';
import { cva, type VariantProps } from 'class-variance-authority';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { cn } from '@/lib/utils';
2024-02-15 02:30:10 +00:00
const buttonVariants = cva(
2024-02-16 01:49:19 +00:00
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium 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',
2024-02-15 02:30:10 +00:00
{
variants: {
variant: {
2024-02-16 01:49:19 +00:00
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
2024-02-15 02:30:10 +00:00
destructive:
2024-02-16 01:49:19 +00:00
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
2024-02-15 02:30:10 +00:00
outline:
2024-02-16 01:49:19 +00:00
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
2024-02-15 02:30:10 +00:00
secondary:
2024-02-16 01:49:19 +00:00
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'text-primary underline-offset-4 hover:underline',
primary: 'bg-sky-700 text-primary-foreground hover:bg-sky-700/90',
transparent: 'bg-transparent text-white hover:bg-white/20',
gray: 'bg-neutral-200 text-secondary-foreground hover:bg-neutral-300',
2024-02-15 02:30:10 +00:00
},
size: {
2024-02-16 01:49:19 +00:00
default: 'h-10 px-4 py-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-11 rounded-md px-8',
icon: 'h-10 w-10',
inline: 'h-auto px-2 py-1.5 text-sm',
2024-02-15 02:30:10 +00:00
},
},
defaultVariants: {
2024-02-16 01:49:19 +00:00
variant: 'default',
size: 'default',
2024-02-15 02:30:10 +00:00
},
}
);
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) => {
2024-02-16 01:49:19 +00:00
const Comp = asChild ? Slot : 'button';
2024-02-15 02:30:10 +00:00
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
);
}
);
2024-02-16 01:49:19 +00:00
Button.displayName = 'Button';
2024-02-15 02:30:10 +00:00
export { Button, buttonVariants };