mirror of
https://github.com/langgenius/dify.git
synced 2025-12-19 17:27:16 -05:00
Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import type { CSSProperties } from 'react'
|
|
import React from 'react'
|
|
import { type VariantProps, cva } from 'class-variance-authority'
|
|
import { cn } from '@/utils/classnames'
|
|
|
|
enum ActionButtonState {
|
|
Destructive = 'destructive',
|
|
Active = 'active',
|
|
Disabled = 'disabled',
|
|
Default = '',
|
|
Hover = 'hover',
|
|
}
|
|
|
|
const actionButtonVariants = cva(
|
|
'action-btn',
|
|
{
|
|
variants: {
|
|
size: {
|
|
xs: 'action-btn-xs',
|
|
m: 'action-btn-m',
|
|
l: 'action-btn-l',
|
|
xl: 'action-btn-xl',
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
size: 'm',
|
|
},
|
|
},
|
|
)
|
|
|
|
export type ActionButtonProps = {
|
|
size?: 'xs' | 's' | 'm' | 'l' | 'xl'
|
|
state?: ActionButtonState
|
|
styleCss?: CSSProperties
|
|
ref?: React.Ref<HTMLButtonElement>
|
|
} & React.ButtonHTMLAttributes<HTMLButtonElement> & VariantProps<typeof actionButtonVariants>
|
|
|
|
function getActionButtonState(state: ActionButtonState) {
|
|
switch (state) {
|
|
case ActionButtonState.Destructive:
|
|
return 'action-btn-destructive'
|
|
case ActionButtonState.Active:
|
|
return 'action-btn-active'
|
|
case ActionButtonState.Disabled:
|
|
return 'action-btn-disabled'
|
|
case ActionButtonState.Hover:
|
|
return 'action-btn-hover'
|
|
default:
|
|
return ''
|
|
}
|
|
}
|
|
|
|
const ActionButton = ({ className, size, state = ActionButtonState.Default, styleCss, children, ref, ...props }: ActionButtonProps) => {
|
|
return (
|
|
<button
|
|
type='button'
|
|
className={cn(actionButtonVariants({ className, size }),
|
|
getActionButtonState(state))}
|
|
ref={ref}
|
|
style={styleCss}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</button>
|
|
)
|
|
}
|
|
ActionButton.displayName = 'ActionButton'
|
|
|
|
export default ActionButton
|
|
export { ActionButton, ActionButtonState, actionButtonVariants }
|