UNPKG

@elastic/eui

Version:

Elastic UI Component Library

82 lines (77 loc) 3.67 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.ICON_SIZES = exports.ICON_SIDES = exports.EuiButtonDisplayContent = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _react = _interopRequireDefault(require("react")); var _services = require("../../../services"); var _loading = require("../../loading"); var _icon = require("../../icon"); var _button_display_content = require("./_button_display_content.styles"); var _classnames = _interopRequireDefault(require("classnames")); var _react2 = require("@emotion/react"); var _excluded = ["children", "textProps", "isLoading", "isDisabled", "iconType", "iconSize", "iconSide"]; /* * 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 ICON_SIZES = ['s', 'm']; exports.ICON_SIZES = ICON_SIZES; var ICON_SIDES = ['left', 'right']; /** * *INTERNAL ONLY* * This component is simply a helper component for reuse within other button components. */ exports.ICON_SIDES = ICON_SIDES; var EuiButtonDisplayContent = function EuiButtonDisplayContent(_ref) { var children = _ref.children, textProps = _ref.textProps, _ref$isLoading = _ref.isLoading, isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading, _ref$isDisabled = _ref.isDisabled, isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled, iconType = _ref.iconType, _ref$iconSize = _ref.iconSize, iconSize = _ref$iconSize === void 0 ? 'm' : _ref$iconSize, _ref$iconSide = _ref.iconSide, iconSide = _ref$iconSide === void 0 ? 'left' : _ref$iconSide, contentProps = (0, _objectWithoutProperties2.default)(_ref, _excluded); var theme = (0, _services.useEuiTheme)(); var styles = (0, _button_display_content.euiButtonDisplayContentStyles)(theme); var cssStyles = [styles.euiButtonDisplayContent]; // Add an icon to the button if one exists. var icon; // When the button is disabled the text gets gray // and in some buttons the background gets a light gray // for better contrast we want to change the border of the spinner // to have the same color of the text. This way we ensure the borders // are always visible. The default spinner color could be very light. var loadingSpinnerColor = isDisabled ? { border: 'currentcolor' } : undefined; if (isLoading) { icon = (0, _react2.jsx)(_loading.EuiLoadingSpinner, { size: iconSize, color: loadingSpinnerColor }); } else if (iconType) { icon = (0, _react2.jsx)(_icon.EuiIcon, { type: iconType, size: iconSize, color: "inherit" // forces the icon to inherit its parent color }); } var isText = typeof children === 'string'; return (0, _react2.jsx)("span", (0, _extends2.default)({ css: cssStyles }, contentProps), iconSide === 'left' && icon, isText || textProps ? (0, _react2.jsx)("span", (0, _extends2.default)({}, textProps, { className: (0, _classnames.default)('eui-textTruncate', textProps === null || textProps === void 0 ? void 0 : textProps.className) }), children) : children, iconSide === 'right' && icon); }; exports.EuiButtonDisplayContent = EuiButtonDisplayContent;