UNPKG

@elastic/eui

Version:

Elastic UI Component Library

108 lines (106 loc) 9.14 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; } /* * 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 { css } from '@emotion/react'; import { makeDisabledContrastColor, transparentize } from '../../../services'; import { mathWithUnits, logicalCSS, logicalShorthandCSS, euiTextShift, euiOutline, euiCanAnimate } from '../../../global_styling'; import { euiButtonFillColor, BUTTON_COLORS } from '../../../themes/amsterdam/global_styling/mixins/button'; import { euiScreenReaderOnly } from '../../accessibility'; import { euiFormVariables } from '../../form/form.styles'; var _ref = process.env.NODE_ENV === "production" ? { name: "nwv4a2-tooltipWrapper", styles: "overflow:hidden;label:tooltipWrapper;" } : { name: "nwv4a2-tooltipWrapper", styles: "overflow:hidden;label:tooltipWrapper;", toString: _EMOTION_STRINGIFIED_CSS_ERROR__ }; var _ref2 = process.env.NODE_ENV === "production" ? { name: "1u3o7zy-hasToolTip", styles: "border-radius:inherit;label:hasToolTip;" } : { name: "1u3o7zy-hasToolTip", styles: "border-radius:inherit;label:hasToolTip;", toString: _EMOTION_STRINGIFIED_CSS_ERROR__ }; export var euiButtonGroupButtonStyles = function euiButtonGroupButtonStyles(euiThemeContext) { var euiTheme = euiThemeContext.euiTheme; var _euiFormVariables = euiFormVariables(euiThemeContext), controlCompressedHeight = _euiFormVariables.controlCompressedHeight, controlCompressedBorderRadius = _euiFormVariables.controlCompressedBorderRadius; var compressedButtonHeight = mathWithUnits([controlCompressedHeight, euiTheme.border.width.thin], function (x, y) { return x - y * 2; }); var uncompressedBorderRadii = function uncompressedBorderRadii(radiusSize) { return "\n border-radius: 0;\n\n &:first-child {\n ".concat(logicalShorthandCSS('border-radius', "".concat(radiusSize, " 0 0 ").concat(radiusSize)), "\n }\n\n &:last-child {\n ").concat(logicalShorthandCSS('border-radius', "0 ".concat(radiusSize, " ").concat(radiusSize, " 0")), "\n }\n "); }; return { // Base euiButtonGroupButton: /*#__PURE__*/css(logicalCSS('min-width', 0), " flex-shrink:1;flex-grow:0;", euiCanAnimate, "{transition:background-color ", euiTheme.animation.normal, " ease-in-out,color ", euiTheme.animation.normal, " ease-in-out;};label:euiButtonGroupButton;"), iconOnly: /*#__PURE__*/css("padding-inline:", euiTheme.size.s, ";;label:iconOnly;"), // Sizes uncompressed: { uncompressed: /*#__PURE__*/css("&:is(.euiButtonGroupButton-isSelected){font-weight:", euiTheme.font.weight.bold, ";}&:focus-visible{", euiOutline(euiThemeContext, 'inset', euiTheme.colors.fullShade), ";};label:uncompressed;"), get borders() { var selectors = '.euiButtonGroupButton-isSelected, .euiButtonGroup__tooltipWrapper-isSelected'; var selectedColor = transparentize(euiTheme.colors.emptyShade, 0.2); var unselectedColor = transparentize(euiTheme.colors.fullShade, 0.1); var borderWidth = euiTheme.border.width.thin; // "Borders" between buttons should be present between two of the same colored buttons, // and absent between selected vs non-selected buttons (different colors) return "\n &:not(".concat(selectors, ") + *:not(").concat(selectors, ") {\n box-shadow: -").concat(borderWidth, " 0 0 0 ").concat(unselectedColor, ";\n }\n &:is(").concat(selectors, ") + *:is(").concat(selectors, ") {\n box-shadow: -").concat(borderWidth, " 0 0 0 ").concat(selectedColor, ";\n }\n "); }, get s() { return /*#__PURE__*/css(this.borders, " ", uncompressedBorderRadii(euiTheme.border.radius.small), ";;label:s;"); }, get m() { return /*#__PURE__*/css(this.borders, " ", uncompressedBorderRadii(euiTheme.border.radius.medium), ";;label:m;"); }, hasToolTip: _ref2 }, compressed: /*#__PURE__*/css(logicalCSS('height', compressedButtonHeight), " line-height:", compressedButtonHeight, ";padding:", mathWithUnits(euiTheme.border.width.thin, function (x) { return x * 2; }), ";background-clip:content-box;border-radius:", mathWithUnits([controlCompressedBorderRadius, euiTheme.border.width.thin], function (x, y) { return x + y; }), ";font-weight:", euiTheme.font.weight.regular, ";&:is(.euiButtonGroupButton-isSelected){font-weight:", euiTheme.font.weight.semiBold, ";};label:compressed;"), // States disabledAndSelected: /*#__PURE__*/css("color:", makeDisabledContrastColor(euiTheme.colors.disabledText)(euiTheme.colors.disabled), ";background-color:", euiTheme.colors.disabled, ";;label:disabledAndSelected;"), // Tooltip anchor wrapper tooltipWrapper: _ref, // Content wrapper content: { euiButtonGroupButton__content: /*#__PURE__*/css(";label:euiButtonGroupButton__content;"), compressed: /*#__PURE__*/css("padding-inline:", euiTheme.size.s, ";;label:compressed;") }, // Text wrapper text: { euiButtonGroupButton__text: /*#__PURE__*/css(euiTextShift('bold', 'data-text', euiTheme), ";;label:euiButtonGroupButton__text;"), euiButtonGroupButton__iconOnly: /*#__PURE__*/css(euiScreenReaderOnly(), ";;label:euiButtonGroupButton__iconOnly;") } }; }; export var _compressedButtonFocusColors = function _compressedButtonFocusColors(euiThemeContext) { var colors = [].concat(_toConsumableArray(BUTTON_COLORS), ['disabled']); return colors.reduce(function (acc, color) { var _euiButtonFillColor = euiButtonFillColor(euiThemeContext, color), backgroundColor = _euiButtonFillColor.backgroundColor; return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, color, /*#__PURE__*/css("&:focus-visible{", euiOutline(euiThemeContext, 'center', backgroundColor), " &:is(.euiButtonGroupButton-isSelected){outline-offset:0;}}"))); }, {}); };