@elastic/eui-theme-common 4.0.0 → 6.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 (54) 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 +22 -14
  8. package/lib/cjs/global_styling/mixins/shadow.js +142 -68
  9. package/lib/cjs/global_styling/variables/borders.d.ts +1 -1
  10. package/lib/cjs/global_styling/variables/components.d.ts +0 -1
  11. package/lib/cjs/global_styling/variables/flags.d.ts +2 -6
  12. package/lib/cjs/global_styling/variables/shadow.d.ts +52 -0
  13. package/lib/cjs/global_styling/variables/shadow.js +8 -2
  14. package/lib/cjs/global_styling/variables/typography.d.ts +1 -1
  15. package/lib/cjs/services/theme/types.d.ts +8 -1
  16. package/lib/cjs/services/vis_color_store.d.ts +3 -7
  17. package/lib/cjs/services/vis_color_store.js +4 -15
  18. package/lib/cjs/services/vis_color_store.test.js +1 -5
  19. package/lib/cjs/utils.d.ts +22 -1
  20. package/lib/cjs/utils.js +39 -1
  21. package/lib/cjs/utils.test.js +38 -0
  22. package/lib/esm/global_styling/functions/shadows.d.ts +12 -0
  23. package/lib/esm/global_styling/functions/shadows.js +40 -1
  24. package/lib/esm/global_styling/mixins/borders.d.ts +23 -0
  25. package/lib/esm/global_styling/mixins/borders.js +50 -0
  26. package/lib/esm/global_styling/mixins/index.d.ts +1 -0
  27. package/lib/esm/global_styling/mixins/index.js +1 -0
  28. package/lib/esm/global_styling/mixins/shadow.d.ts +22 -14
  29. package/lib/esm/global_styling/mixins/shadow.js +126 -81
  30. package/lib/esm/global_styling/variables/borders.d.ts +1 -1
  31. package/lib/esm/global_styling/variables/components.d.ts +0 -1
  32. package/lib/esm/global_styling/variables/flags.d.ts +2 -6
  33. package/lib/esm/global_styling/variables/shadow.d.ts +52 -0
  34. package/lib/esm/global_styling/variables/shadow.js +1 -0
  35. package/lib/esm/global_styling/variables/typography.d.ts +1 -1
  36. package/lib/esm/services/theme/types.d.ts +8 -1
  37. package/lib/esm/services/vis_color_store.d.ts +3 -7
  38. package/lib/esm/services/vis_color_store.js +3 -12
  39. package/lib/esm/services/vis_color_store.test.js +1 -5
  40. package/lib/esm/utils.d.ts +22 -1
  41. package/lib/esm/utils.js +31 -0
  42. package/lib/esm/utils.test.js +22 -1
  43. package/package.json +1 -1
  44. package/src/global_styling/mixins/_index.scss +0 -7
  45. package/src/global_styling/mixins/_states.scss +1 -1
  46. package/src/global_styling/variables/_index.scss +0 -1
  47. package/src/global_styling/mixins/_button.scss +0 -149
  48. package/src/global_styling/mixins/_form.scss +0 -272
  49. package/src/global_styling/mixins/_link.scss +0 -11
  50. package/src/global_styling/mixins/_loading.scss +0 -6
  51. package/src/global_styling/mixins/_panel.scss +0 -55
  52. package/src/global_styling/mixins/_range.scss +0 -59
  53. package/src/global_styling/mixins/_shadow.scss +0 -100
  54. package/src/global_styling/variables/_shadows.scss +0 -2
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports._EuiShadowSizesDescriptions = exports.EuiThemeShadowSizes = void 0;
6
+ exports._EuiShadowSizesDescriptions = exports.EuiThemeShadowSizes = exports.EuiThemeShadowHoverSizes = void 0;
7
7
  /*
8
8
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
9
9
  * or more contributor license agreements. Licensed under the Elastic License
@@ -13,6 +13,7 @@ exports._EuiShadowSizesDescriptions = exports.EuiThemeShadowSizes = void 0;
13
13
  */
14
14
 
15
15
  var EuiThemeShadowSizes = exports.EuiThemeShadowSizes = ['xs', 's', 'm', 'l', 'xl'];
16
+ var EuiThemeShadowHoverSizes = exports.EuiThemeShadowHoverSizes = ['s', 'm', 'l', 'xl', 'xxl'];
16
17
  /**
17
18
  * Shadow t-shirt sizes descriptions
18
19
  */
@@ -22,4 +23,9 @@ var _EuiShadowSizesDescriptions = exports._EuiShadowSizesDescriptions = {
22
23
  m: 'Used on small sized portalled content like popovers.',
23
24
  l: 'Primary shadow used in most cases to add visible depth.',
24
25
  xl: 'Very large shadows used for large portalled style containers like modals and flyouts.'
25
- };
26
+ };
27
+
28
+ /**
29
+ * Represents a single shadow
30
+ * @see https://tr.designtokens.org/format/#shadow
31
+ */
@@ -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
  };
@@ -79,3 +81,8 @@ export interface UseEuiTheme<T extends {} = {}> {
79
81
  highContrastMode: EuiThemeHighContrastMode;
80
82
  modifications: EuiThemeModifications<T>;
81
83
  }
84
+ export interface EUI_THEME {
85
+ text: string;
86
+ value: string;
87
+ provider?: EuiThemeSystem;
88
+ }
@@ -6,28 +6,24 @@ export declare type VisColorStoreEvents = keyof typeof VIS_COLOR_STORE_EVENTS;
6
6
  declare type EventId = string;
7
7
  export declare type _EuiVisColorStore = {
8
8
  visColors: _EuiThemeVisColors;
9
- hasVisColorAdjustment: boolean;
10
- setVisColors: (colors: _EuiThemeVisColors, hasVisColorAdjustment?: boolean) => void;
9
+ setVisColors: (colors: _EuiThemeVisColors) => void;
11
10
  subscribe: (eventName: VisColorStoreEvents, callback: any) => EventId;
12
11
  unsubscribe: (eventName: VisColorStoreEvents, id: EventId) => void;
13
12
  };
14
13
  declare class EuiVisColorStoreImpl implements _EuiVisColorStore {
15
14
  private _visColors;
16
- private _hasVisColorAdjustment;
17
15
  private events;
18
16
  constructor(dependencies: {
19
17
  defaultColors: _EuiThemeVisColors;
20
- hasVisColorAdjustment: boolean;
21
18
  });
22
19
  get visColors(): _EuiVisColorStore['visColors'];
23
- get hasVisColorAdjustment(): _EuiVisColorStore['hasVisColorAdjustment'];
24
- setVisColors: (colors: _EuiThemeVisColors, hasColorAdjustment?: boolean | undefined) => void;
20
+ setVisColors: (colors: _EuiThemeVisColors) => void;
25
21
  subscribe: (eventName: VisColorStoreEvents, callback: NonNullable<any>) => string;
26
22
  unsubscribe: (eventName: VisColorStoreEvents, id: EventId) => void;
27
23
  private publishUpdate;
28
24
  }
29
25
  export declare class EuiVisColorStore {
30
26
  private static instance;
31
- static getInstance(defaultColors: _EuiThemeVisColors, hasVisColorAdjustment: boolean): EuiVisColorStoreImpl;
27
+ static getInstance(defaultColors: _EuiThemeVisColors): EuiVisColorStoreImpl;
32
28
  }
33
29
  export {};
@@ -28,14 +28,10 @@ var EuiVisColorStoreImpl = /*#__PURE__*/function () {
28
28
  var _this = this;
29
29
  _classCallCheck(this, EuiVisColorStoreImpl);
30
30
  _defineProperty(this, "_visColors", void 0);
31
- _defineProperty(this, "_hasVisColorAdjustment", void 0);
32
31
  _defineProperty(this, "events", {});
33
- _defineProperty(this, "setVisColors", function (colors, hasColorAdjustment) {
34
- if (!(0, _isEqual["default"])(_this._visColors, colors) || hasColorAdjustment !== _this._hasVisColorAdjustment) {
32
+ _defineProperty(this, "setVisColors", function (colors) {
33
+ if (!(0, _isEqual["default"])(_this._visColors, colors)) {
35
34
  _this._visColors = colors;
36
- if (hasColorAdjustment != null) {
37
- _this._hasVisColorAdjustment = hasColorAdjustment;
38
- }
39
35
  _this.publishUpdate(VIS_COLOR_STORE_EVENTS.UPDATE, _this._visColors);
40
36
  }
41
37
  });
@@ -61,18 +57,12 @@ var EuiVisColorStoreImpl = /*#__PURE__*/function () {
61
57
  });
62
58
  });
63
59
  this._visColors = dependencies.defaultColors;
64
- this._hasVisColorAdjustment = dependencies.hasVisColorAdjustment;
65
60
  }
66
61
  return _createClass(EuiVisColorStoreImpl, [{
67
62
  key: "visColors",
68
63
  get: function get() {
69
64
  return this._visColors;
70
65
  }
71
- }, {
72
- key: "hasVisColorAdjustment",
73
- get: function get() {
74
- return this._hasVisColorAdjustment;
75
- }
76
66
  }]);
77
67
  }();
78
68
  var EuiVisColorStore = exports.EuiVisColorStore = /*#__PURE__*/function () {
@@ -81,11 +71,10 @@ var EuiVisColorStore = exports.EuiVisColorStore = /*#__PURE__*/function () {
81
71
  }
82
72
  return _createClass(EuiVisColorStore, null, [{
83
73
  key: "getInstance",
84
- value: function getInstance(defaultColors, hasVisColorAdjustment) {
74
+ value: function getInstance(defaultColors) {
85
75
  if (!this.instance) {
86
76
  this.instance = new EuiVisColorStoreImpl({
87
- defaultColors: defaultColors,
88
- hasVisColorAdjustment: hasVisColorAdjustment
77
+ defaultColors: defaultColors
89
78
  });
90
79
  }
91
80
  return this.instance;
@@ -18,7 +18,7 @@ var visColors = {
18
18
  euiColorVis0: '#aabbcc'
19
19
  };
20
20
  describe('EuiVisColorStore', function () {
21
- var visColorStore = _vis_color_store.EuiVisColorStore.getInstance(visColors, false);
21
+ var visColorStore = _vis_color_store.EuiVisColorStore.getInstance(visColors);
22
22
  var updateFn;
23
23
  beforeEach(function () {
24
24
  updateFn = jest.fn();
@@ -37,10 +37,6 @@ describe('EuiVisColorStore', function () {
37
37
  visColorStore.setVisColors(customColors);
38
38
  expect(visColorStore.visColors).toEqual(customColors);
39
39
  });
40
- it('updates hasVisColorAdjustment', function () {
41
- visColorStore.setVisColors(customColors, true);
42
- expect(visColorStore.hasVisColorAdjustment).toEqual(true);
43
- });
44
40
  });
45
41
  describe('subcribe and unsubscribe', function () {
46
42
  it('subscribes to store updates', function () {
@@ -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,53 @@
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
  *
41
47
  * Similar to shadow medium but without the bottom depth.
42
48
  * Useful for popovers that drop UP rather than DOWN.
43
49
  */
44
- export declare const euiShadowFlat: ({ euiTheme, colorMode, highContrastMode }: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
50
+ export declare const euiShadowFlat: (euiThemeContext: UseEuiTheme, options?: EuiShadowOptions | undefined) => string;
45
51
  export declare const euiShadow: (euiThemeContext: UseEuiTheme, size?: _EuiThemeShadowSize, options?: EuiShadowOptions | undefined) => string;
52
+ /** Hover shadows */
53
+ export declare const euiShadowHover: (euiThemeContext: UseEuiTheme, size?: _EuiThemeShadowSize | 'base', options?: EuiShadowOptions | undefined) => string;