@elastic/eui
Version:
Elastic UI Component Library
158 lines (157 loc) • 12.1 kB
JavaScript
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 { euiFontSize, euiFocusRing, euiTextTruncate, highContrastModeStyles, logicalCSS, logicalShorthandCSS, logicalTextAlignCSS, mathWithUnits, euiButtonInteractionStyles } from '../../global_styling';
import { euiBadgeColors } from './color_utils';
var _ref = process.env.NODE_ENV === "production" ? {
name: "1jbvl30-euiBadge__iconButton",
styles: "font-size:0;&:disabled{cursor:not-allowed;}.euiBadge__icon{margin:0!important;};label:euiBadge__iconButton;"
} : {
name: "1jbvl30-euiBadge__iconButton",
styles: "font-size:0;&:disabled{cursor:not-allowed;}.euiBadge__icon{margin:0!important;};label:euiBadge__iconButton;",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
};
var _ref2 = process.env.NODE_ENV === "production" ? {
name: "1hw5vc4-clickable",
styles: "cursor:pointer;label:clickable;"
} : {
name: "1hw5vc4-clickable",
styles: "cursor:pointer;label:clickable;",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
};
export var euiBadgeStyles = function euiBadgeStyles(euiThemeContext) {
var euiTheme = euiThemeContext.euiTheme;
var badgeColors = euiBadgeColors(euiThemeContext);
var defaultBadgeColors = badgeColors.fill.default;
var focusOutlineOffset = mathWithUnits([euiTheme.focus.width, euiTheme.border.width.thin], function (x, y) {
return x + y;
});
var setBadgeColorVars = function setBadgeColorVars(colors) {
return "\n --euiBadgeTextColor: ".concat(colors.color, ";\n --euiBadgeBackgroundColor: ").concat(colors.backgroundColor, ";\n --euiBadgeBackgroundHoverColor: ").concat(colors.backgroundHover, ";\n --euiBadgeBackgroundActiveColor: ").concat(colors.backgroundActive, ";\n ").concat(colors.borderColor ? "--euiBadgeBorder: ".concat(euiTheme.border.width.thin, " solid ").concat(colors.borderColor, ";") : '', "\n ");
};
var getButtonInteractionStyles = function getButtonInteractionStyles(euiThemeContext) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fill';
return "\n ".concat(euiButtonInteractionStyles(euiThemeContext, {
color: 'var(--euiBadgeTextColor)',
background: 'var(--euiBadgeBackgroundColor)',
borderColor: 'var(--euiBadgeBorder)',
backgroundHover: 'var(--euiBadgeBackgroundHoverColor)',
backgroundActive: 'var(--euiBadgeBackgroundActiveColor)'
}, type), "\n ");
};
var highContrastStyles = highContrastModeStyles(euiThemeContext, {
preferred: "\n text-decoration: underline;\n ",
forced: "\n &::after { display: none; }\n "
});
var focusStyles = "\n &:focus {\n ".concat(euiFocusRing(euiThemeContext, 'outset'), "\n /* uses custom offset as the default \"outset\" is not enough */\n outline-offset: ").concat(focusOutlineOffset, ";\n }\n ");
var getClickableStyles = function getClickableStyles(interactionStyles) {
return "\n &:not(:disabled) {\n ".concat(interactionStyles, "\n\n &:hover,\n &:focus {\n ").concat(highContrastStyles, "\n }\n\n ").concat(focusStyles, "\n }\n\n &:disabled {\n cursor: not-allowed;\n }\n ");
};
var customInteractiveStyles = "\n &:hover {\n background-color: var(--euiBadgeBackgroundHoverColor);\n }\n\n &:active {\n background-color: var(--euiBadgeBackgroundActiveColor);\n }\n\n ".concat(focusStyles, "\n ");
var inlinePadding = mathWithUnits(
// Account for the (usually transparent) border so that the visual
// padding is of size s
[euiTheme.size.s, euiTheme.border.width.thin], function (size, borderWidth) {
return size - borderWidth;
});
return {
euiBadge: /*#__PURE__*/css("display:inline-block;vertical-align:middle;", logicalShorthandCSS('padding', "0 ".concat(inlinePadding)), " ", logicalCSS('max-width', '100%'), " font-size:", euiFontSize(euiThemeContext, 'xs').fontSize, ";line-height:", mathWithUnits(
// Account for the border
[euiTheme.size.base, euiTheme.border.width.thin], function (x, y) {
return x + y * 2;
}), ";font-weight:", euiTheme.font.weight.medium, ";white-space:nowrap;text-decoration:none;cursor:inherit;border:", euiTheme.border.width.thin, " solid transparent;border-radius:", euiTheme.size.l, ";", logicalTextAlignCSS('left'), "color:var(--euiBadgeTextColor, ", defaultBadgeColors.color, ");background-color:var(\n --euiBadgeBackgroundColor,\n ", defaultBadgeColors.backgroundColor, "\n );", highContrastModeStyles(euiThemeContext, {
preferred: "border: var(--euiBadgeBorder, ".concat(euiTheme.border.thin, ");")
}), "*::selection{color:var(\n --euiBadgeBackgroundColor,\n ", defaultBadgeColors.backgroundColor, "\n );background-color:var(--euiBadgeTextColor, ", defaultBadgeColors.color, ");}&:focus-within{", euiFocusRing(euiThemeContext), ";}&+.euiBadge{", logicalCSS('margin-left', euiTheme.size.xs), ";};label:euiBadge;"),
iconOnly: /*#__PURE__*/css("padding-inline:", mathWithUnits(
// Account for the border
[euiTheme.size.xs, euiTheme.border.width.thin], function (size, borderWidth) {
return size - borderWidth;
}), ";;label:iconOnly;"),
get clickable() {
// ensures border colors are aligned with the background colors
var borderHoverStyles = "\n &:hover { \n border-color: var(--euiBadgeBackgroundHoverColor);\n }\n &:active {\n border-color: var(--euiBadgeBackgroundActiveColor);\n }\n ";
return {
fill: /*#__PURE__*/css(getClickableStyles(getButtonInteractionStyles(euiThemeContext, 'fill')), " ", borderHoverStyles, ";;label:fill;"),
base: /*#__PURE__*/css(getClickableStyles(getButtonInteractionStyles(euiThemeContext, 'overlay')), " ", highContrastModeStyles(euiThemeContext, {
none: borderHoverStyles
}), ";;label:base;"),
// hollow has a visible border that must not be overwritten on hover
hollow: /*#__PURE__*/css(getClickableStyles(getButtonInteractionStyles(euiThemeContext, 'overlay')), " &:hover,&:focus{", highContrastStyles, ";};label:hollow;"),
custom: /*#__PURE__*/css("&:not(:disabled){", customInteractiveStyles, ";&:hover,&:focus{", highContrastStyles, ";}};label:custom;")
};
},
// on icon button hover, we apply hover styles on the entire badge
get iconClickable() {
var iconButtonSelector = function iconButtonSelector() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ':hover';
return "&:not(:disabled):where(:has(.euiBadge__iconButton".concat(state, "))");
};
var borderHoverStyles = "\n border-color: var(--euiBadgeBackgroundHoverColor);\n ";
return {
fill: /*#__PURE__*/css(iconButtonSelector(), "{", getButtonInteractionStyles(euiThemeContext, 'fill'), " ", borderHoverStyles, ";}", iconButtonSelector(':is(:hover, :focus)'), "{", highContrastStyles, ";};label:fill;"),
base: /*#__PURE__*/css(iconButtonSelector(), "{", getButtonInteractionStyles(euiThemeContext, 'overlay'), " ", highContrastModeStyles(euiThemeContext, {
none: borderHoverStyles
}), ";}", iconButtonSelector(':is(:hover, :focus)'), "{", highContrastStyles, ";};label:base;"),
// hollow has a visible border that must not be overwritten on hover
hollow: /*#__PURE__*/css(iconButtonSelector(), "{", getButtonInteractionStyles(euiThemeContext, 'overlay'), ";}", iconButtonSelector(':is(:hover, :focus)'), "{", highContrastStyles, ";};label:hollow;"),
custom: /*#__PURE__*/css(iconButtonSelector(':is(:hover, :focus)'), "{", highContrastStyles, " ", customInteractiveStyles, ";};label:custom;")
};
},
colors: {
fill: {
default: /*#__PURE__*/css(setBadgeColorVars(badgeColors.fill.default), " border-color:", badgeColors.fill.default.borderColor, ";;label:default;"),
hollow: /*#__PURE__*/css(setBadgeColorVars(badgeColors.hollow), " border-color:", badgeColors.hollow.borderColor, ";;label:hollow;"),
primary: /*#__PURE__*/css(setBadgeColorVars(badgeColors.fill.primary), ";label:primary;"),
accent: /*#__PURE__*/css(setBadgeColorVars(badgeColors.fill.accent), ";label:accent;"),
neutral: /*#__PURE__*/css(setBadgeColorVars(badgeColors.fill.neutral), ";label:neutral;"),
success: /*#__PURE__*/css(setBadgeColorVars(badgeColors.fill.success), ";label:success;"),
warning: /*#__PURE__*/css(setBadgeColorVars(badgeColors.fill.warning), ";label:warning;"),
risk: /*#__PURE__*/css(setBadgeColorVars(badgeColors.fill.risk), ";label:risk;"),
danger: /*#__PURE__*/css(setBadgeColorVars(badgeColors.fill.danger), ";label:danger;")
},
base: {
default: /*#__PURE__*/css(setBadgeColorVars(badgeColors.base.default), " border-color:", badgeColors.base.default.borderColor, ";;label:default;"),
hollow: /*#__PURE__*/css(setBadgeColorVars(badgeColors.hollow), " border-color:", badgeColors.hollow.borderColor, ";;label:hollow;"),
primary: /*#__PURE__*/css(setBadgeColorVars(badgeColors.base.primary), ";label:primary;"),
accent: /*#__PURE__*/css(setBadgeColorVars(badgeColors.base.accent), ";label:accent;"),
neutral: /*#__PURE__*/css(setBadgeColorVars(badgeColors.base.neutral), ";label:neutral;"),
success: /*#__PURE__*/css(setBadgeColorVars(badgeColors.base.success), ";label:success;"),
warning: /*#__PURE__*/css(setBadgeColorVars(badgeColors.base.warning), ";label:warning;"),
risk: /*#__PURE__*/css(setBadgeColorVars(badgeColors.base.risk), ";label:risk;"),
danger: /*#__PURE__*/css(setBadgeColorVars(badgeColors.base.danger), ";label:danger;")
}
},
disabled: /*#__PURE__*/css(setBadgeColorVars(badgeColors.disabled), " border-color:", badgeColors.disabled.borderColor, ";*::selection{color:", euiTheme.colors.backgroundBasePlain, ";};label:disabled;"),
// Content wrapper
euiBadge__content: /*#__PURE__*/css(logicalCSS(
// Ensure proper height in case of just displaying an icon
'min-height', "".concat(mathWithUnits(euiTheme.border.width.thin, function (x) {
return euiTheme.base + x * 2;
}))), " display:flex;align-items:center;overflow:hidden;;label:euiBadge__content;"),
// Text
text: {
euiBadge__text: /*#__PURE__*/css(euiTextTruncate(), " padding-inline:", euiTheme.size.xxs, ";cursor:inherit;;label:euiBadge__text;"),
clickable: _ref2
},
// Icon
icon: {
euiBadge__icon: /*#__PURE__*/css(";label:euiBadge__icon;"),
right: /*#__PURE__*/css("&:not(:only-child){", logicalCSS('margin-left', euiTheme.size.xxs), ";};label:right;"),
left: /*#__PURE__*/css("&:not(:only-child){", logicalCSS('margin-right', euiTheme.size.xxs), ";};label:left;")
},
// Clickable icons (iconOnClick)
iconButton: {
euiBadge__iconButton: _ref,
right: /*#__PURE__*/css(logicalCSS('margin-left', euiTheme.size.xxs), ";;label:right;"),
left: /*#__PURE__*/css(logicalCSS('margin-right', euiTheme.size.xxs), ";;label:left;")
},
// Used in badges with both onClick & iconOnClick
euiBadge__childButton: /*#__PURE__*/css(euiTextTruncate(), " text-align:inherit;font-weight:inherit;line-height:inherit;color:inherit;&:disabled{cursor:not-allowed;}&:not(:disabled){&:hover,&:focus{text-decoration:underline;}};label:euiBadge__childButton;")
};
};