mirror of
https://github.com/langgenius/dify.git
synced 2026-04-17 20:09:34 +08:00
71 lines
1.6 KiB
TypeScript
71 lines
1.6 KiB
TypeScript
import type { Button as BaseButtonNS } from '@base-ui/react/button'
|
|
import type { VariantProps } from 'class-variance-authority'
|
|
import { Button as BaseButton } from '@base-ui/react/button'
|
|
import { cva } from 'class-variance-authority'
|
|
import { cn } from '@/utils/classnames'
|
|
|
|
const buttonVariants = cva(
|
|
'btn',
|
|
{
|
|
variants: {
|
|
variant: {
|
|
'primary': 'btn-primary',
|
|
'secondary': 'btn-secondary',
|
|
'secondary-accent': 'btn-secondary-accent',
|
|
'ghost': 'btn-ghost',
|
|
'ghost-accent': 'btn-ghost-accent',
|
|
'tertiary': 'btn-tertiary',
|
|
},
|
|
size: {
|
|
small: 'btn-small',
|
|
medium: 'btn-medium',
|
|
large: 'btn-large',
|
|
},
|
|
destructive: {
|
|
true: 'btn-destructive',
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
variant: 'secondary',
|
|
size: 'medium',
|
|
},
|
|
},
|
|
)
|
|
|
|
export type ButtonProps
|
|
= Omit<BaseButtonNS.Props, 'className'>
|
|
& VariantProps<typeof buttonVariants> & {
|
|
loading?: boolean
|
|
className?: string
|
|
}
|
|
|
|
export function Button({
|
|
className,
|
|
variant,
|
|
size,
|
|
destructive,
|
|
loading,
|
|
disabled,
|
|
type = 'button',
|
|
children,
|
|
...props
|
|
}: ButtonProps) {
|
|
return (
|
|
<BaseButton
|
|
type={type}
|
|
className={cn(buttonVariants({ variant, size, destructive, className }))}
|
|
disabled={disabled || loading}
|
|
aria-busy={loading || undefined}
|
|
{...props}
|
|
>
|
|
{children}
|
|
{loading && (
|
|
<i
|
|
className="ml-1 i-ri-loader-2-line size-3 animate-spin motion-reduce:animate-none"
|
|
aria-hidden="true"
|
|
/>
|
|
)}
|
|
</BaseButton>
|
|
)
|
|
}
|