@wise/components-theming 0.0.0-experimental-02f72a1 → 0.0.0-experimental-128143a
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
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,
|
|
6
|
+
export declare const ThemeProvider: ({ theme, screenMode, 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,
|
|
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,6CAK3B,kBAAkB,gCAyBpB,CAAC"}
|
package/dist/ThemeProvider.js
CHANGED
|
@@ -11,14 +11,13 @@ 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,
|
|
15
14
|
children,
|
|
16
15
|
className = undefined
|
|
17
16
|
}) => {
|
|
18
17
|
const isContextRoot = react.useContext(ThemeProviderContext.ThemeContext) === undefined;
|
|
19
18
|
// useEffect hook used to apply the theme class to the HTML element
|
|
20
19
|
react.useEffect(() => {
|
|
21
|
-
if (
|
|
20
|
+
if (isContextRoot) {
|
|
22
21
|
// Remove all the theme classes from the documentElement
|
|
23
22
|
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
24
23
|
document.documentElement.classList.remove(item);
|
|
@@ -27,7 +26,7 @@ const ThemeProvider = ({
|
|
|
27
26
|
document.documentElement.classList.add(item);
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
|
-
}, [
|
|
29
|
+
}, [isContextRoot, theme, screenMode]);
|
|
31
30
|
const contextValue = react.useMemo(() => ({
|
|
32
31
|
theme,
|
|
33
32
|
screenMode
|
|
@@ -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
|
|
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}: 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 (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(() => ({ 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","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;EAChCC,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,IAAIH,aAAa,EAAE;AACjB;AACAI,MAAAA,QAAQ,CAACC,eAAe,CAACP,SAAS,CAACQ,KAAK,CAACf,UAAU,CAAC,EAAEgB,OAAO,CAAEC,IAAI,IAAI;QACrEJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACC,MAAM,CAACF,IAAI,CAAC;AACjD,MAAA,CAAC,CAAC;AACFG,MAAAA,yBAAiB,CAAClB,KAAK,EAAEE,UAAU,CAAC,CACjCiB,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,CAACR,aAAa,EAAEP,KAAK,EAAEE,UAAU,CAAC,CAAC;AAEtC,EAAA,MAAMmB,YAAY,GAAGC,aAAO,CAAC,OAAO;IAAEtB,KAAK;AAAEE,IAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEF,KAAK,CAAC,CAAC;AAEhF,EAAA,oBACEuB,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
|
@@ -9,14 +9,13 @@ 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,
|
|
13
12
|
children,
|
|
14
13
|
className = undefined
|
|
15
14
|
}) => {
|
|
16
15
|
const isContextRoot = useContext(ThemeContext) === undefined;
|
|
17
16
|
// useEffect hook used to apply the theme class to the HTML element
|
|
18
17
|
useEffect(() => {
|
|
19
|
-
if (
|
|
18
|
+
if (isContextRoot) {
|
|
20
19
|
// Remove all the theme classes from the documentElement
|
|
21
20
|
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
22
21
|
document.documentElement.classList.remove(item);
|
|
@@ -25,7 +24,7 @@ const ThemeProvider = ({
|
|
|
25
24
|
document.documentElement.classList.add(item);
|
|
26
25
|
});
|
|
27
26
|
}
|
|
28
|
-
}, [
|
|
27
|
+
}, [isContextRoot, theme, screenMode]);
|
|
29
28
|
const contextValue = useMemo(() => ({
|
|
30
29
|
theme,
|
|
31
30
|
screenMode
|
|
@@ -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
|
|
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}: 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 (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(() => ({ 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","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;EAChCC,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,IAAIH,aAAa,EAAE;AACjB;AACAI,MAAAA,QAAQ,CAACC,eAAe,CAACP,SAAS,CAACQ,KAAK,CAACf,UAAU,CAAC,EAAEgB,OAAO,CAAEC,IAAI,IAAI;QACrEJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACC,MAAM,CAACF,IAAI,CAAC;AACjD,MAAA,CAAC,CAAC;AACFG,MAAAA,iBAAiB,CAAClB,KAAK,EAAEE,UAAU,CAAC,CACjCiB,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,CAACR,aAAa,EAAEP,KAAK,EAAEE,UAAU,CAAC,CAAC;AAEtC,EAAA,MAAMmB,YAAY,GAAGC,OAAO,CAAC,OAAO;IAAEtB,KAAK;AAAEE,IAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEF,KAAK,CAAC,CAAC;AAEhF,EAAA,oBACEuB,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/package.json
CHANGED
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 = DEFAULT_BASE_THEME,
|
|
16
16
|
screenMode = DEFAULT_SCREEN_MODE,
|
|
17
|
-
isNotRootProvider = false,
|
|
18
17
|
children,
|
|
19
18
|
className = undefined,
|
|
20
19
|
}: ThemeProviderProps) => {
|
|
@@ -22,7 +21,7 @@ export const ThemeProvider = ({
|
|
|
22
21
|
|
|
23
22
|
// useEffect hook used to apply the theme class to the HTML element
|
|
24
23
|
useEffect(() => {
|
|
25
|
-
if (
|
|
24
|
+
if (isContextRoot) {
|
|
26
25
|
// Remove all the theme classes from the documentElement
|
|
27
26
|
document.documentElement.className.match(themeClass)?.forEach((item) => {
|
|
28
27
|
document.documentElement.classList.remove(item);
|
|
@@ -33,7 +32,7 @@ export const ThemeProvider = ({
|
|
|
33
32
|
document.documentElement.classList.add(item);
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
|
-
}, [
|
|
35
|
+
}, [isContextRoot, theme, screenMode]);
|
|
37
36
|
|
|
38
37
|
const contextValue = useMemo(() => ({ theme, screenMode }), [screenMode, theme]);
|
|
39
38
|
|