@elastic/eui
Version:
Elastic UI Component Library
56 lines (55 loc) • 3.51 kB
JavaScript
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
/*
* 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, tint } from '../../services';
import { euiButtonColor, euiButtonFillColor } from '../../themes/amsterdam/global_styling/mixins';
import { chromaValid, parseColor } from '../color_picker/utils';
export var euiBadgeColors = function euiBadgeColors(euiThemeContext) {
var euiTheme = euiThemeContext.euiTheme,
colorMode = euiThemeContext.colorMode;
return {
// Colors shared between buttons and badges
primary: euiButtonFillColor(euiThemeContext, 'primary'),
success: euiButtonFillColor(euiThemeContext, 'success'),
warning: euiButtonFillColor(euiThemeContext, 'warning'),
danger: euiButtonFillColor(euiThemeContext, 'danger'),
accent: euiButtonFillColor(euiThemeContext, 'accent'),
disabled: euiButtonColor(euiThemeContext, 'disabled'),
// Colors unique to badges
default: getBadgeColors(euiThemeContext, euiTheme.colors.lightShade),
// Hollow has a border and is used for autocompleters and beta badges
hollow: _objectSpread(_objectSpread({}, getBadgeColors(euiThemeContext, euiTheme.colors.emptyShade)), {}, {
borderColor: colorMode === 'DARK' ? tint(euiTheme.border.color, 0.15) : euiTheme.border.color
}),
// Colors used by beta and notification badges
subdued: getBadgeColors(euiThemeContext, tint(euiTheme.colors.lightShade, 0.3)),
accentText: getBadgeColors(euiThemeContext, euiTheme.colors.accentText)
};
};
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.ghost : euiTheme.colors.ink;
return textColor;
};
export var getColorContrast = function getColorContrast(textColor, color) {
return chroma.contrast(textColor, color);
};
export var getIsValidColor = function getIsValidColor(color) {
return chromaValid(parseColor(color || '') || '');
};