/** * Copyright Schrodinger, LLC * * @fileoverview Simple button component */ import { IconDefinition } from '@fortawesome/fontawesome-svg-core' import { isFunction, noop } from 'lodash' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import React, { PureComponent, SyntheticEvent, MouseEvent } from 'react' import clsx from 'clsx' import styles from './styles.module.scss' export enum ButtonSize { LARGE = 'LARGE', MEDIUM = 'MEDIUM', SMALL = 'SMALL', } export enum ButtonColor { GREEN = 'GREEN', GRAY = 'GRAY', NONE = 'NONE', } export class Button extends PureComponent { static defaultProps = { size: ButtonSize.MEDIUM, color: ButtonColor.GREEN, disabled: false, onMouseEnter: noop, onMouseLeave: noop, } render(): JSX.Element { return ( ) } getThemeClasses(): string { const size = this.props.size.toLowerCase() const color = this.props.color.toLowerCase() return clsx(this.props.className, styles[size], styles[color], styles['button'], { [styles['disabled']]: this.props.disabled, [styles['icon']]: this.props.icon, }) } getDescription(): React.ReactChild | React.ReactFragment | string { return this.props.children ?? 'Submit' } getIcon(): JSX.Element | null { if (!this.props.icon) { return null } return ; } onClick = (event: SyntheticEvent): void => { if (isFunction(this.props.onClick)) { this.props.onClick(event) } } } export interface ButtonProps { /** * Relative button size */ size: ButtonSize /** * Button color */ color: ButtonColor /** * Extra custom classes */ className?: string /** * Font-Awesome SVG icon definition for icon to be displayed in the button * e.g. `import { faEnvelope } from '@fortawesome/free-solid-svg-icons'` */ icon?: IconDefinition /** * Whether the button is disabled */ disabled: boolean /** * Click Event */ onClick: (event: SyntheticEvent) => void /** * Mouse Enter */ onMouseEnter: (event: MouseEvent) => void /** * Mouse Leave */ onMouseLeave: (event: MouseEvent) => void }