import * as Nerv from 'nervjs' import Component from '@lib/component' import ButtonGroup from './button-group' export type ButtonType = 'default' | 'primary' | 'success' | 'error' | 'warning' | 'info' | 'text' export type ButtonSize = 'large' | 'small' | 'smaller' export interface ButtonProps { type?: ButtonType className?: string icon?: string size?: ButtonSize hollow?: boolean nativeType?: string loading?: boolean circle?: boolean disabled?: boolean } class Button extends Component { static Group: typeof ButtonGroup static defaultProps = { loading: false, type: 'default', disabled: false } renderButtonClassNames (props: ButtonProps, hasChildren) { return this.classnames( 'at-btn', [ props.type ? `at-btn--${props.type}` : '', props.size ? `at-btn--${props.size}` : '', props.hollow ? `at-btn--${props.type}--hollow` : '', props.circle && !hasChildren ? 'at-btn--circle' : '' ], props.className ) } handleClick = (e) => { const onClick = this.props.onClick if (onClick) { onClick(e) } } render () { const props = this.props const { loading, icon, children, style, disabled, nativeType } = props const hasChildren = Array.isArray(children) ? children.length : !!children const classNames = this.renderButtonClassNames(props, hasChildren) return ( ) } } export default Button