@elastic/eui
Version:
Elastic UI Component Library
100 lines (98 loc) • 7.26 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
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 _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;}}")));
}, {});
};