@kaizen/design-tokens 10.3.2-canary.40 → 10.3.3

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 (59) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/ThemeManager.d.ts +26 -0
  3. package/dist/ThemeManager.d.ts.map +1 -0
  4. package/dist/ThemeManager.js +75 -0
  5. package/dist/ThemeManager.js.map +1 -0
  6. package/dist/index.d.ts +8 -360
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +28 -545
  9. package/dist/index.js.map +1 -0
  10. package/dist/lib/__tests__/themeForTesting.d.ts +39 -0
  11. package/dist/lib/__tests__/themeForTesting.d.ts.map +1 -0
  12. package/dist/lib/__tests__/themeForTesting.js +21 -0
  13. package/dist/lib/__tests__/themeForTesting.js.map +1 -0
  14. package/dist/lib/addExtraThemeEntries.d.ts +23 -0
  15. package/dist/lib/addExtraThemeEntries.d.ts.map +1 -0
  16. package/dist/lib/addExtraThemeEntries.js +60 -0
  17. package/dist/lib/addExtraThemeEntries.js.map +1 -0
  18. package/dist/lib/cssVariables.d.ts +23 -0
  19. package/dist/lib/cssVariables.d.ts.map +1 -0
  20. package/dist/lib/cssVariables.js +34 -0
  21. package/dist/lib/cssVariables.js.map +1 -0
  22. package/dist/lib/makeCssVariableDefinitionsMap.d.ts +30 -0
  23. package/dist/lib/makeCssVariableDefinitionsMap.d.ts.map +1 -0
  24. package/dist/lib/makeCssVariableDefinitionsMap.js +58 -0
  25. package/dist/lib/makeCssVariableDefinitionsMap.js.map +1 -0
  26. package/dist/lib/makeCssVariableTheme.d.ts +35 -0
  27. package/dist/lib/makeCssVariableTheme.d.ts.map +1 -0
  28. package/dist/lib/makeCssVariableTheme.js +58 -0
  29. package/dist/lib/makeCssVariableTheme.js.map +1 -0
  30. package/dist/lib/mapLeafsOfObject.d.ts +23 -0
  31. package/dist/lib/mapLeafsOfObject.d.ts.map +1 -0
  32. package/dist/lib/mapLeafsOfObject.js +62 -0
  33. package/dist/lib/mapLeafsOfObject.js.map +1 -0
  34. package/dist/lib/patterns.d.ts +3 -0
  35. package/dist/lib/patterns.d.ts.map +1 -0
  36. package/dist/lib/patterns.js +6 -0
  37. package/dist/lib/patterns.js.map +1 -0
  38. package/dist/react/ThemeProvider.d.ts +16 -0
  39. package/dist/react/ThemeProvider.d.ts.map +1 -0
  40. package/dist/react/ThemeProvider.js +75 -0
  41. package/dist/react/ThemeProvider.js.map +1 -0
  42. package/dist/react/index.d.ts +2 -0
  43. package/dist/react/index.d.ts.map +1 -0
  44. package/dist/react/index.js +18 -0
  45. package/dist/react/index.js.map +1 -0
  46. package/dist/themes/heart.d.ts +3 -0
  47. package/dist/themes/heart.d.ts.map +1 -0
  48. package/dist/themes/heart.js +312 -0
  49. package/dist/themes/heart.js.map +1 -0
  50. package/dist/themes/index.d.ts +3 -0
  51. package/dist/themes/index.d.ts.map +1 -0
  52. package/dist/themes/index.js +8 -0
  53. package/dist/themes/index.js.map +1 -0
  54. package/dist/types.d.ts +230 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +3 -0
  57. package/dist/types.js.map +1 -0
  58. package/package.json +4 -5
  59. package/dist/esm/index.js +0 -546
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [10.3.3](https://github.com/cultureamp/kaizen-design-system/compare/@kaizen/design-tokens@10.3.2...@kaizen/design-tokens@10.3.3) (2023-03-29)
7
+
8
+ **Note:** Version bump only for package @kaizen/design-tokens
9
+
10
+
11
+
12
+
13
+
14
+ ## [10.3.2](https://github.com/cultureamp/kaizen-design-system/compare/@kaizen/design-tokens@10.3.1...@kaizen/design-tokens@10.3.2) (2023-03-23)
15
+
16
+ **Note:** Version bump only for package @kaizen/design-tokens
17
+
18
+
19
+
20
+
21
+
6
22
  ## [10.3.1](https://github.com/cultureamp/kaizen-design-system/compare/@kaizen/design-tokens@10.3.0...@kaizen/design-tokens@10.3.1) (2023-02-21)
7
23
 
8
24
  **Note:** Version bump only for package @kaizen/design-tokens
@@ -0,0 +1,26 @@
1
+ import { Theme as BaseTheme } from "./types";
2
+ /**
3
+ * Use this class to set and apply themes, and to access or subscribe to the currently active one.
4
+ * This class fulfills the idea of theming and runtime theme switching by relying on CSS variables,
5
+ * and the ability to update them in JavaScript - a framework agnostic method.
6
+ *
7
+ * It works by converting a Theme interface to a flattened map of CSS variable keys and values, then calling `document.documentElement.style.setProperty(key, value)`.
8
+ */
9
+ export declare class ThemeManager<Theme extends BaseTheme = BaseTheme> {
10
+ private themeChangeListeners;
11
+ private theme;
12
+ private rootElement;
13
+ private rootElementId;
14
+ constructor(theme: Theme, rootElementId?: string, apply?: boolean);
15
+ getRootElement: () => HTMLElement | null;
16
+ getRootElementId: () => string;
17
+ getCurrentTheme: () => Theme;
18
+ setRootElement: (element: HTMLElement) => void;
19
+ setRootElementId: (rootElementId: string) => string;
20
+ setAndApplyTheme: (theme: Theme, force?: boolean) => void;
21
+ addThemeChangeListener: (listener: (theme: Theme) => void) => void;
22
+ removeThemeChangeListener: (listener: (theme: Theme) => void) => void;
23
+ applyCurrentTheme: () => void;
24
+ private notifyThemeChangeListeners;
25
+ }
26
+ //# sourceMappingURL=ThemeManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeManager.d.ts","sourceRoot":"","sources":["../src/ThemeManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,SAAS,CAAA;AAC5C;;;;;;GAMG;AACH,qBAAa,YAAY,CAAC,KAAK,SAAS,SAAS,GAAG,SAAS;IAC3D,OAAO,CAAC,oBAAoB,CAAsC;IAClE,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,aAAa,CAAQ;gBAG3B,KAAK,EAAE,KAAK,EACZ,aAAa,GAAE,MAAW,EAE1B,KAAK,GAAE,OAAc;IAWhB,cAAc,QAAO,WAAW,GAAG,IAAI,CAAoB;IAC3D,gBAAgB,QAAO,MAAM,CAAsB;IACnD,eAAe,QAAO,KAAK,CAAc;IAEzC,cAAc,YAAa,WAAW,KAAG,IAAI,CAEnD;IACM,gBAAgB,kBAAmB,MAAM,KAAG,MAAM,CACnB;IAC/B,gBAAgB,UAAW,KAAK,UAAU,OAAO,KAAG,IAAI,CAO9D;IAEM,sBAAsB,qBAAsB,KAAK,KAAK,IAAI,KAAG,IAAI,CAEvE;IACM,yBAAyB,qBACZ,KAAK,KAAK,IAAI,KAC/B,IAAI,CAIN;IACM,iBAAiB,QAAO,IAAI,CAUlC;IAED,OAAO,CAAC,0BAA0B,CAEjC;CACF"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThemeManager = void 0;
4
+ var makeCssVariableDefinitionsMap_1 = require("./lib/makeCssVariableDefinitionsMap");
5
+ /**
6
+ * Use this class to set and apply themes, and to access or subscribe to the currently active one.
7
+ * This class fulfills the idea of theming and runtime theme switching by relying on CSS variables,
8
+ * and the ability to update them in JavaScript - a framework agnostic method.
9
+ *
10
+ * It works by converting a Theme interface to a flattened map of CSS variable keys and values, then calling `document.documentElement.style.setProperty(key, value)`.
11
+ */
12
+ var ThemeManager = /** @class */ (function () {
13
+ function ThemeManager(theme, rootElementId,
14
+ /* This allows you to stop the class from applying the theme automatically during construction. Defaults to true */
15
+ apply) {
16
+ if (rootElementId === void 0) { rootElementId = ""; }
17
+ if (apply === void 0) { apply = true; }
18
+ var _this = this;
19
+ this.themeChangeListeners = [];
20
+ this.rootElement = null;
21
+ this.getRootElement = function () { return _this.rootElement; };
22
+ this.getRootElementId = function () { return _this.rootElementId; };
23
+ this.getCurrentTheme = function () { return _this.theme; };
24
+ this.setRootElement = function (element) {
25
+ _this.rootElement = element;
26
+ };
27
+ this.setRootElementId = function (rootElementId) {
28
+ return (_this.rootElementId = rootElementId);
29
+ };
30
+ this.setAndApplyTheme = function (theme, force) {
31
+ if (!force) {
32
+ if (_this.theme === theme)
33
+ return;
34
+ }
35
+ _this.theme = theme;
36
+ _this.applyCurrentTheme();
37
+ _this.notifyThemeChangeListeners(theme);
38
+ };
39
+ this.addThemeChangeListener = function (listener) {
40
+ _this.themeChangeListeners.push(listener);
41
+ };
42
+ this.removeThemeChangeListener = function (listener) {
43
+ _this.themeChangeListeners = _this.themeChangeListeners.filter(function (l) { return l !== listener; });
44
+ };
45
+ this.applyCurrentTheme = function () {
46
+ var _a;
47
+ if (typeof window !== "undefined") {
48
+ _this.setRootElement((_a = document.getElementById(_this.rootElementId)) !== null && _a !== void 0 ? _a : document.documentElement);
49
+ var cssVariableDefinitions = (0, makeCssVariableDefinitionsMap_1.makeCssVariableDefinitionsMap)(_this.theme);
50
+ Object.entries(cssVariableDefinitions).forEach(function (_a) {
51
+ var _b;
52
+ var key = _a[0], value = _a[1];
53
+ (_b = _this.rootElement) === null || _b === void 0 ? void 0 : _b.style.setProperty(key, value);
54
+ });
55
+ }
56
+ };
57
+ this.notifyThemeChangeListeners = function (theme) {
58
+ _this.themeChangeListeners.forEach(function (listener) { return listener(theme); });
59
+ };
60
+ /*
61
+ For some reason, storybook likes this way of defining class properties better.
62
+ If you use `constructor( private theme: Theme, ...)` - theme becomes undefined within the class's methods.
63
+ */
64
+ this.theme = theme;
65
+ this.rootElementId = rootElementId;
66
+ if (apply)
67
+ this.applyCurrentTheme();
68
+ }
69
+ return ThemeManager;
70
+ }());
71
+ exports.ThemeManager = ThemeManager;
72
+ // I would like to expose this, but instantiating ThemeManager in some situations or runtimes (such as nodejs) cause exceptions.
73
+ // For now it is not exposed, but we might come back to it, as it makes sense to have a singleton ThemeManager in almost all cases
74
+ /* export const defaultThemeManager = new ThemeManager(defaultTheme) */
75
+ //# sourceMappingURL=ThemeManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeManager.js","sourceRoot":"","sources":["../src/ThemeManager.ts"],"names":[],"mappings":";;;AAAA,qFAAmF;AAEnF;;;;;;GAMG;AACH;IAME,sBACE,KAAY,EACZ,aAA0B;IAC1B,oHAAoH;IACpH,KAAqB;QAFrB,8BAAA,EAAA,kBAA0B;QAE1B,sBAAA,EAAA,YAAqB;QAJvB,iBAaC;QAlBO,yBAAoB,GAAG,EAAmC,CAAA;QAE1D,gBAAW,GAAuB,IAAI,CAAA;QAkBvC,mBAAc,GAAG,cAA0B,OAAA,KAAI,CAAC,WAAW,EAAhB,CAAgB,CAAA;QAC3D,qBAAgB,GAAG,cAAc,OAAA,KAAI,CAAC,aAAa,EAAlB,CAAkB,CAAA;QACnD,oBAAe,GAAG,cAAa,OAAA,KAAI,CAAC,KAAK,EAAV,CAAU,CAAA;QAEzC,mBAAc,GAAG,UAAC,OAAoB;YAC3C,KAAI,CAAC,WAAW,GAAG,OAAO,CAAA;QAC5B,CAAC,CAAA;QACM,qBAAgB,GAAG,UAAC,aAAqB;YAC9C,OAAA,CAAC,KAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAApC,CAAoC,CAAA;QAC/B,qBAAgB,GAAG,UAAC,KAAY,EAAE,KAAe;YACtD,IAAI,CAAC,KAAK,EAAE;gBACV,IAAI,KAAI,CAAC,KAAK,KAAK,KAAK;oBAAE,OAAM;aACjC;YACD,KAAI,CAAC,KAAK,GAAG,KAAK,CAAA;YAClB,KAAI,CAAC,iBAAiB,EAAE,CAAA;YACxB,KAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAA;QACxC,CAAC,CAAA;QAEM,2BAAsB,GAAG,UAAC,QAAgC;YAC/D,KAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC1C,CAAC,CAAA;QACM,8BAAyB,GAAG,UACjC,QAAgC;YAEhC,KAAI,CAAC,oBAAoB,GAAG,KAAI,CAAC,oBAAoB,CAAC,MAAM,CAC1D,UAAA,CAAC,IAAI,OAAA,CAAC,KAAK,QAAQ,EAAd,CAAc,CACpB,CAAA;QACH,CAAC,CAAA;QACM,sBAAiB,GAAG;;YACzB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;gBACjC,KAAI,CAAC,cAAc,CACjB,MAAA,QAAQ,CAAC,cAAc,CAAC,KAAI,CAAC,aAAa,CAAC,mCAAI,QAAQ,CAAC,eAAe,CACxE,CAAA;gBACD,IAAM,sBAAsB,GAAG,IAAA,6DAA6B,EAAC,KAAI,CAAC,KAAK,CAAC,CAAA;gBACxE,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAAC,UAAC,EAAY;;wBAAX,GAAG,QAAA,EAAE,KAAK,QAAA;oBACzD,MAAA,KAAI,CAAC,WAAW,0CAAE,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;gBACjD,CAAC,CAAC,CAAA;aACH;QACH,CAAC,CAAA;QAEO,+BAA0B,GAAG,UAAC,KAAY;YAChD,KAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,KAAK,CAAC,EAAf,CAAe,CAAC,CAAA;QAChE,CAAC,CAAA;QAnDC;;;UAGE;QACF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,KAAK;YAAE,IAAI,CAAC,iBAAiB,EAAE,CAAA;IACrC,CAAC;IA6CH,mBAAC;AAAD,CAAC,AAhED,IAgEC;AAhEY,oCAAY;AAkEzB,gIAAgI;AAChI,kIAAkI;AAClI,uEAAuE"}
package/dist/index.d.ts CHANGED
@@ -1,360 +1,8 @@
1
- import React, { CSSProperties } from 'react';
2
-
3
- /**
4
- * Use a custom type for CSS properties becauase we should eventually write a more strongly typed version using template literal types.
5
- * This could definitely be contributed back to the community too. An example starting point here https://github.com/ghoullier/awesome-template-literal-types#css-parser
6
- * For example:
7
- * ```ts
8
- * type Font = {
9
- * fontSize: `${number}rem`,
10
- *
11
- * }
12
- * type HexDigit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F ;
13
- * type Color = `rgba(${number}, ${number}, ${number}, ${number}) | #${HexDigit}${HexDigit}${HexDigit}` // You get the point
14
- *
15
- * ```
16
- * */
17
- type KaizenCSSProperties = CSSProperties;
18
- type Hex = string;
19
- type TypographyFont = {
20
- fontFamily: KaizenCSSProperties["fontFamily"];
21
- fontWeight: KaizenCSSProperties["fontWeight"];
22
- fontSize: KaizenCSSProperties["fontSize"];
23
- lineHeight: KaizenCSSProperties["lineHeight"];
24
- letterSpacing: KaizenCSSProperties["letterSpacing"];
25
- };
26
- type ThemeKey = "heart" | "custom";
27
- type Theme = {
28
- themeKey: ThemeKey;
29
- border: {
30
- solid: {
31
- borderWidth: KaizenCSSProperties["borderWidth"];
32
- borderRadius: KaizenCSSProperties["borderRadius"];
33
- borderStyle: KaizenCSSProperties["borderStyle"];
34
- borderColor: KaizenCSSProperties["borderColor"];
35
- };
36
- dashed: {
37
- borderWidth: KaizenCSSProperties["borderWidth"];
38
- borderRadius: KaizenCSSProperties["borderRadius"];
39
- borderStyle: KaizenCSSProperties["borderStyle"];
40
- };
41
- borderless: {
42
- borderWidth: KaizenCSSProperties["borderWidth"];
43
- borderRadius: KaizenCSSProperties["borderRadius"];
44
- borderStyle: KaizenCSSProperties["borderStyle"];
45
- borderColor: KaizenCSSProperties["borderColor"];
46
- };
47
- focusRing: {
48
- borderWidth: KaizenCSSProperties["borderWidth"];
49
- borderRadius: KaizenCSSProperties["borderRadius"];
50
- borderStyle: KaizenCSSProperties["borderStyle"];
51
- };
52
- };
53
- animation: {
54
- easingFunction: {
55
- easeInOut: string;
56
- easeIn: string;
57
- easeOut: string;
58
- linear: string;
59
- bounceIn: string;
60
- bounceOut: string;
61
- bounceInOut: string;
62
- };
63
- duration: {
64
- instant: string;
65
- immediate: string;
66
- rapid: string;
67
- fast: string;
68
- slow: string;
69
- deliberate: string;
70
- };
71
- };
72
- color: {
73
- purple: {
74
- "100": Hex;
75
- "200": Hex;
76
- "300": Hex;
77
- "400": Hex;
78
- "500": Hex;
79
- "600": Hex;
80
- "700": Hex;
81
- "800": Hex;
82
- };
83
- blue: {
84
- "100": Hex;
85
- "200": Hex;
86
- "300": Hex;
87
- "400": Hex;
88
- "500": Hex;
89
- "600": Hex;
90
- "700": Hex;
91
- };
92
- green: {
93
- "100": Hex;
94
- "200": Hex;
95
- "300": Hex;
96
- "400": Hex;
97
- "500": Hex;
98
- "600": Hex;
99
- "700": Hex;
100
- };
101
- yellow: {
102
- "100": Hex;
103
- "200": Hex;
104
- "300": Hex;
105
- "400": Hex;
106
- "500": Hex;
107
- "600": Hex;
108
- "700": Hex;
109
- };
110
- red: {
111
- "100": Hex;
112
- "200": Hex;
113
- "300": Hex;
114
- "400": Hex;
115
- "500": Hex;
116
- "600": Hex;
117
- "700": Hex;
118
- };
119
- orange: {
120
- "100": Hex;
121
- "200": Hex;
122
- "300": Hex;
123
- "400": Hex;
124
- "500": Hex;
125
- "600": Hex;
126
- "700": Hex;
127
- };
128
- gray: {
129
- "100": Hex;
130
- "200": Hex;
131
- "300": Hex;
132
- "400": Hex;
133
- "500": Hex;
134
- "600": Hex;
135
- };
136
- white: Hex;
137
- };
138
- dataViz: {
139
- favorable: Hex;
140
- unfavorable: Hex;
141
- };
142
- layout: {
143
- contentMaxWidth: string;
144
- contentMaxWidthWithSidebar: string;
145
- contentSideMargin: string;
146
- mobileActionsDrawerHeight: string;
147
- navigationBarHeight: string;
148
- breakpoints: {
149
- medium: string;
150
- large: string;
151
- };
152
- };
153
- shadow: {
154
- small: {
155
- boxShadow: string;
156
- };
157
- large: {
158
- boxShadow: string;
159
- };
160
- };
161
- spacing: {
162
- xs: string;
163
- sm: string;
164
- md: string;
165
- lg: string;
166
- xl: string;
167
- xxl: string;
168
- xxxl: string;
169
- xxxxl: string;
170
- xxxxxl: string;
171
- 0: string;
172
- 1: string;
173
- 2: string;
174
- 4: string;
175
- 6: string;
176
- 8: string;
177
- 12: string;
178
- 16: string;
179
- 24: string;
180
- 32: string;
181
- 40: string;
182
- 48: string;
183
- 56: string;
184
- 64: string;
185
- 72: string;
186
- 80: string;
187
- 96: string;
188
- 112: string;
189
- 128: string;
190
- 160: string;
191
- 200: string;
192
- 240: string;
193
- 280: string;
194
- 320: string;
195
- };
196
- typography: {
197
- dataLarge: TypographyFont;
198
- dataLargeUnits: TypographyFont;
199
- dataMedium: TypographyFont;
200
- dataMediumUnits: TypographyFont;
201
- dataSmall: TypographyFont;
202
- dataSmallUnits: TypographyFont;
203
- display0: TypographyFont;
204
- heading1: TypographyFont;
205
- heading2: TypographyFont;
206
- heading3: TypographyFont;
207
- heading4: TypographyFont;
208
- heading5: TypographyFont;
209
- heading6: TypographyFont;
210
- paragraphIntroLede: TypographyFont;
211
- paragraphBody: TypographyFont;
212
- paragraphSmall: TypographyFont;
213
- paragraphExtraSmall: TypographyFont;
214
- paragraphBold: {
215
- fontWeight: KaizenCSSProperties["fontWeight"];
216
- };
217
- buttonPrimary: TypographyFont;
218
- buttonSecondary: TypographyFont;
219
- };
220
- };
221
- type DeepMapObjectLeafs<T, LeafType> = T extends string | number | bigint | boolean | symbol | null | undefined | ((...params: any[]) => any) ? LeafType : T extends Record<any, any> ? {
222
- [Key in keyof T]: DeepMapObjectLeafs<T[Key], LeafType>;
223
- } : T;
224
- /**
225
- * Apologies for the complex types.
226
- * This type represents the Theme type but with every leaf value in the tree mapped strictly to a string, rather than a number or a more complex type such as a string union.
227
- * The reason for this is to have a more accurate type for the generated hierarchy of design tokens which are represented as CSS custom properties, e.g. `var(--color-purple-800)`.
228
- */
229
- type CSSVariableTheme = DeepMapObjectLeafs<Theme, string>;
230
-
231
- declare const heartTheme: Theme;
232
-
233
- declare const defaultTheme: Theme;
234
-
235
- /**
236
- * Use this class to set and apply themes, and to access or subscribe to the currently active one.
237
- * This class fulfills the idea of theming and runtime theme switching by relying on CSS variables,
238
- * and the ability to update them in JavaScript - a framework agnostic method.
239
- *
240
- * It works by converting a Theme interface to a flattened map of CSS variable keys and values, then calling `document.documentElement.style.setProperty(key, value)`.
241
- */
242
- declare class ThemeManager<Theme extends Theme = Theme> {
243
- private themeChangeListeners;
244
- private theme;
245
- private rootElement;
246
- private rootElementId;
247
- constructor(theme: Theme, rootElementId?: string, apply?: boolean);
248
- getRootElement: () => HTMLElement | null;
249
- getRootElementId: () => string;
250
- getCurrentTheme: () => Theme;
251
- setRootElement: (element: HTMLElement) => void;
252
- setRootElementId: (rootElementId: string) => string;
253
- setAndApplyTheme: (theme: Theme, force?: boolean) => void;
254
- addThemeChangeListener: (listener: (theme: Theme) => void) => void;
255
- removeThemeChangeListener: (listener: (theme: Theme) => void) => void;
256
- applyCurrentTheme: () => void;
257
- private notifyThemeChangeListeners;
258
- }
259
-
260
- declare const ThemeContext: React.Context<Theme>;
261
- /**
262
- * Wrap your application in this provider using a ThemeManager, to synchronise it with a react context.
263
- * This allows child react elements to more easily use theme variables, using the {@link useTheme} hook.
264
- */
265
- /**
266
- * @deprecated ThemeProvider is deprecated. Please use KaizenProvider from "@kaizen/components" instead.
267
- */
268
- declare const ThemeProvider: ({ themeManager, ...props }: {
269
- themeManager?: ThemeManager<Theme> | undefined;
270
- children: React.ReactNode;
271
- }) => JSX.Element;
272
- declare const useTheme: () => Theme;
273
-
274
- /**
275
-
276
- * Make a map of CSS variables -> values in a consistent way.
277
- * Use this to, for example, create a CSS file that declares each theme variable on the `:root` pseudo element.
278
- * Or for example when you're defining CSS variables using `rootElement.style.setProperty` within ThemeManager.
279
- *
280
- * It is paramount that this function defines every variable that {@link makeCssVariableTheme} expects to be defined.
281
- * Otherwise, it's possible that a CSS variable token (something that looks like var(--color-purple-100-rgb)) won't have a matching defined
282
- * CSS variable like `--color-purple-100-rgb: 123, 123, 123;`
283
- *
284
- *
285
- * For example:
286
- * Input:
287
- * ```
288
- * {
289
- * color: {
290
- * whatever: {
291
- * 100: "#ff0022"
292
- * }
293
- * }
294
- * }
295
- * ```
296
- * Output:
297
- * ```
298
- * {
299
- * "--color-whatever-100": "#ff0022"
300
- * }
301
- */
302
- declare function makeCssVariableDefinitionsMap(theme: Record<string | number, unknown>): Record<string, string>;
303
-
304
- /**
305
- * This function could use a new name during a breaking change
306
- *
307
- * Given a Theme (which is the source of truth and doesn't contain any computed properties), add extra necessary properties to the tree such as `-rgb` suffixed keys with R, G, B triple values, and
308
- * convert the leaf values of a theme to a value like `var(--parent1key-parent2key-leafkey)` - a CSS variable with an identifier that represents it's hierarchy.
309
- *
310
- * Example:
311
- * ```
312
- * {
313
- * color: {
314
- * purple: {
315
- * 100: "#f0f1f4"
316
- * }
317
- * }
318
- * }
319
- * ```
320
- * Transforms into:
321
- * ```
322
- * {
323
- * color: {
324
- * purple: {
325
- * 100: "var(--color-purple-100, "#f0f1f4")",
326
- * "100-rgb": "var(--color-purple-100-rgb, 240, 241, 244)",
327
- * "100-id": "--color-purple-100",
328
- * "100-rgb-id": "--color-purple-100-rgb"
329
- * }
330
- * }
331
- * }
332
- * ```
333
- *
334
- * See {@link addExtraThemeEntries} for how these extra entries are added.
335
- */
336
- declare function makeCSSVariableTheme<ThemeType extends Record<string | number, unknown>>(theme: ThemeType, printValue?: (path: string[], value: unknown) => string): DeepMapObjectLeafs<ThemeType, string>;
337
-
338
- /**
339
- * This allows you to map the leaf nodes of an object, and you're provided the path to that leaf as well as the value as parameters to your mapper function.
340
- * This function was build to support mapping theme values to their respective CSS variable identifiers.
341
- * For example:
342
- * ```ts
343
- * mapLeafsOfObject({
344
- * one: {
345
- * two: 4
346
- * }
347
- * }, (path, value) => value + 7)
348
- * ```
349
- * Results in:
350
- * ```
351
- * {
352
- * one: {
353
- * two: 11
354
- * }
355
- * }
356
- * ```
357
- */
358
- declare function mapLeafsOfObject<Obj extends Record<string | number, unknown>, Value>(object: Obj, mapper: (pathToLeaf: string[], value: unknown) => Value): DeepMapObjectLeafs<Obj, Value>;
359
-
360
- export { CSSVariableTheme, DeepMapObjectLeafs, Theme, ThemeContext, ThemeKey, ThemeManager, ThemeProvider, TypographyFont, defaultTheme, heartTheme, makeCSSVariableTheme, makeCssVariableDefinitionsMap, mapLeafsOfObject, useTheme };
1
+ export * from "./themes";
2
+ export * from "./types";
3
+ export * from "./ThemeManager";
4
+ export * from "./react";
5
+ export { makeCssVariableDefinitionsMap } from "./lib/makeCssVariableDefinitionsMap";
6
+ export { makeCSSVariableTheme } from "./lib/makeCssVariableTheme";
7
+ export { mapLeafsOfObject } from "./lib/mapLeafsOfObject";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA;AAEvB,OAAO,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA"}