@wise/components-theming 0.0.0-experimental-c043dab → 0.0.0-experimental-10d0572
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/ThemeProvider.d.ts +1 -1
- package/dist/ThemeProvider.d.ts.map +1 -1
- package/dist/ThemeProvider.js +3 -13
- package/dist/ThemeProvider.js.map +1 -1
- package/dist/ThemeProvider.mjs +4 -14
- package/dist/ThemeProvider.mjs.map +1 -1
- package/dist/const.js +2 -0
- package/dist/const.js.map +1 -1
- package/dist/const.mjs +2 -1
- package/dist/const.mjs.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +30 -8
- package/dist/helpers.js.map +1 -1
- package/dist/helpers.mjs +31 -9
- package/dist/helpers.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ThemeProvider.tsx +6 -18
- package/src/helpers.ts +36 -9
package/dist/ThemeProvider.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import type { Theming } from './const';
|
|
|
3
3
|
type ThemeProviderProps = PropsWithChildren<Theming> & {
|
|
4
4
|
className?: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const ThemeProvider: ({ theme, screenMode, children, className,
|
|
6
|
+
export declare const ThemeProvider: ({ theme, screenMode, isNotRootProvider, children, className, }: ThemeProviderProps) => import("react").JSX.Element;
|
|
7
7
|
export {};
|
|
8
8
|
//# sourceMappingURL=ThemeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../src/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAkC,MAAM,OAAO,CAAC;AAG1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKvC,KAAK,kBAAkB,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAK9E,eAAO,MAAM,aAAa,GAAI,gEAM3B,kBAAkB,
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../src/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAkC,MAAM,OAAO,CAAC;AAG1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKvC,KAAK,kBAAkB,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAK9E,eAAO,MAAM,aAAa,GAAI,gEAM3B,kBAAkB,gCAyBpB,CAAC"}
|
package/dist/ThemeProvider.js
CHANGED
|
@@ -11,9 +11,9 @@ const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
|
11
11
|
const ThemeProvider = ({
|
|
12
12
|
theme = _const.DEFAULT_BASE_THEME,
|
|
13
13
|
screenMode = _const.DEFAULT_SCREEN_MODE,
|
|
14
|
+
isNotRootProvider = false,
|
|
14
15
|
children,
|
|
15
|
-
className = undefined
|
|
16
|
-
isNotRootProvider = false
|
|
16
|
+
className = undefined
|
|
17
17
|
}) => {
|
|
18
18
|
const isContextRoot = react.useContext(ThemeProviderContext.ThemeContext) === undefined;
|
|
19
19
|
// useEffect hook used to apply the theme class to the HTML element
|
|
@@ -23,19 +23,9 @@ const ThemeProvider = ({
|
|
|
23
23
|
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
24
24
|
document.documentElement.classList.remove(item);
|
|
25
25
|
});
|
|
26
|
-
|
|
27
|
-
// Auto-detection: Add np-theme-personal for business and platform themes when this is a root provider (page wrapper)
|
|
28
|
-
const isBusinessTheme = theme === 'business' || theme?.startsWith('business');
|
|
29
|
-
const isPlatformTheme = theme === 'platform' || theme?.startsWith('platform');
|
|
30
|
-
const shouldAddPersonalClass = (isBusinessTheme || isPlatformTheme) && !isNotRootProvider;
|
|
31
|
-
// Apply theme classes
|
|
32
|
-
themeClasses.forEach(item => {
|
|
26
|
+
helpers.getThemeClassName(theme, screenMode).split(' ').forEach(item => {
|
|
33
27
|
document.documentElement.classList.add(item);
|
|
34
28
|
});
|
|
35
|
-
// Add np-theme-personal for business and platform themes only in root provider (page wrapper)
|
|
36
|
-
if (shouldAddPersonalClass) {
|
|
37
|
-
document.documentElement.classList.add('np-theme-personal');
|
|
38
|
-
}
|
|
39
29
|
}
|
|
40
30
|
}, [isNotRootProvider, isContextRoot, theme, screenMode]);
|
|
41
31
|
const contextValue = react.useMemo(() => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.js","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import { PropsWithChildren, useContext, useEffect, useMemo } from 'react';\n\nimport { ThemedChildren } from './ThemedChildren';\nimport type { Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { getThemeClassName } from './helpers';\nimport { ThemeContext } from './ThemeProviderContext';\n\ntype ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };\n\n// RegEx to check for `np-theme-` class name\nconst themeClass = /\\bnp-theme-[a-z-]+\\b/g;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_BASE_THEME,\n screenMode = DEFAULT_SCREEN_MODE,\n children,\n className = undefined,\n
|
|
1
|
+
{"version":3,"file":"ThemeProvider.js","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import { PropsWithChildren, useContext, useEffect, useMemo } from 'react';\n\nimport { ThemedChildren } from './ThemedChildren';\nimport type { Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { getThemeClassName } from './helpers';\nimport { ThemeContext } from './ThemeProviderContext';\n\ntype ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };\n\n// RegEx to check for `np-theme-` class name\nconst themeClass = /\\bnp-theme-[a-z-]+\\b/g;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_BASE_THEME,\n screenMode = DEFAULT_SCREEN_MODE,\n isNotRootProvider = false,\n children,\n className = undefined,\n}: ThemeProviderProps) => {\n const isContextRoot = useContext(ThemeContext) === undefined;\n\n // useEffect hook used to apply the theme class to the HTML element\n useEffect(() => {\n if (!isNotRootProvider && isContextRoot) {\n // Remove all the theme classes from the documentElement\n document.documentElement.className.match(themeClass)?.forEach((item) => {\n document.documentElement.classList.remove(item);\n });\n getThemeClassName(theme, screenMode)\n .split(' ')\n .forEach((item) => {\n document.documentElement.classList.add(item);\n });\n }\n }, [isNotRootProvider, isContextRoot, theme, screenMode]);\n\n const contextValue = useMemo(() => ({ theme, screenMode }), [screenMode, theme]);\n\n return (\n <ThemeContext.Provider value={contextValue}>\n <ThemedChildren className={className}>{children}</ThemedChildren>\n </ThemeContext.Provider>\n );\n};\n"],"names":["themeClass","ThemeProvider","theme","DEFAULT_BASE_THEME","screenMode","DEFAULT_SCREEN_MODE","isNotRootProvider","children","className","undefined","isContextRoot","useContext","ThemeContext","useEffect","document","documentElement","match","forEach","item","classList","remove","getThemeClassName","split","add","contextValue","useMemo","_jsx","Provider","value","ThemedChildren"],"mappings":";;;;;;;;;AAWA,MAAMA,UAAU,GAAG,uBAAuB;AAEnC,MAAMC,aAAa,GAAGA,CAAC;AAC5BC,EAAAA,KAAK,GAAGC,yBAAkB;AAC1BC,EAAAA,UAAU,GAAGC,0BAAmB;AAChCC,EAAAA,iBAAiB,GAAG,KAAK;EACzBC,QAAQ;AACRC,EAAAA,SAAS,GAAGC;AAAS,CACF,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,gBAAU,CAACC,iCAAY,CAAC,KAAKH,SAAS;AAE5D;AACAI,EAAAA,eAAS,CAAC,MAAK;AACb,IAAA,IAAI,CAACP,iBAAiB,IAAII,aAAa,EAAE;AACvC;AACAI,MAAAA,QAAQ,CAACC,eAAe,CAACP,SAAS,CAACQ,KAAK,CAAChB,UAAU,CAAC,EAAEiB,OAAO,CAAEC,IAAI,IAAI;QACrEJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACC,MAAM,CAACF,IAAI,CAAC;AACjD,MAAA,CAAC,CAAC;AACFG,MAAAA,yBAAiB,CAACnB,KAAK,EAAEE,UAAU,CAAC,CACjCkB,KAAK,CAAC,GAAG,CAAC,CACVL,OAAO,CAAEC,IAAI,IAAI;QAChBJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACI,GAAG,CAACL,IAAI,CAAC;AAC9C,MAAA,CAAC,CAAC;AACN,IAAA;EACF,CAAC,EAAE,CAACZ,iBAAiB,EAAEI,aAAa,EAAER,KAAK,EAAEE,UAAU,CAAC,CAAC;AAEzD,EAAA,MAAMoB,YAAY,GAAGC,aAAO,CAAC,OAAO;IAAEvB,KAAK;AAAEE,IAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEF,KAAK,CAAC,CAAC;AAEhF,EAAA,oBACEwB,cAAA,CAACd,iCAAY,CAACe,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAEJ,YAAa;IAAAjB,QAAA,eACzCmB,cAAA,CAACG,6BAAc,EAAA;AAACrB,MAAAA,SAAS,EAAEA,SAAU;AAAAD,MAAAA,QAAA,EAAEA;KAAyB;AAClE,GAAuB,CAAC;AAE5B;;;;"}
|
package/dist/ThemeProvider.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext, useEffect, useMemo } from 'react';
|
|
2
2
|
import { ThemedChildren } from './ThemedChildren.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { DEFAULT_SCREEN_MODE, DEFAULT_BASE_THEME } from './const.mjs';
|
|
4
4
|
import { getThemeClassName } from './helpers.mjs';
|
|
5
5
|
import { ThemeContext } from './ThemeProviderContext.mjs';
|
|
6
6
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -9,9 +9,9 @@ const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
|
9
9
|
const ThemeProvider = ({
|
|
10
10
|
theme = DEFAULT_BASE_THEME,
|
|
11
11
|
screenMode = DEFAULT_SCREEN_MODE,
|
|
12
|
+
isNotRootProvider = false,
|
|
12
13
|
children,
|
|
13
|
-
className = undefined
|
|
14
|
-
isNotRootProvider = false
|
|
14
|
+
className = undefined
|
|
15
15
|
}) => {
|
|
16
16
|
const isContextRoot = useContext(ThemeContext) === undefined;
|
|
17
17
|
// useEffect hook used to apply the theme class to the HTML element
|
|
@@ -21,19 +21,9 @@ const ThemeProvider = ({
|
|
|
21
21
|
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
22
22
|
document.documentElement.classList.remove(item);
|
|
23
23
|
});
|
|
24
|
-
|
|
25
|
-
// Auto-detection: Add np-theme-personal for business and platform themes when this is a root provider (page wrapper)
|
|
26
|
-
const isBusinessTheme = theme === 'business' || theme?.startsWith('business');
|
|
27
|
-
const isPlatformTheme = theme === 'platform' || theme?.startsWith('platform');
|
|
28
|
-
const shouldAddPersonalClass = (isBusinessTheme || isPlatformTheme) && !isNotRootProvider;
|
|
29
|
-
// Apply theme classes
|
|
30
|
-
themeClasses.forEach(item => {
|
|
24
|
+
getThemeClassName(theme, screenMode).split(' ').forEach(item => {
|
|
31
25
|
document.documentElement.classList.add(item);
|
|
32
26
|
});
|
|
33
|
-
// Add np-theme-personal for business and platform themes only in root provider (page wrapper)
|
|
34
|
-
if (shouldAddPersonalClass) {
|
|
35
|
-
document.documentElement.classList.add('np-theme-personal');
|
|
36
|
-
}
|
|
37
27
|
}
|
|
38
28
|
}, [isNotRootProvider, isContextRoot, theme, screenMode]);
|
|
39
29
|
const contextValue = useMemo(() => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.mjs","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import { PropsWithChildren, useContext, useEffect, useMemo } from 'react';\n\nimport { ThemedChildren } from './ThemedChildren';\nimport type { Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { getThemeClassName } from './helpers';\nimport { ThemeContext } from './ThemeProviderContext';\n\ntype ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };\n\n// RegEx to check for `np-theme-` class name\nconst themeClass = /\\bnp-theme-[a-z-]+\\b/g;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_BASE_THEME,\n screenMode = DEFAULT_SCREEN_MODE,\n children,\n className = undefined,\n
|
|
1
|
+
{"version":3,"file":"ThemeProvider.mjs","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import { PropsWithChildren, useContext, useEffect, useMemo } from 'react';\n\nimport { ThemedChildren } from './ThemedChildren';\nimport type { Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { getThemeClassName } from './helpers';\nimport { ThemeContext } from './ThemeProviderContext';\n\ntype ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };\n\n// RegEx to check for `np-theme-` class name\nconst themeClass = /\\bnp-theme-[a-z-]+\\b/g;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_BASE_THEME,\n screenMode = DEFAULT_SCREEN_MODE,\n isNotRootProvider = false,\n children,\n className = undefined,\n}: ThemeProviderProps) => {\n const isContextRoot = useContext(ThemeContext) === undefined;\n\n // useEffect hook used to apply the theme class to the HTML element\n useEffect(() => {\n if (!isNotRootProvider && isContextRoot) {\n // Remove all the theme classes from the documentElement\n document.documentElement.className.match(themeClass)?.forEach((item) => {\n document.documentElement.classList.remove(item);\n });\n getThemeClassName(theme, screenMode)\n .split(' ')\n .forEach((item) => {\n document.documentElement.classList.add(item);\n });\n }\n }, [isNotRootProvider, isContextRoot, theme, screenMode]);\n\n const contextValue = useMemo(() => ({ theme, screenMode }), [screenMode, theme]);\n\n return (\n <ThemeContext.Provider value={contextValue}>\n <ThemedChildren className={className}>{children}</ThemedChildren>\n </ThemeContext.Provider>\n );\n};\n"],"names":["themeClass","ThemeProvider","theme","DEFAULT_BASE_THEME","screenMode","DEFAULT_SCREEN_MODE","isNotRootProvider","children","className","undefined","isContextRoot","useContext","ThemeContext","useEffect","document","documentElement","match","forEach","item","classList","remove","getThemeClassName","split","add","contextValue","useMemo","_jsx","Provider","value","ThemedChildren"],"mappings":";;;;;;;AAWA,MAAMA,UAAU,GAAG,uBAAuB;AAEnC,MAAMC,aAAa,GAAGA,CAAC;AAC5BC,EAAAA,KAAK,GAAGC,kBAAkB;AAC1BC,EAAAA,UAAU,GAAGC,mBAAmB;AAChCC,EAAAA,iBAAiB,GAAG,KAAK;EACzBC,QAAQ;AACRC,EAAAA,SAAS,GAAGC;AAAS,CACF,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,UAAU,CAACC,YAAY,CAAC,KAAKH,SAAS;AAE5D;AACAI,EAAAA,SAAS,CAAC,MAAK;AACb,IAAA,IAAI,CAACP,iBAAiB,IAAII,aAAa,EAAE;AACvC;AACAI,MAAAA,QAAQ,CAACC,eAAe,CAACP,SAAS,CAACQ,KAAK,CAAChB,UAAU,CAAC,EAAEiB,OAAO,CAAEC,IAAI,IAAI;QACrEJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACC,MAAM,CAACF,IAAI,CAAC;AACjD,MAAA,CAAC,CAAC;AACFG,MAAAA,iBAAiB,CAACnB,KAAK,EAAEE,UAAU,CAAC,CACjCkB,KAAK,CAAC,GAAG,CAAC,CACVL,OAAO,CAAEC,IAAI,IAAI;QAChBJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACI,GAAG,CAACL,IAAI,CAAC;AAC9C,MAAA,CAAC,CAAC;AACN,IAAA;EACF,CAAC,EAAE,CAACZ,iBAAiB,EAAEI,aAAa,EAAER,KAAK,EAAEE,UAAU,CAAC,CAAC;AAEzD,EAAA,MAAMoB,YAAY,GAAGC,OAAO,CAAC,OAAO;IAAEvB,KAAK;AAAEE,IAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEF,KAAK,CAAC,CAAC;AAEhF,EAAA,oBACEwB,GAAA,CAACd,YAAY,CAACe,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAEJ,YAAa;IAAAjB,QAAA,eACzCmB,GAAA,CAACG,cAAc,EAAA;AAACrB,MAAAA,SAAS,EAAEA,SAAU;AAAAD,MAAAA,QAAA,EAAEA;KAAyB;AAClE,GAAuB,CAAC;AAE5B;;;;"}
|
package/dist/const.js
CHANGED
|
@@ -5,12 +5,14 @@ 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'];
|
|
8
9
|
const DEFAULT_BASE_THEME = 'light';
|
|
9
10
|
const DEFAULT_SCREEN_MODE = 'light';
|
|
10
11
|
|
|
11
12
|
exports.DEFAULT_BASE_THEME = DEFAULT_BASE_THEME;
|
|
12
13
|
exports.DEFAULT_SCREEN_MODE = DEFAULT_SCREEN_MODE;
|
|
13
14
|
exports.baseThemes = baseThemes;
|
|
15
|
+
exports.businessThemes = businessThemes;
|
|
14
16
|
exports.extraThemes = extraThemes;
|
|
15
17
|
exports.modernThemes = modernThemes;
|
|
16
18
|
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","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;
|
|
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","businessThemes","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;AAClE,MAAMG,cAAc,GAAG,CAC5B,UAAU,EACV,wBAAwB,EACxB,wBAAwB;AAkBnB,MAAMC,kBAAkB,GAAG;AAC3B,MAAMC,mBAAmB,GAAG;;;;;;;;;;"}
|
package/dist/const.mjs
CHANGED
|
@@ -3,8 +3,9 @@ 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'];
|
|
6
7
|
const DEFAULT_BASE_THEME = 'light';
|
|
7
8
|
const DEFAULT_SCREEN_MODE = 'light';
|
|
8
9
|
|
|
9
|
-
export { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE, baseThemes, extraThemes, modernThemes, screenModes };
|
|
10
|
+
export { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE, baseThemes, businessThemes, extraThemes, modernThemes, screenModes };
|
|
10
11
|
//# 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","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;
|
|
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","businessThemes","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;AAClE,MAAMG,cAAc,GAAG,CAC5B,UAAU,EACV,wBAAwB,EACxB,wBAAwB;AAkBnB,MAAMC,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":"AACA,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,WAwC7F,CAAC"}
|
package/dist/helpers.js
CHANGED
|
@@ -7,16 +7,38 @@ 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
|
-
|
|
10
|
+
// Legacy themes
|
|
11
|
+
if (theme === 'light') {
|
|
12
|
+
return `np-theme-${theme}`;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
// Personal light is always there by default
|
|
15
|
+
const themeClasses = ['np-theme-personal'];
|
|
16
|
+
// Personal dark theme
|
|
17
|
+
if (theme === 'personal' && _const.screenModes[1] === screenMode) {
|
|
18
|
+
themeClasses.push(`np-theme-personal--${screenMode}`);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
// Personal forest-green and bright-green themes
|
|
21
|
+
else if (isExtraTheme(theme)) {
|
|
22
|
+
themeClasses.push(`np-theme-personal--${theme}`);
|
|
23
|
+
}
|
|
24
|
+
// Business light
|
|
25
|
+
else if (_const.businessThemes[0] === theme) {
|
|
26
|
+
themeClasses.push(`np-theme-business`);
|
|
27
|
+
// Business dark theme
|
|
28
|
+
if (_const.screenModes[1] === screenMode) {
|
|
29
|
+
themeClasses.push(`np-theme-business--${screenMode}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Business forest-green and bright-green themes
|
|
33
|
+
// @ts-expect-error relax TS
|
|
34
|
+
else if ([_const.businessThemes[1], _const.businessThemes[2]].includes(theme)) {
|
|
35
|
+
themeClasses.push(`np-theme-${theme}`);
|
|
36
|
+
}
|
|
37
|
+
// Platform themes
|
|
38
|
+
else if (theme.startsWith('platform')) {
|
|
39
|
+
themeClasses.push(`np-theme-${theme}`);
|
|
40
|
+
}
|
|
41
|
+
return themeClasses.join(' ');
|
|
20
42
|
};
|
|
21
43
|
|
|
22
44
|
exports.getThemeClassName = getThemeClassName;
|
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":["/* eslint-disable functional/immutable-data */\nimport type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes, businessThemes } 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 // Legacy themes\n if (theme === 'light') {\n return `np-theme-${theme}`;\n }\n\n // Personal light is always there by default\n const themeClasses = ['np-theme-personal'];\n\n // Personal dark theme\n if (theme === 'personal' && screenModes[1] === screenMode) {\n themeClasses.push(`np-theme-personal--${screenMode}`);\n }\n\n // Personal forest-green and bright-green themes\n else if (isExtraTheme(theme)) {\n themeClasses.push(`np-theme-personal--${theme}`);\n }\n\n // Business light\n else if (businessThemes[0] === theme) {\n themeClasses.push(`np-theme-business`);\n // Business dark theme\n if (screenModes[1] === screenMode) {\n themeClasses.push(`np-theme-business--${screenMode}`);\n }\n }\n\n // Business forest-green and bright-green themes\n // @ts-expect-error relax TS\n else if ([businessThemes[1], businessThemes[2]].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\n return themeClasses.join(' ');\n};\n"],"names":["isThemeModern","theme","modernThemes","includes","isExtraTheme","extraThemes","isForestGreenTheme","isScreenModeDark","screenMode","screenModes","getThemeClassName","themeClasses","push","businessThemes","startsWith","join"],"mappings":";;;;AAWO,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;AAChG;EACA,IAAIP,KAAK,KAAK,OAAO,EAAE;IACrB,OAAO,CAAA,SAAA,EAAYA,KAAK,CAAA,CAAE;AAC5B,EAAA;AAEA;AACA,EAAA,MAAMU,YAAY,GAAG,CAAC,mBAAmB,CAAC;AAE1C;EACA,IAAIV,KAAK,KAAK,UAAU,IAAIQ,kBAAW,CAAC,CAAC,CAAC,KAAKD,UAAU,EAAE;AACzDG,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBJ,UAAU,EAAE,CAAC;AACvD,EAAA;AAEA;AAAA,OACK,IAAIJ,YAAY,CAACH,KAAK,CAAC,EAAE;AAC5BU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBX,KAAK,EAAE,CAAC;AAClD,EAAA;AAEA;AAAA,OACK,IAAIY,qBAAc,CAAC,CAAC,CAAC,KAAKZ,KAAK,EAAE;AACpCU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,iBAAA,CAAmB,CAAC;AACtC;AACA,IAAA,IAAIH,kBAAW,CAAC,CAAC,CAAC,KAAKD,UAAU,EAAE;AACjCG,MAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBJ,UAAU,EAAE,CAAC;AACvD,IAAA;AACF,EAAA;AAEA;AACA;AAAA,OACK,IAAI,CAACK,qBAAc,CAAC,CAAC,CAAC,EAAEA,qBAAc,CAAC,CAAC,CAAC,CAAC,CAACV,QAAQ,CAACF,KAAK,CAAC,EAAE;AAC/DU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,SAAA,EAAYX,KAAK,EAAE,CAAC;AACxC,EAAA;AAEA;AAAA,OACK,IAAIA,KAAK,CAACa,UAAU,CAAC,UAAU,CAAC,EAAE;AACrCH,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,SAAA,EAAYX,KAAK,EAAE,CAAC;AACxC,EAAA;AAEA,EAAA,OAAOU,YAAY,CAACI,IAAI,CAAC,GAAG,CAAC;AAC/B;;;;;;;;"}
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
|
-
import { modernThemes, extraThemes, screenModes } from './const.mjs';
|
|
1
|
+
import { modernThemes, extraThemes, screenModes, businessThemes } 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
|
-
|
|
8
|
+
// Legacy themes
|
|
9
|
+
if (theme === 'light') {
|
|
10
|
+
return `np-theme-${theme}`;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
// Personal light is always there by default
|
|
13
|
+
const themeClasses = ['np-theme-personal'];
|
|
14
|
+
// Personal dark theme
|
|
15
|
+
if (theme === 'personal' && screenModes[1] === screenMode) {
|
|
16
|
+
themeClasses.push(`np-theme-personal--${screenMode}`);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
// Personal forest-green and bright-green themes
|
|
19
|
+
else if (isExtraTheme(theme)) {
|
|
20
|
+
themeClasses.push(`np-theme-personal--${theme}`);
|
|
21
|
+
}
|
|
22
|
+
// Business light
|
|
23
|
+
else if (businessThemes[0] === theme) {
|
|
24
|
+
themeClasses.push(`np-theme-business`);
|
|
25
|
+
// Business dark theme
|
|
26
|
+
if (screenModes[1] === screenMode) {
|
|
27
|
+
themeClasses.push(`np-theme-business--${screenMode}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Business forest-green and bright-green themes
|
|
31
|
+
// @ts-expect-error relax TS
|
|
32
|
+
else if ([businessThemes[1], businessThemes[2]].includes(theme)) {
|
|
33
|
+
themeClasses.push(`np-theme-${theme}`);
|
|
34
|
+
}
|
|
35
|
+
// Platform themes
|
|
36
|
+
else if (theme.startsWith('platform')) {
|
|
37
|
+
themeClasses.push(`np-theme-${theme}`);
|
|
38
|
+
}
|
|
39
|
+
return themeClasses.join(' ');
|
|
18
40
|
};
|
|
19
41
|
|
|
20
42
|
export { getThemeClassName, isExtraTheme, isForestGreenTheme, isScreenModeDark, isThemeModern };
|
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":["/* eslint-disable functional/immutable-data */\nimport type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes, businessThemes } 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 // Legacy themes\n if (theme === 'light') {\n return `np-theme-${theme}`;\n }\n\n // Personal light is always there by default\n const themeClasses = ['np-theme-personal'];\n\n // Personal dark theme\n if (theme === 'personal' && screenModes[1] === screenMode) {\n themeClasses.push(`np-theme-personal--${screenMode}`);\n }\n\n // Personal forest-green and bright-green themes\n else if (isExtraTheme(theme)) {\n themeClasses.push(`np-theme-personal--${theme}`);\n }\n\n // Business light\n else if (businessThemes[0] === theme) {\n themeClasses.push(`np-theme-business`);\n // Business dark theme\n if (screenModes[1] === screenMode) {\n themeClasses.push(`np-theme-business--${screenMode}`);\n }\n }\n\n // Business forest-green and bright-green themes\n // @ts-expect-error relax TS\n else if ([businessThemes[1], businessThemes[2]].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\n return themeClasses.join(' ');\n};\n"],"names":["isThemeModern","theme","modernThemes","includes","isExtraTheme","extraThemes","isForestGreenTheme","isScreenModeDark","screenMode","screenModes","getThemeClassName","themeClasses","push","businessThemes","startsWith","join"],"mappings":";;AAWO,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;AAChG;EACA,IAAIP,KAAK,KAAK,OAAO,EAAE;IACrB,OAAO,CAAA,SAAA,EAAYA,KAAK,CAAA,CAAE;AAC5B,EAAA;AAEA;AACA,EAAA,MAAMU,YAAY,GAAG,CAAC,mBAAmB,CAAC;AAE1C;EACA,IAAIV,KAAK,KAAK,UAAU,IAAIQ,WAAW,CAAC,CAAC,CAAC,KAAKD,UAAU,EAAE;AACzDG,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBJ,UAAU,EAAE,CAAC;AACvD,EAAA;AAEA;AAAA,OACK,IAAIJ,YAAY,CAACH,KAAK,CAAC,EAAE;AAC5BU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBX,KAAK,EAAE,CAAC;AAClD,EAAA;AAEA;AAAA,OACK,IAAIY,cAAc,CAAC,CAAC,CAAC,KAAKZ,KAAK,EAAE;AACpCU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,iBAAA,CAAmB,CAAC;AACtC;AACA,IAAA,IAAIH,WAAW,CAAC,CAAC,CAAC,KAAKD,UAAU,EAAE;AACjCG,MAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,mBAAA,EAAsBJ,UAAU,EAAE,CAAC;AACvD,IAAA;AACF,EAAA;AAEA;AACA;AAAA,OACK,IAAI,CAACK,cAAc,CAAC,CAAC,CAAC,EAAEA,cAAc,CAAC,CAAC,CAAC,CAAC,CAACV,QAAQ,CAACF,KAAK,CAAC,EAAE;AAC/DU,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,SAAA,EAAYX,KAAK,EAAE,CAAC;AACxC,EAAA;AAEA;AAAA,OACK,IAAIA,KAAK,CAACa,UAAU,CAAC,UAAU,CAAC,EAAE;AACrCH,IAAAA,YAAY,CAACC,IAAI,CAAC,CAAA,SAAA,EAAYX,KAAK,EAAE,CAAC;AACxC,EAAA;AAEA,EAAA,OAAOU,YAAY,CAACI,IAAI,CAAC,GAAG,CAAC;AAC/B;;;;"}
|
package/package.json
CHANGED
package/src/ThemeProvider.tsx
CHANGED
|
@@ -14,9 +14,9 @@ const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
|
14
14
|
export const ThemeProvider = ({
|
|
15
15
|
theme = DEFAULT_BASE_THEME,
|
|
16
16
|
screenMode = DEFAULT_SCREEN_MODE,
|
|
17
|
+
isNotRootProvider = false,
|
|
17
18
|
children,
|
|
18
19
|
className = undefined,
|
|
19
|
-
isNotRootProvider = false,
|
|
20
20
|
}: ThemeProviderProps) => {
|
|
21
21
|
const isContextRoot = useContext(ThemeContext) === undefined;
|
|
22
22
|
|
|
@@ -27,23 +27,11 @@ export const ThemeProvider = ({
|
|
|
27
27
|
document.documentElement.className.match(themeClass)?.forEach((item) => {
|
|
28
28
|
document.documentElement.classList.remove(item);
|
|
29
29
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const isPlatformTheme = theme === 'platform' || theme?.startsWith('platform');
|
|
36
|
-
const shouldAddPersonalClass = (isBusinessTheme || isPlatformTheme) && !isNotRootProvider;
|
|
37
|
-
|
|
38
|
-
// Apply theme classes
|
|
39
|
-
themeClasses.forEach((item) => {
|
|
40
|
-
document.documentElement.classList.add(item);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Add np-theme-personal for business and platform themes only in root provider (page wrapper)
|
|
44
|
-
if (shouldAddPersonalClass) {
|
|
45
|
-
document.documentElement.classList.add('np-theme-personal');
|
|
46
|
-
}
|
|
30
|
+
getThemeClassName(theme, screenMode)
|
|
31
|
+
.split(' ')
|
|
32
|
+
.forEach((item) => {
|
|
33
|
+
document.documentElement.classList.add(item);
|
|
34
|
+
});
|
|
47
35
|
}
|
|
48
36
|
}, [isNotRootProvider, isContextRoot, theme, screenMode]);
|
|
49
37
|
|
package/src/helpers.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable functional/immutable-data */
|
|
1
2
|
import type {
|
|
2
3
|
ModernTheme,
|
|
3
4
|
ExtraTheme,
|
|
@@ -6,7 +7,7 @@ import type {
|
|
|
6
7
|
ScreenModeDark,
|
|
7
8
|
Theming,
|
|
8
9
|
} from './const';
|
|
9
|
-
import { extraThemes, screenModes, modernThemes } from './const';
|
|
10
|
+
import { extraThemes, screenModes, modernThemes, businessThemes } from './const';
|
|
10
11
|
|
|
11
12
|
export const isThemeModern = (theme: NonNullable<Theming['theme']>): theme is ModernTheme =>
|
|
12
13
|
modernThemes.includes(theme as ModernTheme);
|
|
@@ -25,17 +26,43 @@ export const isScreenModeDark = (
|
|
|
25
26
|
isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;
|
|
26
27
|
|
|
27
28
|
export const getThemeClassName = (theme: NonNullable<Theming['theme']>, screenMode: ScreenMode) => {
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
// Legacy themes
|
|
30
|
+
if (theme === 'light') {
|
|
31
|
+
return `np-theme-${theme}`;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
// Personal light is always there by default
|
|
35
|
+
const themeClasses = ['np-theme-personal'];
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
classes += ` ${classes}--${screenMode}`;
|
|
37
|
+
// Personal dark theme
|
|
38
|
+
if (theme === 'personal' && screenModes[1] === screenMode) {
|
|
39
|
+
themeClasses.push(`np-theme-personal--${screenMode}`);
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
// Personal forest-green and bright-green themes
|
|
43
|
+
else if (isExtraTheme(theme)) {
|
|
44
|
+
themeClasses.push(`np-theme-personal--${theme}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Business light
|
|
48
|
+
else if (businessThemes[0] === theme) {
|
|
49
|
+
themeClasses.push(`np-theme-business`);
|
|
50
|
+
// Business dark theme
|
|
51
|
+
if (screenModes[1] === screenMode) {
|
|
52
|
+
themeClasses.push(`np-theme-business--${screenMode}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Business forest-green and bright-green themes
|
|
57
|
+
// @ts-expect-error relax TS
|
|
58
|
+
else if ([businessThemes[1], businessThemes[2]].includes(theme)) {
|
|
59
|
+
themeClasses.push(`np-theme-${theme}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Platform themes
|
|
63
|
+
else if (theme.startsWith('platform')) {
|
|
64
|
+
themeClasses.push(`np-theme-${theme}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return themeClasses.join(' ');
|
|
41
68
|
};
|