@elastic/eui
Version:
Elastic UI Component Library
143 lines (140 loc) • 5.53 kB
JavaScript
var _excluded = ["className", "buttonRef", "size", "color", "fill"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
/*
* 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 PropTypes from "prop-types";
import classNames from 'classnames';
import { BUTTON_COLORS, useEuiButtonColorCSS, useEuiButtonFocusCSS } from '../../global_styling/mixins/_button';
import { EuiButtonDisplay, isButtonDisabled } from './button_display/_button_display';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var COLORS = BUTTON_COLORS;
export var SIZES = ['s', 'm'];
// For some reason, Storybook doesn't parse `EuiButtonDisplayCommonProps` unless we include it here
/**
* EuiButton is largely responsible for providing relevant props
* and the logic for element-specific attributes
*/
export var EuiButton = function EuiButton(_ref) {
var className = _ref.className,
buttonRef = _ref.buttonRef,
_ref$size = _ref.size,
size = _ref$size === void 0 ? 'm' : _ref$size,
_ref$color = _ref.color,
color = _ref$color === void 0 ? 'primary' : _ref$color,
fill = _ref.fill,
rest = _objectWithoutProperties(_ref, _excluded);
var isDisabled = isButtonDisabled({
href: rest.href,
isDisabled: rest.isDisabled || rest.disabled,
isLoading: rest.isLoading
});
var buttonColorStyles = useEuiButtonColorCSS({
display: fill ? 'fill' : 'base'
})[isDisabled ? 'disabled' : color];
var buttonFocusStyle = useEuiButtonFocusCSS();
var classes = classNames('euiButton', className);
var cssStyles = [buttonColorStyles, buttonFocusStyle];
return ___EmotionJSX(EuiButtonDisplay, _extends({
className: classes,
css: cssStyles,
ref: buttonRef,
size: size
}, rest));
};
EuiButton.propTypes = {
href: PropTypes.string,
onClick: PropTypes.func,
children: PropTypes.node,
/**
* Make button a solid color for prominence
*/
/**
* Make button a solid color for prominence
*/
fill: PropTypes.bool,
/**
* Any of the named color palette options.
*
* Do not use the following colors for standalone buttons directly,
* they exist to serve other components:
* - accent
* - warning
* - neutral
* - risk
*/
color: PropTypes.any,
/**
* Use size `s` in confined spaces
*/
/**
* Use size `s` in confined spaces
*/
size: PropTypes.any,
/**
* Controls the disabled behavior via the native `disabled` attribute.
*/
/**
* Controls the disabled behavior via the native `disabled` attribute.
*/
isDisabled: PropTypes.bool,
/**
* NOTE: Beta feature, may be changed or removed in the future
*
* Changes the native `disabled` attribute to `aria-disabled` to preserve focusability.
* This results in a semantically disabled button without the default browser handling of the disabled state.
*
* Use e.g. when a disabled button should have a tooltip.
*/
/**
* NOTE: Beta feature, may be changed or removed in the future
*
* Changes the native `disabled` attribute to `aria-disabled` to preserve focusability.
* This results in a semantically disabled button without the default browser handling of the disabled state.
*
* Use e.g. when a disabled button should have a tooltip.
*/
hasAriaDisabled: PropTypes.bool,
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any,
buttonRef: PropTypes.any,
element: PropTypes.oneOf(["a", "button", "span"]),
/**
* Applies the boolean state as the `aria-pressed` property to create a toggle button.
* *Only use when the readable text does not change between states.*
*/
isSelected: PropTypes.bool,
/**
* Extends the button to 100% width
*/
fullWidth: PropTypes.bool,
/**
* Override the default minimum width
*/
minWidth: PropTypes.oneOfType([PropTypes.any.isRequired, PropTypes.oneOf([false])]),
/**
* Force disables the button and changes the icon to a loading spinner
*/
isLoading: PropTypes.bool,
/**
* Object of props passed to the <span/> wrapping the button's content
*/
contentProps: PropTypes.shape({
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any
}),
style: PropTypes.any,
type: PropTypes.any
};
EuiButton.displayName = 'EuiButton';