UNPKG

@elastic/eui

Version:

Elastic UI Component Library

181 lines (173 loc) 13.1 kB
var _templateObject; function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); } 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, keyframes } from '@emotion/react'; import { logicalCSS, logicalTextAlignCSS, euiCanAnimate, euiCantAnimate, euiFontSize, euiTextTruncate } from '../../global_styling'; import { highContrastModeStyles } from '../../global_styling/functions/high_contrast'; import { makeHighContrastColor } from '../../services'; import { euiText } from '../text/text.styles'; /** * DRY utilities for native/determinate progress components vs non-native indeterminate */ var crossBrowserProgressValue = function crossBrowserProgressValue(cssProperties) { return "\n &::-webkit-progress-value {\n ".concat(cssProperties, "\n }\n &::-moz-progress-bar {\n ").concat(cssProperties, "\n }\n"); }; var indeterminateProgressValue = function indeterminateProgressValue(cssProperties) { return "\n &::before {\n ".concat(cssProperties, "\n }\n"); }; /** * Color utilities */ var nativeVsIndeterminateColor = function nativeVsIndeterminateColor(color, isNative, highContrastMode) { var selectors = isNative ? crossBrowserProgressValue : indeterminateProgressValue; return "\n ".concat(selectors("background-color: ".concat(color, ";")), "\n ").concat(isNative && highContrastMode === 'preferred' // see highContrastModeStyles.preferred comment below ? "border-color: ".concat(color, ";") : '', "\n ").trim(); }; /** * DRY utils for non-static positions */ var nonStaticPositioning = function nonStaticPositioning(isNative) { return "\n ".concat(logicalCSS('top', 0), "\n ").concat(logicalCSS('left', 0), "\n ").concat(logicalCSS('right', 0), "\n background-color: transparent;\n ").concat(isNative ? "\n &::-webkit-progress-bar {\n background-color: transparent;\n }" : '', "\n"); }; /** * Animations */ var euiIndeterminateAnimation = keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n transform: scaleX(1) translateX(-100%);\n }\n 100% {\n transform: scaleX(1) translateX(100%);\n }\n"]))); /** * Emotion styles */ var _ref2 = process.env.NODE_ENV === "production" ? { name: "187h6sp-static", styles: "position:relative;label:static;" } : { name: "187h6sp-static", styles: "position:relative;label:static;", toString: _EMOTION_STRINGIFIED_CSS_ERROR__ }; export var euiProgressStyles = function euiProgressStyles(euiThemeContext, isNative) { var euiTheme = euiThemeContext.euiTheme, highContrastMode = euiThemeContext.highContrastMode; var backgroundColor = highContrastMode ? euiTheme.colors.emptyShade : euiTheme.colors.lightShade; return { euiProgress: /*#__PURE__*/css("overflow:hidden;background-color:", backgroundColor, ";;label:euiProgress;"), // https://css-tricks.com/html5-progress-element/ // Good resource if you need to work in here. There's some gotchas with // dealing with cross-browser progress bars. native: /*#__PURE__*/css("display:block;", logicalCSS('width', '100%'), " &::-webkit-progress-bar{background-color:", backgroundColor, ";}", highContrastModeStyles(euiThemeContext, { none: "\n appearance: none;\n border: none;\n border-radius: ".concat(euiTheme.size.s, ";\n "), // For some reason we absolutely cannot set any border CSS in Windows high contrast // or the native element stops rendering. However, we do want the extra border for // MacOS high contrast, so #ternarylife preferred: highContrastMode !== 'forced' ? "\n border: ".concat(euiTheme.border.thin, ";\n border-radius: ").concat(euiTheme.size.s, ";\n ").concat(logicalCSS('min-height', euiTheme.size.s), "\n ") : // Increase small sizes, otherwise the border is hard to distinguish, // However, native element heights seem to render differently, // so we need to tweak the min-height accordingly logicalCSS('min-height', euiTheme.size.m), // Also doesn't render without this ¯\_(ツ)_/¯ forced: 'background-color: revert;' }), " ", euiCanAnimate, "{/* Note: FF/Mozilla doesn't actually support animating the native progress bar\n @see https://bugzilla.mozilla.org/show_bug.cgi?id=662351 */", crossBrowserProgressValue("transition: width ".concat(euiTheme.animation.normal, " linear")), ";};label:native;"), // An indeterminate bar has an unreliable end time. Because of a Firefox animation issue, // we apply this style to a <div> instead of a <progress> element. // See https://css-tricks.com/html5-progress-element/ for more info. indeterminate: /*#__PURE__*/css("&::before{position:absolute;content:'';", logicalCSS('width', '100%'), " ", logicalCSS('top', 0), " ", logicalCSS('bottom', 0), " ", logicalCSS('left', 0), " transform:scaleX(0) translateX(0%);animation:", euiIndeterminateAnimation, " 1s ", euiTheme.animation.resistance, " infinite;", highContrastModeStyles(euiThemeContext, { // Windows high contrast themes ignore backgrounds, so use a border instead forced: "\n ".concat(logicalCSS('border-top-style', 'solid'), "\n ").concat(logicalCSS('border-top-color', 'transparent'), "\n ") }), ";", euiCantAnimate, "{animation:none;transform:scaleX(1) translateX(0%);background:repeating-linear-gradient(\n -45deg,\n transparent,\n transparent ", euiTheme.size.m, ",\n rgb(0, 0, 0, 0.25) ", euiTheme.size.m, ",\n rgb(0, 0, 0, 0.25) ", euiTheme.size.l, "\n );}};label:indeterminate;"), // Sizes _sharedSizeCSS: function _sharedSizeCSS(size) { return "\n ".concat(logicalCSS('height', size), "\n ").concat(highContrastModeStyles(euiThemeContext, { forced: "\n &::before {\n ".concat(logicalCSS('border-top-width', size), "\n }") }), "\n "); }, get xs() { return /*#__PURE__*/css( // Increased visibility/size for high contrast modes this._sharedSizeCSS(highContrastMode ? euiTheme.size.xs : euiTheme.size.xxs), ";label:xs;"); }, get s() { return /*#__PURE__*/css(this._sharedSizeCSS(euiTheme.size.xs), ";label:s;"); }, get m() { return /*#__PURE__*/css(this._sharedSizeCSS(euiTheme.size.s), ";label:m;"); }, get l() { return /*#__PURE__*/css(this._sharedSizeCSS(euiTheme.size.m), ";label:l;"); }, // Positioning fixed: /*#__PURE__*/css("position:fixed;z-index:", Number(euiTheme.levels.header) + 1, ";", nonStaticPositioning(isNative), ";;label:fixed;"), absolute: /*#__PURE__*/css("position:absolute;", nonStaticPositioning(isNative), " ", logicalCSS('border-top-left-radius', 'inherit'), " ", logicalCSS('border-top-right-radius', 'inherit'), ";;label:absolute;"), static: _ref2, // Colors primary: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.primary, isNative, highContrastMode), ";;label:primary;"), success: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.success, isNative, highContrastMode), ";;label:success;"), warning: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.warning, isNative, highContrastMode), ";;label:warning;"), danger: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.danger, isNative, highContrastMode), ";;label:danger;"), subdued: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.textSubdued, isNative, highContrastMode), ";;label:subdued;"), accent: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.accent, isNative, highContrastMode), ";;label:accent;"), accentSecondary: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.accentSecondary, isNative, highContrastMode), ";;label:accentSecondary;"), vis0: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis0, isNative, highContrastMode), ";;label:vis0;"), vis1: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis1, isNative, highContrastMode), ";;label:vis1;"), vis2: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis2, isNative, highContrastMode), ";;label:vis2;"), vis3: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis3, isNative, highContrastMode), ";;label:vis3;"), vis4: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis4, isNative, highContrastMode), ";;label:vis4;"), vis5: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis5, isNative, highContrastMode), ";;label:vis5;"), vis6: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis6, isNative, highContrastMode), ";;label:vis6;"), vis7: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis7, isNative, highContrastMode), ";;label:vis7;"), vis8: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis8, isNative, highContrastMode), ";;label:vis8;"), vis9: /*#__PURE__*/css(nativeVsIndeterminateColor(euiTheme.colors.vis.euiColorVis9, isNative, highContrastMode), ";;label:vis9;"), customColor: /*#__PURE__*/css(nativeVsIndeterminateColor('currentColor', isNative, highContrastMode), ";;label:customColor;") }; }; /** * Data styles */ export var euiProgressDataStyles = function euiProgressDataStyles(euiThemeContext) { return { euiProgress__data: /*#__PURE__*/css("display:flex;justify-content:space-between;gap:", euiThemeContext.euiTheme.size.xs, ";", euiText(euiThemeContext.euiTheme), " ", euiFontSize(euiThemeContext, 'xs'), ";;label:euiProgress__data;"), // Sizes l: /*#__PURE__*/css(euiFontSize(euiThemeContext, 's'), ";;label:l;") }; }; export var euiProgressLabelStyles = { euiProgress__label: /*#__PURE__*/css("flex-grow:1;", euiTextTruncate(), ";;label:euiProgress__label;") }; var _ref = process.env.NODE_ENV === "production" ? { name: "15ioh86-customColor", styles: "color:currentColor;label:customColor;" } : { name: "15ioh86-customColor", styles: "color:currentColor;label:customColor;", toString: _EMOTION_STRINGIFIED_CSS_ERROR__ }; export var euiProgressValueTextStyles = function euiProgressValueTextStyles(_ref3) { var euiTheme = _ref3.euiTheme; return { euiProgress__valueText: /*#__PURE__*/css("flex-grow:1;flex-shrink:0;font-feature-settings:'tnum' 1;", logicalTextAlignCSS('right'), " ", euiTextTruncate(), ";;label:euiProgress__valueText;"), // Colors primary: /*#__PURE__*/css("color:", euiTheme.colors.textPrimary, ";;label:primary;"), success: /*#__PURE__*/css("color:", euiTheme.colors.textSuccess, ";;label:success;"), warning: /*#__PURE__*/css("color:", euiTheme.colors.textWarning, ";;label:warning;"), danger: /*#__PURE__*/css("color:", euiTheme.colors.textDanger, ";;label:danger;"), subdued: /*#__PURE__*/css("color:", euiTheme.colors.textSubdued, ";;label:subdued;"), accent: /*#__PURE__*/css("color:", euiTheme.colors.textAccent, ";;label:accent;"), accentSecondary: /*#__PURE__*/css("color:", euiTheme.colors.textAccentSecondary, ";;label:accentSecondary;"), vis0: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis0)(euiTheme), ";;label:vis0;"), vis1: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis1)(euiTheme), ";;label:vis1;"), vis2: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis2)(euiTheme), ";;label:vis2;"), vis3: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis3)(euiTheme), ";;label:vis3;"), vis4: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis4)(euiTheme), ";;label:vis4;"), vis5: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis5)(euiTheme), ";;label:vis5;"), vis6: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis6)(euiTheme), ";;label:vis6;"), vis7: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis7)(euiTheme), ";;label:vis7;"), vis8: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis8)(euiTheme), ";;label:vis8;"), vis9: /*#__PURE__*/css("color:", makeHighContrastColor(euiTheme.colors.vis.euiColorVis9)(euiTheme), ";;label:vis9;"), customColor: _ref }; };