/** * @file * @copyright 2020 Aleksej Komarov * @license MIT */ import { KEY_ENTER, KEY_ESCAPE, KEY_SPACE } from 'common/keycodes'; import { classes, pureComponentHooks } from 'common/react'; import { Component, createRef } from 'inferno'; import { createLogger } from '../logging'; import { Box, computeBoxClassName, computeBoxProps } from './Box'; import { Icon } from './Icon'; import { Tooltip } from './Tooltip'; const logger = createLogger('Button'); export const Button = (props) => { const { className, fluid, icon, iconRotation, iconSpin, iconColor, iconPosition, iconSize, // VOREStation Addition color, disabled, selected, tooltip, tooltipPosition, ellipsis, compact, circular, content, children, onclick, onClick, ...rest } = props; const hasContent = !!(content || children); // A warning about the lowercase onclick if (onclick) { logger.warn( `Lowercase 'onclick' is not supported on Button and lowercase` + ` prop names are discouraged in general. Please use a camelCase` + `'onClick' instead and read: ` + `https://infernojs.org/docs/guides/event-handling` ); } rest.onClick = (e) => { if (!disabled && onClick) { onClick(e); } }; // IE8: Use "unselectable" because "user-select" doesn't work. if (Byond.IS_LTE_IE8) { rest.unselectable = true; } let buttonContent = (
{ if (props.captureKeys === false) { return; } const keyCode = window.event ? e.which : e.keyCode; // Simulate a click when pressing space or enter. if (keyCode === KEY_SPACE || keyCode === KEY_ENTER) { e.preventDefault(); if (!disabled && onClick) { onClick(e); } return; } // Refocus layout on pressing escape. if (keyCode === KEY_ESCAPE) { e.preventDefault(); return; } }} {...computeBoxProps(rest)}> {icon && iconPosition !== 'right' && ( )} {content} {children} {icon && iconPosition === 'right' && ( )}
); if (tooltip) { buttonContent = ( {buttonContent} ); } return buttonContent; }; Button.defaultHooks = pureComponentHooks; export const ButtonCheckbox = (props) => { const { checked, ...rest } = props; return