UNPKG

@elastic/eui

Version:

Elastic UI Component Library

67 lines (65 loc) 2.64 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; var _excluded = ["className", "buttonRef", "color", "fill"]; /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ import React from 'react'; import classNames from 'classnames'; import { BUTTON_COLORS, useEuiButtonColorCSS, useEuiButtonFocusCSS } from '../../themes/amsterdam/global_styling/mixins/button'; import { EuiButtonDisplay, isButtonDisabled } from './button_display/_button_display'; import { EuiThemeProvider } from '../../services'; import { jsx as ___EmotionJSX } from "@emotion/react"; export var COLORS = [].concat(_toConsumableArray(BUTTON_COLORS), ['ghost']); export var SIZES = ['s', 'm']; /** * EuiButton is largely responsible for providing relevant props * and the logic for element-specific attributes */ export var EuiButton = function EuiButton(props) { var className = props.className, buttonRef = props.buttonRef, _props$color = props.color, _color = _props$color === void 0 ? 'primary' : _props$color, fill = props.fill, rest = _objectWithoutProperties(props, _excluded); var buttonIsDisabled = isButtonDisabled({ href: rest.href, isDisabled: rest.isDisabled || rest.disabled, isLoading: rest.isLoading }); var color = buttonIsDisabled ? 'disabled' : _color; var buttonColorStyles = useEuiButtonColorCSS({ display: fill ? 'fill' : 'base' })[color === 'ghost' ? 'text' : color]; var buttonFocusStyle = useEuiButtonFocusCSS(); var classes = classNames('euiButton', className); var cssStyles = [buttonColorStyles, buttonFocusStyle]; if (_color === 'ghost') { // INCEPTION: If `ghost`, re-implement with a wrapping dark mode theme provider return ___EmotionJSX(EuiThemeProvider, { colorMode: "dark", wrapperProps: { cloneElement: true } }, ___EmotionJSX(EuiButton, _extends({}, props, { color: "text" }))); } return ___EmotionJSX(EuiButtonDisplay, _extends({ className: classes, css: cssStyles, ref: buttonRef }, rest)); }; EuiButton.displayName = 'EuiButton'; // Use defaultProps for simple pass-through props EuiButton.defaultProps = { size: 'm', color: 'primary' };