2025-02-01 00:43:21 +08:00
|
|
|
import { cva, type VariantProps } from 'class-variance-authority'
|
2025-02-20 07:01:36 +08:00
|
|
|
import type { ReactNode, ElementType, ComponentPropsWithoutRef } from 'react'
|
2025-02-01 00:43:21 +08:00
|
|
|
import { twMerge } from 'tailwind-merge'
|
|
|
|
|
|
|
|
|
|
const buttonVariants = cva(
|
|
|
|
|
'inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0',
|
|
|
|
|
{
|
|
|
|
|
variants: {
|
|
|
|
|
variant: {
|
|
|
|
|
newsPrimary: 'bg-[#2E2F7C] text-white text-lg',
|
2025-02-01 15:52:08 +08:00
|
|
|
newsPrimaryOutline: 'border-[3px] border-white text-white text-lg',
|
2025-02-01 00:43:21 +08:00
|
|
|
newsSecondary: 'border-[3px] border-[#2E2F7C] text-[#2E2F7C] text-lg',
|
2025-02-01 04:59:28 +08:00
|
|
|
icon: '',
|
2025-02-01 00:43:21 +08:00
|
|
|
},
|
|
|
|
|
size: {
|
|
|
|
|
default: 'h-[50px] w-[150px]',
|
|
|
|
|
block: 'h-[50px] w-full',
|
2025-02-01 04:59:28 +08:00
|
|
|
icon: 'h-9 w-9',
|
2025-02-20 01:37:35 +07:00
|
|
|
sm: 'h-8 rounded-md px-3 text-xs',
|
|
|
|
|
lg: 'h-10 rounded-md px-8',
|
2025-02-01 00:43:21 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
defaultVariants: {
|
|
|
|
|
variant: 'newsPrimary',
|
|
|
|
|
size: 'default',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
2025-02-20 07:01:36 +08:00
|
|
|
type ButtonBaseProperties = {
|
2025-02-01 00:43:21 +08:00
|
|
|
children: ReactNode
|
|
|
|
|
variant?: VariantProps<typeof buttonVariants>['variant']
|
|
|
|
|
size?: VariantProps<typeof buttonVariants>['size']
|
2025-02-20 07:01:36 +08:00
|
|
|
className?: string
|
2025-02-01 00:43:21 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-20 07:01:36 +08:00
|
|
|
type PolymorphicReference<C extends ElementType> =
|
|
|
|
|
ComponentPropsWithoutRef<C>['ref']
|
|
|
|
|
|
|
|
|
|
type ButtonProperties<C extends ElementType> = ButtonBaseProperties & {
|
|
|
|
|
as?: C
|
|
|
|
|
ref?: PolymorphicReference<C>
|
|
|
|
|
} & Omit<ComponentPropsWithoutRef<C>, keyof ButtonBaseProperties>
|
|
|
|
|
|
|
|
|
|
export const Button = <C extends ElementType = 'button'>({
|
|
|
|
|
as,
|
|
|
|
|
children,
|
|
|
|
|
variant,
|
|
|
|
|
size,
|
|
|
|
|
className,
|
|
|
|
|
...properties
|
|
|
|
|
}: ButtonProperties<C>) => {
|
|
|
|
|
const Component = as || 'button'
|
|
|
|
|
const classes = twMerge(buttonVariants({ variant, size, className }))
|
|
|
|
|
|
2025-02-01 00:43:21 +08:00
|
|
|
return (
|
2025-02-20 07:01:36 +08:00
|
|
|
<Component
|
|
|
|
|
className={classes}
|
|
|
|
|
{...properties}
|
2025-02-01 00:43:21 +08:00
|
|
|
>
|
|
|
|
|
{children}
|
2025-02-20 07:01:36 +08:00
|
|
|
</Component>
|
2025-02-01 00:43:21 +08:00
|
|
|
)
|
2025-01-31 19:34:22 +08:00
|
|
|
}
|