import React, { MouseEvent, ReactNode } from "react"; import classNames from "classnames"; import { withRouter, RouteComponentProps } from "react-router-dom"; import Icon from "../Icon"; export type ButtonProps = { label?: string; loading?: boolean; disabled?: boolean; action?: (event: MouseEvent) => void; link?: string; className?: string; icon?: string; fullWidth?: boolean; reducedMobile?: boolean; children?: ReactNode; }; type Props = ButtonProps & RouteComponentProps & { type?: "button" | "submit" | "reset"; color?: string; }; class Button extends React.Component { static defaultProps: Partial = { type: "button", color: "default" }; onClick = (event: React.MouseEvent) => { const { action, link, history } = this.props; if (action) { action(event); } else if (link) { history.push(link); } }; render() { const { label, loading, disabled, type, color, className, icon, fullWidth, reducedMobile, children } = this.props; const loadingClass = loading ? "is-loading" : ""; const fullWidthClass = fullWidth ? "is-fullwidth" : ""; const reducedMobileClass = reducedMobile ? "is-reduced-mobile" : ""; if (icon) { return ( ); } return ( ); } } export default withRouter(Button);