@elastic/eui-theme-common 4.0.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 (37) 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/_index.scss +0 -1
  35. package/src/global_styling/variables/_index.scss +0 -1
  36. package/src/global_styling/mixins/_shadow.scss +0 -100
  37. package/src/global_styling/variables/_shadows.scss +0 -2
@@ -1,6 +1,7 @@
1
1
  export declare type EuiThemeVariantFlags = {
2
2
  buttonVariant: 'classic' | 'refresh';
3
3
  formVariant: 'classic' | 'refresh';
4
+ shadowVariant: 'classic' | 'refresh';
4
5
  };
5
6
  /**
6
7
  * Theme specific setting flags
@@ -1,5 +1,9 @@
1
+ import { CSSProperties } from 'react';
2
+ import { ColorModeSwitch } from '../../services/theme/types';
1
3
  export declare const EuiThemeShadowSizes: readonly ["xs", "s", "m", "l", "xl"];
2
4
  export declare type _EuiThemeShadowSize = (typeof EuiThemeShadowSizes)[number];
5
+ export declare const EuiThemeShadowHoverSizes: readonly ["s", "m", "l", "xl", "xxl"];
6
+ export declare type _EuiThemeShadowHoverSize = (typeof EuiThemeShadowHoverSizes)[number];
3
7
  /**
4
8
  * Shadow t-shirt sizes descriptions
5
9
  */
@@ -9,3 +13,51 @@ export interface _EuiThemeShadowCustomColor {
9
13
  property?: 'box-shadow' | 'filter';
10
14
  borderAllInHighContrastMode?: boolean;
11
15
  }
16
+ export declare type _EuiThemeShadow = {
17
+ /** Default direction of the shadow */
18
+ down: CSSProperties['boxShadow'];
19
+ /** Reverse direction */
20
+ up: CSSProperties['boxShadow'];
21
+ };
22
+ export declare type _EuiThemeShadows = ColorModeSwitch<{
23
+ colors: {
24
+ base: string;
25
+ };
26
+ xs: _EuiThemeShadow;
27
+ s: _EuiThemeShadow;
28
+ m: _EuiThemeShadow;
29
+ l: _EuiThemeShadow;
30
+ xl: _EuiThemeShadow;
31
+ hover: {
32
+ base: _EuiThemeShadow;
33
+ xl: _EuiThemeShadow;
34
+ };
35
+ /** @deprecated - Defined only to support the legacy `euiShadowFlat` mixin;
36
+ * will be removed in the future
37
+ */
38
+ flat: _EuiThemeShadow;
39
+ }>;
40
+ /**
41
+ * Represents a single shadow
42
+ * @see https://tr.designtokens.org/format/#shadow
43
+ */
44
+ export declare type _EuiThemeShadowLayer = {
45
+ opacity: number;
46
+ x: number;
47
+ y: number;
48
+ blur: number;
49
+ spread: number;
50
+ };
51
+ export declare type _EuiThemeShadowPrimitive = {
52
+ light: _EuiThemeShadowLayer[];
53
+ dark: _EuiThemeShadowLayer[];
54
+ };
55
+ export declare type _EuiThemeShadowPrimitives = {
56
+ xs: _EuiThemeShadowPrimitive;
57
+ s: _EuiThemeShadowPrimitive;
58
+ m: _EuiThemeShadowPrimitive;
59
+ l: _EuiThemeShadowPrimitive;
60
+ xl: _EuiThemeShadowPrimitive;
61
+ xxl: _EuiThemeShadowPrimitive;
62
+ flat: _EuiThemeShadowPrimitive;
63
+ };
@@ -6,6 +6,7 @@
6
6
  * Side Public License, v 1.
7
7
  */
8
8
  export const EuiThemeShadowSizes = ['xs', 's', 'm', 'l', 'xl'];
9
+ export const EuiThemeShadowHoverSizes = ['s', 'm', 'l', 'xl', 'xxl'];
9
10
  /**
10
11
  * Shadow t-shirt sizes descriptions
11
12
  */
@@ -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/esm/utils.js CHANGED
@@ -5,6 +5,7 @@
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 chroma from 'chroma-js';
8
9
  import { COLOR_MODES_STANDARD, COLOR_MODES_INVERSE, EUI_THEME_OVERRIDES_KEY, EUI_THEME_HIGH_CONTRAST_MODE_KEY, } from './global_styling';
9
10
  export const DEFAULT_COLOR_MODE = COLOR_MODES_STANDARD.light;
10
11
  /**
@@ -331,3 +332,33 @@ export const getTokenName = (prefix, variant, suffix) => {
331
332
  const colorName = variant.charAt(0).toUpperCase() + variant.slice(1);
332
333
  return `${prefix}${getCapitalized(colorName)}${_suffix}`;
333
334
  };
335
+ /**
336
+ * Format an array of shadow "objects" into a string for CSS.
337
+ * The "up" direction is built by making the y offset from layers
338
+ * two and any subsequent layers, negative.
339
+ *
340
+ * It will add `inset` to the first layer when color mode is "DARK"
341
+ * and `spread` is 1, to ensure the dark mode-only floating border
342
+ * is rendered inside the container to match the position of the
343
+ * regular panel border (implemented with a pseudo element).
344
+ *
345
+ * @todo add a color space param to replace the hard-coded `hsl`
346
+ *
347
+ * @param layers
348
+ * @param options
349
+ * @param options.up - Modifies some values in order to get the "up" direction
350
+ * @returns - A value for the CSS `box-shadow` property
351
+ */
352
+ export function formatMultipleBoxShadow(layers, options) {
353
+ if (layers.length === 0) {
354
+ return 'none';
355
+ }
356
+ const { direction = 'down', color = '#000' } = options ?? {};
357
+ /* prettier-ignore */
358
+ const shadowLayers = layers.map((layer, i) => {
359
+ const y = (direction === 'up' && i > 0) ? -layer.y : layer.y;
360
+ const shadowColor = chroma(color).alpha(layer.opacity).css('hsl');
361
+ return `${layer.x}px ${y}px ${layer.blur}px ${layer.spread}px ${shadowColor}`;
362
+ });
363
+ return shadowLayers.join(', ');
364
+ }
@@ -5,7 +5,7 @@
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 { isInverseColorMode, getColorMode, getOn, setOn, computed, Computed, getComputed, buildTheme, mergeDeep, getTokenName, } from './utils';
8
+ import { isInverseColorMode, getColorMode, getOn, setOn, computed, Computed, getComputed, buildTheme, mergeDeep, getTokenName, formatMultipleBoxShadow, } from './utils';
9
9
  describe('isInverseColorMode', () => {
10
10
  it("true only if 'inverse'", () => {
11
11
  expect(isInverseColorMode('LIGHT')).toBe(false);
@@ -233,3 +233,24 @@ describe('getTokenName', () => {
233
233
  expect(getTokenName('backgroundBase', 'primary', 'hovered')).toEqual('backgroundBasePrimaryHovered');
234
234
  });
235
235
  });
236
+ describe('formatMultipleBoxShadow', () => {
237
+ const layers = [
238
+ { x: 0, y: 4, blur: 8, spread: 0, opacity: 0.1 },
239
+ { x: 0, y: 2, blur: 4, spread: 0, opacity: 0.05 },
240
+ ];
241
+ const options = {
242
+ color: '#000000',
243
+ };
244
+ it('returns a valid CSS box-shadow value', () => {
245
+ expect(formatMultipleBoxShadow(layers, options)).toEqual('0px 4px 8px 0px hsla(0,0%,0%,0.1), 0px 2px 4px 0px hsla(0,0%,0%,0.05)');
246
+ });
247
+ it('handles a single layer', () => {
248
+ expect(formatMultipleBoxShadow([layers[0]], options)).toEqual('0px 4px 8px 0px hsla(0,0%,0%,0.1)');
249
+ });
250
+ it('formats the "up" variant', () => {
251
+ expect(formatMultipleBoxShadow(layers, { ...options, direction: 'up' })).toEqual('0px 4px 8px 0px hsla(0,0%,0%,0.1), 0px -2px 4px 0px hsla(0,0%,0%,0.05)');
252
+ });
253
+ it('return "none" for no layers', () => {
254
+ expect(formatMultipleBoxShadow([], options)).toEqual('none');
255
+ });
256
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elastic/eui-theme-common",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "EUI theme common",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "scripts": {
@@ -1,5 +1,4 @@
1
1
  @import 'responsive';
2
- @import 'shadow';
3
2
  @import 'size';
4
3
  @import 'typography';
5
4
  @import 'helpers';
@@ -14,7 +14,6 @@
14
14
  @import 'typography';
15
15
  @import 'borders';
16
16
  @import 'responsive';
17
- @import 'shadows';
18
17
  @import 'states';
19
18
  @import 'z_index';
20
19
 
@@ -1,100 +0,0 @@
1
- @function shadowOpacity($opacity) {
2
- @if (lightness($euiColorTextParagraph) < 50) {
3
- @return $opacity * 1;
4
- } @else {
5
- @return $opacity * 2.5;
6
- }
7
- }
8
-
9
- @mixin euiSlightShadow($color: $euiShadowColor) {
10
- box-shadow:
11
- 0 .8px .8px rgba($color, shadowOpacity(.04)),
12
- 0 2.3px 2px rgba($color, shadowOpacity(.03));
13
- }
14
-
15
- @mixin euiBottomShadowSmall($color: $euiShadowColor) {
16
- box-shadow:
17
- 0 .7px 1.4px rgba($color, shadowOpacity(.07)),
18
- 0 1.9px 4px rgba($color, shadowOpacity(.05)),
19
- 0 4.5px 10px rgba($color, shadowOpacity(.05));
20
- }
21
-
22
- @mixin euiBottomShadowMedium($color: $euiShadowColor) {
23
- box-shadow:
24
- 0 .9px 4px -1px rgba($color, shadowOpacity(.08)),
25
- 0 2.6px 8px -1px rgba($color, shadowOpacity(.06)),
26
- 0 5.7px 12px -1px rgba($color, shadowOpacity(.05)),
27
- 0 15px 15px -1px rgba($color, shadowOpacity(.04));
28
- }
29
-
30
- // Similar to shadow medium but without the bottom depth. Useful for popovers
31
- // that drop UP rather than DOWN.
32
- @mixin euiBottomShadowFlat($color: $euiShadowColor) {
33
- box-shadow:
34
- 0 0 .8px rgba($color, shadowOpacity(.06)),
35
- 0 0 2px rgba($color, shadowOpacity(.04)),
36
- 0 0 5px rgba($color, shadowOpacity(.04)),
37
- 0 0 17px rgba($color, shadowOpacity(.03));
38
- }
39
-
40
- @mixin euiBottomShadow($color: $euiShadowColor) {
41
- box-shadow:
42
- 0 1px 5px rgba($color, shadowOpacity(.1)),
43
- 0 3.6px 13px rgba($color, shadowOpacity(.07)),
44
- 0 8.4px 23px rgba($color, shadowOpacity(.06)),
45
- 0 23px 35px rgba($color, shadowOpacity(.05));
46
- }
47
-
48
- @mixin euiBottomShadowLarge(
49
- $color: $euiShadowColor,
50
- $opacity: 0,
51
- $reverse: false
52
- ) {
53
- @if ($reverse) {
54
- box-shadow:
55
- 0 -2.7px 9px rgba($color, shadowOpacity(.13)),
56
- 0 -9.4px 24px rgba($color, shadowOpacity(.09)),
57
- 0 -21.8px 43px rgba($color, shadowOpacity(.08));
58
- } @else {
59
- box-shadow:
60
- 0 2.7px 9px rgba($color, shadowOpacity(.13)),
61
- 0 9.4px 24px rgba($color, shadowOpacity(.09)),
62
- 0 21.8px 43px rgba($color, shadowOpacity(.08));
63
- }
64
- }
65
-
66
- // stylelint-disable color-named
67
- @mixin euiOverflowShadow($direction: 'y', $side: 'both') {
68
- $hideHeight: $euiScrollBarCornerThin * 1.25;
69
- $gradient: null;
70
- $gradientStart:
71
- transparentize(red, .9) 0%,
72
- transparentize(red, 0) $hideHeight;
73
- $gradientEnd:
74
- transparentize(red, 0) calc(100% - #{$hideHeight}),
75
- transparentize(red, .9) 100%;
76
- @if ($side == 'both' or $side == 'start' or $side == 'end') {
77
- @if ($side == 'both') {
78
- $gradient: $gradientStart, $gradientEnd;
79
- } @else if ($side == 'start') {
80
- $gradient: $gradientStart;
81
- } @else {
82
- $gradient: $gradientEnd;
83
- }
84
- } @else {
85
- @warn "euiOverflowShadow() expects side to be 'both', 'start' or 'end' but got '#{$side}'";
86
- }
87
-
88
- @if ($direction == 'y') {
89
- mask-image: linear-gradient(to bottom, #{$gradient});
90
- } @else if ($direction == 'x') {
91
- mask-image: linear-gradient(to right, #{$gradient});
92
- } @else {
93
- @warn "euiOverflowShadow() expects direction to be 'y' or 'x' but got '#{$direction}'";
94
- }
95
-
96
- // Chrome+Edge has a very bizarre edge case bug where `mask-image` stops working
97
- // This workaround forces a stacking context on the scrolling container, which
98
- // hopefully addresses the bug. @see https://github.com/elastic/eui/pull/7855
99
- transform: translateZ(0);
100
- }
@@ -1,2 +0,0 @@
1
- // Shadows
2
- $euiShadowColor: $euiColorInk !default;