@wise/components-theming 0.0.0-experimental-57b6bbd → 0.0.0-experimental-5535cba
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 +2 -6
- package/dist/ThemeProvider.d.ts.map +1 -1
- package/dist/ThemeProvider.js +20 -5
- package/dist/ThemeProvider.js.map +1 -1
- package/dist/ThemeProvider.mjs +21 -5
- package/dist/ThemeProvider.mjs.map +1 -1
- package/dist/ThemeProviderContext.d.ts +6 -0
- package/dist/ThemeProviderContext.d.ts.map +1 -0
- package/dist/ThemeProviderContext.js +8 -0
- package/dist/ThemeProviderContext.js.map +1 -0
- package/dist/ThemeProviderContext.mjs +6 -0
- package/dist/ThemeProviderContext.mjs.map +1 -0
- package/dist/ThemedChildren.d.ts +8 -0
- package/dist/ThemedChildren.d.ts.map +1 -0
- package/dist/{ThemedLayer.js → ThemedChildren.js} +5 -8
- package/dist/ThemedChildren.js.map +1 -0
- package/dist/{ThemedLayer.mjs → ThemedChildren.mjs} +5 -8
- package/dist/ThemedChildren.mjs.map +1 -0
- package/dist/const.d.ts +0 -1
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js.map +1 -1
- package/dist/const.mjs.map +1 -1
- package/dist/helpers.d.ts +0 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +0 -4
- package/dist/helpers.js.map +1 -1
- package/dist/helpers.mjs +0 -4
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/useTheme.d.ts +0 -4
- package/dist/useTheme.d.ts.map +1 -1
- package/dist/useTheme.js +2 -2
- package/dist/useTheme.js.map +1 -1
- package/dist/useTheme.mjs +1 -1
- package/dist/useTheme.mjs.map +1 -1
- package/package.json +6 -3
- package/src/ThemeProvider.tsx +27 -12
- package/src/ThemeProviderContext.tsx +10 -0
- package/src/ThemedChildren.tsx +12 -0
- package/src/const.ts +0 -1
- package/src/helpers.ts +0 -4
- package/src/index.ts +1 -2
- package/src/useTheme.ts +1 -5
- package/dist/ThemedLayer.d.ts +0 -8
- package/dist/ThemedLayer.d.ts.map +0 -1
- package/dist/ThemedLayer.js.map +0 -1
- package/dist/ThemedLayer.mjs.map +0 -1
- package/src/ThemedLayer.tsx +0 -14
package/dist/ThemeProvider.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const ThemeContext: import("react").Context<{
|
|
4
|
-
theme: NonNullable<Theming["theme"]>;
|
|
5
|
-
screenMode: ScreenMode;
|
|
6
|
-
} | undefined>;
|
|
2
|
+
import type { Theming } from './const';
|
|
7
3
|
type ThemeProviderProps = PropsWithChildren<Theming> & {
|
|
8
4
|
className?: string;
|
|
9
5
|
};
|
|
10
|
-
export declare const ThemeProvider: ({ theme, screenMode, children, className, }: ThemeProviderProps) => import("react").JSX.Element;
|
|
6
|
+
export declare const ThemeProvider: ({ theme, screenMode, isNotRootProvider, children, className, }: ThemeProviderProps) => import("react").JSX.Element;
|
|
11
7
|
export {};
|
|
12
8
|
//# sourceMappingURL=ThemeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../src/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,mEAMvB,kBAAkB,gCAyBpB,CAAC"}
|
package/dist/ThemeProvider.js
CHANGED
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
|
-
var
|
|
4
|
+
var ThemedChildren = require('./ThemedChildren.js');
|
|
5
5
|
var _const = require('./const.js');
|
|
6
|
+
var helpers = require('./helpers.js');
|
|
7
|
+
var ThemeProviderContext = require('./ThemeProviderContext.js');
|
|
6
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
9
|
|
|
8
|
-
const
|
|
10
|
+
const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
9
11
|
const ThemeProvider = ({
|
|
10
12
|
theme = _const.DEFAULT_BASE_THEME,
|
|
11
13
|
screenMode = _const.DEFAULT_SCREEN_MODE,
|
|
14
|
+
isNotRootProvider = false,
|
|
12
15
|
children,
|
|
13
16
|
className = undefined
|
|
14
17
|
}) => {
|
|
18
|
+
const isContextRoot = react.useContext(ThemeProviderContext.ThemeContext) === undefined;
|
|
19
|
+
// useEffect hook used to apply the theme class to the HTML element
|
|
20
|
+
react.useEffect(() => {
|
|
21
|
+
if (!isNotRootProvider && isContextRoot) {
|
|
22
|
+
// Remove all the theme classes from the documentElement
|
|
23
|
+
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
24
|
+
document.documentElement.classList.remove(item);
|
|
25
|
+
});
|
|
26
|
+
helpers.getThemeClassName(theme, screenMode).split(' ').forEach(item => {
|
|
27
|
+
document.documentElement.classList.add(item);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}, [isNotRootProvider, isContextRoot, theme, screenMode]);
|
|
15
31
|
const contextValue = react.useMemo(() => ({
|
|
16
32
|
theme,
|
|
17
33
|
screenMode
|
|
18
34
|
}), [screenMode, theme]);
|
|
19
|
-
return /*#__PURE__*/jsxRuntime.jsx(ThemeContext.Provider, {
|
|
35
|
+
return /*#__PURE__*/jsxRuntime.jsx(ThemeProviderContext.ThemeContext.Provider, {
|
|
20
36
|
value: contextValue,
|
|
21
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
|
37
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ThemedChildren.ThemedChildren, {
|
|
22
38
|
className: className,
|
|
23
39
|
children: children
|
|
24
40
|
})
|
|
25
41
|
});
|
|
26
42
|
};
|
|
27
43
|
|
|
28
|
-
exports.ThemeContext = ThemeContext;
|
|
29
44
|
exports.ThemeProvider = ThemeProvider;
|
|
30
45
|
//# sourceMappingURL=ThemeProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.js","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import {
|
|
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,CAAA;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,SAAAA;AACO,CAAA,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,gBAAU,CAACC,iCAAY,CAAC,KAAKH,SAAS,CAAA;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,CAAA;AACjD,OAAC,CAAC,CAAA;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,CAAA;AAC9C,OAAC,CAAC,CAAA;AACN,KAAA;GACD,EAAE,CAACZ,iBAAiB,EAAEI,aAAa,EAAER,KAAK,EAAEE,UAAU,CAAC,CAAC,CAAA;AAEzD,EAAA,MAAMoB,YAAY,GAAGC,aAAO,CAAC,OAAO;IAAEvB,KAAK;AAAEE,IAAAA,UAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEF,KAAK,CAAC,CAAC,CAAA;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,QAAAA;KAAyB,CAAA;AAClE,GAAuB,CAAC,CAAA;AAE5B;;;;"}
|
package/dist/ThemeProvider.mjs
CHANGED
|
@@ -1,27 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useContext, useEffect, useMemo } from 'react';
|
|
2
|
+
import { ThemedChildren } from './ThemedChildren.mjs';
|
|
3
3
|
import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const.mjs';
|
|
4
|
+
import { getThemeClassName } from './helpers.mjs';
|
|
5
|
+
import { ThemeContext } from './ThemeProviderContext.mjs';
|
|
4
6
|
import { jsx } from 'react/jsx-runtime';
|
|
5
7
|
|
|
6
|
-
const
|
|
8
|
+
const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
7
9
|
const ThemeProvider = ({
|
|
8
10
|
theme = DEFAULT_BASE_THEME,
|
|
9
11
|
screenMode = DEFAULT_SCREEN_MODE,
|
|
12
|
+
isNotRootProvider = false,
|
|
10
13
|
children,
|
|
11
14
|
className = undefined
|
|
12
15
|
}) => {
|
|
16
|
+
const isContextRoot = useContext(ThemeContext) === undefined;
|
|
17
|
+
// useEffect hook used to apply the theme class to the HTML element
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!isNotRootProvider && isContextRoot) {
|
|
20
|
+
// Remove all the theme classes from the documentElement
|
|
21
|
+
document.documentElement.className.match(themeClass)?.forEach(item => {
|
|
22
|
+
document.documentElement.classList.remove(item);
|
|
23
|
+
});
|
|
24
|
+
getThemeClassName(theme, screenMode).split(' ').forEach(item => {
|
|
25
|
+
document.documentElement.classList.add(item);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}, [isNotRootProvider, isContextRoot, theme, screenMode]);
|
|
13
29
|
const contextValue = useMemo(() => ({
|
|
14
30
|
theme,
|
|
15
31
|
screenMode
|
|
16
32
|
}), [screenMode, theme]);
|
|
17
33
|
return /*#__PURE__*/jsx(ThemeContext.Provider, {
|
|
18
34
|
value: contextValue,
|
|
19
|
-
children: /*#__PURE__*/jsx(
|
|
35
|
+
children: /*#__PURE__*/jsx(ThemedChildren, {
|
|
20
36
|
className: className,
|
|
21
37
|
children: children
|
|
22
38
|
})
|
|
23
39
|
});
|
|
24
40
|
};
|
|
25
41
|
|
|
26
|
-
export {
|
|
42
|
+
export { ThemeProvider };
|
|
27
43
|
//# sourceMappingURL=ThemeProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.mjs","sources":["../src/ThemeProvider.tsx"],"sourcesContent":["import {
|
|
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,CAAA;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,SAAAA;AACO,CAAA,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,UAAU,CAACC,YAAY,CAAC,KAAKH,SAAS,CAAA;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,CAAA;AACjD,OAAC,CAAC,CAAA;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,CAAA;AAC9C,OAAC,CAAC,CAAA;AACN,KAAA;GACD,EAAE,CAACZ,iBAAiB,EAAEI,aAAa,EAAER,KAAK,EAAEE,UAAU,CAAC,CAAC,CAAA;AAEzD,EAAA,MAAMoB,YAAY,GAAGC,OAAO,CAAC,OAAO;IAAEvB,KAAK;AAAEE,IAAAA,UAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEF,KAAK,CAAC,CAAC,CAAA;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,QAAAA;KAAyB,CAAA;AAClE,GAAuB,CAAC,CAAA;AAE5B;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeProviderContext.d.ts","sourceRoot":"","sources":["../src/ThemeProviderContext.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEnD,eAAO,MAAM,YAAY;WAEZ,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBACxB,UAAU;cAGhB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeProviderContext.js","sources":["../src/ThemeProviderContext.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type { ScreenMode, Theming } from './const';\n\nexport const ThemeContext = createContext<\n | {\n theme: NonNullable<Theming['theme']>;\n screenMode: ScreenMode;\n }\n | undefined\n>(undefined);\n"],"names":["ThemeContext","createContext","undefined"],"mappings":";;;;MAGaA,YAAY,gBAAGC,mBAAa,CAMvCC,SAAS;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeProviderContext.mjs","sources":["../src/ThemeProviderContext.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport type { ScreenMode, Theming } from './const';\n\nexport const ThemeContext = createContext<\n | {\n theme: NonNullable<Theming['theme']>;\n screenMode: ScreenMode;\n }\n | undefined\n>(undefined);\n"],"names":["ThemeContext","createContext","undefined"],"mappings":";;MAGaA,YAAY,gBAAGC,aAAa,CAMvCC,SAAS;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
type ThemedChildrenProps = {
|
|
3
|
+
className?: string;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
};
|
|
6
|
+
export declare const ThemedChildren: ({ className, children }: ThemedChildrenProps) => import("react").JSX.Element;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=ThemedChildren.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemedChildren.d.ts","sourceRoot":"","sources":["../src/ThemedChildren.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,KAAK,mBAAmB,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,CAAC;AAEvE,eAAO,MAAM,cAAc,4BAAyC,mBAAmB,gCAItF,CAAC"}
|
|
@@ -2,23 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var clsx = require('clsx');
|
|
4
4
|
var useTheme = require('./useTheme.js');
|
|
5
|
-
var helpers = require('./helpers.js');
|
|
6
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
6
|
|
|
8
|
-
const
|
|
9
|
-
className,
|
|
7
|
+
const ThemedChildren = ({
|
|
8
|
+
className = undefined,
|
|
10
9
|
children
|
|
11
10
|
}) => {
|
|
12
11
|
const {
|
|
13
|
-
|
|
14
|
-
screenMode
|
|
12
|
+
className: themeClass
|
|
15
13
|
} = useTheme.useTheme();
|
|
16
|
-
const themeClass = helpers.getThemeClassName(theme, screenMode);
|
|
17
14
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
18
15
|
className: clsx.clsx(themeClass, className),
|
|
19
16
|
children: children
|
|
20
17
|
});
|
|
21
18
|
};
|
|
22
19
|
|
|
23
|
-
exports.
|
|
24
|
-
//# sourceMappingURL=
|
|
20
|
+
exports.ThemedChildren = ThemedChildren;
|
|
21
|
+
//# sourceMappingURL=ThemedChildren.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemedChildren.js","sources":["../src/ThemedChildren.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { ReactNode } from 'react';\n\nimport { useTheme } from './useTheme';\n\ntype ThemedChildrenProps = { className?: string; children: ReactNode };\n\nexport const ThemedChildren = ({ className = undefined, children }: ThemedChildrenProps) => {\n const { className: themeClass } = useTheme();\n\n return <div className={clsx(themeClass, className)}>{children}</div>;\n};\n"],"names":["ThemedChildren","className","undefined","children","themeClass","useTheme","_jsx","clsx"],"mappings":";;;;;;AAOO,MAAMA,cAAc,GAAGA,CAAC;AAAEC,EAAAA,SAAS,GAAGC,SAAS;AAAEC,EAAAA,QAAAA;AAAQ,CAAuB,KAAI;EACzF,MAAM;AAAEF,IAAAA,SAAS,EAAEG,UAAAA;GAAY,GAAGC,iBAAQ,EAAE,CAAA;AAE5C,EAAA,oBAAOC,cAAA,CAAA,KAAA,EAAA;AAAKL,IAAAA,SAAS,EAAEM,SAAI,CAACH,UAAU,EAAEH,SAAS,CAAE;AAAAE,IAAAA,QAAA,EAAEA,QAAAA;AAAQ,GAAM,CAAC,CAAA;AACtE;;;;"}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import { useTheme } from './useTheme.mjs';
|
|
3
|
-
import { getThemeClassName } from './helpers.mjs';
|
|
4
3
|
import { jsx } from 'react/jsx-runtime';
|
|
5
4
|
|
|
6
|
-
const
|
|
7
|
-
className,
|
|
5
|
+
const ThemedChildren = ({
|
|
6
|
+
className = undefined,
|
|
8
7
|
children
|
|
9
8
|
}) => {
|
|
10
9
|
const {
|
|
11
|
-
|
|
12
|
-
screenMode
|
|
10
|
+
className: themeClass
|
|
13
11
|
} = useTheme();
|
|
14
|
-
const themeClass = getThemeClassName(theme, screenMode);
|
|
15
12
|
return /*#__PURE__*/jsx("div", {
|
|
16
13
|
className: clsx(themeClass, className),
|
|
17
14
|
children: children
|
|
18
15
|
});
|
|
19
16
|
};
|
|
20
17
|
|
|
21
|
-
export {
|
|
22
|
-
//# sourceMappingURL=
|
|
18
|
+
export { ThemedChildren };
|
|
19
|
+
//# sourceMappingURL=ThemedChildren.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemedChildren.mjs","sources":["../src/ThemedChildren.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { ReactNode } from 'react';\n\nimport { useTheme } from './useTheme';\n\ntype ThemedChildrenProps = { className?: string; children: ReactNode };\n\nexport const ThemedChildren = ({ className = undefined, children }: ThemedChildrenProps) => {\n const { className: themeClass } = useTheme();\n\n return <div className={clsx(themeClass, className)}>{children}</div>;\n};\n"],"names":["ThemedChildren","className","undefined","children","themeClass","useTheme","_jsx","clsx"],"mappings":";;;;AAOO,MAAMA,cAAc,GAAGA,CAAC;AAAEC,EAAAA,SAAS,GAAGC,SAAS;AAAEC,EAAAA,QAAAA;AAAQ,CAAuB,KAAI;EACzF,MAAM;AAAEF,IAAAA,SAAS,EAAEG,UAAAA;GAAY,GAAGC,QAAQ,EAAE,CAAA;AAE5C,EAAA,oBAAOC,GAAA,CAAA,KAAA,EAAA;AAAKL,IAAAA,SAAS,EAAEM,IAAI,CAACH,UAAU,EAAEH,SAAS,CAAE;AAAAE,IAAAA,QAAA,EAAEA,QAAAA;AAAQ,GAAM,CAAC,CAAA;AACtE;;;;"}
|
package/dist/const.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export declare const DEFAULT_SCREEN_MODE = "light";
|
|
|
17
17
|
export type Theming = {
|
|
18
18
|
theme?: ComponentTheme | BaseTheme | ExtraTheme | PlatformTheme | PlatformForestGreenTheme;
|
|
19
19
|
screenMode?: ScreenMode;
|
|
20
|
-
/** @deprecated no-op */
|
|
21
20
|
isNotRootProvider?: boolean | undefined;
|
|
22
21
|
};
|
|
23
22
|
//# 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,gCAAiC,CAAC;AACzD,eAAO,MAAM,WAAW,2CAA4C,CAAC;AACrE,eAAO,MAAM,WAAW,4BAA6B,CAAC;AACtD,eAAO,MAAM,YAAY,uDAA2C,CAAC;AACrE,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,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAElE,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAC1C,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,aAAa,GAAG,wBAAwB,CAAC;IAC3F,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,gCAAiC,CAAC;AACzD,eAAO,MAAM,WAAW,2CAA4C,CAAC;AACrE,eAAO,MAAM,WAAW,4BAA6B,CAAC;AACtD,eAAO,MAAM,YAAY,uDAA2C,CAAC;AACrE,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,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAElE,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAC1C,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,aAAa,GAAG,wBAAwB,CAAC;IAC3F,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,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'] as const;\nexport const extraThemes = ['forest-green', 'bright-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], ...extraThemes] 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];\n\nexport const DEFAULT_BASE_THEME = 'light';\nexport const DEFAULT_SCREEN_MODE = 'light';\n\nexport type Theming = {\n theme?: ComponentTheme | BaseTheme | ExtraTheme | PlatformTheme | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\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'] as const;\nexport const extraThemes = ['forest-green', 'bright-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], ...extraThemes] 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];\n\nexport const DEFAULT_BASE_THEME = 'light';\nexport const DEFAULT_SCREEN_MODE = 'light';\n\nexport type Theming = {\n theme?: ComponentTheme | BaseTheme | ExtraTheme | PlatformTheme | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\n isNotRootProvider?: boolean | undefined;\n};\n"],"names":["baseThemes","extraThemes","screenModes","modernThemes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE"],"mappings":";;AAAA;MACaA,UAAU,GAAG,CAAC,OAAO,EAAE,UAAU,EAAU;MAC3CC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc,EAAU;MACvDC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,EAAU;AAC9C,MAAMC,YAAY,GAAG,CAACH,UAAU,CAAC,CAAC,CAAC,EAAE,GAAGC,WAAW,EAAU;AAc7D,MAAMG,kBAAkB,GAAG,QAAO;AAClC,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'] as const;\nexport const extraThemes = ['forest-green', 'bright-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], ...extraThemes] 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];\n\nexport const DEFAULT_BASE_THEME = 'light';\nexport const DEFAULT_SCREEN_MODE = 'light';\n\nexport type Theming = {\n theme?: ComponentTheme | BaseTheme | ExtraTheme | PlatformTheme | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\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'] as const;\nexport const extraThemes = ['forest-green', 'bright-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], ...extraThemes] 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];\n\nexport const DEFAULT_BASE_THEME = 'light';\nexport const DEFAULT_SCREEN_MODE = 'light';\n\nexport type Theming = {\n theme?: ComponentTheme | BaseTheme | ExtraTheme | PlatformTheme | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\n isNotRootProvider?: boolean | undefined;\n};\n"],"names":["baseThemes","extraThemes","screenModes","modernThemes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE"],"mappings":"AAAA;MACaA,UAAU,GAAG,CAAC,OAAO,EAAE,UAAU,EAAU;MAC3CC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc,EAAU;MACvDC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,EAAU;AAC9C,MAAMC,YAAY,GAAG,CAACH,UAAU,CAAC,CAAC,CAAC,EAAE,GAAGC,WAAW,EAAU;AAc7D,MAAMG,kBAAkB,GAAG,QAAO;AAClC,MAAMC,mBAAmB,GAAG;;;;"}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { ModernTheme, ExtraTheme, ForestGreenTheme, ScreenMode, ScreenModeDark, Theming } from './const';
|
|
2
|
-
/** @deprecated */
|
|
3
2
|
export declare const isThemeModern: (theme: NonNullable<Theming["theme"]>) => theme is ModernTheme;
|
|
4
|
-
/** @deprecated */
|
|
5
3
|
export declare const isExtraTheme: (theme: NonNullable<Theming["theme"]>) => theme is ExtraTheme;
|
|
6
|
-
/** @deprecated */
|
|
7
4
|
export declare const isForestGreenTheme: (theme: NonNullable<Theming["theme"]>) => theme is ForestGreenTheme;
|
|
8
|
-
/** @deprecated */
|
|
9
5
|
export declare const isScreenModeDark: (theme: NonNullable<Theming["theme"]>, screenMode: ScreenMode) => screenMode is ScreenModeDark;
|
|
10
6
|
export declare const getThemeClassName: (theme: NonNullable<Theming["theme"]>, screenMode: ScreenMode) => string;
|
|
11
7
|
//# sourceMappingURL=helpers.d.ts.map
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,OAAO,EACR,MAAM,SAAS,CAAC;AAGjB,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,OAAO,EACR,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,aAAa,UAAW,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAG,KAAK,IAAI,WACjC,CAAC;AAE9C,eAAO,MAAM,YAAY,UAAW,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAG,KAAK,IAAI,UAClC,CAAC;AAE5C,eAAO,MAAM,kBAAkB,UACtB,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KACnC,KAAK,IAAI,gBAA4C,CAAC;AAEzD,eAAO,MAAM,gBAAgB,UACpB,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cACxB,UAAU,KACrB,UAAU,IAAI,cACqD,CAAC;AAEvE,eAAO,MAAM,iBAAiB,UAAW,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,UAAU,WAc7F,CAAC"}
|
package/dist/helpers.js
CHANGED
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var _const = require('./const.js');
|
|
4
4
|
|
|
5
|
-
/** @deprecated */
|
|
6
5
|
const isThemeModern = theme => _const.modernThemes.includes(theme);
|
|
7
|
-
/** @deprecated */
|
|
8
6
|
const isExtraTheme = theme => _const.extraThemes.includes(theme);
|
|
9
|
-
/** @deprecated */
|
|
10
7
|
const isForestGreenTheme = theme => theme === _const.extraThemes[0];
|
|
11
|
-
/** @deprecated */
|
|
12
8
|
const isScreenModeDark = (theme, screenMode) => isThemeModern(theme) && _const.screenModes[1] === screenMode;
|
|
13
9
|
const getThemeClassName = (theme, screenMode) => {
|
|
14
10
|
if (!isThemeModern(theme)) {
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":["../src/helpers.ts"],"sourcesContent":["import type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../src/helpers.ts"],"sourcesContent":["import type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (theme: NonNullable<Theming['theme']>): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isExtraTheme = (theme: NonNullable<Theming['theme']>): theme is ExtraTheme =>\n extraThemes.includes(theme as ExtraTheme);\n\nexport const isForestGreenTheme = (\n theme: NonNullable<Theming['theme']>,\n): theme is ForestGreenTheme => theme === extraThemes[0];\n\nexport const isScreenModeDark = (\n theme: NonNullable<Theming['theme']>,\n screenMode: ScreenMode,\n): screenMode is ScreenModeDark =>\n isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;\n\nexport const getThemeClassName = (theme: NonNullable<Theming['theme']>, screenMode: ScreenMode) => {\n if (!isThemeModern(theme)) {\n return `np-theme-${theme || 'personal'}`;\n }\n\n let classes = `np-theme-personal`;\n\n if (isExtraTheme(theme)) {\n classes += ` ${classes}--${theme}`;\n } else if (screenModes[1] === screenMode) {\n classes += ` ${classes}--${screenMode}`;\n }\n\n return classes;\n};\n"],"names":["isThemeModern","theme","modernThemes","includes","isExtraTheme","extraThemes","isForestGreenTheme","isScreenModeDark","screenMode","screenModes","getThemeClassName","classes"],"mappings":";;;;AAUO,MAAMA,aAAa,GAAIC,KAAoC,IAChEC,mBAAY,CAACC,QAAQ,CAACF,KAAoB,EAAC;AAEtC,MAAMG,YAAY,GAAIH,KAAoC,IAC/DI,kBAAW,CAACF,QAAQ,CAACF,KAAmB,EAAC;AAEpC,MAAMK,kBAAkB,GAC7BL,KAAoC,IACNA,KAAK,KAAKI,kBAAW,CAAC,CAAC,EAAC;MAE3CE,gBAAgB,GAAGA,CAC9BN,KAAoC,EACpCO,UAAsB,KAEtBR,aAAa,CAACC,KAAoB,CAAC,IAAIQ,kBAAW,CAAC,CAAC,CAAC,KAAKD,WAAU;MAEzDE,iBAAiB,GAAGA,CAACT,KAAoC,EAAEO,UAAsB,KAAI;AAChG,EAAA,IAAI,CAACR,aAAa,CAACC,KAAK,CAAC,EAAE;AACzB,IAAA,OAAO,CAAYA,SAAAA,EAAAA,KAAK,IAAI,UAAU,CAAE,CAAA,CAAA;AAC1C,GAAA;EAEA,IAAIU,OAAO,GAAG,CAAmB,iBAAA,CAAA,CAAA;AAEjC,EAAA,IAAIP,YAAY,CAACH,KAAK,CAAC,EAAE;AACvBU,IAAAA,OAAO,IAAI,CAAA,CAAA,EAAIA,OAAO,CAAA,EAAA,EAAKV,KAAK,CAAE,CAAA,CAAA;GACnC,MAAM,IAAIQ,kBAAW,CAAC,CAAC,CAAC,KAAKD,UAAU,EAAE;AACxCG,IAAAA,OAAO,IAAI,CAAA,CAAA,EAAIA,OAAO,CAAA,EAAA,EAAKH,UAAU,CAAE,CAAA,CAAA;AACzC,GAAA;AAEA,EAAA,OAAOG,OAAO,CAAA;AAChB;;;;;;;;"}
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { modernThemes, extraThemes, screenModes } from './const.mjs';
|
|
2
2
|
|
|
3
|
-
/** @deprecated */
|
|
4
3
|
const isThemeModern = theme => modernThemes.includes(theme);
|
|
5
|
-
/** @deprecated */
|
|
6
4
|
const isExtraTheme = theme => extraThemes.includes(theme);
|
|
7
|
-
/** @deprecated */
|
|
8
5
|
const isForestGreenTheme = theme => theme === extraThemes[0];
|
|
9
|
-
/** @deprecated */
|
|
10
6
|
const isScreenModeDark = (theme, screenMode) => isThemeModern(theme) && screenModes[1] === screenMode;
|
|
11
7
|
const getThemeClassName = (theme, screenMode) => {
|
|
12
8
|
if (!isThemeModern(theme)) {
|
package/dist/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","sources":["../src/helpers.ts"],"sourcesContent":["import type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\
|
|
1
|
+
{"version":3,"file":"helpers.mjs","sources":["../src/helpers.ts"],"sourcesContent":["import type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (theme: NonNullable<Theming['theme']>): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isExtraTheme = (theme: NonNullable<Theming['theme']>): theme is ExtraTheme =>\n extraThemes.includes(theme as ExtraTheme);\n\nexport const isForestGreenTheme = (\n theme: NonNullable<Theming['theme']>,\n): theme is ForestGreenTheme => theme === extraThemes[0];\n\nexport const isScreenModeDark = (\n theme: NonNullable<Theming['theme']>,\n screenMode: ScreenMode,\n): screenMode is ScreenModeDark =>\n isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;\n\nexport const getThemeClassName = (theme: NonNullable<Theming['theme']>, screenMode: ScreenMode) => {\n if (!isThemeModern(theme)) {\n return `np-theme-${theme || 'personal'}`;\n }\n\n let classes = `np-theme-personal`;\n\n if (isExtraTheme(theme)) {\n classes += ` ${classes}--${theme}`;\n } else if (screenModes[1] === screenMode) {\n classes += ` ${classes}--${screenMode}`;\n }\n\n return classes;\n};\n"],"names":["isThemeModern","theme","modernThemes","includes","isExtraTheme","extraThemes","isForestGreenTheme","isScreenModeDark","screenMode","screenModes","getThemeClassName","classes"],"mappings":";;AAUO,MAAMA,aAAa,GAAIC,KAAoC,IAChEC,YAAY,CAACC,QAAQ,CAACF,KAAoB,EAAC;AAEtC,MAAMG,YAAY,GAAIH,KAAoC,IAC/DI,WAAW,CAACF,QAAQ,CAACF,KAAmB,EAAC;AAEpC,MAAMK,kBAAkB,GAC7BL,KAAoC,IACNA,KAAK,KAAKI,WAAW,CAAC,CAAC,EAAC;MAE3CE,gBAAgB,GAAGA,CAC9BN,KAAoC,EACpCO,UAAsB,KAEtBR,aAAa,CAACC,KAAoB,CAAC,IAAIQ,WAAW,CAAC,CAAC,CAAC,KAAKD,WAAU;MAEzDE,iBAAiB,GAAGA,CAACT,KAAoC,EAAEO,UAAsB,KAAI;AAChG,EAAA,IAAI,CAACR,aAAa,CAACC,KAAK,CAAC,EAAE;AACzB,IAAA,OAAO,CAAYA,SAAAA,EAAAA,KAAK,IAAI,UAAU,CAAE,CAAA,CAAA;AAC1C,GAAA;EAEA,IAAIU,OAAO,GAAG,CAAmB,iBAAA,CAAA,CAAA;AAEjC,EAAA,IAAIP,YAAY,CAACH,KAAK,CAAC,EAAE;AACvBU,IAAAA,OAAO,IAAI,CAAA,CAAA,EAAIA,OAAO,CAAA,EAAA,EAAKV,KAAK,CAAE,CAAA,CAAA;GACnC,MAAM,IAAIQ,WAAW,CAAC,CAAC,CAAC,KAAKD,UAAU,EAAE;AACxCG,IAAAA,OAAO,IAAI,CAAA,CAAA,EAAIA,OAAO,CAAA,EAAA,EAAKH,UAAU,CAAE,CAAA,CAAA;AACzC,GAAA;AAEA,EAAA,OAAOG,OAAO,CAAA;AAChB;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';
|
|
2
2
|
export { isThemeModern, isExtraTheme, isForestGreenTheme, isScreenModeDark, getThemeClassName, } from './helpers';
|
|
3
|
-
export { ThemeProvider
|
|
3
|
+
export { ThemeProvider } from './ThemeProvider';
|
|
4
4
|
export { useTheme } from './useTheme';
|
|
5
|
-
export { ThemedLayer } from './ThemedLayer';
|
|
6
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EACL,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EACL,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
var helpers = require('./helpers.js');
|
|
5
5
|
var ThemeProvider = require('./ThemeProvider.js');
|
|
6
6
|
var useTheme = require('./useTheme.js');
|
|
7
|
-
var ThemedLayer = require('./ThemedLayer.js');
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
|
|
@@ -13,8 +12,6 @@ exports.isExtraTheme = helpers.isExtraTheme;
|
|
|
13
12
|
exports.isForestGreenTheme = helpers.isForestGreenTheme;
|
|
14
13
|
exports.isScreenModeDark = helpers.isScreenModeDark;
|
|
15
14
|
exports.isThemeModern = helpers.isThemeModern;
|
|
16
|
-
exports.ThemeContext = ThemeProvider.ThemeContext;
|
|
17
15
|
exports.ThemeProvider = ThemeProvider.ThemeProvider;
|
|
18
16
|
exports.useTheme = useTheme.useTheme;
|
|
19
|
-
exports.ThemedLayer = ThemedLayer.ThemedLayer;
|
|
20
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
export { getThemeClassName, isExtraTheme, isForestGreenTheme, isScreenModeDark, isThemeModern } from './helpers.mjs';
|
|
3
|
-
export {
|
|
3
|
+
export { ThemeProvider } from './ThemeProvider.mjs';
|
|
4
4
|
export { useTheme } from './useTheme.mjs';
|
|
5
|
-
export { ThemedLayer } from './ThemedLayer.mjs';
|
|
6
5
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
package/dist/useTheme.d.ts
CHANGED
|
@@ -2,13 +2,9 @@ import type { ScreenMode, Theming } from './const';
|
|
|
2
2
|
interface ThemeHookValue {
|
|
3
3
|
theme: NonNullable<Theming['theme']>;
|
|
4
4
|
screenMode: ScreenMode;
|
|
5
|
-
/** @deprecated */
|
|
6
5
|
isModern: boolean;
|
|
7
|
-
/** @deprecated */
|
|
8
6
|
isForestGreenTheme: boolean;
|
|
9
|
-
/** @deprecated */
|
|
10
7
|
isScreenModeDark: boolean;
|
|
11
|
-
/** @deprecated */
|
|
12
8
|
className: string;
|
|
13
9
|
}
|
|
14
10
|
export declare const useTheme: () => ThemeHookValue;
|
package/dist/useTheme.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../src/useTheme.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAInD,UAAU,cAAc;IACtB,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACrC,UAAU,EAAE,UAAU,CAAC;IACvB,
|
|
1
|
+
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../src/useTheme.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAInD,UAAU,cAAc;IACtB,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACrC,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAeD,eAAO,MAAM,QAAQ,QAAO,cAuB3B,CAAC"}
|
package/dist/useTheme.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
|
-
var
|
|
4
|
+
var ThemeProviderContext = require('./ThemeProviderContext.js');
|
|
5
5
|
var _const = require('./const.js');
|
|
6
6
|
var helpers = require('./helpers.js');
|
|
7
7
|
|
|
@@ -17,7 +17,7 @@ const isNotProduction = () => {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
const useTheme = () => {
|
|
20
|
-
const theming = react.useContext(
|
|
20
|
+
const theming = react.useContext(ThemeProviderContext.ThemeContext);
|
|
21
21
|
if (!theming && isNotProduction()) {
|
|
22
22
|
// eslint-disable-next-line no-console
|
|
23
23
|
console.warn('Call to useTheme outside a ThemeProvider');
|
package/dist/useTheme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.js","sources":["../src/useTheme.ts"],"sourcesContent":["import { useContext, useMemo } from 'react';\n\nimport { ThemeContext } from './
|
|
1
|
+
{"version":3,"file":"useTheme.js","sources":["../src/useTheme.ts"],"sourcesContent":["import { useContext, useMemo } from 'react';\n\nimport { ThemeContext } from './ThemeProviderContext';\nimport type { ScreenMode, Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { isThemeModern, isForestGreenTheme, isScreenModeDark, getThemeClassName } from './helpers';\n\ninterface ThemeHookValue {\n theme: NonNullable<Theming['theme']>;\n screenMode: ScreenMode;\n isModern: boolean;\n isForestGreenTheme: boolean;\n isScreenModeDark: boolean;\n className: string;\n}\n\nconst FALLBACK_VALUES = {\n theme: DEFAULT_BASE_THEME,\n screenMode: DEFAULT_SCREEN_MODE,\n} as const;\n\nconst isNotProduction = () => {\n try {\n return ['localhost', 'dev-wi.se'].includes(window.location.hostname);\n } catch {\n return false;\n }\n};\n\nexport const useTheme = (): ThemeHookValue => {\n const theming = useContext(ThemeContext);\n\n if (!theming && isNotProduction()) {\n // eslint-disable-next-line no-console\n console.warn('Call to useTheme outside a ThemeProvider');\n }\n\n const { theme, screenMode: contextScreenMode } = theming ?? FALLBACK_VALUES;\n\n const screenMode = theme === DEFAULT_BASE_THEME ? DEFAULT_SCREEN_MODE : contextScreenMode;\n\n return useMemo(\n () => ({\n theme,\n screenMode,\n isModern: isThemeModern(theme),\n isForestGreenTheme: isForestGreenTheme(theme),\n isScreenModeDark: isScreenModeDark(theme, screenMode),\n className: getThemeClassName(theme, screenMode),\n }),\n [theme, screenMode],\n );\n};\n"],"names":["FALLBACK_VALUES","theme","DEFAULT_BASE_THEME","screenMode","DEFAULT_SCREEN_MODE","isNotProduction","includes","window","location","hostname","useTheme","theming","useContext","ThemeContext","console","warn","contextScreenMode","useMemo","isModern","isThemeModern","isForestGreenTheme","isScreenModeDark","className","getThemeClassName"],"mappings":";;;;;;;AAgBA,MAAMA,eAAe,GAAG;AACtBC,EAAAA,KAAK,EAAEC,yBAAkB;AACzBC,EAAAA,UAAU,EAAEC,0BAAAA;CACJ,CAAA;AAEV,MAAMC,eAAe,GAAGA,MAAK;EAC3B,IAAI;AACF,IAAA,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAACC,QAAQ,CAACC,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAA;AACtE,GAAC,CAAC,MAAM;AACN,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AACF,CAAC,CAAA;AAEYC,MAAAA,QAAQ,GAAGA,MAAqB;AAC3C,EAAA,MAAMC,OAAO,GAAGC,gBAAU,CAACC,iCAAY,CAAC,CAAA;AAExC,EAAA,IAAI,CAACF,OAAO,IAAIN,eAAe,EAAE,EAAE;AACjC;AACAS,IAAAA,OAAO,CAACC,IAAI,CAAC,0CAA0C,CAAC,CAAA;AAC1D,GAAA;EAEA,MAAM;IAAEd,KAAK;AAAEE,IAAAA,UAAU,EAAEa,iBAAAA;GAAmB,GAAGL,OAAO,IAAIX,eAAe,CAAA;EAE3E,MAAMG,UAAU,GAAGF,KAAK,KAAKC,yBAAkB,GAAGE,0BAAmB,GAAGY,iBAAiB,CAAA;EAEzF,OAAOC,aAAO,CACZ,OAAO;IACLhB,KAAK;IACLE,UAAU;AACVe,IAAAA,QAAQ,EAAEC,qBAAa,CAAClB,KAAK,CAAC;AAC9BmB,IAAAA,kBAAkB,EAAEA,0BAAkB,CAACnB,KAAK,CAAC;AAC7CoB,IAAAA,gBAAgB,EAAEA,wBAAgB,CAACpB,KAAK,EAAEE,UAAU,CAAC;AACrDmB,IAAAA,SAAS,EAAEC,yBAAiB,CAACtB,KAAK,EAAEE,UAAU,CAAA;AAC/C,GAAA,CAAC,EACF,CAACF,KAAK,EAAEE,UAAU,CAAC,CACpB,CAAA;AACH;;;;"}
|
package/dist/useTheme.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContext, useMemo } from 'react';
|
|
2
|
-
import { ThemeContext } from './
|
|
2
|
+
import { ThemeContext } from './ThemeProviderContext.mjs';
|
|
3
3
|
import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const.mjs';
|
|
4
4
|
import { isThemeModern, isForestGreenTheme, isScreenModeDark, getThemeClassName } from './helpers.mjs';
|
|
5
5
|
|
package/dist/useTheme.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.mjs","sources":["../src/useTheme.ts"],"sourcesContent":["import { useContext, useMemo } from 'react';\n\nimport { ThemeContext } from './
|
|
1
|
+
{"version":3,"file":"useTheme.mjs","sources":["../src/useTheme.ts"],"sourcesContent":["import { useContext, useMemo } from 'react';\n\nimport { ThemeContext } from './ThemeProviderContext';\nimport type { ScreenMode, Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { isThemeModern, isForestGreenTheme, isScreenModeDark, getThemeClassName } from './helpers';\n\ninterface ThemeHookValue {\n theme: NonNullable<Theming['theme']>;\n screenMode: ScreenMode;\n isModern: boolean;\n isForestGreenTheme: boolean;\n isScreenModeDark: boolean;\n className: string;\n}\n\nconst FALLBACK_VALUES = {\n theme: DEFAULT_BASE_THEME,\n screenMode: DEFAULT_SCREEN_MODE,\n} as const;\n\nconst isNotProduction = () => {\n try {\n return ['localhost', 'dev-wi.se'].includes(window.location.hostname);\n } catch {\n return false;\n }\n};\n\nexport const useTheme = (): ThemeHookValue => {\n const theming = useContext(ThemeContext);\n\n if (!theming && isNotProduction()) {\n // eslint-disable-next-line no-console\n console.warn('Call to useTheme outside a ThemeProvider');\n }\n\n const { theme, screenMode: contextScreenMode } = theming ?? FALLBACK_VALUES;\n\n const screenMode = theme === DEFAULT_BASE_THEME ? DEFAULT_SCREEN_MODE : contextScreenMode;\n\n return useMemo(\n () => ({\n theme,\n screenMode,\n isModern: isThemeModern(theme),\n isForestGreenTheme: isForestGreenTheme(theme),\n isScreenModeDark: isScreenModeDark(theme, screenMode),\n className: getThemeClassName(theme, screenMode),\n }),\n [theme, screenMode],\n );\n};\n"],"names":["FALLBACK_VALUES","theme","DEFAULT_BASE_THEME","screenMode","DEFAULT_SCREEN_MODE","isNotProduction","includes","window","location","hostname","useTheme","theming","useContext","ThemeContext","console","warn","contextScreenMode","useMemo","isModern","isThemeModern","isForestGreenTheme","isScreenModeDark","className","getThemeClassName"],"mappings":";;;;;AAgBA,MAAMA,eAAe,GAAG;AACtBC,EAAAA,KAAK,EAAEC,kBAAkB;AACzBC,EAAAA,UAAU,EAAEC,mBAAAA;CACJ,CAAA;AAEV,MAAMC,eAAe,GAAGA,MAAK;EAC3B,IAAI;AACF,IAAA,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAACC,QAAQ,CAACC,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAA;AACtE,GAAC,CAAC,MAAM;AACN,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AACF,CAAC,CAAA;AAEYC,MAAAA,QAAQ,GAAGA,MAAqB;AAC3C,EAAA,MAAMC,OAAO,GAAGC,UAAU,CAACC,YAAY,CAAC,CAAA;AAExC,EAAA,IAAI,CAACF,OAAO,IAAIN,eAAe,EAAE,EAAE;AACjC;AACAS,IAAAA,OAAO,CAACC,IAAI,CAAC,0CAA0C,CAAC,CAAA;AAC1D,GAAA;EAEA,MAAM;IAAEd,KAAK;AAAEE,IAAAA,UAAU,EAAEa,iBAAAA;GAAmB,GAAGL,OAAO,IAAIX,eAAe,CAAA;EAE3E,MAAMG,UAAU,GAAGF,KAAK,KAAKC,kBAAkB,GAAGE,mBAAmB,GAAGY,iBAAiB,CAAA;EAEzF,OAAOC,OAAO,CACZ,OAAO;IACLhB,KAAK;IACLE,UAAU;AACVe,IAAAA,QAAQ,EAAEC,aAAa,CAAClB,KAAK,CAAC;AAC9BmB,IAAAA,kBAAkB,EAAEA,kBAAkB,CAACnB,KAAK,CAAC;AAC7CoB,IAAAA,gBAAgB,EAAEA,gBAAgB,CAACpB,KAAK,EAAEE,UAAU,CAAC;AACrDmB,IAAAA,SAAS,EAAEC,iBAAiB,CAACtB,KAAK,EAAEE,UAAU,CAAA;AAC/C,GAAA,CAAC,EACF,CAACF,KAAK,EAAEE,UAAU,CAAC,CACpB,CAAA;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/components-theming",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-5535cba",
|
|
4
4
|
"description": "Provides theming support for the Wise Design system components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -31,10 +31,13 @@
|
|
|
31
31
|
"@types/jest": "^29.5.12",
|
|
32
32
|
"@types/react": "^18.3.11",
|
|
33
33
|
"@types/react-dom": "^18.3.1",
|
|
34
|
+
"@wise/eslint-config": "^12.3.0",
|
|
35
|
+
"eslint": "^9.22.0",
|
|
34
36
|
"jest": "^29.7.0",
|
|
35
37
|
"jest-environment-jsdom": "^29.7.0",
|
|
36
38
|
"rollup": "^4.18.1",
|
|
37
|
-
"rollup-preserve-directives": "^1.1.1"
|
|
39
|
+
"rollup-preserve-directives": "^1.1.1",
|
|
40
|
+
"@wise/wds-configs": "0.0.0"
|
|
38
41
|
},
|
|
39
42
|
"peerDependencies": {
|
|
40
43
|
"react": ">=18",
|
|
@@ -68,7 +71,7 @@
|
|
|
68
71
|
"lint": "pnpm run lint:check",
|
|
69
72
|
"lint:check": "npm-run-all --parallel lint:check:*",
|
|
70
73
|
"lint:check:format": "prettier --check --ignore-path ../../.prettierignore .",
|
|
71
|
-
"lint:check:js+ts": "eslint
|
|
74
|
+
"lint:check:js+ts": "eslint .",
|
|
72
75
|
"lint:check:types": "tsc --noEmit --emitDeclarationOnly false",
|
|
73
76
|
"lint:fix": "npm-run-all --serial lint:fix:*",
|
|
74
77
|
"lint:fix:format": "prettier --write --ignore-path ../../.prettierignore .",
|
package/src/ThemeProvider.tsx
CHANGED
|
@@ -1,30 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren, useContext, useEffect, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
3
|
+
import { ThemedChildren } from './ThemedChildren';
|
|
4
|
+
import type { Theming } from './const';
|
|
5
5
|
import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
| {
|
|
9
|
-
theme: NonNullable<Theming['theme']>;
|
|
10
|
-
screenMode: ScreenMode;
|
|
11
|
-
}
|
|
12
|
-
| undefined
|
|
13
|
-
>(undefined);
|
|
6
|
+
import { getThemeClassName } from './helpers';
|
|
7
|
+
import { ThemeContext } from './ThemeProviderContext';
|
|
14
8
|
|
|
15
9
|
type ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };
|
|
16
10
|
|
|
11
|
+
// RegEx to check for `np-theme-` class name
|
|
12
|
+
const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
13
|
+
|
|
17
14
|
export const ThemeProvider = ({
|
|
18
15
|
theme = DEFAULT_BASE_THEME,
|
|
19
16
|
screenMode = DEFAULT_SCREEN_MODE,
|
|
17
|
+
isNotRootProvider = false,
|
|
20
18
|
children,
|
|
21
19
|
className = undefined,
|
|
22
20
|
}: ThemeProviderProps) => {
|
|
21
|
+
const isContextRoot = useContext(ThemeContext) === undefined;
|
|
22
|
+
|
|
23
|
+
// useEffect hook used to apply the theme class to the HTML element
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!isNotRootProvider && isContextRoot) {
|
|
26
|
+
// Remove all the theme classes from the documentElement
|
|
27
|
+
document.documentElement.className.match(themeClass)?.forEach((item) => {
|
|
28
|
+
document.documentElement.classList.remove(item);
|
|
29
|
+
});
|
|
30
|
+
getThemeClassName(theme, screenMode)
|
|
31
|
+
.split(' ')
|
|
32
|
+
.forEach((item) => {
|
|
33
|
+
document.documentElement.classList.add(item);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}, [isNotRootProvider, isContextRoot, theme, screenMode]);
|
|
37
|
+
|
|
23
38
|
const contextValue = useMemo(() => ({ theme, screenMode }), [screenMode, theme]);
|
|
24
39
|
|
|
25
40
|
return (
|
|
26
41
|
<ThemeContext.Provider value={contextValue}>
|
|
27
|
-
<
|
|
42
|
+
<ThemedChildren className={className}>{children}</ThemedChildren>
|
|
28
43
|
</ThemeContext.Provider>
|
|
29
44
|
);
|
|
30
45
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { clsx } from 'clsx';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useTheme } from './useTheme';
|
|
5
|
+
|
|
6
|
+
type ThemedChildrenProps = { className?: string; children: ReactNode };
|
|
7
|
+
|
|
8
|
+
export const ThemedChildren = ({ className = undefined, children }: ThemedChildrenProps) => {
|
|
9
|
+
const { className: themeClass } = useTheme();
|
|
10
|
+
|
|
11
|
+
return <div className={clsx(themeClass, className)}>{children}</div>;
|
|
12
|
+
};
|
package/src/const.ts
CHANGED
|
@@ -22,6 +22,5 @@ export const DEFAULT_SCREEN_MODE = 'light';
|
|
|
22
22
|
export type Theming = {
|
|
23
23
|
theme?: ComponentTheme | BaseTheme | ExtraTheme | PlatformTheme | PlatformForestGreenTheme;
|
|
24
24
|
screenMode?: ScreenMode;
|
|
25
|
-
/** @deprecated no-op */
|
|
26
25
|
isNotRootProvider?: boolean | undefined;
|
|
27
26
|
};
|
package/src/helpers.ts
CHANGED
|
@@ -8,20 +8,16 @@ import type {
|
|
|
8
8
|
} from './const';
|
|
9
9
|
import { extraThemes, screenModes, modernThemes } from './const';
|
|
10
10
|
|
|
11
|
-
/** @deprecated */
|
|
12
11
|
export const isThemeModern = (theme: NonNullable<Theming['theme']>): theme is ModernTheme =>
|
|
13
12
|
modernThemes.includes(theme as ModernTheme);
|
|
14
13
|
|
|
15
|
-
/** @deprecated */
|
|
16
14
|
export const isExtraTheme = (theme: NonNullable<Theming['theme']>): theme is ExtraTheme =>
|
|
17
15
|
extraThemes.includes(theme as ExtraTheme);
|
|
18
16
|
|
|
19
|
-
/** @deprecated */
|
|
20
17
|
export const isForestGreenTheme = (
|
|
21
18
|
theme: NonNullable<Theming['theme']>,
|
|
22
19
|
): theme is ForestGreenTheme => theme === extraThemes[0];
|
|
23
20
|
|
|
24
|
-
/** @deprecated */
|
|
25
21
|
export const isScreenModeDark = (
|
|
26
22
|
theme: NonNullable<Theming['theme']>,
|
|
27
23
|
screenMode: ScreenMode,
|
package/src/index.ts
CHANGED
package/src/useTheme.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import { ThemeContext } from './
|
|
3
|
+
import { ThemeContext } from './ThemeProviderContext';
|
|
4
4
|
import type { ScreenMode, Theming } from './const';
|
|
5
5
|
import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';
|
|
6
6
|
import { isThemeModern, isForestGreenTheme, isScreenModeDark, getThemeClassName } from './helpers';
|
|
@@ -8,13 +8,9 @@ import { isThemeModern, isForestGreenTheme, isScreenModeDark, getThemeClassName
|
|
|
8
8
|
interface ThemeHookValue {
|
|
9
9
|
theme: NonNullable<Theming['theme']>;
|
|
10
10
|
screenMode: ScreenMode;
|
|
11
|
-
/** @deprecated */
|
|
12
11
|
isModern: boolean;
|
|
13
|
-
/** @deprecated */
|
|
14
12
|
isForestGreenTheme: boolean;
|
|
15
|
-
/** @deprecated */
|
|
16
13
|
isScreenModeDark: boolean;
|
|
17
|
-
/** @deprecated */
|
|
18
14
|
className: string;
|
|
19
15
|
}
|
|
20
16
|
|
package/dist/ThemedLayer.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
type ThemedLayerProps = {
|
|
3
|
-
className?: string;
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
};
|
|
6
|
-
export declare const ThemedLayer: ({ className, children }: ThemedLayerProps) => import("react").JSX.Element;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=ThemedLayer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ThemedLayer.d.ts","sourceRoot":"","sources":["../src/ThemedLayer.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlC,KAAK,gBAAgB,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,CAAC;AAEpE,eAAO,MAAM,WAAW,4BAA6B,gBAAgB,gCAKpE,CAAC"}
|
package/dist/ThemedLayer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ThemedLayer.js","sources":["../src/ThemedLayer.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { ReactNode } from 'react';\n\nimport { useTheme } from './useTheme';\nimport { getThemeClassName } from './helpers';\n\ntype ThemedLayerProps = { className?: string; children: ReactNode };\n\nexport const ThemedLayer = ({ className, children }: ThemedLayerProps) => {\n const { theme, screenMode } = useTheme();\n const themeClass = getThemeClassName(theme, screenMode);\n\n return <div className={clsx(themeClass, className)}>{children}</div>;\n};\n"],"names":["ThemedLayer","className","children","theme","screenMode","useTheme","themeClass","getThemeClassName","_jsx","clsx"],"mappings":";;;;;;;AAQO,MAAMA,WAAW,GAAGA,CAAC;EAAEC,SAAS;AAAEC,EAAAA,QAAAA;AAA4B,CAAA,KAAI;EACvE,MAAM;IAAEC,KAAK;AAAEC,IAAAA,UAAAA;GAAY,GAAGC,iBAAQ,EAAE,CAAA;AACxC,EAAA,MAAMC,UAAU,GAAGC,yBAAiB,CAACJ,KAAK,EAAEC,UAAU,CAAC,CAAA;AAEvD,EAAA,oBAAOI,cAAA,CAAA,KAAA,EAAA;AAAKP,IAAAA,SAAS,EAAEQ,SAAI,CAACH,UAAU,EAAEL,SAAS,CAAE;AAAAC,IAAAA,QAAA,EAAEA,QAAAA;AAAQ,GAAM,CAAC,CAAA;AACtE;;;;"}
|
package/dist/ThemedLayer.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ThemedLayer.mjs","sources":["../src/ThemedLayer.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { ReactNode } from 'react';\n\nimport { useTheme } from './useTheme';\nimport { getThemeClassName } from './helpers';\n\ntype ThemedLayerProps = { className?: string; children: ReactNode };\n\nexport const ThemedLayer = ({ className, children }: ThemedLayerProps) => {\n const { theme, screenMode } = useTheme();\n const themeClass = getThemeClassName(theme, screenMode);\n\n return <div className={clsx(themeClass, className)}>{children}</div>;\n};\n"],"names":["ThemedLayer","className","children","theme","screenMode","useTheme","themeClass","getThemeClassName","_jsx","clsx"],"mappings":";;;;;AAQO,MAAMA,WAAW,GAAGA,CAAC;EAAEC,SAAS;AAAEC,EAAAA,QAAAA;AAA4B,CAAA,KAAI;EACvE,MAAM;IAAEC,KAAK;AAAEC,IAAAA,UAAAA;GAAY,GAAGC,QAAQ,EAAE,CAAA;AACxC,EAAA,MAAMC,UAAU,GAAGC,iBAAiB,CAACJ,KAAK,EAAEC,UAAU,CAAC,CAAA;AAEvD,EAAA,oBAAOI,GAAA,CAAA,KAAA,EAAA;AAAKP,IAAAA,SAAS,EAAEQ,IAAI,CAACH,UAAU,EAAEL,SAAS,CAAE;AAAAC,IAAAA,QAAA,EAAEA,QAAAA;AAAQ,GAAM,CAAC,CAAA;AACtE;;;;"}
|
package/src/ThemedLayer.tsx
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { clsx } from 'clsx';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
import { useTheme } from './useTheme';
|
|
5
|
-
import { getThemeClassName } from './helpers';
|
|
6
|
-
|
|
7
|
-
type ThemedLayerProps = { className?: string; children: ReactNode };
|
|
8
|
-
|
|
9
|
-
export const ThemedLayer = ({ className, children }: ThemedLayerProps) => {
|
|
10
|
-
const { theme, screenMode } = useTheme();
|
|
11
|
-
const themeClass = getThemeClassName(theme, screenMode);
|
|
12
|
-
|
|
13
|
-
return <div className={clsx(themeClass, className)}>{children}</div>;
|
|
14
|
-
};
|