@elastic/eui
Version:
Elastic UI Component Library
117 lines (115 loc) • 4.38 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SIZES = exports.EuiButton = exports.COLORS = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _button = require("../../themes/amsterdam/global_styling/mixins/button");
var _button_display = require("./button_display/_button_display");
var _services = require("../../services");
var _react2 = require("@emotion/react");
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.
*/
var COLORS = [].concat((0, _toConsumableArray2.default)(_button.BUTTON_COLORS), ['ghost']);
exports.COLORS = COLORS;
var SIZES = ['s', 'm'];
exports.SIZES = SIZES;
/**
* EuiButton is largely responsible for providing relevant props
* and the logic for element-specific attributes
*/
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 = (0, _objectWithoutProperties2.default)(props, _excluded);
var buttonIsDisabled = (0, _button_display.isButtonDisabled)({
href: rest.href,
isDisabled: rest.isDisabled || rest.disabled,
isLoading: rest.isLoading
});
var color = buttonIsDisabled ? 'disabled' : _color;
var buttonColorStyles = (0, _button.useEuiButtonColorCSS)({
display: fill ? 'fill' : 'base'
})[color === 'ghost' ? 'text' : color];
var buttonFocusStyle = (0, _button.useEuiButtonFocusCSS)();
var classes = (0, _classnames.default)('euiButton', className);
var cssStyles = [buttonColorStyles, buttonFocusStyle];
if (_color === 'ghost') {
// INCEPTION: If `ghost`, re-implement with a wrapping dark mode theme provider
return (0, _react2.jsx)(_services.EuiThemeProvider, {
colorMode: "dark",
wrapperProps: {
cloneElement: true
}
}, (0, _react2.jsx)(EuiButton, (0, _extends2.default)({}, props, {
color: "text"
})));
}
return (0, _react2.jsx)(_button_display.EuiButtonDisplay, (0, _extends2.default)({
className: classes,
css: cssStyles,
ref: buttonRef
}, rest));
};
exports.EuiButton = EuiButton;
EuiButton.propTypes = {
href: _propTypes.default.string,
onClick: _propTypes.default.func,
children: _propTypes.default.node,
/**
* Make button a solid color for prominence
*/
/**
* Make button a solid color for prominence
*/
fill: _propTypes.default.bool,
/**
* Any of the named color palette options.
* **`'ghost'` is set for deprecation. Use EuiThemeProvide.colorMode = 'dark' instead.**
*/
/**
* Any of the named color palette options.
* **`'ghost'` is set for deprecation. Use EuiThemeProvide.colorMode = 'dark' instead.**
*/
color: _propTypes.default.oneOfType([_propTypes.default.any.isRequired, _propTypes.default.oneOf(["ghost"])]),
/**
* Use size `s` in confined spaces
*/
/**
* Use size `s` in confined spaces
*/
size: _propTypes.default.any,
/**
* `disabled` is also allowed
*/
/**
* `disabled` is also allowed
*/
isDisabled: _propTypes.default.bool,
className: _propTypes.default.string,
"aria-label": _propTypes.default.string,
"data-test-subj": _propTypes.default.string,
css: _propTypes.default.any,
buttonRef: _propTypes.default.any
};
EuiButton.displayName = 'EuiButton';
// Use defaultProps for simple pass-through props
EuiButton.defaultProps = {
size: 'm',
color: 'primary'
};