import "./button.scss"; import React, { ButtonHTMLAttributes, ReactNode } from "react"; import { cssNames } from "../../utils"; import { TooltipDecoratorProps, withTooltip } from "../tooltip"; export interface ButtonProps extends ButtonHTMLAttributes, TooltipDecoratorProps { label?: React.ReactNode; waiting?: boolean; primary?: boolean; accent?: boolean; secondary?: boolean; action?: boolean; plain?: boolean; hidden?: boolean; active?: boolean; big?: boolean; round?: boolean; href?: string; // render as hyperlink target?: "_blank"; // in case of using @href } @withTooltip export class Button extends React.PureComponent { private link: HTMLAnchorElement; private button: HTMLButtonElement; render() { const { className, waiting, label, primary, accent, plain, hidden, active, big, round, tooltip, children, secondary, action, ...props } = this.props; const btnProps = props as Partial; if (hidden) return null; btnProps.className = cssNames('Button', className, { waiting, primary, accent, plain, active, big, round, secondary, action, }); const btnContent: ReactNode = ( <> {label} {children} ); // render as link if (this.props.href) { return ( this.link = e}> {btnContent} ) } // render as button return ( ) } }