dify/web/app/components/base/ui/button/index.tsx
yyh e1bbe57f9c
refactor(web): re-design button api (#35166)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-04-14 13:22:23 +00:00

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>
)
}