@wise/components-theming 1.9.3 → 1.9.4
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 +2 -3
- package/dist/ThemeProvider.js.map +1 -1
- package/dist/ThemeProvider.mjs +2 -3
- package/dist/ThemeProvider.mjs.map +1 -1
- package/dist/const.d.ts +3 -0
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js.map +1 -1
- package/dist/const.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ThemeProvider.spec.tsx +28 -0
- package/src/ThemeProvider.tsx +2 -3
- package/src/const.ts +3 -0
package/dist/ThemeProvider.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import type { Theming } from './const';
|
|
|
3
3
|
export type ThemeProviderProps = PropsWithChildren<Theming> & {
|
|
4
4
|
className?: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const ThemeProvider: ({ theme: initialTheme, screenMode: initialScreenMode,
|
|
6
|
+
export declare const ThemeProvider: ({ theme: initialTheme, screenMode: initialScreenMode, children, className, }: ThemeProviderProps) => import("react").JSX.Element;
|
|
7
7
|
//# 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,EAA4C,MAAM,OAAO,CAAC;AAGpF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKvC,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAKrF,eAAO,MAAM,aAAa,GAAI,
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../src/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA4C,MAAM,OAAO,CAAC;AAGpF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKvC,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAKrF,eAAO,MAAM,aAAa,GAAI,8EAK3B,kBAAkB,gCAuCpB,CAAC"}
|
package/dist/ThemeProvider.js
CHANGED
|
@@ -11,7 +11,6 @@ const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
|
11
11
|
const ThemeProvider = ({
|
|
12
12
|
theme: initialTheme = _const.DEFAULT_BASE_THEME,
|
|
13
13
|
screenMode: initialScreenMode = _const.DEFAULT_SCREEN_MODE,
|
|
14
|
-
isNotRootProvider = false,
|
|
15
14
|
children,
|
|
16
15
|
className = undefined
|
|
17
16
|
}) => {
|
|
@@ -27,7 +26,7 @@ const ThemeProvider = ({
|
|
|
27
26
|
}, [initialScreenMode]);
|
|
28
27
|
// useEffect hook used to apply the theme class to the HTML element
|
|
29
28
|
react.useEffect(() => {
|
|
30
|
-
if (
|
|
29
|
+
if (isContextRoot) {
|
|
31
30
|
// Remove all the theme classes from the documentElement
|
|
32
31
|
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
33
32
|
document.documentElement.classList.remove(item);
|
|
@@ -36,7 +35,7 @@ const ThemeProvider = ({
|
|
|
36
35
|
document.documentElement.classList.add(item);
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
|
-
}, [
|
|
38
|
+
}, [isContextRoot, theme, screenMode]);
|
|
40
39
|
const contextValue = react.useMemo(() => ({
|
|
41
40
|
theme,
|
|
42
41
|
screenMode,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.js","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import { PropsWithChildren, useContext, useEffect, useMemo, useState } 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\nexport type 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: initialTheme = DEFAULT_BASE_THEME,\n screenMode: initialScreenMode = DEFAULT_SCREEN_MODE,\n
|
|
1
|
+
{"version":3,"file":"ThemeProvider.js","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import { PropsWithChildren, useContext, useEffect, useMemo, useState } 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\nexport type 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: initialTheme = DEFAULT_BASE_THEME,\n screenMode: initialScreenMode = DEFAULT_SCREEN_MODE,\n children,\n className = undefined,\n}: ThemeProviderProps) => {\n const isContextRoot = useContext(ThemeContext) === undefined;\n const [theme, setTheme] = useState(initialTheme);\n const [screenMode, setScreenMode] = useState(initialScreenMode);\n\n // Update state when props change (for controlled usage)\n useEffect(() => {\n setTheme(initialTheme);\n }, [initialTheme]);\n\n useEffect(() => {\n setScreenMode(initialScreenMode);\n }, [initialScreenMode]);\n\n // useEffect hook used to apply the theme class to the HTML element\n useEffect(() => {\n if (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 }, [isContextRoot, theme, screenMode]);\n\n const contextValue = useMemo(\n () => ({ theme, screenMode, setTheme, setScreenMode }),\n [theme, screenMode, setTheme, setScreenMode],\n );\n\n return (\n <ThemeContext.Provider value={contextValue}>\n <ThemedChildren className={className}>{children}</ThemedChildren>\n </ThemeContext.Provider>\n );\n};\n"],"names":["themeClass","ThemeProvider","theme","initialTheme","DEFAULT_BASE_THEME","screenMode","initialScreenMode","DEFAULT_SCREEN_MODE","children","className","undefined","isContextRoot","useContext","ThemeContext","setTheme","useState","setScreenMode","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;EAC5BC,KAAK,EAAEC,YAAY,GAAGC,yBAAkB;EACxCC,UAAU,EAAEC,iBAAiB,GAAGC,0BAAmB;EACnDC,QAAQ;AACRC,EAAAA,SAAS,GAAGC;AAAS,CACF,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,gBAAU,CAACC,iCAAY,CAAC,KAAKH,SAAS;EAC5D,MAAM,CAACR,KAAK,EAAEY,QAAQ,CAAC,GAAGC,cAAQ,CAACZ,YAAY,CAAC;EAChD,MAAM,CAACE,UAAU,EAAEW,aAAa,CAAC,GAAGD,cAAQ,CAACT,iBAAiB,CAAC;AAE/D;AACAW,EAAAA,eAAS,CAAC,MAAK;IACbH,QAAQ,CAACX,YAAY,CAAC;AACxB,EAAA,CAAC,EAAE,CAACA,YAAY,CAAC,CAAC;AAElBc,EAAAA,eAAS,CAAC,MAAK;IACbD,aAAa,CAACV,iBAAiB,CAAC;AAClC,EAAA,CAAC,EAAE,CAACA,iBAAiB,CAAC,CAAC;AAEvB;AACAW,EAAAA,eAAS,CAAC,MAAK;AACb,IAAA,IAAIN,aAAa,EAAE;AACjB;AACAO,MAAAA,QAAQ,CAACC,eAAe,CAACV,SAAS,CAACW,KAAK,CAACpB,UAAU,CAAC,EAAEqB,OAAO,CAAEC,IAAI,IAAI;QACrEJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACC,MAAM,CAACF,IAAI,CAAC;AACjD,MAAA,CAAC,CAAC;AACFG,MAAAA,yBAAiB,CAACvB,KAAK,EAAEG,UAAU,CAAC,CACjCqB,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,CAACX,aAAa,EAAET,KAAK,EAAEG,UAAU,CAAC,CAAC;AAEtC,EAAA,MAAMuB,YAAY,GAAGC,aAAO,CAC1B,OAAO;IAAE3B,KAAK;IAAEG,UAAU;IAAES,QAAQ;AAAEE,IAAAA;GAAe,CAAC,EACtD,CAACd,KAAK,EAAEG,UAAU,EAAES,QAAQ,EAAEE,aAAa,CAAC,CAC7C;AAED,EAAA,oBACEc,cAAA,CAACjB,iCAAY,CAACkB,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAEJ,YAAa;IAAApB,QAAA,eACzCsB,cAAA,CAACG,6BAAc,EAAA;AAACxB,MAAAA,SAAS,EAAEA,SAAU;AAAAD,MAAAA,QAAA,EAAEA;KAAyB;AAClE,GAAuB,CAAC;AAE5B;;;;"}
|
package/dist/ThemeProvider.mjs
CHANGED
|
@@ -9,7 +9,6 @@ const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
|
9
9
|
const ThemeProvider = ({
|
|
10
10
|
theme: initialTheme = DEFAULT_BASE_THEME,
|
|
11
11
|
screenMode: initialScreenMode = DEFAULT_SCREEN_MODE,
|
|
12
|
-
isNotRootProvider = false,
|
|
13
12
|
children,
|
|
14
13
|
className = undefined
|
|
15
14
|
}) => {
|
|
@@ -25,7 +24,7 @@ const ThemeProvider = ({
|
|
|
25
24
|
}, [initialScreenMode]);
|
|
26
25
|
// useEffect hook used to apply the theme class to the HTML element
|
|
27
26
|
useEffect(() => {
|
|
28
|
-
if (
|
|
27
|
+
if (isContextRoot) {
|
|
29
28
|
// Remove all the theme classes from the documentElement
|
|
30
29
|
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
31
30
|
document.documentElement.classList.remove(item);
|
|
@@ -34,7 +33,7 @@ const ThemeProvider = ({
|
|
|
34
33
|
document.documentElement.classList.add(item);
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
|
-
}, [
|
|
36
|
+
}, [isContextRoot, theme, screenMode]);
|
|
38
37
|
const contextValue = useMemo(() => ({
|
|
39
38
|
theme,
|
|
40
39
|
screenMode,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.mjs","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import { PropsWithChildren, useContext, useEffect, useMemo, useState } 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\nexport type 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: initialTheme = DEFAULT_BASE_THEME,\n screenMode: initialScreenMode = DEFAULT_SCREEN_MODE,\n
|
|
1
|
+
{"version":3,"file":"ThemeProvider.mjs","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import { PropsWithChildren, useContext, useEffect, useMemo, useState } 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\nexport type 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: initialTheme = DEFAULT_BASE_THEME,\n screenMode: initialScreenMode = DEFAULT_SCREEN_MODE,\n children,\n className = undefined,\n}: ThemeProviderProps) => {\n const isContextRoot = useContext(ThemeContext) === undefined;\n const [theme, setTheme] = useState(initialTheme);\n const [screenMode, setScreenMode] = useState(initialScreenMode);\n\n // Update state when props change (for controlled usage)\n useEffect(() => {\n setTheme(initialTheme);\n }, [initialTheme]);\n\n useEffect(() => {\n setScreenMode(initialScreenMode);\n }, [initialScreenMode]);\n\n // useEffect hook used to apply the theme class to the HTML element\n useEffect(() => {\n if (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 }, [isContextRoot, theme, screenMode]);\n\n const contextValue = useMemo(\n () => ({ theme, screenMode, setTheme, setScreenMode }),\n [theme, screenMode, setTheme, setScreenMode],\n );\n\n return (\n <ThemeContext.Provider value={contextValue}>\n <ThemedChildren className={className}>{children}</ThemedChildren>\n </ThemeContext.Provider>\n );\n};\n"],"names":["themeClass","ThemeProvider","theme","initialTheme","DEFAULT_BASE_THEME","screenMode","initialScreenMode","DEFAULT_SCREEN_MODE","children","className","undefined","isContextRoot","useContext","ThemeContext","setTheme","useState","setScreenMode","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;EAC5BC,KAAK,EAAEC,YAAY,GAAGC,kBAAkB;EACxCC,UAAU,EAAEC,iBAAiB,GAAGC,mBAAmB;EACnDC,QAAQ;AACRC,EAAAA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,aAAa,CAAC,CAC7C;AAED,EAAA,oBACEc,GAAA,CAACjB,YAAY,CAACkB,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAEJ,YAAa;IAAApB,QAAA,eACzCsB,GAAA,CAACG,cAAc,EAAA;AAACxB,MAAAA,SAAS,EAAEA,SAAU;AAAAD,MAAAA,QAAA,EAAEA;KAAyB;AAClE,GAAuB,CAAC;AAE5B;;;;"}
|
package/dist/const.d.ts
CHANGED
|
@@ -21,6 +21,9 @@ export declare const DEFAULT_SCREEN_MODE = "light";
|
|
|
21
21
|
export type Theming = {
|
|
22
22
|
theme?: ComponentTheme | BaseTheme | ExtraTheme | BusinessTheme | BusinessForestGreenTheme | BusinessBrightGreenTheme | PlatformTheme | PlatformForestGreenTheme;
|
|
23
23
|
screenMode?: ScreenMode;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated this property has not effect, safe to delete
|
|
26
|
+
*/
|
|
24
27
|
isNotRootProvider?: boolean | undefined;
|
|
25
28
|
};
|
|
26
29
|
//# sourceMappingURL=const.d.ts.map
|
package/dist/const.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,4CAA6C,CAAC;AACrE,eAAO,MAAM,WAAW,2CAA4C,CAAC;AACrE,eAAO,MAAM,WAAW,4BAA6B,CAAC;AACtD,eAAO,MAAM,YAAY,mEAA0D,CAAC;AACpF,eAAO,MAAM,cAAc,2EAIjB,CAAC;AACX,eAAO,MAAM,cAAc,iDAAkD,CAAC;AAG9E,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CA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aAAa,GACb,wBAAwB,GACxB,wBAAwB,GACxB,aAAa,GACb,wBAAwB,CAAC;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACzC,CAAC"}
|
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;AAsBlE,MAAMG,kBAAkB,GAAG;AAC3B,MAAMC,mBAAmB,GAAG;;;;;;;;;"}
|
|
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 /**\n * @deprecated this property has not effect, safe to delete\n */\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.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;AAsBlE,MAAMG,kBAAkB,GAAG;AAC3B,MAAMC,mBAAmB,GAAG;;;;"}
|
|
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 /**\n * @deprecated this property has not effect, safe to delete\n */\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/package.json
CHANGED
|
@@ -4,6 +4,34 @@ import { ThemeProvider, ThemeProviderProps } from './ThemeProvider';
|
|
|
4
4
|
import { useState } from 'react';
|
|
5
5
|
|
|
6
6
|
describe('ThemeProvider', () => {
|
|
7
|
+
it('tests root provider set root theme (on html element) and it is not affected by nested provider(s)', () => {
|
|
8
|
+
render(
|
|
9
|
+
<ThemeProvider theme="personal" screenMode="dark">
|
|
10
|
+
<div>root-dark-theme</div>
|
|
11
|
+
<ThemeProvider theme="forest-green">
|
|
12
|
+
<div>nested-forest-green</div>
|
|
13
|
+
</ThemeProvider>
|
|
14
|
+
<ThemeProvider theme="personal" screenMode="light">
|
|
15
|
+
<div>nested-personal</div>
|
|
16
|
+
</ThemeProvider>
|
|
17
|
+
</ThemeProvider>,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// root provider set dark theme and it wasn't changed by two nested providers
|
|
21
|
+
expect(document.documentElement).toHaveClass('np-theme-personal np-theme-personal--dark');
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
24
|
+
expect(screen.getByText('root-dark-theme').parentElement).toHaveClass(
|
|
25
|
+
'np-theme-personal np-theme-personal--dark',
|
|
26
|
+
);
|
|
27
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
28
|
+
expect(screen.getByText('nested-forest-green').parentElement).toHaveClass(
|
|
29
|
+
'np-theme-personal np-theme-personal--forest-green',
|
|
30
|
+
);
|
|
31
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
32
|
+
expect(screen.getByText('nested-personal').parentElement).toHaveClass('np-theme-personal');
|
|
33
|
+
});
|
|
34
|
+
|
|
7
35
|
it('can nest theme providers', () => {
|
|
8
36
|
render(
|
|
9
37
|
<ThemeProvider theme="light">
|
package/src/ThemeProvider.tsx
CHANGED
|
@@ -14,7 +14,6 @@ const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
|
14
14
|
export const ThemeProvider = ({
|
|
15
15
|
theme: initialTheme = DEFAULT_BASE_THEME,
|
|
16
16
|
screenMode: initialScreenMode = DEFAULT_SCREEN_MODE,
|
|
17
|
-
isNotRootProvider = false,
|
|
18
17
|
children,
|
|
19
18
|
className = undefined,
|
|
20
19
|
}: ThemeProviderProps) => {
|
|
@@ -33,7 +32,7 @@ export const ThemeProvider = ({
|
|
|
33
32
|
|
|
34
33
|
// useEffect hook used to apply the theme class to the HTML element
|
|
35
34
|
useEffect(() => {
|
|
36
|
-
if (
|
|
35
|
+
if (isContextRoot) {
|
|
37
36
|
// Remove all the theme classes from the documentElement
|
|
38
37
|
document.documentElement.className.match(themeClass)?.forEach((item) => {
|
|
39
38
|
document.documentElement.classList.remove(item);
|
|
@@ -44,7 +43,7 @@ export const ThemeProvider = ({
|
|
|
44
43
|
document.documentElement.classList.add(item);
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
|
-
}, [
|
|
46
|
+
}, [isContextRoot, theme, screenMode]);
|
|
48
47
|
|
|
49
48
|
const contextValue = useMemo(
|
|
50
49
|
() => ({ theme, screenMode, setTheme, setScreenMode }),
|