import * as React from 'react'; import classnames from 'classnames'; import { CnBalloon } from '@alife/cn-ui'; import { ButtonProps } from 'src/types/op-button'; import { LoadingIcon } from '../common-view'; import event from '../event'; import './index.scss'; export default function Button(props: ButtonProps) { const { children, hotkey, className, type = 'normal', text = false, size = 'medium', disabled = false, loading = false, onClick = () => {}, hotkeyHandler, style, balloon = {}, fullWidth, } = props; React.useEffect(() => { const bindHandler = () => { if (hotkeyHandler instanceof Function) { hotkeyHandler(); } else if (onClick instanceof Function) { onClick(); } }; if (hotkey && hotkey?.toLowerCase) { event.bind(hotkey.toLowerCase(), bindHandler); } return () => { if (hotkey && hotkey?.toLowerCase) { event.unbind(hotkey.toLowerCase(), bindHandler); } }; }, [onClick, hotkeyHandler, hotkey]); const btn = ( ); const { children: balloonChildren, ...rest } = balloon; return balloonChildren ? ( {balloonChildren} ) : ( btn ); }