import classnames from 'classnames/bind'; import React from 'react'; import { SilkeBox } from '../silke-box'; import { SilkeIcon } from '../silke-icon'; import { SilkeSkeleton } from '../silke-skeleton'; import { useButtonContext } from './context'; import { SilkeButtonProps } from './silke-button'; import styles from './silke-button.scss'; const cl = classnames.bind(styles); type SilkeFileSelectButtonProps = { accept?: string; multiple?: boolean; onSelect: (files: FileList) => any; } & Omit; export function SilkeFileSelectButton({ accept, multiple, onSelect, label, kind, size, icon, focus, hover, className, loading, type = 'button', selected, ...rest }: SilkeFileSelectButtonProps) { const context = useButtonContext(); const iconOnly = icon && !label; size = size || context.size || 'base'; className = cl('button', className, kind || context.kind || 'primary', size, { iconOnly, focus, hover, selected, }); if (loading) rest.disabled = true; if (type === 'submit' && context.disableSubmit) rest.disabled = true; return ( e.currentTarget.files && onSelect(e.currentTarget.files)} /> {loading && ( )} {label} {icon && ( )} ); }