OpChan/app/src/components/ui/button.tsx

29 lines
763 B
TypeScript
Raw Normal View History

2025-08-30 18:34:50 +05:30
import * as React from 'react';
import { Slot } from '@radix-ui/react-slot';
import { type VariantProps } from 'class-variance-authority';
2025-04-15 16:28:03 +05:30
2025-10-03 19:00:01 +05:30
import { cn } from '../../utils';
2025-08-30 18:34:50 +05:30
import { buttonVariants } from './button-variants';
2025-04-15 16:28:03 +05:30
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
2025-08-30 18:34:50 +05:30
asChild?: boolean;
2025-04-15 16:28:03 +05:30
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
2025-08-30 18:34:50 +05:30
const Comp = asChild ? Slot : 'button';
2025-04-15 16:28:03 +05:30
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
2025-08-30 18:34:50 +05:30
);
2025-04-15 16:28:03 +05:30
}
2025-08-30 18:34:50 +05:30
);
Button.displayName = 'Button';
2025-04-15 16:28:03 +05:30
2025-08-30 18:34:50 +05:30
export { Button };