mirror of
https://github.com/ershisan99/lib-with-storybook-starter.git
synced 2025-12-16 20:59:22 +00:00
24 lines
761 B
TypeScript
24 lines
761 B
TypeScript
import { ComponentPropsWithoutRef, ElementType } from 'react'
|
|
|
|
import { clsx } from 'clsx'
|
|
|
|
import s from './button.module.scss'
|
|
|
|
export const buttonVariant = ['icon', 'link', 'primary', 'secondary', 'tertiary'] as const
|
|
|
|
export type ButtonVariant = (typeof buttonVariant)[number]
|
|
|
|
export type ButtonProps<T extends ElementType = 'button'> = {
|
|
as?: T
|
|
fullWidth?: boolean
|
|
variant?: ButtonVariant
|
|
} & ComponentPropsWithoutRef<T>
|
|
|
|
export const Button = <T extends ElementType = 'button'>(props: ButtonProps<T>) => {
|
|
const { as: Component = 'button', className, fullWidth, variant = 'primary', ...rest } = props
|
|
|
|
const classNames = clsx(s.button, s[variant], fullWidth && s.fullWidth, className)
|
|
|
|
return <Component className={classNames} {...rest} />
|
|
}
|