@elastic/eui-theme-common 3.1.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/lib/cjs/global_styling/functions/shadows.d.ts +12 -0
  2. package/lib/cjs/global_styling/functions/shadows.js +49 -4
  3. package/lib/cjs/global_styling/mixins/borders.d.ts +23 -0
  4. package/lib/cjs/global_styling/mixins/borders.js +50 -0
  5. package/lib/cjs/global_styling/mixins/index.d.ts +1 -0
  6. package/lib/cjs/global_styling/mixins/index.js +11 -0
  7. package/lib/cjs/global_styling/mixins/shadow.d.ts +23 -14
  8. package/lib/cjs/global_styling/mixins/shadow.js +143 -68
  9. package/lib/cjs/global_styling/variables/flags.d.ts +1 -0
  10. package/lib/cjs/global_styling/variables/shadow.d.ts +52 -0
  11. package/lib/cjs/global_styling/variables/shadow.js +8 -2
  12. package/lib/cjs/global_styling/variables/typography.d.ts +1 -1
  13. package/lib/cjs/services/theme/types.d.ts +3 -1
  14. package/lib/cjs/utils.d.ts +22 -1
  15. package/lib/cjs/utils.js +39 -1
  16. package/lib/cjs/utils.test.js +38 -0
  17. package/lib/esm/global_styling/functions/shadows.d.ts +12 -0
  18. package/lib/esm/global_styling/functions/shadows.js +40 -1
  19. package/lib/esm/global_styling/mixins/borders.d.ts +23 -0
  20. package/lib/esm/global_styling/mixins/borders.js +50 -0
  21. package/lib/esm/global_styling/mixins/index.d.ts +1 -0
  22. package/lib/esm/global_styling/mixins/index.js +1 -0
  23. package/lib/esm/global_styling/mixins/shadow.d.ts +23 -14
  24. package/lib/esm/global_styling/mixins/shadow.js +127 -81
  25. package/lib/esm/global_styling/variables/flags.d.ts +1 -0
  26. package/lib/esm/global_styling/variables/shadow.d.ts +52 -0
  27. package/lib/esm/global_styling/variables/shadow.js +1 -0
  28. package/lib/esm/global_styling/variables/typography.d.ts +1 -1
  29. package/lib/esm/services/theme/types.d.ts +3 -1
  30. package/lib/esm/utils.d.ts +22 -1
  31. package/lib/esm/utils.js +31 -0
  32. package/lib/esm/utils.test.js +22 -1
  33. package/package.json +1 -1
  34. package/src/global_styling/mixins/_form.scss +0 -1
  35. package/src/global_styling/mixins/_index.scss +0 -1
  36. package/src/global_styling/mixins/_range.scss +0 -3
  37. package/src/global_styling/mixins/_typography.scss +0 -1
  38. package/src/global_styling/variables/_index.scss +0 -1
  39. package/src/global_styling/variables/_typography.scss +1 -68
  40. package/src/global_styling/mixins/_shadow.scss +0 -100
  41. package/src/global_styling/variables/_shadows.scss +0 -2
@@ -84,7 +84,7 @@ export interface _EuiThemeTitle {
84
84
  export declare type _EuiThemeFont = _EuiThemeFontBase & {
85
85
  scale: _EuiThemeFontScales;
86
86
  /**
87
- * See {@link https://eui.elastic.co/#/theming/typography/values%23font-weight | Reference} for more information
87
+ * See {@link https://eui.elastic.co/docs/getting-started/theming/tokens/typography/font-weight/ | Reference} for more information
88
88
  */
89
89
  weight: _EuiThemeFontWeights;
90
90
  body: _EuiThemeBody;
@@ -7,6 +7,7 @@ import type { _EuiThemeColors } from '../../global_styling/variables/colors';
7
7
  import type { _EuiThemeBase, _EuiThemeSizes } from '../../global_styling/variables/size';
8
8
  import type { _EuiThemeFont } from '../../global_styling/variables/typography';
9
9
  import type { _EuiThemeFocus } from '../../global_styling/variables/states';
10
+ import type { _EuiThemeShadows } from '../../global_styling/variables/shadow';
10
11
  import type { _EuiThemeLevels } from '../../global_styling/variables/levels';
11
12
  import type { _EuiThemeComponents } from '../../global_styling/variables/components';
12
13
  import type { _EuiThemeFlags } from '../../global_styling/variables';
@@ -34,7 +35,7 @@ export declare type EuiThemeShapeBase = {
34
35
  /** - Default value: 16 */
35
36
  base: _EuiThemeBase;
36
37
  /**
37
- * See {@link https://eui.elastic.co/#/theming/sizing | Reference} for more information
38
+ * See {@link https://eui.elastic.co/docs/getting-started/theming/tokens/sizing/ | Reference} for more information
38
39
  */
39
40
  size: _EuiThemeSizes;
40
41
  font: _EuiThemeFont;
@@ -43,6 +44,7 @@ export declare type EuiThemeShapeBase = {
43
44
  animation: _EuiThemeAnimation;
44
45
  breakpoint: _EuiThemeBreakpoints;
45
46
  levels: _EuiThemeLevels;
47
+ shadows: _EuiThemeShadows;
46
48
  components: _EuiThemeComponents;
47
49
  flags: _EuiThemeFlags;
48
50
  };
@@ -1,4 +1,4 @@
1
- import { EuiThemeColorMode, EuiThemeColorModeStandard, EuiThemeSystem, EuiThemeShape, EuiThemeComputed, EuiThemeHighContrastMode } from './global_styling';
1
+ import { EuiThemeColorMode, EuiThemeColorModeStandard, EuiThemeSystem, EuiThemeShape, EuiThemeComputed, _EuiThemeShadowLayer, EuiThemeHighContrastMode } from './global_styling';
2
2
  export declare const DEFAULT_COLOR_MODE: "LIGHT";
3
3
  /**
4
4
  * Returns whether the provided color mode is `inverse`
@@ -104,3 +104,24 @@ export declare const mergeDeep: (_target: {
104
104
  * and additional prefix/suffix
105
105
  */
106
106
  export declare const getTokenName: (prefix: string, variant?: string | undefined, suffix?: string | undefined) => string;
107
+ /**
108
+ * Format an array of shadow "objects" into a string for CSS.
109
+ * The "up" direction is built by making the y offset from layers
110
+ * two and any subsequent layers, negative.
111
+ *
112
+ * It will add `inset` to the first layer when color mode is "DARK"
113
+ * and `spread` is 1, to ensure the dark mode-only floating border
114
+ * is rendered inside the container to match the position of the
115
+ * regular panel border (implemented with a pseudo element).
116
+ *
117
+ * @todo add a color space param to replace the hard-coded `hsl`
118
+ *
119
+ * @param layers
120
+ * @param options
121
+ * @param options.up - Modifies some values in order to get the "up" direction
122
+ * @returns - A value for the CSS `box-shadow` property
123
+ */
124
+ export declare function formatMultipleBoxShadow(layers: _EuiThemeShadowLayer[], options?: {
125
+ direction?: 'down' | 'up';
126
+ color: string;
127
+ }): string;
package/lib/cjs/utils.js CHANGED
@@ -5,8 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildTheme = exports.DEFAULT_COLOR_MODE = exports.Computed = void 0;
7
7
  exports.computed = computed;
8
+ exports.formatMultipleBoxShadow = formatMultipleBoxShadow;
8
9
  exports.setOn = exports.mergeDeep = exports.isInverseColorMode = exports.getTokenName = exports.getOn = exports.getComputed = exports.getColorMode = void 0;
10
+ var _chromaJs = _interopRequireDefault(require("chroma-js"));
9
11
  var _global_styling = require("./global_styling");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
13
  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; }
11
14
  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; }
12
15
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -357,4 +360,39 @@ var getTokenName = exports.getTokenName = function getTokenName(prefix, variant,
357
360
  }
358
361
  var colorName = variant.charAt(0).toUpperCase() + variant.slice(1);
359
362
  return "".concat(prefix).concat(getCapitalized(colorName)).concat(_suffix);
360
- };
363
+ };
364
+
365
+ /**
366
+ * Format an array of shadow "objects" into a string for CSS.
367
+ * The "up" direction is built by making the y offset from layers
368
+ * two and any subsequent layers, negative.
369
+ *
370
+ * It will add `inset` to the first layer when color mode is "DARK"
371
+ * and `spread` is 1, to ensure the dark mode-only floating border
372
+ * is rendered inside the container to match the position of the
373
+ * regular panel border (implemented with a pseudo element).
374
+ *
375
+ * @todo add a color space param to replace the hard-coded `hsl`
376
+ *
377
+ * @param layers
378
+ * @param options
379
+ * @param options.up - Modifies some values in order to get the "up" direction
380
+ * @returns - A value for the CSS `box-shadow` property
381
+ */
382
+ function formatMultipleBoxShadow(layers, options) {
383
+ if (layers.length === 0) {
384
+ return 'none';
385
+ }
386
+ var _ref3 = options !== null && options !== void 0 ? options : {},
387
+ _ref3$direction = _ref3.direction,
388
+ direction = _ref3$direction === void 0 ? 'down' : _ref3$direction,
389
+ _ref3$color = _ref3.color,
390
+ color = _ref3$color === void 0 ? '#000' : _ref3$color;
391
+ /* prettier-ignore */
392
+ var shadowLayers = layers.map(function (layer, i) {
393
+ var y = direction === 'up' && i > 0 ? -layer.y : layer.y;
394
+ var shadowColor = (0, _chromaJs["default"])(color).alpha(layer.opacity).css('hsl');
395
+ return "".concat(layer.x, "px ").concat(y, "px ").concat(layer.blur, "px ").concat(layer.spread, "px ").concat(shadowColor);
396
+ });
397
+ return shadowLayers.join(', ');
398
+ }
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  var _utils = require("./utils");
5
+ 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; }
6
+ 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; }
7
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
9
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
10
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
5
11
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
12
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -395,4 +401,36 @@ describe('getTokenName', function () {
395
401
  expect((0, _utils.getTokenName)('backgroundBase', 'primary')).toEqual('backgroundBasePrimary');
396
402
  expect((0, _utils.getTokenName)('backgroundBase', 'primary', 'hovered')).toEqual('backgroundBasePrimaryHovered');
397
403
  });
404
+ });
405
+ describe('formatMultipleBoxShadow', function () {
406
+ var layers = [{
407
+ x: 0,
408
+ y: 4,
409
+ blur: 8,
410
+ spread: 0,
411
+ opacity: 0.1
412
+ }, {
413
+ x: 0,
414
+ y: 2,
415
+ blur: 4,
416
+ spread: 0,
417
+ opacity: 0.05
418
+ }];
419
+ var options = {
420
+ color: '#000000'
421
+ };
422
+ it('returns a valid CSS box-shadow value', function () {
423
+ expect((0, _utils.formatMultipleBoxShadow)(layers, options)).toEqual('0px 4px 8px 0px hsla(0,0%,0%,0.1), 0px 2px 4px 0px hsla(0,0%,0%,0.05)');
424
+ });
425
+ it('handles a single layer', function () {
426
+ expect((0, _utils.formatMultipleBoxShadow)([layers[0]], options)).toEqual('0px 4px 8px 0px hsla(0,0%,0%,0.1)');
427
+ });
428
+ it('formats the "up" variant', function () {
429
+ expect((0, _utils.formatMultipleBoxShadow)(layers, _objectSpread(_objectSpread({}, options), {}, {
430
+ direction: 'up'
431
+ }))).toEqual('0px 4px 8px 0px hsla(0,0%,0%,0.1), 0px -2px 4px 0px hsla(0,0%,0%,0.05)');
432
+ });
433
+ it('return "none" for no layers', function () {
434
+ expect((0, _utils.formatMultipleBoxShadow)([], options)).toEqual('none');
435
+ });
398
436
  });
@@ -1,2 +1,14 @@
1
1
  import { EuiThemeColorModeStandard } from '../../services/theme/types';
2
2
  export declare const getShadowColor: (color: string, opacity: number, colorMode: EuiThemeColorModeStandard) => string;
3
+ /**
4
+ * Converts a `box-shadow` string to a `filter: drop-shadow()` string.
5
+ *
6
+ * @todo check whether this is actually needed in +2025, the original code replacing
7
+ * box-shadow with filter: drop-shadow() had the following comment:
8
+ * > Using only one drop-shadow filter instead of multiple is more
9
+ * > performant & prevents Safari bugs
10
+ *
11
+ * @param boxShadow The `box-shadow` string to convert.
12
+ * @returns The converted `filter` string.
13
+ */
14
+ export declare const boxShadowToFilterDropShadow: (boxShadow: string) => string;
@@ -9,8 +9,47 @@ import chroma from 'chroma-js';
9
9
  import { COLOR_MODES_STANDARD, } from '../../services/theme/types';
10
10
  // Create a CSS color value using whose opacity is determined based
11
11
  // on either a light or dark theme. We use a multiplier
12
- // of 1 for light themes and 2.5 for dark themes
12
+ // of 1 for light themes and 3.5 for dark themes
13
13
  export const getShadowColor = (color, opacity, colorMode) => {
14
14
  const themeOpacity = colorMode === COLOR_MODES_STANDARD.dark ? opacity * 3.5 : opacity * 1;
15
15
  return chroma(color).alpha(themeOpacity).css();
16
16
  };
17
+ /**
18
+ * Converts a `box-shadow` string to a `filter: drop-shadow()` string.
19
+ *
20
+ * @todo check whether this is actually needed in +2025, the original code replacing
21
+ * box-shadow with filter: drop-shadow() had the following comment:
22
+ * > Using only one drop-shadow filter instead of multiple is more
23
+ * > performant & prevents Safari bugs
24
+ *
25
+ * @param boxShadow The `box-shadow` string to convert.
26
+ * @returns The converted `filter` string.
27
+ */
28
+ export const boxShadowToFilterDropShadow = (boxShadow) => {
29
+ const dropShadows = boxShadow
30
+ .split(/,(?![^(]*\))/) // split by comma, but not inside parentheses
31
+ .map((shadow) => {
32
+ shadow = shadow.trim();
33
+ // remove `inset`, not supported by drop-shadow
34
+ if (shadow.startsWith('inset ')) {
35
+ shadow = shadow.slice(6);
36
+ }
37
+ // can be complex (hsl, rgb, etc.), used AI for this
38
+ const colorMatch = shadow.match(/(hsl|rgb)a?\(.*\)|#[0-9a-fA-F]{3,8}|[a-zA-Z]+$/);
39
+ let color;
40
+ let parts;
41
+ if (colorMatch) {
42
+ color = colorMatch[0];
43
+ parts = shadow.substring(0, colorMatch.index).trim().split(/\s+/);
44
+ }
45
+ else {
46
+ color = '#000'; // fallback to black
47
+ parts = shadow.trim().split(/\s+/);
48
+ }
49
+ // drop-shadow doesn't support spread, so we only take x, y, blur
50
+ const [x, y, blur] = parts;
51
+ return `drop-shadow(${x} ${y} ${blur} ${color})`;
52
+ })
53
+ .join(' ');
54
+ return `filter: ${dropShadows};`;
55
+ };
@@ -0,0 +1,23 @@
1
+ import { UseEuiTheme } from '../../services/theme/types';
2
+ export declare const getBorderSide: (side: BorderSides) => string;
3
+ export declare type BorderSides = 'left' | 'right' | 'top' | 'bottom' | 'horizontal' | 'vertical' | 'all';
4
+ /**
5
+ * Defines styles for floating boarders applied in DARK mode via EUI shadow utils
6
+ */
7
+ export declare const euiShadowFloatingBorderStyles: (euiThemeContext: UseEuiTheme, options: {
8
+ side?: BorderSides;
9
+ borderColor?: string;
10
+ borderWidth?: string;
11
+ borderStyle?: string;
12
+ }) => string;
13
+ /**
14
+ * Shared style for floating borders.
15
+ * Uses a pseudo element with `border` attribute to prevent both dimension changes due to
16
+ * the border width as well as visible gaps due to the need of a transparent border in LIGHT mode.
17
+ */
18
+ export declare const euiBorderStyles: (euiThemeContext: UseEuiTheme, options: {
19
+ side?: BorderSides;
20
+ borderColor?: string;
21
+ borderWidth?: string;
22
+ borderStyle?: string;
23
+ }) => string;
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+ const logicalSide = {
9
+ left: 'inline-start',
10
+ right: 'inline-end',
11
+ top: 'block-start',
12
+ bottom: 'block-end',
13
+ horizontal: 'inline',
14
+ vertical: 'block',
15
+ };
16
+ export const getBorderSide = (side) => side === 'all' ? 'border' : `border-${logicalSide[side]}`;
17
+ /**
18
+ * Defines styles for floating boarders applied in DARK mode via EUI shadow utils
19
+ */
20
+ export const euiShadowFloatingBorderStyles = (euiThemeContext, options) => {
21
+ return `
22
+ /* create a containing block without using \`position\` to prevent CSS specificity issues and unexpected overrides;
23
+ \`transform: translateZ(0)\` is the least likely to affect other behaviors (overflow, layout) */
24
+ transform: translateZ(0);
25
+
26
+ ${euiBorderStyles(euiThemeContext, options)}
27
+ `;
28
+ };
29
+ /**
30
+ * Shared style for floating borders.
31
+ * Uses a pseudo element with `border` attribute to prevent both dimension changes due to
32
+ * the border width as well as visible gaps due to the need of a transparent border in LIGHT mode.
33
+ */
34
+ export const euiBorderStyles = (euiThemeContext, options) => {
35
+ const { euiTheme } = euiThemeContext;
36
+ const { side = 'all', borderColor = euiTheme.border.color, borderWidth = euiTheme.border.width.thin, borderStyle = 'solid', } = options;
37
+ const borderProperty = getBorderSide(side);
38
+ return `
39
+ &::after {
40
+ content: '';
41
+ position: absolute;
42
+ inset: 0;
43
+ /* ensure to keep on top of flush content */
44
+ z-index: 0;
45
+ ${borderProperty}: ${borderWidth} ${borderStyle} ${borderColor};
46
+ border-radius: inherit;
47
+ pointer-events: none;
48
+ }
49
+ `;
50
+ };
@@ -1 +1,2 @@
1
1
  export * from './shadow';
2
+ export * from './borders';
@@ -6,3 +6,4 @@
6
6
  * Side Public License, v 1.
7
7
  */
8
8
  export * from './shadow';
9
+ export * from './borders';
@@ -1,45 +1,54 @@
1
1
  import type { UseEuiTheme } from '../../services/theme/types';
2
2
  import { _EuiThemeShadowSize } from '../variables/shadow';
3
+ import { BorderSides } from './borders';
3
4
  export interface EuiShadowOptions {
5
+ /** @deprecated */
4
6
  color?: string;
7
+ /** @default `down` */
8
+ direction?: 'down' | 'up';
5
9
  /**
6
10
  * Note: not supported by all shadow utilities.
7
11
  */
8
12
  property?: 'box-shadow' | 'filter';
9
13
  borderAllInHighContrastMode?: boolean;
14
+ border?: BorderSides | 'none';
10
15
  }
11
16
  /**
12
- * euiSlightShadow
17
+ * x-small shadow
13
18
  */
14
- export declare const euiShadowXSmall: ({ euiTheme, colorMode, highContrastMode }: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
19
+ export declare const euiShadowXSmall: (euiThemeContext: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
15
20
  /**
16
- * bottomShadowSmall
21
+ * small shadow
17
22
  */
18
- export declare const euiShadowSmall: ({ euiTheme, colorMode, highContrastMode }: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
23
+ export declare const euiShadowSmall: (euiThemeContext: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
19
24
  /**
20
- * bottomShadowMedium
25
+ * medium shadow
21
26
  */
22
- export declare const euiShadowMedium: ({ euiTheme, colorMode, highContrastMode }: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
27
+ export declare const euiShadowMedium: (euiThemeContext: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
23
28
  /**
24
- * bottomShadow
29
+ * large shadow
25
30
  */
26
- export declare const euiShadowLarge: ({ euiTheme, colorMode, highContrastMode }: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
31
+ export declare const euiShadowLarge: (euiThemeContext: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
27
32
  /**
28
- * bottomShadowLarge
33
+ * x-large shadow
29
34
  */
30
35
  export interface EuiShadowXLarge extends EuiShadowOptions {
31
36
  reverse?: boolean;
32
37
  }
33
- export declare const euiShadowXLarge: ({ euiTheme, colorMode, highContrastMode }: UseEuiTheme, options?: EuiShadowXLarge | undefined) => string;
38
+ export declare const euiShadowXLarge: (euiThemeContext: UseEuiTheme, options?: EuiShadowXLarge | undefined) => string;
34
39
  /**
35
- * slightShadowHover
40
+ * flat shadow
41
+ * @deprecated - use euiShadowHover instead
36
42
  */
37
- export declare const euiSlightShadowHover: ({ euiTheme, colorMode, highContrastMode }: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
43
+ export declare const euiSlightShadowHover: (euiThemeContext: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
38
44
  /**
39
- * bottomShadowFlat
45
+ * @deprecated - use euiShadowXSmall instead
40
46
  *
47
+ * Remains for backwards compatibility for the Amsterdam theme.
41
48
  * Similar to shadow medium but without the bottom depth.
42
49
  * Useful for popovers that drop UP rather than DOWN.
43
50
  */
44
- export declare const euiShadowFlat: ({ euiTheme, colorMode, highContrastMode }: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
51
+ export declare const euiShadowFlat: (euiThemeContext: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
45
52
  export declare const euiShadow: (euiThemeContext: UseEuiTheme, size?: _EuiThemeShadowSize, options?: EuiShadowOptions | undefined) => string;
53
+ /** Hover shadows */
54
+ export declare const euiShadowHover: (euiThemeContext: UseEuiTheme, size?: _EuiThemeShadowSize | 'base', options?: EuiShadowOptions | undefined) => string;
@@ -5,123 +5,114 @@
5
5
  * in compliance with, at your election, the Elastic License 2.0 or the Server
6
6
  * Side Public License, v 1.
7
7
  */
8
- import { getShadowColor } from '../functions';
8
+ import { boxShadowToFilterDropShadow } from '../functions';
9
+ import { euiShadowFloatingBorderStyles } from './borders';
9
10
  /**
10
- * euiSlightShadow
11
+ * x-small shadow
11
12
  */
12
- export const euiShadowXSmall = ({ euiTheme, colorMode, highContrastMode }, options) => {
13
+ export const euiShadowXSmall = (euiThemeContext, options) => {
14
+ const { euiTheme, highContrastMode } = euiThemeContext;
13
15
  if (highContrastMode) {
14
- return _highContrastBorder(euiTheme, options);
16
+ return _highContrastBorder(euiThemeContext, options);
15
17
  }
16
- const color = options?.color || euiTheme.colors.shadow;
17
- return `
18
- box-shadow:
19
- 0 .8px .8px ${getShadowColor(color, 0.04, colorMode)},
20
- 0 2.3px 2px ${getShadowColor(color, 0.03, colorMode)};
21
- `;
18
+ const direction = options?.direction ?? 'down';
19
+ return _shadowStyles(euiThemeContext, euiTheme.shadows.xs[direction], {
20
+ border: options?.border,
21
+ });
22
22
  };
23
23
  /**
24
- * bottomShadowSmall
24
+ * small shadow
25
25
  */
26
- export const euiShadowSmall = ({ euiTheme, colorMode, highContrastMode }, options) => {
26
+ export const euiShadowSmall = (euiThemeContext, options) => {
27
+ const { euiTheme, highContrastMode } = euiThemeContext;
27
28
  if (highContrastMode) {
28
- return _highContrastBorder(euiTheme, options);
29
+ return _highContrastBorder(euiThemeContext, options);
29
30
  }
30
- const color = options?.color || euiTheme.colors.shadow;
31
- return `
32
- box-shadow:
33
- 0 .7px 1.4px ${getShadowColor(color, 0.07, colorMode)},
34
- 0 1.9px 4px ${getShadowColor(color, 0.05, colorMode)},
35
- 0 4.5px 10px ${getShadowColor(color, 0.05, colorMode)};
36
- `;
31
+ const direction = options?.direction ?? 'down';
32
+ return _shadowStyles(euiThemeContext, euiTheme.shadows.s[direction], {
33
+ border: options?.border,
34
+ });
37
35
  };
38
36
  /**
39
- * bottomShadowMedium
37
+ * medium shadow
40
38
  */
41
- export const euiShadowMedium = ({ euiTheme, colorMode, highContrastMode }, options) => {
39
+ export const euiShadowMedium = (euiThemeContext, options) => {
40
+ const { euiTheme, highContrastMode } = euiThemeContext;
42
41
  if (highContrastMode) {
43
- return _highContrastBorder(euiTheme, options);
42
+ return _highContrastBorder(euiThemeContext, options);
44
43
  }
45
- const color = options?.color || euiTheme.colors.shadow;
44
+ const direction = options?.direction ?? 'down';
45
+ const boxShadow = euiTheme.shadows.m[direction];
46
46
  if (options?.property === 'filter') {
47
- // Using only one drop-shadow filter instead of multiple is more performant & prevents Safari bugs
48
- return `filter: drop-shadow(0 5.7px 9px ${getShadowColor(color, 0.2, colorMode)});`;
49
- }
50
- else {
51
- return `box-shadow:
52
- 0 .9px 4px ${getShadowColor(color, 0.08, colorMode)},
53
- 0 2.6px 8px ${getShadowColor(color, 0.06, colorMode)},
54
- 0 5.7px 12px ${getShadowColor(color, 0.05, colorMode)},
55
- 0 15px 15px ${getShadowColor(color, 0.04, colorMode)};`;
47
+ return boxShadow
48
+ ? _shadowStyles(euiThemeContext, boxShadowToFilterDropShadow(boxShadow), {
49
+ border: options?.border,
50
+ type: 'filter',
51
+ })
52
+ : '';
56
53
  }
54
+ return _shadowStyles(euiThemeContext, boxShadow, {
55
+ border: options?.border,
56
+ });
57
57
  };
58
58
  /**
59
- * bottomShadow
59
+ * large shadow
60
60
  */
61
- export const euiShadowLarge = ({ euiTheme, colorMode, highContrastMode }, options) => {
61
+ export const euiShadowLarge = (euiThemeContext, options) => {
62
+ const { euiTheme, highContrastMode } = euiThemeContext;
62
63
  if (highContrastMode) {
63
- return _highContrastBorder(euiTheme, options);
64
+ return _highContrastBorder(euiThemeContext, options);
64
65
  }
65
- const color = options?.color || euiTheme.colors.shadow;
66
- return `
67
- box-shadow:
68
- 0 1px 5px ${getShadowColor(color, 0.1, colorMode)},
69
- 0 3.6px 13px ${getShadowColor(color, 0.07, colorMode)},
70
- 0 8.4px 23px ${getShadowColor(color, 0.06, colorMode)},
71
- 0 23px 35px ${getShadowColor(color, 0.05, colorMode)};
72
- `;
66
+ const direction = options?.direction ?? 'down';
67
+ return _shadowStyles(euiThemeContext, euiTheme.shadows.l[direction], {
68
+ border: options?.border,
69
+ });
73
70
  };
74
- export const euiShadowXLarge = ({ euiTheme, colorMode, highContrastMode }, options) => {
71
+ export const euiShadowXLarge = (euiThemeContext, options) => {
72
+ const { euiTheme, highContrastMode } = euiThemeContext;
75
73
  if (highContrastMode) {
76
- return _highContrastBorder(euiTheme, options);
74
+ return _highContrastBorder(euiThemeContext, options);
77
75
  }
78
- const color = options?.color || euiTheme.colors.shadow;
79
- const reverse = options?.reverse ?? false;
80
- return `
81
- box-shadow:
82
- 0 ${reverse ? '-' : ''}2.7px 9px ${getShadowColor(color, 0.13, colorMode)},
83
- 0 ${reverse ? '-' : ''}9.4px 24px ${getShadowColor(color, 0.09, colorMode)},
84
- 0 ${reverse ? '-' : ''}21.8px 43px ${getShadowColor(color, 0.08, colorMode)};
85
- `;
76
+ const direction = options?.direction ?? 'down';
77
+ return _shadowStyles(euiThemeContext, euiTheme.shadows.xl[direction], {
78
+ border: options?.border,
79
+ });
86
80
  };
87
81
  /**
88
- * slightShadowHover
82
+ * flat shadow
83
+ * @deprecated - use euiShadowHover instead
89
84
  */
90
- export const euiSlightShadowHover = ({ euiTheme, colorMode, highContrastMode }, options) => {
85
+ export const euiSlightShadowHover = (euiThemeContext, options) => {
86
+ const { euiTheme, highContrastMode } = euiThemeContext;
91
87
  if (highContrastMode) {
92
- return _highContrastBorder(euiTheme, options);
88
+ return _highContrastBorder(euiThemeContext, options);
93
89
  }
94
- const color = options?.color || euiTheme.colors.shadow;
95
- return `
96
- box-shadow:
97
- 0 1px 5px ${getShadowColor(color, 0.1, colorMode)},
98
- 0 3.6px 13px ${getShadowColor(color, 0.07, colorMode)},
99
- 0 8.4px 23px ${getShadowColor(color, 0.06, colorMode)},
100
- 0 23px 35px ${getShadowColor(color, 0.05, colorMode)};
101
- `;
90
+ const direction = options?.direction ?? 'down';
91
+ return _shadowStyles(euiThemeContext, euiTheme.shadows.s[direction], {
92
+ border: options?.border,
93
+ });
102
94
  };
103
95
  /**
104
- * bottomShadowFlat
96
+ * @deprecated - use euiShadowXSmall instead
105
97
  *
98
+ * Remains for backwards compatibility for the Amsterdam theme.
106
99
  * Similar to shadow medium but without the bottom depth.
107
100
  * Useful for popovers that drop UP rather than DOWN.
108
101
  */
109
- export const euiShadowFlat = ({ euiTheme, colorMode, highContrastMode }, options) => {
102
+ export const euiShadowFlat = (euiThemeContext, options) => {
103
+ const { euiTheme, highContrastMode } = euiThemeContext;
110
104
  if (highContrastMode) {
111
- return _highContrastBorder(euiTheme, options);
105
+ return _highContrastBorder(euiThemeContext, options);
112
106
  }
113
- const color = options?.color || euiTheme.colors.shadow;
114
- return `
115
- box-shadow:
116
- 0 0 .8px ${getShadowColor(color, 0.06, colorMode)},
117
- 0 0 2px ${getShadowColor(color, 0.04, colorMode)},
118
- 0 0 5px ${getShadowColor(color, 0.04, colorMode)},
119
- 0 0 17px ${getShadowColor(color, 0.03, colorMode)};
120
- `;
107
+ const direction = options?.direction ?? 'down';
108
+ const value = euiTheme.shadows.flat?.[direction];
109
+ return _shadowStyles(euiThemeContext, value, {
110
+ border: options?.border,
111
+ });
121
112
  };
122
113
  export const euiShadow = (euiThemeContext, size = 'l', options) => {
123
114
  if (euiThemeContext.highContrastMode) {
124
- return _highContrastBorder(euiThemeContext.euiTheme, options);
115
+ return _highContrastBorder(euiThemeContext, options);
125
116
  }
126
117
  switch (size) {
127
118
  case 'xs':
@@ -139,13 +130,68 @@ export const euiShadow = (euiThemeContext, size = 'l', options) => {
139
130
  return '';
140
131
  }
141
132
  };
133
+ /** Hover shadows */
134
+ export const euiShadowHover = (euiThemeContext, size = 'base', options) => {
135
+ if (euiThemeContext.highContrastMode) {
136
+ return _highContrastBorder(euiThemeContext, options);
137
+ }
138
+ switch (size) {
139
+ case 'base':
140
+ return _euiShadowHover(euiThemeContext, 'base', options);
141
+ case 'xs':
142
+ return _euiShadowHover(euiThemeContext, 's', options);
143
+ case 's':
144
+ return _euiShadowHover(euiThemeContext, 'm', options);
145
+ case 'm':
146
+ return _euiShadowHover(euiThemeContext, 'l', options);
147
+ case 'l':
148
+ return _euiShadowHover(euiThemeContext, 'xl', options);
149
+ case 'xl':
150
+ return _euiShadowHover(euiThemeContext, 'xxl', options);
151
+ default:
152
+ console.warn('Please provide a valid size option to useEuiShadow');
153
+ return '';
154
+ }
155
+ };
156
+ const _euiShadowHover = (euiThemeContext, size = 'l', options) => {
157
+ const { euiTheme, highContrastMode } = euiThemeContext;
158
+ if (highContrastMode) {
159
+ return _highContrastBorder(euiThemeContext, options);
160
+ }
161
+ const direction = options?.direction ?? 'down';
162
+ const shadow = size === 'base'
163
+ ? euiTheme.shadows.hover.base[direction]
164
+ : size === 'xxl'
165
+ ? euiTheme.shadows.hover.xl[direction]
166
+ : euiTheme.shadows[size][direction];
167
+ return _shadowStyles(euiThemeContext, shadow, {
168
+ border: options?.border,
169
+ });
170
+ };
142
171
  /**
143
172
  * Internal utilities for replacing shadows with high contrast borders instead.
144
173
  * NOTE: Windows' high contrast themes ignore *all* `box-shadow` CSS,
145
174
  * so we use `border` CSS explicitly instead of shadows
146
175
  */
147
- const _highContrastBorder = ({ border }, { borderAllInHighContrastMode } = {}) => {
148
- return borderAllInHighContrastMode
149
- ? `border: ${border.thin};`
150
- : `border-block-end: ${border.thin};`;
176
+ const _highContrastBorder = (euiThemeContext, { border = 'all', borderAllInHighContrastMode } = {}) => {
177
+ const { euiTheme } = euiThemeContext;
178
+ const hasFullBorder = borderAllInHighContrastMode || (border && border !== 'none');
179
+ return hasFullBorder
180
+ ? `border: ${euiTheme.border.thin};`
181
+ : `border-block-end: ${euiTheme.border.thin};`;
182
+ };
183
+ const _shadowStyles = (euiThemeContext, shadow, options) => {
184
+ const { euiTheme } = euiThemeContext;
185
+ const isRefreshVariant = euiTheme.flags.shadowVariant === 'refresh';
186
+ const { border = 'all', type = 'box-shadow' } = options;
187
+ const borderStyle = euiThemeContext.colorMode === 'DARK' && border !== 'none'
188
+ ? `${euiShadowFloatingBorderStyles(euiThemeContext, {
189
+ side: border ?? 'all',
190
+ })}`
191
+ : '';
192
+ const shadowStyle = type === 'filter' ? shadow : `box-shadow: ${shadow};`;
193
+ return `
194
+ ${shadowStyle};
195
+ ${isRefreshVariant && borderStyle};
196
+ `;
151
197
  };