@wise/components-theming 0.0.0-experimental-17de653 → 0.0.0-experimental-6ec1604
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.
- package/dist/const.js +0 -2
- package/dist/const.js.map +1 -1
- package/dist/const.mjs +1 -2
- package/dist/const.mjs.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +8 -8
- package/dist/helpers.js.map +1 -1
- package/dist/helpers.mjs +9 -9
- package/dist/helpers.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ThemeProvider.spec.tsx +16 -137
- package/src/helpers.ts +9 -11
package/dist/const.js
CHANGED
|
@@ -5,14 +5,12 @@ const baseThemes = ['light', 'personal', 'business'];
|
|
|
5
5
|
const extraThemes = ['forest-green', 'bright-green'];
|
|
6
6
|
const screenModes = ['light', 'dark'];
|
|
7
7
|
const modernThemes = [baseThemes[1], baseThemes[2], ...extraThemes];
|
|
8
|
-
const businessThemes = ['business', 'business--forest-green', 'business--bright-green'];
|
|
9
8
|
const DEFAULT_BASE_THEME = 'light';
|
|
10
9
|
const DEFAULT_SCREEN_MODE = 'light';
|
|
11
10
|
|
|
12
11
|
exports.DEFAULT_BASE_THEME = DEFAULT_BASE_THEME;
|
|
13
12
|
exports.DEFAULT_SCREEN_MODE = DEFAULT_SCREEN_MODE;
|
|
14
13
|
exports.baseThemes = baseThemes;
|
|
15
|
-
exports.businessThemes = businessThemes;
|
|
16
14
|
exports.extraThemes = extraThemes;
|
|
17
15
|
exports.modernThemes = modernThemes;
|
|
18
16
|
exports.screenModes = screenModes;
|
package/dist/const.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sources":["../src/const.ts"],"sourcesContent":["// TODO: Change 'light' with 'legacy' in the future\nexport const baseThemes = ['light', 'personal', 'business'] as const;\nexport const extraThemes = ['forest-green', 'bright-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], baseThemes[2], ...extraThemes] as const;\nexport const businessThemes = [\n 'business',\n 'business--forest-green',\n 'business--bright-green',\n] as const;\nexport const platformThemes = ['platform', 'platform--forest-green'] as const;\n\n// TODO: componentThemes returned back for backward compatibility, refactor this place in the future\nexport type ComponentTheme = (typeof baseThemes)[number];\nexport type ModernTheme = (typeof modernThemes)[number];\nexport type BaseTheme = (typeof baseThemes)[number];\nexport type ExtraTheme = (typeof extraThemes)[number];\nexport type ForestGreenTheme = (typeof extraThemes)[0];\nexport type ScreenMode = (typeof screenModes)[number];\nexport type ScreenModeDark = (typeof screenModes)[1];\nexport type PlatformTheme = (typeof platformThemes)[0];\nexport type PlatformForestGreenTheme = (typeof platformThemes)[1];\nexport type BusinessTheme = (typeof businessThemes)[0];\nexport type BusinessForestGreenTheme = (typeof businessThemes)[1];\nexport type BusinessBrightGreenTheme = (typeof businessThemes)[2];\n\nexport const DEFAULT_BASE_THEME = 'light';\nexport const DEFAULT_SCREEN_MODE = 'light';\n\nexport type Theming = {\n theme?:\n | ComponentTheme\n | BaseTheme\n | ExtraTheme\n | BusinessTheme\n | BusinessForestGreenTheme\n | BusinessBrightGreenTheme\n | PlatformTheme\n | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\n isNotRootProvider?: boolean | undefined;\n};\n"],"names":["baseThemes","extraThemes","screenModes","modernThemes","
|
|
1
|
+
{"version":3,"file":"const.js","sources":["../src/const.ts"],"sourcesContent":["// TODO: Change 'light' with 'legacy' in the future\nexport const baseThemes = ['light', 'personal', 'business'] as const;\nexport const extraThemes = ['forest-green', 'bright-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], baseThemes[2], ...extraThemes] as const;\nexport const businessThemes = [\n 'business',\n 'business--forest-green',\n 'business--bright-green',\n] as const;\nexport const platformThemes = ['platform', 'platform--forest-green'] as const;\n\n// TODO: componentThemes returned back for backward compatibility, refactor this place in the future\nexport type ComponentTheme = (typeof baseThemes)[number];\nexport type ModernTheme = (typeof modernThemes)[number];\nexport type BaseTheme = (typeof baseThemes)[number];\nexport type ExtraTheme = (typeof extraThemes)[number];\nexport type ForestGreenTheme = (typeof extraThemes)[0];\nexport type ScreenMode = (typeof screenModes)[number];\nexport type ScreenModeDark = (typeof screenModes)[1];\nexport type PlatformTheme = (typeof platformThemes)[0];\nexport type PlatformForestGreenTheme = (typeof platformThemes)[1];\nexport type BusinessTheme = (typeof businessThemes)[0];\nexport type BusinessForestGreenTheme = (typeof businessThemes)[1];\nexport type BusinessBrightGreenTheme = (typeof businessThemes)[2];\n\nexport const DEFAULT_BASE_THEME = 'light';\nexport const DEFAULT_SCREEN_MODE = 'light';\n\nexport type Theming = {\n theme?:\n | ComponentTheme\n | BaseTheme\n | ExtraTheme\n | BusinessTheme\n | BusinessForestGreenTheme\n | BusinessBrightGreenTheme\n | PlatformTheme\n | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\n isNotRootProvider?: boolean | undefined;\n};\n"],"names":["baseThemes","extraThemes","screenModes","modernThemes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE"],"mappings":";;AAAA;AACO,MAAMA,UAAU,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU;MAC7CC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc;MAC7CC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM;MAC9BC,YAAY,GAAG,CAACH,UAAU,CAAC,CAAC,CAAC,EAAEA,UAAU,CAAC,CAAC,CAAC,EAAE,GAAGC,WAAW;AAsBlE,MAAMG,kBAAkB,GAAG;AAC3B,MAAMC,mBAAmB,GAAG;;;;;;;;;"}
|
package/dist/const.mjs
CHANGED
|
@@ -3,9 +3,8 @@ const baseThemes = ['light', 'personal', 'business'];
|
|
|
3
3
|
const extraThemes = ['forest-green', 'bright-green'];
|
|
4
4
|
const screenModes = ['light', 'dark'];
|
|
5
5
|
const modernThemes = [baseThemes[1], baseThemes[2], ...extraThemes];
|
|
6
|
-
const businessThemes = ['business', 'business--forest-green', 'business--bright-green'];
|
|
7
6
|
const DEFAULT_BASE_THEME = 'light';
|
|
8
7
|
const DEFAULT_SCREEN_MODE = 'light';
|
|
9
8
|
|
|
10
|
-
export { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE, baseThemes,
|
|
9
|
+
export { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE, baseThemes, extraThemes, modernThemes, screenModes };
|
|
11
10
|
//# sourceMappingURL=const.mjs.map
|
package/dist/const.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.mjs","sources":["../src/const.ts"],"sourcesContent":["// TODO: Change 'light' with 'legacy' in the future\nexport const baseThemes = ['light', 'personal', 'business'] as const;\nexport const extraThemes = ['forest-green', 'bright-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], baseThemes[2], ...extraThemes] as const;\nexport const businessThemes = [\n 'business',\n 'business--forest-green',\n 'business--bright-green',\n] as const;\nexport const platformThemes = ['platform', 'platform--forest-green'] as const;\n\n// TODO: componentThemes returned back for backward compatibility, refactor this place in the future\nexport type ComponentTheme = (typeof baseThemes)[number];\nexport type ModernTheme = (typeof modernThemes)[number];\nexport type BaseTheme = (typeof baseThemes)[number];\nexport type ExtraTheme = (typeof extraThemes)[number];\nexport type ForestGreenTheme = (typeof extraThemes)[0];\nexport type ScreenMode = (typeof screenModes)[number];\nexport type ScreenModeDark = (typeof screenModes)[1];\nexport type PlatformTheme = (typeof platformThemes)[0];\nexport type PlatformForestGreenTheme = (typeof platformThemes)[1];\nexport type BusinessTheme = (typeof businessThemes)[0];\nexport type BusinessForestGreenTheme = (typeof businessThemes)[1];\nexport type BusinessBrightGreenTheme = (typeof businessThemes)[2];\n\nexport const DEFAULT_BASE_THEME = 'light';\nexport const DEFAULT_SCREEN_MODE = 'light';\n\nexport type Theming = {\n theme?:\n | ComponentTheme\n | BaseTheme\n | ExtraTheme\n | BusinessTheme\n | BusinessForestGreenTheme\n | BusinessBrightGreenTheme\n | PlatformTheme\n | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\n isNotRootProvider?: boolean | undefined;\n};\n"],"names":["baseThemes","extraThemes","screenModes","modernThemes","
|
|
1
|
+
{"version":3,"file":"const.mjs","sources":["../src/const.ts"],"sourcesContent":["// TODO: Change 'light' with 'legacy' in the future\nexport const baseThemes = ['light', 'personal', 'business'] as const;\nexport const extraThemes = ['forest-green', 'bright-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], baseThemes[2], ...extraThemes] as const;\nexport const businessThemes = [\n 'business',\n 'business--forest-green',\n 'business--bright-green',\n] as const;\nexport const platformThemes = ['platform', 'platform--forest-green'] as const;\n\n// TODO: componentThemes returned back for backward compatibility, refactor this place in the future\nexport type ComponentTheme = (typeof baseThemes)[number];\nexport type ModernTheme = (typeof modernThemes)[number];\nexport type BaseTheme = (typeof baseThemes)[number];\nexport type ExtraTheme = (typeof extraThemes)[number];\nexport type ForestGreenTheme = (typeof extraThemes)[0];\nexport type ScreenMode = (typeof screenModes)[number];\nexport type ScreenModeDark = (typeof screenModes)[1];\nexport type PlatformTheme = (typeof platformThemes)[0];\nexport type PlatformForestGreenTheme = (typeof platformThemes)[1];\nexport type BusinessTheme = (typeof businessThemes)[0];\nexport type BusinessForestGreenTheme = (typeof businessThemes)[1];\nexport type BusinessBrightGreenTheme = (typeof businessThemes)[2];\n\nexport const DEFAULT_BASE_THEME = 'light';\nexport const DEFAULT_SCREEN_MODE = 'light';\n\nexport type Theming = {\n theme?:\n | ComponentTheme\n | BaseTheme\n | ExtraTheme\n | BusinessTheme\n | BusinessForestGreenTheme\n | BusinessBrightGreenTheme\n | PlatformTheme\n | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\n isNotRootProvider?: boolean | undefined;\n};\n"],"names":["baseThemes","extraThemes","screenModes","modernThemes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE"],"mappings":"AAAA;AACO,MAAMA,UAAU,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU;MAC7CC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc;MAC7CC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM;MAC9BC,YAAY,GAAG,CAACH,UAAU,CAAC,CAAC,CAAC,EAAEA,UAAU,CAAC,CAAC,CAAC,EAAE,GAAGC,WAAW;AAsBlE,MAAMG,kBAAkB,GAAG;AAC3B,MAAMC,mBAAmB,GAAG;;;;"}
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,OAAO,EACR,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,aAAa,GAAI,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAG,KAAK,IAAI,WACjC,CAAC;AAE9C,eAAO,MAAM,YAAY,GAAI,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAG,KAAK,IAAI,UAClC,CAAC;AAE5C,eAAO,MAAM,kBAAkB,GAC7B,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KACnC,KAAK,IAAI,gBAA4C,CAAC;AAEzD,eAAO,MAAM,gBAAgB,GAC3B,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EACpC,YAAY,UAAU,KACrB,UAAU,IAAI,cACqD,CAAC;AAEvE,eAAO,MAAM,iBAAiB,GAAI,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,YAAY,UAAU,WAuC7F,CAAC"}
|
package/dist/helpers.js
CHANGED
|
@@ -7,37 +7,37 @@ const isExtraTheme = theme => _const.extraThemes.includes(theme);
|
|
|
7
7
|
const isForestGreenTheme = theme => theme === _const.extraThemes[0];
|
|
8
8
|
const isScreenModeDark = (theme, screenMode) => isThemeModern(theme) && _const.screenModes[1] === screenMode;
|
|
9
9
|
const getThemeClassName = (theme, screenMode) => {
|
|
10
|
-
|
|
11
|
-
if (theme === 'light') {
|
|
10
|
+
if (['light'].includes(theme)) {
|
|
12
11
|
return `np-theme-${theme}`;
|
|
13
12
|
}
|
|
14
13
|
// Personal light is always there by default
|
|
15
14
|
const themeClasses = ['np-theme-personal'];
|
|
15
|
+
/* eslint-disable functional/immutable-data */
|
|
16
16
|
// Personal dark theme
|
|
17
|
-
if (theme === 'personal' &&
|
|
17
|
+
if (theme === 'personal' && screenMode === 'dark') {
|
|
18
18
|
themeClasses.push(`np-theme-personal--${screenMode}`);
|
|
19
19
|
}
|
|
20
20
|
// Personal forest-green and bright-green themes
|
|
21
|
-
else if (
|
|
21
|
+
else if (['forest-green', 'bright-green'].includes(theme)) {
|
|
22
22
|
themeClasses.push(`np-theme-personal--${theme}`);
|
|
23
23
|
}
|
|
24
24
|
// Business light
|
|
25
|
-
else if (
|
|
25
|
+
else if (theme === 'business') {
|
|
26
26
|
themeClasses.push(`np-theme-business`);
|
|
27
27
|
// Business dark theme
|
|
28
|
-
if (
|
|
28
|
+
if (screenMode === 'dark') {
|
|
29
29
|
themeClasses.push(`np-theme-business--${screenMode}`);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
// Business forest-green and bright-green themes
|
|
33
|
-
|
|
34
|
-
else if ([_const.businessThemes[1], _const.businessThemes[2]].includes(theme)) {
|
|
33
|
+
else if (['business--forest-green', 'business--bright-green'].includes(theme)) {
|
|
35
34
|
themeClasses.push(`np-theme-${theme}`);
|
|
36
35
|
}
|
|
37
36
|
// Platform themes
|
|
38
37
|
else if (theme.startsWith('platform')) {
|
|
39
38
|
themeClasses.push(`np-theme-${theme}`);
|
|
40
39
|
}
|
|
40
|
+
/* eslint-enable functional/immutable-data */
|
|
41
41
|
return themeClasses.join(' ');
|
|
42
42
|
};
|
|
43
43
|
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":["../src/helpers.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../src/helpers.ts"],"sourcesContent":["import type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (theme: NonNullable<Theming['theme']>): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isExtraTheme = (theme: NonNullable<Theming['theme']>): theme is ExtraTheme =>\n extraThemes.includes(theme as ExtraTheme);\n\nexport const isForestGreenTheme = (\n theme: NonNullable<Theming['theme']>,\n): theme is ForestGreenTheme => theme === extraThemes[0];\n\nexport const isScreenModeDark = (\n theme: NonNullable<Theming['theme']>,\n screenMode: ScreenMode,\n): screenMode is ScreenModeDark =>\n isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;\n\nexport const getThemeClassName = (theme: NonNullable<Theming['theme']>, screenMode: ScreenMode) => {\n if (['light'].includes(theme)) {\n return `np-theme-${theme}`;\n }\n\n // Personal light is always there by default\n const themeClasses = ['np-theme-personal'];\n\n /* eslint-disable functional/immutable-data */\n // Personal dark theme\n if (theme === 'personal' && screenMode === 'dark') {\n themeClasses.push(`np-theme-personal--${screenMode}`);\n }\n\n // Personal forest-green and bright-green themes\n else if (['forest-green', 'bright-green'].includes(theme)) {\n themeClasses.push(`np-theme-personal--${theme}`);\n }\n\n // Business light\n else if (theme === 'business') {\n themeClasses.push(`np-theme-business`);\n // Business dark theme\n if (screenMode === 'dark') {\n themeClasses.push(`np-theme-business--${screenMode}`);\n }\n }\n\n // Business forest-green and bright-green themes\n else if (['business--forest-green', 'business--bright-green'].includes(theme)) {\n themeClasses.push(`np-theme-${theme}`);\n }\n\n // Platform themes\n else if (theme.startsWith('platform')) {\n themeClasses.push(`np-theme-${theme}`);\n }\n /* eslint-enable functional/immutable-data */\n return themeClasses.join(' ');\n};\n"],"names":["isThemeModern","theme","modernThemes","includes","isExtraTheme","extraThemes","isForestGreenTheme","isScreenModeDark","screenMode","screenModes","getThemeClassName","themeClasses","push","startsWith","join"],"mappings":";;;;AAUO,MAAMA,aAAa,GAAIC,KAAoC,IAChEC,mBAAY,CAACC,QAAQ,CAACF,KAAoB;AAErC,MAAMG,YAAY,GAAIH,KAAoC,IAC/DI,kBAAW,CAACF,QAAQ,CAACF,KAAmB;AAEnC,MAAMK,kBAAkB,GAC7BL,KAAoC,IACNA,KAAK,KAAKI,kBAAW,CAAC,CAAC;MAE1CE,gBAAgB,GAAGA,CAC9BN,KAAoC,EACpCO,UAAsB,KAEtBR,aAAa,CAACC,KAAoB,CAAC,IAAIQ,kBAAW,CAAC,CAAC,CAAC,KAAKD;MAE/CE,iBAAiB,GAAGA,CAACT,KAAoC,EAAEO,UAAsB,KAAI;EAChG,IAAI,CAAC,OAAO,CAAC,CAACL,QAAQ,CAACF,KAAK,CAAC,EAAE;IAC7B,OAAO,CAAA,SAAA,EAAYA,KAAK,CAAA,CAAE;AAC5B,EAAA;AAEA;AACA,EAAA,MAAMU,YAAY,GAAG,CAAC,mBAAmB,CAAC;AAE1C;AACA;AACA,EAAA,IAAIV,KAAK,KAAK,UAAU,IAAIO,UAAU,KAAK,MAAM,EAAE;AACjDG,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBJ,UAAU,EAAE,CAAC;AACvD,EAAA;AAEA;OACK,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAACL,QAAQ,CAACF,KAAK,CAAC,EAAE;AACzDU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBX,KAAK,EAAE,CAAC;AAClD,EAAA;AAEA;AAAA,OACK,IAAIA,KAAK,KAAK,UAAU,EAAE;AAC7BU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,iBAAA,CAAmB,CAAC;AACtC;IACA,IAAIJ,UAAU,KAAK,MAAM,EAAE;AACzBG,MAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBJ,UAAU,EAAE,CAAC;AACvD,IAAA;AACF,EAAA;AAEA;OACK,IAAI,CAAC,wBAAwB,EAAE,wBAAwB,CAAC,CAACL,QAAQ,CAACF,KAAK,CAAC,EAAE;AAC7EU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,SAAA,EAAYX,KAAK,EAAE,CAAC;AACxC,EAAA;AAEA;AAAA,OACK,IAAIA,KAAK,CAACY,UAAU,CAAC,UAAU,CAAC,EAAE;AACrCF,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,SAAA,EAAYX,KAAK,EAAE,CAAC;AACxC,EAAA;AACA;AACA,EAAA,OAAOU,YAAY,CAACG,IAAI,CAAC,GAAG,CAAC;AAC/B;;;;;;;;"}
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { modernThemes, extraThemes, screenModes
|
|
1
|
+
import { modernThemes, extraThemes, screenModes } from './const.mjs';
|
|
2
2
|
|
|
3
3
|
const isThemeModern = theme => modernThemes.includes(theme);
|
|
4
4
|
const isExtraTheme = theme => extraThemes.includes(theme);
|
|
5
5
|
const isForestGreenTheme = theme => theme === extraThemes[0];
|
|
6
6
|
const isScreenModeDark = (theme, screenMode) => isThemeModern(theme) && screenModes[1] === screenMode;
|
|
7
7
|
const getThemeClassName = (theme, screenMode) => {
|
|
8
|
-
|
|
9
|
-
if (theme === 'light') {
|
|
8
|
+
if (['light'].includes(theme)) {
|
|
10
9
|
return `np-theme-${theme}`;
|
|
11
10
|
}
|
|
12
11
|
// Personal light is always there by default
|
|
13
12
|
const themeClasses = ['np-theme-personal'];
|
|
13
|
+
/* eslint-disable functional/immutable-data */
|
|
14
14
|
// Personal dark theme
|
|
15
|
-
if (theme === 'personal' &&
|
|
15
|
+
if (theme === 'personal' && screenMode === 'dark') {
|
|
16
16
|
themeClasses.push(`np-theme-personal--${screenMode}`);
|
|
17
17
|
}
|
|
18
18
|
// Personal forest-green and bright-green themes
|
|
19
|
-
else if (
|
|
19
|
+
else if (['forest-green', 'bright-green'].includes(theme)) {
|
|
20
20
|
themeClasses.push(`np-theme-personal--${theme}`);
|
|
21
21
|
}
|
|
22
22
|
// Business light
|
|
23
|
-
else if (
|
|
23
|
+
else if (theme === 'business') {
|
|
24
24
|
themeClasses.push(`np-theme-business`);
|
|
25
25
|
// Business dark theme
|
|
26
|
-
if (
|
|
26
|
+
if (screenMode === 'dark') {
|
|
27
27
|
themeClasses.push(`np-theme-business--${screenMode}`);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
// Business forest-green and bright-green themes
|
|
31
|
-
|
|
32
|
-
else if ([businessThemes[1], businessThemes[2]].includes(theme)) {
|
|
31
|
+
else if (['business--forest-green', 'business--bright-green'].includes(theme)) {
|
|
33
32
|
themeClasses.push(`np-theme-${theme}`);
|
|
34
33
|
}
|
|
35
34
|
// Platform themes
|
|
36
35
|
else if (theme.startsWith('platform')) {
|
|
37
36
|
themeClasses.push(`np-theme-${theme}`);
|
|
38
37
|
}
|
|
38
|
+
/* eslint-enable functional/immutable-data */
|
|
39
39
|
return themeClasses.join(' ');
|
|
40
40
|
};
|
|
41
41
|
|
package/dist/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","sources":["../src/helpers.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"helpers.mjs","sources":["../src/helpers.ts"],"sourcesContent":["import type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (theme: NonNullable<Theming['theme']>): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isExtraTheme = (theme: NonNullable<Theming['theme']>): theme is ExtraTheme =>\n extraThemes.includes(theme as ExtraTheme);\n\nexport const isForestGreenTheme = (\n theme: NonNullable<Theming['theme']>,\n): theme is ForestGreenTheme => theme === extraThemes[0];\n\nexport const isScreenModeDark = (\n theme: NonNullable<Theming['theme']>,\n screenMode: ScreenMode,\n): screenMode is ScreenModeDark =>\n isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;\n\nexport const getThemeClassName = (theme: NonNullable<Theming['theme']>, screenMode: ScreenMode) => {\n if (['light'].includes(theme)) {\n return `np-theme-${theme}`;\n }\n\n // Personal light is always there by default\n const themeClasses = ['np-theme-personal'];\n\n /* eslint-disable functional/immutable-data */\n // Personal dark theme\n if (theme === 'personal' && screenMode === 'dark') {\n themeClasses.push(`np-theme-personal--${screenMode}`);\n }\n\n // Personal forest-green and bright-green themes\n else if (['forest-green', 'bright-green'].includes(theme)) {\n themeClasses.push(`np-theme-personal--${theme}`);\n }\n\n // Business light\n else if (theme === 'business') {\n themeClasses.push(`np-theme-business`);\n // Business dark theme\n if (screenMode === 'dark') {\n themeClasses.push(`np-theme-business--${screenMode}`);\n }\n }\n\n // Business forest-green and bright-green themes\n else if (['business--forest-green', 'business--bright-green'].includes(theme)) {\n themeClasses.push(`np-theme-${theme}`);\n }\n\n // Platform themes\n else if (theme.startsWith('platform')) {\n themeClasses.push(`np-theme-${theme}`);\n }\n /* eslint-enable functional/immutable-data */\n return themeClasses.join(' ');\n};\n"],"names":["isThemeModern","theme","modernThemes","includes","isExtraTheme","extraThemes","isForestGreenTheme","isScreenModeDark","screenMode","screenModes","getThemeClassName","themeClasses","push","startsWith","join"],"mappings":";;AAUO,MAAMA,aAAa,GAAIC,KAAoC,IAChEC,YAAY,CAACC,QAAQ,CAACF,KAAoB;AAErC,MAAMG,YAAY,GAAIH,KAAoC,IAC/DI,WAAW,CAACF,QAAQ,CAACF,KAAmB;AAEnC,MAAMK,kBAAkB,GAC7BL,KAAoC,IACNA,KAAK,KAAKI,WAAW,CAAC,CAAC;MAE1CE,gBAAgB,GAAGA,CAC9BN,KAAoC,EACpCO,UAAsB,KAEtBR,aAAa,CAACC,KAAoB,CAAC,IAAIQ,WAAW,CAAC,CAAC,CAAC,KAAKD;MAE/CE,iBAAiB,GAAGA,CAACT,KAAoC,EAAEO,UAAsB,KAAI;EAChG,IAAI,CAAC,OAAO,CAAC,CAACL,QAAQ,CAACF,KAAK,CAAC,EAAE;IAC7B,OAAO,CAAA,SAAA,EAAYA,KAAK,CAAA,CAAE;AAC5B,EAAA;AAEA;AACA,EAAA,MAAMU,YAAY,GAAG,CAAC,mBAAmB,CAAC;AAE1C;AACA;AACA,EAAA,IAAIV,KAAK,KAAK,UAAU,IAAIO,UAAU,KAAK,MAAM,EAAE;AACjDG,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBJ,UAAU,EAAE,CAAC;AACvD,EAAA;AAEA;OACK,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAACL,QAAQ,CAACF,KAAK,CAAC,EAAE;AACzDU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBX,KAAK,EAAE,CAAC;AAClD,EAAA;AAEA;AAAA,OACK,IAAIA,KAAK,KAAK,UAAU,EAAE;AAC7BU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,iBAAA,CAAmB,CAAC;AACtC;IACA,IAAIJ,UAAU,KAAK,MAAM,EAAE;AACzBG,MAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBJ,UAAU,EAAE,CAAC;AACvD,IAAA;AACF,EAAA;AAEA;OACK,IAAI,CAAC,wBAAwB,EAAE,wBAAwB,CAAC,CAACL,QAAQ,CAACF,KAAK,CAAC,EAAE;AAC7EU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,SAAA,EAAYX,KAAK,EAAE,CAAC;AACxC,EAAA;AAEA;AAAA,OACK,IAAIA,KAAK,CAACY,UAAU,CAAC,UAAU,CAAC,EAAE;AACrCF,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,SAAA,EAAYX,KAAK,EAAE,CAAC;AACxC,EAAA;AACA;AACA,EAAA,OAAOU,YAAY,CAACG,IAAI,CAAC,GAAG,CAAC;AAC/B;;;;"}
|
package/package.json
CHANGED
|
@@ -40,9 +40,13 @@ describe('ThemeProvider', () => {
|
|
|
40
40
|
// eslint-disable-next-line testing-library/no-node-access
|
|
41
41
|
expect(screen.getByText('personal').parentElement).toHaveClass('np-theme-personal');
|
|
42
42
|
// eslint-disable-next-line testing-library/no-node-access
|
|
43
|
-
expect(screen.getByText('platform').parentElement).toHaveClass(
|
|
43
|
+
expect(screen.getByText('platform').parentElement).toHaveClass(
|
|
44
|
+
'np-theme-personal',
|
|
45
|
+
'np-theme-platform',
|
|
46
|
+
);
|
|
44
47
|
// eslint-disable-next-line testing-library/no-node-access
|
|
45
48
|
expect(screen.getByText('platform--forest-green').parentElement).toHaveClass(
|
|
49
|
+
'np-theme-personal',
|
|
46
50
|
'np-theme-platform--forest-green',
|
|
47
51
|
);
|
|
48
52
|
});
|
|
@@ -64,153 +68,28 @@ describe('ThemeProvider', () => {
|
|
|
64
68
|
);
|
|
65
69
|
|
|
66
70
|
// eslint-disable-next-line testing-library/no-node-access
|
|
67
|
-
expect(screen.getByText('business').parentElement).toHaveClass(
|
|
71
|
+
expect(screen.getByText('business').parentElement).toHaveClass(
|
|
72
|
+
'np-theme-personal',
|
|
73
|
+
'np-theme-business',
|
|
74
|
+
);
|
|
68
75
|
// eslint-disable-next-line testing-library/no-node-access
|
|
69
|
-
expect(screen.getByText('business-dark').parentElement).toHaveClass(
|
|
76
|
+
expect(screen.getByText('business-dark').parentElement).toHaveClass(
|
|
77
|
+
'np-theme-personal',
|
|
78
|
+
'np-theme-business',
|
|
79
|
+
'np-theme-business--dark',
|
|
80
|
+
);
|
|
70
81
|
// eslint-disable-next-line testing-library/no-node-access
|
|
71
82
|
expect(screen.getByText('business--bright-green').parentElement).toHaveClass(
|
|
83
|
+
'np-theme-personal',
|
|
72
84
|
'np-theme-business--bright-green',
|
|
73
85
|
);
|
|
74
86
|
// eslint-disable-next-line testing-library/no-node-access
|
|
75
87
|
expect(screen.getByText('business--forest-green').parentElement).toHaveClass(
|
|
88
|
+
'np-theme-personal',
|
|
76
89
|
'np-theme-business--forest-green',
|
|
77
90
|
);
|
|
78
91
|
});
|
|
79
92
|
|
|
80
|
-
it('adds personal class for business theme when isNotRootProvider=false (default)', () => {
|
|
81
|
-
const mockClassList = {
|
|
82
|
-
add: jest.fn(),
|
|
83
|
-
remove: jest.fn(),
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
Object.defineProperty(document, 'documentElement', {
|
|
87
|
-
value: { className: '', classList: mockClassList },
|
|
88
|
-
writable: true,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
render(
|
|
92
|
-
<ThemeProvider theme="business">
|
|
93
|
-
<div>business-auto-fix</div>
|
|
94
|
-
</ThemeProvider>,
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
expect(mockClassList.add).toHaveBeenCalledWith('np-theme-personal');
|
|
98
|
-
expect(mockClassList.add).toHaveBeenCalledWith('np-theme-business');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('does not add personal class for business theme with isNotRootProvider=true', () => {
|
|
102
|
-
const mockClassList = {
|
|
103
|
-
add: jest.fn(),
|
|
104
|
-
remove: jest.fn(),
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
Object.defineProperty(document, 'documentElement', {
|
|
108
|
-
value: { className: '', classList: mockClassList },
|
|
109
|
-
writable: true,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
render(
|
|
113
|
-
<ThemeProvider theme="business" isNotRootProvider>
|
|
114
|
-
<div>business-component</div>
|
|
115
|
-
</ThemeProvider>,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
expect(mockClassList.add).not.toHaveBeenCalledWith('np-theme-personal');
|
|
119
|
-
expect(mockClassList.add).not.toHaveBeenCalled();
|
|
120
|
-
|
|
121
|
-
// The component wrapper should still get the business theme class via ThemedChildren
|
|
122
|
-
expect(screen.getByText('business-component')).toBeInTheDocument();
|
|
123
|
-
// Note: We can't easily test the wrapper class without direct node access,
|
|
124
|
-
// but the functionality is verified by the existing integration tests
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('adds personal class for personal theme', () => {
|
|
128
|
-
const mockClassList = {
|
|
129
|
-
add: jest.fn(),
|
|
130
|
-
remove: jest.fn(),
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
Object.defineProperty(document, 'documentElement', {
|
|
134
|
-
value: { className: '', classList: mockClassList },
|
|
135
|
-
writable: true,
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
render(
|
|
139
|
-
<ThemeProvider theme="personal">
|
|
140
|
-
<div>personal</div>
|
|
141
|
-
</ThemeProvider>,
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
expect(mockClassList.add).toHaveBeenCalledWith('np-theme-personal');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('does not add personal class for light theme', () => {
|
|
148
|
-
const mockClassList = {
|
|
149
|
-
add: jest.fn(),
|
|
150
|
-
remove: jest.fn(),
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
Object.defineProperty(document, 'documentElement', {
|
|
154
|
-
value: { className: '', classList: mockClassList },
|
|
155
|
-
writable: true,
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
render(
|
|
159
|
-
<ThemeProvider theme="light">
|
|
160
|
-
<div>light</div>
|
|
161
|
-
</ThemeProvider>,
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
expect(mockClassList.add).toHaveBeenCalledWith('np-theme-light');
|
|
165
|
-
expect(mockClassList.add).not.toHaveBeenCalledWith('np-theme-personal');
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('adds personal class for platform theme when isNotRootProvider=false (default)', () => {
|
|
169
|
-
const mockClassList = {
|
|
170
|
-
add: jest.fn(),
|
|
171
|
-
remove: jest.fn(),
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
Object.defineProperty(document, 'documentElement', {
|
|
175
|
-
value: { className: '', classList: mockClassList },
|
|
176
|
-
writable: true,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
render(
|
|
180
|
-
<ThemeProvider theme="platform">
|
|
181
|
-
<div>platform-auto-fix</div>
|
|
182
|
-
</ThemeProvider>,
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
expect(mockClassList.add).toHaveBeenCalledWith('np-theme-personal');
|
|
186
|
-
expect(mockClassList.add).toHaveBeenCalledWith('np-theme-platform');
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('does not add personal class for platform theme with isNotRootProvider=true', () => {
|
|
190
|
-
const mockClassList = {
|
|
191
|
-
add: jest.fn(),
|
|
192
|
-
remove: jest.fn(),
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
Object.defineProperty(document, 'documentElement', {
|
|
196
|
-
value: { className: '', classList: mockClassList },
|
|
197
|
-
writable: true,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
render(
|
|
201
|
-
<ThemeProvider theme="platform" isNotRootProvider>
|
|
202
|
-
<div>platform-component</div>
|
|
203
|
-
</ThemeProvider>,
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
expect(mockClassList.add).not.toHaveBeenCalledWith('np-theme-personal');
|
|
207
|
-
expect(mockClassList.add).not.toHaveBeenCalled();
|
|
208
|
-
|
|
209
|
-
// The component wrapper should still get the platform theme class via ThemedChildren
|
|
210
|
-
expect(screen.getByText('platform-component')).toBeInTheDocument();
|
|
211
|
-
// Note: We can't easily test the wrapper class without direct node access,
|
|
212
|
-
// but the functionality is verified by the existing integration tests
|
|
213
|
-
});
|
|
214
93
|
it('matches snapshot', () => {
|
|
215
94
|
const { asFragment } = render(
|
|
216
95
|
<ThemeProvider theme="light">
|
package/src/helpers.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable functional/immutable-data */
|
|
2
1
|
import type {
|
|
3
2
|
ModernTheme,
|
|
4
3
|
ExtraTheme,
|
|
@@ -7,7 +6,7 @@ import type {
|
|
|
7
6
|
ScreenModeDark,
|
|
8
7
|
Theming,
|
|
9
8
|
} from './const';
|
|
10
|
-
import { extraThemes, screenModes, modernThemes
|
|
9
|
+
import { extraThemes, screenModes, modernThemes } from './const';
|
|
11
10
|
|
|
12
11
|
export const isThemeModern = (theme: NonNullable<Theming['theme']>): theme is ModernTheme =>
|
|
13
12
|
modernThemes.includes(theme as ModernTheme);
|
|
@@ -26,36 +25,35 @@ export const isScreenModeDark = (
|
|
|
26
25
|
isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;
|
|
27
26
|
|
|
28
27
|
export const getThemeClassName = (theme: NonNullable<Theming['theme']>, screenMode: ScreenMode) => {
|
|
29
|
-
|
|
30
|
-
if (theme === 'light') {
|
|
28
|
+
if (['light'].includes(theme)) {
|
|
31
29
|
return `np-theme-${theme}`;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
// Personal light is always there by default
|
|
35
33
|
const themeClasses = ['np-theme-personal'];
|
|
36
34
|
|
|
35
|
+
/* eslint-disable functional/immutable-data */
|
|
37
36
|
// Personal dark theme
|
|
38
|
-
if (theme === 'personal' &&
|
|
37
|
+
if (theme === 'personal' && screenMode === 'dark') {
|
|
39
38
|
themeClasses.push(`np-theme-personal--${screenMode}`);
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
// Personal forest-green and bright-green themes
|
|
43
|
-
else if (
|
|
42
|
+
else if (['forest-green', 'bright-green'].includes(theme)) {
|
|
44
43
|
themeClasses.push(`np-theme-personal--${theme}`);
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
// Business light
|
|
48
|
-
else if (
|
|
47
|
+
else if (theme === 'business') {
|
|
49
48
|
themeClasses.push(`np-theme-business`);
|
|
50
49
|
// Business dark theme
|
|
51
|
-
if (
|
|
50
|
+
if (screenMode === 'dark') {
|
|
52
51
|
themeClasses.push(`np-theme-business--${screenMode}`);
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
// Business forest-green and bright-green themes
|
|
57
|
-
|
|
58
|
-
else if ([businessThemes[1], businessThemes[2]].includes(theme)) {
|
|
56
|
+
else if (['business--forest-green', 'business--bright-green'].includes(theme)) {
|
|
59
57
|
themeClasses.push(`np-theme-${theme}`);
|
|
60
58
|
}
|
|
61
59
|
|
|
@@ -63,6 +61,6 @@ export const getThemeClassName = (theme: NonNullable<Theming['theme']>, screenMo
|
|
|
63
61
|
else if (theme.startsWith('platform')) {
|
|
64
62
|
themeClasses.push(`np-theme-${theme}`);
|
|
65
63
|
}
|
|
66
|
-
|
|
64
|
+
/* eslint-enable functional/immutable-data */
|
|
67
65
|
return themeClasses.join(' ');
|
|
68
66
|
};
|