/* @flow */ import React from 'react' import classnames from 'classnames' import { buildAriaProps, buildDataProps } from '../utilities/props' import { globalProps } from '../utilities/globalProps.js' import Icon from '../pb_icon/_icon.jsx' type EventHandler = (SyntheticInputEvent) => void type ButtonPropTypes = { aria?: object, children?: array, className?: string | array, data?: object, disabled?: boolean, fixedWidth?: boolean, fullWidth?: boolean, icon?: string, id?: string, link?: string, loading?: boolean, newWindow?: boolean, onClick?: EventHandler, size?: 'sm' | 'md' | 'lg', text?: string, type: 'inline' | null, htmlType: string | 'button', value?: string | null, variant: 'primary' | 'secondary' | 'link', wrapperClass: string, } const buttonClassName = (props: ButtonPropTypes) => { const { disabled = false, fullWidth = false, loading = false, type = 'inline', variant = 'primary', size = null, } = props let className = 'pb_button_kit' className += `${variant !== null ? `_${variant}` : ''}` className += `${type !== null ? `_${type}` : ''}` className += `${fullWidth ? '_block' : ''}` className += disabled ? '_disabled' : '_enabled' className += loading ? '_loading' : '' className += `${size !== null ? ` size_${size}` : ''}` return className } const Button = (props: ButtonPropTypes) => { const { aria = {}, children, className, data = {}, disabled, icon = null, id, loading = false, onClick = () => {}, link = null, newWindow = false, text, htmlType = 'button', value, } = props const ariaProps = buildAriaProps(aria) const dataProps = buildDataProps(data) const css = classnames( buttonClassName(props), globalProps(props), className ) const loadingIcon = (
) const content = ( {' '} {text || children} ) return ( {loadingIcon} {content} ) } export default Button