UNPKG

@elastic/eui

Version:

Elastic UI Component Library

102 lines (100 loc) 6.14 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; 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; } /* * 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 chroma from 'chroma-js'; import { isColorDark } from '../../services'; import { getEuiButtonColorValues, getEuiFilledButtonColorValues } from '../../global_styling/mixins/_button'; import { chromaValid, parseColor } from '../color_picker/utils'; export var euiBadgeColors = function euiBadgeColors(euiThemeContext) { var euiTheme = euiThemeContext.euiTheme, highContrastMode = euiThemeContext.highContrastMode; var badgeColorsAccentText = getBadgeColors(euiThemeContext, euiTheme.colors.textAccent); var fill = { // Colors shared between buttons and badges primary: getEuiFilledButtonColorValues(euiThemeContext, 'primary'), neutral: getEuiFilledButtonColorValues(euiThemeContext, 'neutral'), success: getEuiFilledButtonColorValues(euiThemeContext, 'success'), warning: getEuiFilledButtonColorValues(euiThemeContext, 'warning'), risk: getEuiFilledButtonColorValues(euiThemeContext, 'risk'), danger: getEuiFilledButtonColorValues(euiThemeContext, 'danger'), accent: getEuiFilledButtonColorValues(euiThemeContext, 'accent'), // Colors unique to badges default: _objectSpread(_objectSpread({}, getBadgeColors(euiThemeContext, euiTheme.components.badgeBackground)), {}, { backgroundHover: euiTheme.components.buttons.backgroundFilledTextHover, backgroundActive: euiTheme.components.buttons.backgroundFilledTextActive, borderColor: 'transparent' }) }; var base = { primary: getEuiButtonColorValues(euiThemeContext, 'primary'), neutral: getEuiButtonColorValues(euiThemeContext, 'neutral'), success: getEuiButtonColorValues(euiThemeContext, 'success'), warning: getEuiButtonColorValues(euiThemeContext, 'warning'), risk: getEuiButtonColorValues(euiThemeContext, 'risk'), danger: getEuiButtonColorValues(euiThemeContext, 'danger'), accent: getEuiButtonColorValues(euiThemeContext, 'accent'), default: _objectSpread(_objectSpread({}, getBadgeColors(euiThemeContext, euiTheme.colors.backgroundLightText)), {}, { backgroundHover: euiTheme.components.buttons.backgroundTextHover, backgroundActive: euiTheme.components.buttons.backgroundTextActive, borderColor: highContrastMode ? euiTheme.border.color : '' }) }; return { fill: fill, base: base, disabled: _objectSpread(_objectSpread({}, getEuiButtonColorValues(euiThemeContext, 'disabled')), {}, { borderColor: highContrastMode ? euiTheme.colors.textDisabled : '' }), // Hollow has a border and is used for autocompleters and beta badges hollow: _objectSpread(_objectSpread({}, getBadgeColors(euiThemeContext, euiTheme.colors.emptyShade)), {}, { backgroundHover: euiTheme.components.buttons.backgroundTextHover, backgroundActive: euiTheme.components.buttons.backgroundTextActive, borderColor: highContrastMode ? euiTheme.border.color : euiTheme.components.badgeBorderColorHollow }), // Colors used by beta and notification badges subdued: _objectSpread(_objectSpread({}, getBadgeColors(euiThemeContext, euiTheme.components.badgeBackgroundSubdued)), {}, { borderColor: highContrastMode ? euiTheme.border.color : '' }), accentText: _objectSpread(_objectSpread({}, badgeColorsAccentText), {}, { borderColor: highContrastMode ? badgeColorsAccentText.backgroundColor : '' }) }; }; export var getBadgeColors = function getBadgeColors(euiThemeContext, backgroundColor) { var color = getTextColor(euiThemeContext, backgroundColor); return { backgroundColor: backgroundColor, color: color }; }; export var getTextColor = function getTextColor(_ref, bgColor) { var euiTheme = _ref.euiTheme; var textColor = isColorDark.apply(void 0, _toConsumableArray(chroma(bgColor).rgb())) ? euiTheme.colors.textGhost : euiTheme.colors.textInk; return textColor; }; /** * Generates the background hover and active colors for custom interactive badges by mixing * the background color with black or white depending on the background color luminance. * @returns { backgroundHover: string, backgroundActive: string } */ export var getCustomInteractiveColors = function getCustomInteractiveColors(_ref2, bgColor) { var euiTheme = _ref2.euiTheme; var isDarkColor = isColorDark.apply(void 0, _toConsumableArray(chroma(bgColor).rgb())); var backgroundHover = isDarkColor ? "color-mix(in oklab, ".concat(bgColor, ", ").concat(euiTheme.colors.textGhost, " 10%)") : "color-mix(in oklab, ".concat(bgColor, ", ").concat(euiTheme.colors.textInk, " 10%)"); var backgroundActive = isDarkColor ? "color-mix(in oklab, ".concat(bgColor, ", ").concat(euiTheme.colors.textGhost, " 15%)") : "color-mix(in oklab, ".concat(bgColor, ", ").concat(euiTheme.colors.textInk, " 15%)"); return { backgroundHover: backgroundHover, backgroundActive: backgroundActive }; }; export var getIsValidColor = function getIsValidColor(color) { return chromaValid(parseColor(color || '') || ''); };