@elastic/eui-theme-common 10.1.0 → 10.2.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.
@@ -6,7 +6,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
6
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
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
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); } /*
9
+ function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); } /*
10
10
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
11
11
  * or more contributor license agreements. Licensed under the Elastic License
12
12
  * 2.0 and the Server Side Public License, v 1; you may not use this file except
@@ -62,4 +62,49 @@ describe('EuiVisColorStore', function () {
62
62
  expect(updateFn).toHaveBeenCalledTimes(0);
63
63
  });
64
64
  });
65
+ });
66
+ describe('getInstance() initialization contract', function () {
67
+ // Each test gets a fresh module registry so the singleton starts
68
+ // uninitialized, as it would for a consumer that imports this package
69
+ // standalone (e.g. without @elastic/eui).
70
+ it('throws when accessed before being initialized with default colors', function () {
71
+ jest.isolateModules(function () {
72
+ var _jest$requireActual = jest.requireActual('./vis_color_store'),
73
+ FreshStore = _jest$requireActual.EuiVisColorStore;
74
+ expect(function () {
75
+ return FreshStore.getInstance();
76
+ }).toThrow('EuiVisColorStore was accessed before it was initialized');
77
+ });
78
+ });
79
+ it('returns the existing instance when called without arguments after initialization', function () {
80
+ jest.isolateModules(function () {
81
+ var _jest$requireActual2 = jest.requireActual('./vis_color_store'),
82
+ FreshStore = _jest$requireActual2.EuiVisColorStore;
83
+ var initialized = FreshStore.getInstance(visColors);
84
+ expect(FreshStore.getInstance()).toBe(initialized);
85
+ expect(FreshStore.getInstance().visColors).toEqual(visColors);
86
+ });
87
+ });
88
+ it('provides palette defaults once a theme package has initialized the store', function () {
89
+ jest.isolateModules(function () {
90
+ var _jest$requireActual3 = jest.requireActual('./vis_color_store'),
91
+ FreshStore = _jest$requireActual3.EuiVisColorStore;
92
+ var _jest$requireActual4 = jest.requireActual('./eui_palettes'),
93
+ euiPaletteColorBlind = _jest$requireActual4.euiPaletteColorBlind;
94
+
95
+ // simulates what a theme package (e.g. @elastic/eui-theme-borealis)
96
+ // does on import
97
+ FreshStore.getInstance(visColors);
98
+ expect(euiPaletteColorBlind()[0]).toBe(visColors.euiColorVis0);
99
+ });
100
+ });
101
+ it('palette functions throw a descriptive error when no theme initialized the store', function () {
102
+ jest.isolateModules(function () {
103
+ var _jest$requireActual5 = jest.requireActual('./eui_palettes'),
104
+ euiPaletteColorBlind = _jest$requireActual5.euiPaletteColorBlind;
105
+ expect(function () {
106
+ return euiPaletteColorBlind();
107
+ }).toThrow('EuiVisColorStore was accessed before it was initialized');
108
+ });
109
+ });
65
110
  });
package/lib/cjs/utils.js CHANGED
@@ -23,7 +23,7 @@ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Can
23
23
  function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
24
24
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
25
25
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
26
- 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); }
26
+ function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
27
27
  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); } /*
28
28
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
29
29
  * or more contributor license agreements. Licensed under the Elastic License
@@ -6,7 +6,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
6
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
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
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); }
9
+ function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
10
10
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
11
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."); }
12
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; } }
@@ -0,0 +1,23 @@
1
+ export declare const MID_COLOR_STOP = "#EBEFF5";
2
+ /**
3
+ * This function takes an array of colors and returns an array of interpolated
4
+ * colors based on the number of steps/len needed for use in UI elements such as charts.
5
+ * Derived from https://github.com/gka/palettes (Unlicensed)
6
+ */
7
+ export declare function colorPalette(
8
+ /**
9
+ * The main color code or array of codes
10
+ */
11
+ colors: string[],
12
+ /**
13
+ * The number of colors in the resulting array (default 10)
14
+ */
15
+ len?: number,
16
+ /**
17
+ * Forces color interpolation to be calculated separately for each half (default false)
18
+ */
19
+ diverging?: boolean,
20
+ /**
21
+ * Uses a more static interpolation for non-continuous spectrums
22
+ */
23
+ categorical?: boolean): string[];
@@ -0,0 +1,79 @@
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
+ import chroma from 'chroma-js';
9
+ export const MID_COLOR_STOP = '#EBEFF5';
10
+ /**
11
+ * This function takes an array of colors and returns an array of interpolated
12
+ * colors based on the number of steps/len needed for use in UI elements such as charts.
13
+ * Derived from https://github.com/gka/palettes (Unlicensed)
14
+ */
15
+ export function colorPalette(
16
+ /**
17
+ * The main color code or array of codes
18
+ */
19
+ colors,
20
+ /**
21
+ * The number of colors in the resulting array (default 10)
22
+ */
23
+ len = 10,
24
+ /**
25
+ * Forces color interpolation to be calculated separately for each half (default false)
26
+ */
27
+ diverging = false,
28
+ /**
29
+ * Uses a more static interpolation for non-continuous spectrums
30
+ */
31
+ categorical = false) {
32
+ let hexStart = colors.slice();
33
+ let hexEnd = [];
34
+ const even = len % 2 === 0;
35
+ const numColorsLeft = diverging ? Math.ceil(len / 2) + (even ? 1 : 0) : len;
36
+ const numColorsRight = diverging ? Math.ceil(len / 2) + (even ? 1 : 0) : 0;
37
+ // If only a single color is provided prepend the mid-point color
38
+ if (hexStart.length === 1) {
39
+ hexStart.unshift(MID_COLOR_STOP);
40
+ }
41
+ // If diverging, split the start array and duplicate the mid color
42
+ if (diverging) {
43
+ // If there's no midpoint, create one
44
+ if (hexStart.length < 3) {
45
+ hexStart[2] = hexStart[1];
46
+ hexStart[1] = MID_COLOR_STOP;
47
+ }
48
+ const numColorsHalf = Math.ceil(hexStart.length / 2);
49
+ const colorsLeft = hexStart.filter(function (item, index) {
50
+ if (index < numColorsHalf) {
51
+ return true; // keep it
52
+ }
53
+ });
54
+ const colorsRight = hexStart
55
+ .reverse()
56
+ .filter(function (item, index) {
57
+ if (index < numColorsHalf) {
58
+ return true; // keep it
59
+ }
60
+ })
61
+ .reverse();
62
+ hexStart = colorsLeft;
63
+ hexEnd = colorsRight;
64
+ }
65
+ function createSteps(colors, steps) {
66
+ if (!colors.length) {
67
+ return colors;
68
+ }
69
+ if (!categorical) {
70
+ return chroma.bezier(colors).scale().correctLightness().colors(steps);
71
+ }
72
+ else {
73
+ return chroma.scale(colors).colors(steps);
74
+ }
75
+ }
76
+ const stepsLeft = createSteps(hexStart, numColorsLeft);
77
+ const stepsRight = createSteps(hexEnd, numColorsRight);
78
+ return (even && diverging ? stepsLeft.slice(0, stepsLeft.length - 1) : stepsLeft).concat(stepsRight.slice(1));
79
+ }
@@ -0,0 +1,132 @@
1
+ import { _EuiThemeVisColors } from '../global_styling';
2
+ export declare type EuiPalette = string[];
3
+ export declare type EuiPaletteCommonProps = {
4
+ /**
5
+ * Defines the default set of colors the palette uses.
6
+ * Defaults to vis colors from `EUI_VIS_COLOR_STORE`.
7
+ * Use this to specify colors when you can't rely on the EuiProvider updates.
8
+ */
9
+ colors?: _EuiThemeVisColors;
10
+ };
11
+ export declare type EuiPaletteRotationProps = {
12
+ /**
13
+ * How many variations of the series is needed
14
+ */
15
+ rotations?: number;
16
+ /**
17
+ * Order similar colors as `group`s or just `append` each variation
18
+ */
19
+ order?: 'append' | 'group';
20
+ /**
21
+ * Specifies if the direction of the color variations
22
+ */
23
+ direction?: 'lighter' | 'darker' | 'both';
24
+ /**
25
+ * Use the default sort order, or re-sort them based on the color wheel (natural)
26
+ */
27
+ sortBy?: 'default' | 'natural';
28
+ /**
29
+ * Shift the sorting order by a certain number when used in conjunction with `'natural'` `sortBy`.
30
+ * Defaults to a number close to green.
31
+ */
32
+ sortShift?: string;
33
+ };
34
+ export declare type EuiPaletteColorBlindProps = EuiPaletteCommonProps & EuiPaletteRotationProps;
35
+ /**
36
+ * For usage in React use the `useEuiPaletteColorBlind` hook instead.
37
+ *
38
+ * NOTE: These functions rely on base vis colors of the theme which are provided via a global
39
+ * singleton instance `EUI_VIS_COLOR_STORE` that's updated by the EuiProvider on theme change.
40
+ * Make sure the function is recalled on theme change to retrieve theme-related colors.
41
+ *
42
+ * Outside of a react component you can use the `subscibe()` method on the `EUI_VIS_COLOR_STORE`
43
+ * to subscribe to updates and update your usages to ensure latest colors are loaded.
44
+ */
45
+ export declare const euiPaletteColorBlind: ({ rotations, order, direction, sortBy, sortShift, colors, }?: EuiPaletteColorBlindProps) => EuiPalette;
46
+ /**
47
+ * For usage in React use the `useEuiPaletteColorBlindBehindText` hook instead.
48
+ *
49
+ * Color blind palette with text is meant for use when text is applied on top of the color.
50
+ * It increases the brightness of the color to give the text more contrast.
51
+ *
52
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
53
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
54
+ */
55
+ export declare const euiPaletteColorBlindBehindText: (paletteProps?: EuiPaletteColorBlindProps) => EuiPalette;
56
+ /**
57
+ * For usage in React use the `useEuiPaletteForStatus` hook instead.
58
+ *
59
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
60
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
61
+ */
62
+ export declare const euiPaletteForStatus: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
63
+ /**
64
+ * For usage in React use the `useEuiPaletteForTemperature` hook instead.
65
+ *
66
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
67
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
68
+ */
69
+ export declare const euiPaletteForTemperature: (steps: any, { colors }?: EuiPaletteCommonProps) => EuiPalette;
70
+ /**
71
+ * For usage in React use the `useEuiPaletteComplementary` hook instead.
72
+ *
73
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
74
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
75
+ */
76
+ export declare const euiPaletteComplementary: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
77
+ /**
78
+ * For usage in React use the `useEuiPaletteRed` hook instead.
79
+ *
80
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
81
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
82
+ */
83
+ export declare const euiPaletteRed: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
84
+ /**
85
+ * For usage in React use the `useEuiPaletteGreen` hook instead.
86
+ *
87
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
88
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
89
+ */
90
+ export declare const euiPaletteGreen: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
91
+ /**
92
+ * For usage in React use the `useEuiPaletteSkyBlue` hook instead.
93
+ *
94
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
95
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
96
+ */
97
+ export declare const euiPaletteSkyBlue: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
98
+ /**
99
+ * For usage in React use the `useEuiPaletteYellow` hook instead.
100
+ *
101
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
102
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
103
+ */
104
+ export declare const euiPaletteYellow: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
105
+ /**
106
+ * For usage in React use the `useEuiPaletteOrange` hook instead.
107
+ *
108
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
109
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
110
+ */
111
+ export declare const euiPaletteOrange: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
112
+ /**
113
+ * For usage in React use the `useEuiPaletteCool` hook instead.
114
+ *
115
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
116
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
117
+ */
118
+ export declare const euiPaletteCool: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
119
+ /**
120
+ * For usage in React use the `useEuiPaletteWarm` hook instead.
121
+ *
122
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
123
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
124
+ */
125
+ export declare const euiPaletteWarm: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
126
+ /**
127
+ * For usage in React use the `useEuiPaletteGray` hook instead.
128
+ *
129
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
130
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
131
+ */
132
+ export declare const euiPaletteGray: (steps: number, { colors }?: EuiPaletteCommonProps) => EuiPalette;
@@ -0,0 +1,291 @@
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
+ import chroma from 'chroma-js';
9
+ import { colorPalette } from './color_palette';
10
+ import { EuiVisColorStore } from './vis_color_store';
11
+ /**
12
+ * Resolves the default vis colors from the global vis color store singleton.
13
+ * The store is initialized by the theme packages (e.g. `@elastic/eui-theme-borealis`)
14
+ * and kept up to date by `EuiProvider` on theme change.
15
+ */
16
+ const getDefaultVisColors = () => EuiVisColorStore.getInstance().visColors;
17
+ const flatten = (arr) => [].concat(...arr);
18
+ const euiPalette = function (colors, steps, diverge = false, categorical = true) {
19
+ // This function also trims the first color so white/black is never a color
20
+ if (!diverge && steps > 1) {
21
+ const palette = colorPalette(colors, steps + 1);
22
+ palette.shift();
23
+ return palette;
24
+ }
25
+ return colorPalette(colors, steps, diverge, categorical);
26
+ };
27
+ /**
28
+ * For usage in React use the `useEuiPaletteColorBlind` hook instead.
29
+ *
30
+ * NOTE: These functions rely on base vis colors of the theme which are provided via a global
31
+ * singleton instance `EUI_VIS_COLOR_STORE` that's updated by the EuiProvider on theme change.
32
+ * Make sure the function is recalled on theme change to retrieve theme-related colors.
33
+ *
34
+ * Outside of a react component you can use the `subscibe()` method on the `EUI_VIS_COLOR_STORE`
35
+ * to subscribe to updates and update your usages to ensure latest colors are loaded.
36
+ */
37
+ export const euiPaletteColorBlind = ({ rotations = 1, order = 'append', direction = 'lighter', sortBy = 'default', sortShift = '-100', colors, } = {}) => {
38
+ let _colors = [];
39
+ const visColors = colors ?? getDefaultVisColors();
40
+ let base = [
41
+ visColors.euiColorVis0,
42
+ visColors.euiColorVis1,
43
+ visColors.euiColorVis2,
44
+ visColors.euiColorVis3,
45
+ visColors.euiColorVis4,
46
+ visColors.euiColorVis5,
47
+ visColors.euiColorVis6,
48
+ visColors.euiColorVis7,
49
+ visColors.euiColorVis8,
50
+ visColors.euiColorVis9,
51
+ ];
52
+ if (sortBy === 'natural') {
53
+ // Sort the colors based on the color wheel, but shifting the values based on sortShift
54
+ base = [...base].sort(function (a, b) {
55
+ return (chroma(a).set('hsl.h', sortShift).hsl()[0] -
56
+ chroma(b).set('hsl.h', sortShift).hsl()[0]);
57
+ });
58
+ }
59
+ if (rotations > 1) {
60
+ const palettes = base.map((color) => {
61
+ // Create the darkest and lightest versions of each color using black and white
62
+ const palette = colorPalette(['black', color, 'white'], 5, false, true);
63
+ // Then removing the extremes
64
+ palette.pop();
65
+ palette.shift();
66
+ switch (direction) {
67
+ case 'lighter':
68
+ return colorPalette([palette[1], palette[2]], rotations, false, true);
69
+ case 'darker':
70
+ return colorPalette([palette[1], palette[0]], rotations, false, true);
71
+ case 'both':
72
+ return colorPalette(palette, rotations, false, true);
73
+ }
74
+ });
75
+ if (order === 'group') {
76
+ _colors = flatten(palettes);
77
+ }
78
+ else {
79
+ for (let i = 0; i < rotations; i++) {
80
+ const rotation = palettes.map((palette) => palette[i]);
81
+ _colors.push(...rotation);
82
+ }
83
+ }
84
+ }
85
+ else {
86
+ _colors = base;
87
+ }
88
+ return _colors;
89
+ };
90
+ /**
91
+ * For usage in React use the `useEuiPaletteColorBlindBehindText` hook instead.
92
+ *
93
+ * Color blind palette with text is meant for use when text is applied on top of the color.
94
+ * It increases the brightness of the color to give the text more contrast.
95
+ *
96
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
97
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
98
+ */
99
+ export const euiPaletteColorBlindBehindText = (paletteProps = {}) => {
100
+ const originalPalette = euiPaletteColorBlind(paletteProps);
101
+ return originalPalette;
102
+ };
103
+ /**
104
+ * For usage in React use the `useEuiPaletteForStatus` hook instead.
105
+ *
106
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
107
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
108
+ */
109
+ export const euiPaletteForStatus = function (steps, { colors } = {}) {
110
+ const visColors = colors ?? getDefaultVisColors();
111
+ if (steps === 1) {
112
+ return [visColors.euiColorVisSuccess0];
113
+ }
114
+ if (steps <= 3) {
115
+ return euiPalette([
116
+ visColors.euiColorVisSuccess0,
117
+ visColors.euiColorVisWarning1,
118
+ visColors.euiColorVisDanger0,
119
+ ], steps, true);
120
+ }
121
+ return euiPalette([
122
+ visColors.euiColorVisSuccess0,
123
+ visColors.euiColorVisSuccess1,
124
+ visColors.euiColorVisWarning1,
125
+ visColors.euiColorVisDanger1,
126
+ visColors.euiColorVisDanger0,
127
+ ], steps, true);
128
+ };
129
+ /**
130
+ * For usage in React use the `useEuiPaletteForTemperature` hook instead.
131
+ *
132
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
133
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
134
+ */
135
+ export const euiPaletteForTemperature = function (steps, { colors } = {}) {
136
+ const visColors = colors ?? getDefaultVisColors();
137
+ if (steps === 1) {
138
+ return [visColors.euiColorVisCool2];
139
+ }
140
+ else if (steps <= 3) {
141
+ return euiPalette([visColors.euiColorVisCool2, visColors.euiColorVisWarm2], steps, true);
142
+ }
143
+ const cools = colorPalette([
144
+ visColors.euiColorVisCool2,
145
+ visColors.euiColorVisCool1,
146
+ visColors.euiColorVisCool0,
147
+ ], 3);
148
+ const warms = colorPalette([
149
+ visColors.euiColorVisWarm0,
150
+ visColors.euiColorVisWarm1,
151
+ visColors.euiColorVisWarm2,
152
+ ], 3);
153
+ const paletteColors = [...cools, visColors.euiColorVisBase0, ...warms];
154
+ return euiPalette(paletteColors, steps, true);
155
+ };
156
+ /**
157
+ * For usage in React use the `useEuiPaletteComplementary` hook instead.
158
+ *
159
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
160
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
161
+ */
162
+ export const euiPaletteComplementary = function (steps, { colors } = {}) {
163
+ const visColors = colors ?? getDefaultVisColors();
164
+ if (steps === 1) {
165
+ return [visColors.euiColorVisComplementary0];
166
+ }
167
+ const paletteColors = [
168
+ visColors.euiColorVisComplementary0,
169
+ visColors.euiColorVisBase0,
170
+ visColors.euiColorVisComplementary1,
171
+ ];
172
+ return euiPalette(paletteColors, steps, true);
173
+ };
174
+ /**
175
+ * For usage in React use the `useEuiPaletteRed` hook instead.
176
+ *
177
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
178
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
179
+ */
180
+ export const euiPaletteRed = function (steps, { colors } = {}) {
181
+ const visColors = colors ?? getDefaultVisColors();
182
+ if (steps === 1) {
183
+ return [visColors.euiColorVisDanger1];
184
+ }
185
+ return euiPalette([visColors.euiColorVisBase0, visColors.euiColorVisDanger0], steps);
186
+ };
187
+ /**
188
+ * For usage in React use the `useEuiPaletteGreen` hook instead.
189
+ *
190
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
191
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
192
+ */
193
+ export const euiPaletteGreen = function (steps, { colors } = {}) {
194
+ const visColors = colors ?? getDefaultVisColors();
195
+ if (steps === 1) {
196
+ return [visColors.euiColorVisSuccess1];
197
+ }
198
+ return euiPalette([visColors.euiColorVisBase0, visColors.euiColorVisSuccess0], steps);
199
+ };
200
+ /**
201
+ * For usage in React use the `useEuiPaletteSkyBlue` hook instead.
202
+ *
203
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
204
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
205
+ */
206
+ export const euiPaletteSkyBlue = function (steps, { colors } = {}) {
207
+ const visColors = colors ?? getDefaultVisColors();
208
+ if (steps === 1) {
209
+ return [visColors.euiColorVisNeutral1];
210
+ }
211
+ return euiPalette([visColors.euiColorVisBase0, visColors.euiColorVisNeutral0], steps);
212
+ };
213
+ /**
214
+ * For usage in React use the `useEuiPaletteYellow` hook instead.
215
+ *
216
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
217
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
218
+ */
219
+ export const euiPaletteYellow = function (steps, { colors } = {}) {
220
+ const visColors = colors ?? getDefaultVisColors();
221
+ if (steps === 1) {
222
+ return [visColors.euiColorVisWarning1];
223
+ }
224
+ return euiPalette([visColors.euiColorVisBase0, visColors.euiColorVisWarning0], steps);
225
+ };
226
+ /**
227
+ * For usage in React use the `useEuiPaletteOrange` hook instead.
228
+ *
229
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
230
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
231
+ */
232
+ export const euiPaletteOrange = function (steps, { colors } = {}) {
233
+ const visColors = colors ?? getDefaultVisColors();
234
+ if (steps === 1) {
235
+ return [visColors.euiColorVisRisk1];
236
+ }
237
+ return euiPalette([visColors.euiColorVisBase0, visColors.euiColorVisRisk0], steps);
238
+ };
239
+ /**
240
+ * For usage in React use the `useEuiPaletteCool` hook instead.
241
+ *
242
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
243
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
244
+ */
245
+ export const euiPaletteCool = function (steps, { colors } = {}) {
246
+ const visColors = colors ?? getDefaultVisColors();
247
+ if (steps === 1) {
248
+ return [visColors.euiColorVisCool1];
249
+ }
250
+ return euiPalette([
251
+ visColors.euiColorVisCool0,
252
+ visColors.euiColorVisCool1,
253
+ visColors.euiColorVisCool2,
254
+ ], steps);
255
+ };
256
+ /**
257
+ * For usage in React use the `useEuiPaletteWarm` hook instead.
258
+ *
259
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
260
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
261
+ */
262
+ export const euiPaletteWarm = function (steps, { colors } = {}) {
263
+ const visColors = colors ?? getDefaultVisColors();
264
+ if (steps === 1) {
265
+ return [visColors.euiColorVisWarm2];
266
+ }
267
+ return euiPalette([
268
+ visColors.euiColorVisWarm0,
269
+ visColors.euiColorVisWarm1,
270
+ visColors.euiColorVisWarm2,
271
+ ], steps);
272
+ };
273
+ /**
274
+ * For usage in React use the `useEuiPaletteGray` hook instead.
275
+ *
276
+ * NOTE: This function is not pure. It relies on `EUI_VIS_COLOR_STORE` which is updated by the
277
+ * EuiProvider on theme change. Ensure to recall the function on theme change or subscribe to the store.
278
+ */
279
+ export const euiPaletteGray = function (steps, { colors } = {}) {
280
+ const visColors = colors ?? getDefaultVisColors();
281
+ if (steps === 1) {
282
+ return [visColors.euiColorVisGrey1];
283
+ }
284
+ return euiPalette([
285
+ visColors.euiColorVisBase0,
286
+ visColors.euiColorVisGrey0,
287
+ visColors.euiColorVisGrey1,
288
+ visColors.euiColorVisGrey2,
289
+ visColors.euiColorVisGrey3,
290
+ ], steps, false);
291
+ };
@@ -1 +1,3 @@
1
+ export * from './color_palette';
2
+ export * from './eui_palettes';
1
3
  export * from './vis_color_store';
@@ -5,4 +5,6 @@
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
+ export * from './color_palette';
9
+ export * from './eui_palettes';
8
10
  export * from './vis_color_store';
@@ -24,6 +24,6 @@ declare class EuiVisColorStoreImpl implements _EuiVisColorStore {
24
24
  }
25
25
  export declare class EuiVisColorStore {
26
26
  private static instance;
27
- static getInstance(defaultColors: _EuiThemeVisColors): EuiVisColorStoreImpl;
27
+ static getInstance(defaultColors?: _EuiThemeVisColors): EuiVisColorStoreImpl;
28
28
  }
29
29
  export {};
@@ -50,6 +50,10 @@ class EuiVisColorStoreImpl {
50
50
  export class EuiVisColorStore {
51
51
  static getInstance(defaultColors) {
52
52
  if (!this.instance) {
53
+ if (!defaultColors) {
54
+ throw new Error('EuiVisColorStore was accessed before it was initialized with default colors. ' +
55
+ 'Import a theme package (e.g. `@elastic/eui-theme-borealis`) or `@elastic/eui` first.');
56
+ }
53
57
  this.instance = new EuiVisColorStoreImpl({
54
58
  defaultColors,
55
59
  });