@wise/components-theming 1.10.0 → 1.10.2
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 -2
- package/dist/ThemeProvider.js.map +1 -1
- package/dist/ThemeProvider.mjs +4 -3
- package/dist/ThemeProvider.mjs.map +1 -1
- package/dist/const.d.ts +9 -1
- 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 +11 -11
- package/src/{ThemeProvider.spec.tsx → ThemeProvider.test.tsx} +23 -3
- package/src/ThemeProvider.tsx +3 -2
- package/src/const.ts +9 -1
- /package/src/{useTheme.spec.tsx → useTheme.test.tsx} +0 -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, children, className, }: ThemeProviderProps) => import("react").JSX.Element;
|
|
6
|
+
export declare const ThemeProvider: ({ theme: initialTheme, screenMode: initialScreenMode, isNotRootProvider: isLocal, 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,0GAM3B,kBAAkB,gCAuCpB,CAAC"}
|
package/dist/ThemeProvider.js
CHANGED
|
@@ -11,6 +11,7 @@ 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: isLocal = false,
|
|
14
15
|
children,
|
|
15
16
|
className = undefined
|
|
16
17
|
}) => {
|
|
@@ -26,7 +27,7 @@ const ThemeProvider = ({
|
|
|
26
27
|
}, [initialScreenMode]);
|
|
27
28
|
// useEffect hook used to apply the theme class to the HTML element
|
|
28
29
|
react.useEffect(() => {
|
|
29
|
-
if (isContextRoot) {
|
|
30
|
+
if (!isLocal && isContextRoot) {
|
|
30
31
|
// Remove all the theme classes from the documentElement
|
|
31
32
|
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
32
33
|
document.documentElement.classList.remove(item);
|
|
@@ -35,7 +36,7 @@ const ThemeProvider = ({
|
|
|
35
36
|
document.documentElement.classList.add(item);
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
|
-
}, [isContextRoot, theme, screenMode]);
|
|
39
|
+
}, [isLocal, isContextRoot, theme, screenMode]);
|
|
39
40
|
const contextValue = react.useMemo(() => ({
|
|
40
41
|
theme,
|
|
41
42
|
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, normalizeTheme } 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(normalizeTheme(initialTheme));\n const [screenMode, setScreenMode] = useState(initialScreenMode);\n\n // Update state when props change (for controlled usage)\n useEffect(() => {\n setTheme(normalizeTheme(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","normalizeTheme","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;AAC5D,EAAA,MAAM,
|
|
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, normalizeTheme } 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 isNotRootProvider: isLocal = false,\n children,\n className = undefined,\n}: ThemeProviderProps) => {\n const isContextRoot = useContext(ThemeContext) === undefined;\n const [theme, setTheme] = useState(normalizeTheme(initialTheme));\n const [screenMode, setScreenMode] = useState(initialScreenMode);\n\n // Update state when props change (for controlled usage)\n useEffect(() => {\n setTheme(normalizeTheme(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 (!isLocal && 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 }, [isLocal, 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","isNotRootProvider","isLocal","children","className","undefined","isContextRoot","useContext","ThemeContext","setTheme","useState","normalizeTheme","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,iBAAiB,EAAEC,OAAO,GAAG,KAAK;EAClCC,QAAQ;AACRC,EAAAA,SAAS,GAAGC;AAAS,CACF,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,gBAAU,CAACC,iCAAY,CAAC,KAAKH,SAAS;AAC5D,EAAA,MAAM,CAACV,KAAK,EAAEc,QAAQ,CAAC,GAAGC,cAAQ,CAACC,sBAAc,CAACf,YAAY,CAAC,CAAC;EAChE,MAAM,CAACE,UAAU,EAAEc,aAAa,CAAC,GAAGF,cAAQ,CAACX,iBAAiB,CAAC;AAE/D;AACAc,EAAAA,e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A,EAAEA;KAAyB;AAClE,GAAuB,CAAC;AAE5B;;;;"}
|
package/dist/ThemeProvider.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext, useState, 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 { normalizeTheme, getThemeClassName } from './helpers.mjs';
|
|
5
5
|
import { ThemeContext } from './ThemeProviderContext.mjs';
|
|
6
6
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -9,6 +9,7 @@ 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: isLocal = false,
|
|
12
13
|
children,
|
|
13
14
|
className = undefined
|
|
14
15
|
}) => {
|
|
@@ -24,7 +25,7 @@ const ThemeProvider = ({
|
|
|
24
25
|
}, [initialScreenMode]);
|
|
25
26
|
// useEffect hook used to apply the theme class to the HTML element
|
|
26
27
|
useEffect(() => {
|
|
27
|
-
if (isContextRoot) {
|
|
28
|
+
if (!isLocal && isContextRoot) {
|
|
28
29
|
// Remove all the theme classes from the documentElement
|
|
29
30
|
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
30
31
|
document.documentElement.classList.remove(item);
|
|
@@ -33,7 +34,7 @@ const ThemeProvider = ({
|
|
|
33
34
|
document.documentElement.classList.add(item);
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
|
-
}, [isContextRoot, theme, screenMode]);
|
|
37
|
+
}, [isLocal, isContextRoot, theme, screenMode]);
|
|
37
38
|
const contextValue = useMemo(() => ({
|
|
38
39
|
theme,
|
|
39
40
|
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, normalizeTheme } 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(normalizeTheme(initialTheme));\n const [screenMode, setScreenMode] = useState(initialScreenMode);\n\n // Update state when props change (for controlled usage)\n useEffect(() => {\n setTheme(normalizeTheme(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","normalizeTheme","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,SAAS,GAAGC;AAAS,CACF,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,UAAU,CAACC,YAAY,CAAC,KAAKH,SAAS;AAC5D,EAAA,MAAM,
|
|
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, normalizeTheme } 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 isNotRootProvider: isLocal = false,\n children,\n className = undefined,\n}: ThemeProviderProps) => {\n const isContextRoot = useContext(ThemeContext) === undefined;\n const [theme, setTheme] = useState(normalizeTheme(initialTheme));\n const [screenMode, setScreenMode] = useState(initialScreenMode);\n\n // Update state when props change (for controlled usage)\n useEffect(() => {\n setTheme(normalizeTheme(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 (!isLocal && 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 }, [isLocal, 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","isNotRootProvider","isLocal","children","className","undefined","isContextRoot","useContext","ThemeContext","setTheme","useState","normalizeTheme","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,iBAAiB,EAAEC,OAAO,GAAG,KAAK;EAClCC,QAAQ;AACRC,EAAAA,SAAS,GAAGC;AAAS,CACF,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,UAAU,CAACC,YAAY,CAAC,KAAKH,SAAS;AAC5D,EAAA,MAAM,CAACV,KAAK,EAAEc,QAAQ,CAAC,GAAGC,QAAQ,CAACC,cAAc,CAACf,YAAY,CAAC,CAAC;EAChE,MAAM,CAACE,UAAU,EAAEc,aAAa,CAAC,GAAGF,QAAQ,CAACX,iBAAiB,CAAC;AAE/D;AACAc,EAAAA,SAAS,CAAC,MAAK;AACbJ,IAAAA,QAAQ,CAACE,cAAc,CAACf,YAAY,CAAC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GED
|
@@ -28,7 +28,15 @@ export type Theming = {
|
|
|
28
28
|
theme?: ComponentTheme | BaseTheme | ExtraTheme | BusinessTheme | BusinessForestGreenTheme | BusinessBrightGreenTheme | PlatformTheme | PlatformForestGreenTheme;
|
|
29
29
|
screenMode?: ScreenMode;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* **global / root theme provider** - one that sets theming globally (at `html` element) + locally (over children);
|
|
32
|
+
*
|
|
33
|
+
* **not root provider / local provider** - one that sets theming only locally (over children)
|
|
34
|
+
*
|
|
35
|
+
* note: in most cases you won't need this property
|
|
36
|
+
*
|
|
37
|
+
* use this property to explicitly define local themes when components in components package set local themes
|
|
38
|
+
* while their global theme provider in defined somewhere far / or even unknown (e.g in another consumer package or different repos)
|
|
39
|
+
* so to avoid global theming misconfiguration you can protect it with this property
|
|
32
40
|
*/
|
|
33
41
|
isNotRootProvider?: boolean | undefined;
|
|
34
42
|
};
|
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;;GAEG;AACH,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;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WA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,EAAE,UAAU,CAAC;IACxB;;;;;;;;;;OAUG;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;\n/**\n * @deprecated \"modern\" theme is released, you should not need check for \"modern\" theme anymore\n */\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];\n/**\n * @deprecated \"modern\" theme is released, you should not need check for \"modern\" theme anymore\n */\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 = 'personal';\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 *
|
|
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;\n/**\n * @deprecated \"modern\" theme is released, you should not need check for \"modern\" theme anymore\n */\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];\n/**\n * @deprecated \"modern\" theme is released, you should not need check for \"modern\" theme anymore\n */\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 = 'personal';\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 * **global / root theme provider** - one that sets theming globally (at `html` element) + locally (over children);\n *\n * **not root provider / local provider** - one that sets theming only locally (over children)\n *\n * note: in most cases you won't need this property\n *\n * use this property to explicitly define local themes when components in components package set local themes\n * while their global theme provider in defined somewhere far / or even unknown (e.g in another consumer package or different repos)\n * so to avoid global theming misconfiguration you can protect it with this property\n */\n isNotRootProvider?: boolean | undefined;\n};\n"],"names":["extraThemes","screenModes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE"],"mappings":";;AAAA;MAEaA,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc;MAC7CC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM;AA6BpC,MAAMC,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;\n/**\n * @deprecated \"modern\" theme is released, you should not need check for \"modern\" theme anymore\n */\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];\n/**\n * @deprecated \"modern\" theme is released, you should not need check for \"modern\" theme anymore\n */\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 = 'personal';\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 *
|
|
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;\n/**\n * @deprecated \"modern\" theme is released, you should not need check for \"modern\" theme anymore\n */\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];\n/**\n * @deprecated \"modern\" theme is released, you should not need check for \"modern\" theme anymore\n */\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 = 'personal';\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 * **global / root theme provider** - one that sets theming globally (at `html` element) + locally (over children);\n *\n * **not root provider / local provider** - one that sets theming only locally (over children)\n *\n * note: in most cases you won't need this property\n *\n * use this property to explicitly define local themes when components in components package set local themes\n * while their global theme provider in defined somewhere far / or even unknown (e.g in another consumer package or different repos)\n * so to avoid global theming misconfiguration you can protect it with this property\n */\n isNotRootProvider?: boolean | undefined;\n};\n"],"names":["extraThemes","screenModes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE"],"mappings":"AAAA;MAEaA,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc;MAC7CC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM;AA6BpC,MAAMC,kBAAkB,GAAG;AAC3B,MAAMC,mBAAmB,GAAG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/components-theming",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "Provides theming support for the Wise Design system components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -12,30 +12,30 @@
|
|
|
12
12
|
"url": "git+https://github.com/transferwise/neptune-web.git"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@babel/runtime": "^7.
|
|
15
|
+
"@babel/runtime": "^7.29.2",
|
|
16
16
|
"clsx": "^2.1.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@babel/core": "^7.
|
|
20
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
21
|
-
"@babel/preset-env": "^7.
|
|
19
|
+
"@babel/core": "^7.29.0",
|
|
20
|
+
"@babel/plugin-transform-runtime": "^7.29.0",
|
|
21
|
+
"@babel/preset-env": "^7.29.3",
|
|
22
22
|
"@babel/preset-react": "^7.28.5",
|
|
23
23
|
"@babel/preset-typescript": "^7.28.5",
|
|
24
|
-
"@rollup/plugin-babel": "^
|
|
24
|
+
"@rollup/plugin-babel": "^7.0.0",
|
|
25
25
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
26
26
|
"@testing-library/dom": "^10.4.1",
|
|
27
27
|
"@testing-library/jest-dom": "^6.9.1",
|
|
28
|
-
"@testing-library/react": "^16.3.
|
|
28
|
+
"@testing-library/react": "^16.3.2",
|
|
29
29
|
"@tsconfig/recommended": "^1.0.13",
|
|
30
30
|
"@types/babel__core": "^7.20.5",
|
|
31
31
|
"@types/jest": "^30.0.0",
|
|
32
|
-
"@types/react": "^18.3.
|
|
32
|
+
"@types/react": "^18.3.28",
|
|
33
33
|
"@types/react-dom": "^18.3.7",
|
|
34
34
|
"@wise/eslint-config": "^13.3.0",
|
|
35
|
-
"eslint": "^9.39.
|
|
36
|
-
"jest": "^30.
|
|
35
|
+
"eslint": "^9.39.4",
|
|
36
|
+
"jest": "^30.3.0",
|
|
37
37
|
"jest-environment-jsdom": "^29.7.0",
|
|
38
|
-
"rollup": "^4.
|
|
38
|
+
"rollup": "^4.60.2",
|
|
39
39
|
"rollup-preserve-directives": "^1.1.3",
|
|
40
40
|
"@wise/wds-configs": "0.0.0"
|
|
41
41
|
},
|
|
@@ -1,9 +1,29 @@
|
|
|
1
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
2
2
|
|
|
3
3
|
import { ThemeProvider, ThemeProviderProps } from './ThemeProvider';
|
|
4
4
|
import { useState } from 'react';
|
|
5
5
|
|
|
6
6
|
describe('ThemeProvider', () => {
|
|
7
|
+
it('tests local theme provider (isNotRootProvider) has not affect on root theme (on html element)', () => {
|
|
8
|
+
render(
|
|
9
|
+
<ThemeProvider theme="personal" screenMode="dark" isNotRootProvider>
|
|
10
|
+
<div>local-theme-provider</div>
|
|
11
|
+
</ThemeProvider>,
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
// global theme isn't affected (in this case isn't set)
|
|
15
|
+
expect(document.documentElement).not.toHaveClass(
|
|
16
|
+
'np-theme-personal',
|
|
17
|
+
'np-theme-personal--dark',
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// only local theme being set
|
|
21
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
22
|
+
expect(screen.getByText('local-theme-provider').parentElement).toHaveClass(
|
|
23
|
+
'np-theme-personal np-theme-personal--dark',
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
7
27
|
it('tests root provider set root theme (on html element) and it is not affected by nested provider(s)', () => {
|
|
8
28
|
render(
|
|
9
29
|
<ThemeProvider theme="personal" screenMode="dark">
|
|
@@ -86,7 +106,7 @@ describe('ThemeProvider', () => {
|
|
|
86
106
|
expect(screen.getByText('content').parentElement).toHaveClass('np-theme-personal');
|
|
87
107
|
|
|
88
108
|
// Change to business theme
|
|
89
|
-
screen.getByText('Change to business')
|
|
109
|
+
fireEvent.click(screen.getByText('Change to business'));
|
|
90
110
|
await waitFor(() => {
|
|
91
111
|
// eslint-disable-next-line testing-library/no-node-access
|
|
92
112
|
expect(screen.getByText('content').parentElement).toHaveClass(
|
|
@@ -96,7 +116,7 @@ describe('ThemeProvider', () => {
|
|
|
96
116
|
});
|
|
97
117
|
|
|
98
118
|
// Change to dark mode
|
|
99
|
-
screen.getByText('Change to dark')
|
|
119
|
+
fireEvent.click(screen.getByText('Change to dark'));
|
|
100
120
|
await waitFor(() => {
|
|
101
121
|
// eslint-disable-next-line testing-library/no-node-access
|
|
102
122
|
expect(screen.getByText('content').parentElement).toHaveClass(
|
package/src/ThemeProvider.tsx
CHANGED
|
@@ -14,6 +14,7 @@ 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: isLocal = false,
|
|
17
18
|
children,
|
|
18
19
|
className = undefined,
|
|
19
20
|
}: ThemeProviderProps) => {
|
|
@@ -32,7 +33,7 @@ export const ThemeProvider = ({
|
|
|
32
33
|
|
|
33
34
|
// useEffect hook used to apply the theme class to the HTML element
|
|
34
35
|
useEffect(() => {
|
|
35
|
-
if (isContextRoot) {
|
|
36
|
+
if (!isLocal && isContextRoot) {
|
|
36
37
|
// Remove all the theme classes from the documentElement
|
|
37
38
|
document.documentElement.className.match(themeClass)?.forEach((item) => {
|
|
38
39
|
document.documentElement.classList.remove(item);
|
|
@@ -43,7 +44,7 @@ export const ThemeProvider = ({
|
|
|
43
44
|
document.documentElement.classList.add(item);
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
|
-
}, [isContextRoot, theme, screenMode]);
|
|
47
|
+
}, [isLocal, isContextRoot, theme, screenMode]);
|
|
47
48
|
|
|
48
49
|
const contextValue = useMemo(
|
|
49
50
|
() => ({ theme, screenMode, setTheme, setScreenMode }),
|
package/src/const.ts
CHANGED
|
@@ -45,7 +45,15 @@ export type Theming = {
|
|
|
45
45
|
| PlatformForestGreenTheme;
|
|
46
46
|
screenMode?: ScreenMode;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* **global / root theme provider** - one that sets theming globally (at `html` element) + locally (over children);
|
|
49
|
+
*
|
|
50
|
+
* **not root provider / local provider** - one that sets theming only locally (over children)
|
|
51
|
+
*
|
|
52
|
+
* note: in most cases you won't need this property
|
|
53
|
+
*
|
|
54
|
+
* use this property to explicitly define local themes when components in components package set local themes
|
|
55
|
+
* while their global theme provider in defined somewhere far / or even unknown (e.g in another consumer package or different repos)
|
|
56
|
+
* so to avoid global theming misconfiguration you can protect it with this property
|
|
49
57
|
*/
|
|
50
58
|
isNotRootProvider?: boolean | undefined;
|
|
51
59
|
};
|
|
File without changes
|