-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy pathButton.tsx
More file actions
40 lines (35 loc) · 1.03 KB
/
Button.tsx
File metadata and controls
40 lines (35 loc) · 1.03 KB
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
36
37
38
39
40
import * as React from 'react'
import { twMerge } from 'tailwind-merge'
export const buttonStyles = [
'flex items-center gap-1.5 rounded-md px-2 py-1.5',
'border border-gray-200 dark:border-gray-700',
'hover:bg-gray-100 dark:hover:bg-gray-800',
'cursor-pointer transition-colors duration-200 text-xs font-medium',
].join(' ')
type ButtonOwnProps<TElement extends React.ElementType = 'button'> = {
as?: TElement
children: React.ReactNode
className?: string
}
type ButtonProps<TElement extends React.ElementType = 'button'> =
ButtonOwnProps<TElement> &
Omit<
React.ComponentPropsWithoutRef<TElement>,
keyof ButtonOwnProps<TElement>
>
type ButtonComponent = <TElement extends React.ElementType = 'button'>(
props: ButtonProps<TElement>,
) => React.ReactNode
export const Button: ButtonComponent = ({
as,
children,
className,
...props
}) => {
const Component = as || 'button'
return React.createElement(
Component,
{ className: twMerge(buttonStyles, className), ...props },
children,
)
}