@elastic/eui
Version:
Elastic UI Component Library
121 lines (117 loc) • 5.72 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "className", "iconType", "iconSide", "iconSize", "color", "size", "flush", "isDisabled", "disabled", "isLoading", "href", "target", "rel", "type", "buttonRef", "contentProps", "textProps", "isSelected"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
/*
* 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 { useEuiTheme, EuiThemeProvider, getSecureRelForTarget } from '../../../services';
import { EuiButtonDisplayContent } from '../button_display/_button_display_content';
import { useEuiButtonColorCSS } from '../../../themes/amsterdam/global_styling/mixins/button';
import { isButtonDisabled } from '../button_display/_button_display';
import { euiButtonEmptyStyles } from './button_empty.styles';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var SIZES = ['xs', 's', 'm'];
export var FLUSH_TYPES = ['left', 'right', 'both'];
/**
* Extends EuiButtonContentProps which provides
* `iconType`, `iconSide`, and `textProps`
*/
export var EuiButtonEmpty = function EuiButtonEmpty(props) {
var children = props.children,
className = props.className,
iconType = props.iconType,
_props$iconSide = props.iconSide,
iconSide = _props$iconSide === void 0 ? 'left' : _props$iconSide,
_props$iconSize = props.iconSize,
iconSize = _props$iconSize === void 0 ? 'm' : _props$iconSize,
_props$color = props.color,
_color = _props$color === void 0 ? 'primary' : _props$color,
_props$size = props.size,
size = _props$size === void 0 ? 'm' : _props$size,
flush = props.flush,
_isDisabled = props.isDisabled,
disabled = props.disabled,
isLoading = props.isLoading,
href = props.href,
target = props.target,
rel = props.rel,
_props$type = props.type,
type = _props$type === void 0 ? 'button' : _props$type,
buttonRef = props.buttonRef,
contentProps = props.contentProps,
textProps = props.textProps,
isSelected = props.isSelected,
rest = _objectWithoutProperties(props, _excluded);
var isDisabled = isButtonDisabled({
isDisabled: _isDisabled || disabled,
href: href,
isLoading: isLoading
});
var color = isDisabled ? 'disabled' : _color === 'ghost' ? 'text' : _color;
var buttonColorStyles = useEuiButtonColorCSS({
display: 'empty'
});
var euiTheme = useEuiTheme();
var styles = euiButtonEmptyStyles(euiTheme);
var cssStyles = [styles.euiButtonEmpty, styles[size], buttonColorStyles[color], flush && styles.flush, flush && styles[flush], isDisabled && styles.isDisabled];
if (_color === 'ghost') {
// INCEPTION: If `ghost`, re-implement with a wrapping dark mode theme provider
return ___EmotionJSX(EuiThemeProvider, {
colorMode: "dark",
wrapperProps: {
cloneElement: true
}
}, ___EmotionJSX(EuiButtonEmpty, _extends({}, props, {
color: "text"
})));
}
var classes = classNames('euiButtonEmpty', className);
var contentClassNames = classNames('euiButtonEmpty__content', contentProps === null || contentProps === void 0 ? void 0 : contentProps.className);
var textClassNames = classNames('euiButtonEmpty__text', textProps === null || textProps === void 0 ? void 0 : textProps.className);
var innerNode = ___EmotionJSX(EuiButtonDisplayContent, _extends({
isDisabled: isDisabled,
isLoading: isLoading,
iconType: iconType,
iconSide: iconSide,
iconSize: size === 'xs' ? 's' : iconSize,
textProps: _objectSpread(_objectSpread({}, textProps), {}, {
className: textClassNames
})
}, _objectSpread(_objectSpread({}, contentProps), {}, {
className: contentClassNames
})), children);
// <a> elements don't respect the `disabled` attribute. So if we're disabled, we'll just pretend
// this is a button and piggyback off its disabled styles.
if (href && !isDisabled) {
var secureRel = getSecureRelForTarget({
href: href,
target: target,
rel: rel
});
return ___EmotionJSX("a", _extends({
className: classes,
css: cssStyles,
href: href,
target: target,
rel: secureRel,
ref: buttonRef
}, rest), innerNode);
}
return ___EmotionJSX("button", _extends({
disabled: isDisabled,
className: classes,
css: cssStyles,
type: type,
ref: buttonRef,
"aria-pressed": isSelected
}, rest), innerNode);
};