import classnames from 'classnames/bind'; import { SilkeIcon, SilkeIcons } from '../silke-icon'; import { SilkeSkeleton } from '../silke-skeleton'; import * as React from 'react'; import { BoxButtonProps, SilkeBox } from '../silke-box'; import { useButtonContext } from './context'; import styles from './silke-button.scss'; const cl = classnames.bind(styles); export type SilkeButtonKind = 'primary' | 'secondary' | 'danger' | 'ghost' | 'upgrade'; export type SilkeButtonSize = 'base' | 's'; export type SilkeButtonProps = { label?: React.ReactNode; kind?: SilkeButtonKind; size?: SilkeButtonSize; loading?: boolean; /** Disable button */ disabled?: boolean; /** Selected */ selected?: boolean; /** Show button as in focus state */ focus?: boolean; /** Show button as in hover state */ hover?: boolean; icon?: SilkeIcons | React.ReactElement; leftIcon?: SilkeIcons | React.ReactElement; link?: string; target?: string; } & Omit; export const SilkeButton = React.forwardRef( ( { label, link, kind, size, icon, leftIcon, focus, hover, className, loading, type = 'button', selected, ...rest }: SilkeButtonProps, ref, ) => { const context = useButtonContext(); const iconOnly = icon && !label; if (!size) size = context.size || 'base'; className = cl( 'button', className, kind || context.kind || 'primary', size || context.size || 'base', { iconOnly, focus, hover, selected, }, ); if (loading) rest.disabled = true; if (type === 'submit' && context.disableSubmit) rest.disabled = true; return ( {loading && ( )} {leftIcon && ( )} {label} {icon && ( )} ); }, ); SilkeButton.displayName = 'SilkeButton';