-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathButton.tsx
More file actions
35 lines (29 loc) · 892 Bytes
/
Button.tsx
File metadata and controls
35 lines (29 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Slot } from '@radix-ui/react-slot'
import type { VariantProps } from 'class-variance-authority'
import React from 'react'
import { cn } from '@/utils'
import { buttonVariants } from './help'
import type { ButtonType } from './help'
import './Button.css'
const DEFAULT_BUTTON_TYPE = 'button'
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
type?: ButtonType
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, type, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : DEFAULT_BUTTON_TYPE
return (
<Comp
type={type}
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
)
},
)
Button.displayName = 'Button'
export { Button }