import React, { Fragment } from 'react'; import classnames from 'classnames'; import propTypes from 'prop-types'; import styles from './styles.module.scss'; export const ButtonContext = React.createContext(null); export const BUTTON_SIZE_STYLES = { small: styles.small, large: styles.large, }; export const BUTTON_VARIANT_STYLES = { default: styles.default, filled: styles.filled, underline: styles.underline, }; export const BUTTON_TYPE_STYLES = { primary: styles.primary, danger: styles.danger, warning: styles.warning, success: styles.success, muted: styles.muted, }; type ButtonPropsBase = { size?: keyof typeof BUTTON_SIZE_STYLES variant?: keyof typeof BUTTON_VARIANT_STYLES type?: keyof typeof BUTTON_TYPE_STYLES disabled?: boolean width?: React.CSSProperties['width'] height?: React.CSSProperties['height'] href?: React.HTMLProps['href'] leftIcon?: React.ReactNode, rightIcon?: React.ReactNode, }; type NativeButtonProps = React.HTMLProps; // Allow passing native button props, but Omit those that we define in ButtonPropsBase so they don't conflict type ButtonProps = Omit & ButtonPropsBase; const Button = React.forwardRef((props, ref) => { const { size, variant = 'default', type = 'primary', disabled, leftIcon, rightIcon, width, height, href, children, ...otherProps } = props; let contents = children; if (leftIcon) { contents = (
{leftIcon}
{contents}
); } if (rightIcon) { contents = ( {contents}
{rightIcon}
); } if (href) { return ( } {...(otherProps as any as React.HTMLProps)} > {contents} ); } else { return ( ); } }); Button.displayName = 'Button'; Button.defaultProps = { variant: 'default', type: 'primary', }; Button.propTypes = { variant: propTypes.oneOf(['default', 'filled', 'underline']), type: propTypes.oneOf([ 'primary', 'danger', 'warning', 'success', 'muted', ]), }; export default Button; export const ButtonGroup: React.FunctionComponent = ({ children }) => { return (
{children}
); } ButtonGroup.displayName = 'ButtonGroup';