@wise/components-theming 1.6.1 → 1.6.3
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 -5
- package/dist/ThemeProvider.d.ts.map +1 -1
- package/dist/ThemeProvider.js +3 -5
- package/dist/ThemeProvider.js.map +1 -1
- package/dist/ThemeProvider.mjs +3 -4
- 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.map +1 -1
- package/dist/ThemedChildren.js.map +1 -1
- package/dist/ThemedChildren.mjs.map +1 -1
- package/dist/const.js.map +1 -1
- package/dist/const.mjs.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js.map +1 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/useTheme.js +2 -2
- package/dist/useTheme.js.map +1 -1
- package/dist/useTheme.mjs +3 -3
- package/dist/useTheme.mjs.map +1 -1
- package/package.json +19 -16
- package/src/ThemeProvider.tsx +3 -10
- package/src/ThemeProviderContext.tsx +10 -0
- package/src/useTheme.ts +1 -1
package/dist/ThemeProvider.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
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
|
};
|
|
@@ -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,GAAI,gEAM3B,kBAAkB,gCAyBpB,CAAC"}
|
package/dist/ThemeProvider.js
CHANGED
|
@@ -4,10 +4,9 @@ var react = require('react');
|
|
|
4
4
|
var ThemedChildren = require('./ThemedChildren.js');
|
|
5
5
|
var _const = require('./const.js');
|
|
6
6
|
var helpers = require('./helpers.js');
|
|
7
|
+
var ThemeProviderContext = require('./ThemeProviderContext.js');
|
|
7
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
9
|
|
|
9
|
-
const ThemeContext = /*#__PURE__*/react.createContext(undefined);
|
|
10
|
-
// RegEx to check for `np-theme-` class name
|
|
11
10
|
const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
12
11
|
const ThemeProvider = ({
|
|
13
12
|
theme = _const.DEFAULT_BASE_THEME,
|
|
@@ -16,7 +15,7 @@ const ThemeProvider = ({
|
|
|
16
15
|
children,
|
|
17
16
|
className = undefined
|
|
18
17
|
}) => {
|
|
19
|
-
const isContextRoot = react.useContext(ThemeContext) === undefined;
|
|
18
|
+
const isContextRoot = react.useContext(ThemeProviderContext.ThemeContext) === undefined;
|
|
20
19
|
// useEffect hook used to apply the theme class to the HTML element
|
|
21
20
|
react.useEffect(() => {
|
|
22
21
|
if (!isNotRootProvider && isContextRoot) {
|
|
@@ -33,7 +32,7 @@ const ThemeProvider = ({
|
|
|
33
32
|
theme,
|
|
34
33
|
screenMode
|
|
35
34
|
}), [screenMode, theme]);
|
|
36
|
-
return /*#__PURE__*/jsxRuntime.jsx(ThemeContext.Provider, {
|
|
35
|
+
return /*#__PURE__*/jsxRuntime.jsx(ThemeProviderContext.ThemeContext.Provider, {
|
|
37
36
|
value: contextValue,
|
|
38
37
|
children: /*#__PURE__*/jsxRuntime.jsx(ThemedChildren.ThemedChildren, {
|
|
39
38
|
className: className,
|
|
@@ -42,6 +41,5 @@ const ThemeProvider = ({
|
|
|
42
41
|
});
|
|
43
42
|
};
|
|
44
43
|
|
|
45
|
-
exports.ThemeContext = ThemeContext;
|
|
46
44
|
exports.ThemeProvider = ThemeProvider;
|
|
47
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;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;AACO,CAAA,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,gBAAU,CAACC,iCAAY,CAAC,KAAKH,SAAS;AAE5D;AACAI,EAAAA,eAAS,CAAC,MAAK;AACb,IAAA,IAAI,CAACP,iBAAiB,IAAII,aAAa,EAAE;AACvC;AACAI,MAAAA,QAAQ,CAACC,eAAe,CAACP,SAAS,CAACQ,KAAK,CAAChB,UAAU,CAAC,EAAEiB,OAAO,CAAEC,IAAI,IAAI;QACrEJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACC,MAAM,CAACF,IAAI,CAAC;AACjD,OAAC,CAAC;AACFG,MAAAA,yBAAiB,CAACnB,KAAK,EAAEE,UAAU,CAAC,CACjCkB,KAAK,CAAC,GAAG,CAAC,CACVL,OAAO,CAAEC,IAAI,IAAI;QAChBJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACI,GAAG,CAACL,IAAI,CAAC;AAC9C,OAAC,CAAC;AACN;GACD,EAAE,CAACZ,iBAAiB,EAAEI,aAAa,EAAER,KAAK,EAAEE,UAAU,CAAC,CAAC;AAEzD,EAAA,MAAMoB,YAAY,GAAGC,aAAO,CAAC,OAAO;IAAEvB,KAAK;AAAEE,IAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEF,KAAK,CAAC,CAAC;AAEhF,EAAA,oBACEwB,cAAA,CAACd,iCAAY,CAACe,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAEJ,YAAa;IAAAjB,QAAA,eACzCmB,cAAA,CAACG,6BAAc,EAAA;AAACrB,MAAAA,SAAS,EAAEA,SAAU;AAAAD,MAAAA,QAAA,EAAEA;KAAyB;AAClE,GAAuB,CAAC;AAE5B;;;;"}
|
package/dist/ThemeProvider.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useContext, useEffect, useMemo } from 'react';
|
|
2
2
|
import { ThemedChildren } from './ThemedChildren.mjs';
|
|
3
3
|
import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const.mjs';
|
|
4
4
|
import { getThemeClassName } from './helpers.mjs';
|
|
5
|
+
import { ThemeContext } from './ThemeProviderContext.mjs';
|
|
5
6
|
import { jsx } from 'react/jsx-runtime';
|
|
6
7
|
|
|
7
|
-
const ThemeContext = /*#__PURE__*/createContext(undefined);
|
|
8
|
-
// RegEx to check for `np-theme-` class name
|
|
9
8
|
const themeClass = /\bnp-theme-[a-z-]+\b/g;
|
|
10
9
|
const ThemeProvider = ({
|
|
11
10
|
theme = DEFAULT_BASE_THEME,
|
|
@@ -40,5 +39,5 @@ const ThemeProvider = ({
|
|
|
40
39
|
});
|
|
41
40
|
};
|
|
42
41
|
|
|
43
|
-
export {
|
|
42
|
+
export { ThemeProvider };
|
|
44
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;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;AACO,CAAA,KAAI;AACvB,EAAA,MAAMC,aAAa,GAAGC,UAAU,CAACC,YAAY,CAAC,KAAKH,SAAS;AAE5D;AACAI,EAAAA,SAAS,CAAC,MAAK;AACb,IAAA,IAAI,CAACP,iBAAiB,IAAII,aAAa,EAAE;AACvC;AACAI,MAAAA,QAAQ,CAACC,eAAe,CAACP,SAAS,CAACQ,KAAK,CAAChB,UAAU,CAAC,EAAEiB,OAAO,CAAEC,IAAI,IAAI;QACrEJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACC,MAAM,CAACF,IAAI,CAAC;AACjD,OAAC,CAAC;AACFG,MAAAA,iBAAiB,CAACnB,KAAK,EAAEE,UAAU,CAAC,CACjCkB,KAAK,CAAC,GAAG,CAAC,CACVL,OAAO,CAAEC,IAAI,IAAI;QAChBJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACI,GAAG,CAACL,IAAI,CAAC;AAC9C,OAAC,CAAC;AACN;GACD,EAAE,CAACZ,iBAAiB,EAAEI,aAAa,EAAER,KAAK,EAAEE,UAAU,CAAC,CAAC;AAEzD,EAAA,MAAMoB,YAAY,GAAGC,OAAO,CAAC,OAAO;IAAEvB,KAAK;AAAEE,IAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEF,KAAK,CAAC,CAAC;AAEhF,EAAA,oBACEwB,GAAA,CAACd,YAAY,CAACe,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAEJ,YAAa;IAAAjB,QAAA,eACzCmB,GAAA,CAACG,cAAc,EAAA;AAACrB,MAAAA,SAAS,EAAEA,SAAU;AAAAD,MAAAA,QAAA,EAAEA;KAAyB;AAClE,GAAuB,CAAC;AAE5B;;;;"}
|
|
@@ -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;;;;"}
|
|
@@ -1 +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,
|
|
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,GAAI,yBAAqC,mBAAmB,gCAItF,CAAC"}
|
|
@@ -1 +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
|
|
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;AAAQ,CAAuB,KAAI;EACzF,MAAM;AAAEF,IAAAA,SAAS,EAAEG;GAAY,GAAGC,iBAAQ,EAAE;AAE5C,EAAA,oBAAOC,cAAA,CAAA,KAAA,EAAA;AAAKL,IAAAA,SAAS,EAAEM,SAAI,CAACH,UAAU,EAAEH,SAAS,CAAE;AAAAE,IAAAA,QAAA,EAAEA;AAAQ,GAAM,CAAC;AACtE;;;;"}
|
|
@@ -1 +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
|
|
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;AAAQ,CAAuB,KAAI;EACzF,MAAM;AAAEF,IAAAA,SAAS,EAAEG;GAAY,GAAGC,QAAQ,EAAE;AAE5C,EAAA,oBAAOC,GAAA,CAAA,KAAA,EAAA;AAAKL,IAAAA,SAAS,EAAEM,IAAI,CAACH,UAAU,EAAEH,SAAS,CAAE;AAAAE,IAAAA,QAAA,EAAEA;AAAQ,GAAM,CAAC;AACtE;;;;"}
|
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 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
|
|
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;MACjCC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc;MAC7CC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM;AACpC,MAAMC,YAAY,GAAG,CAACH,UAAU,CAAC,CAAC,CAAC,EAAE,GAAGC,WAAW;AAcnD,MAAMG,kBAAkB,GAAG;AAC3B,MAAMC,mBAAmB,GAAG;;;;;;;;;"}
|
package/dist/const.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.mjs","sources":["../src/const.ts"],"sourcesContent":["// TODO: Change 'light' with 'legacy' in the future\nexport const baseThemes = ['light', 'personal'] 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
|
|
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;MACjCC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc;MAC7CC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM;AACpC,MAAMC,YAAY,GAAG,CAACH,UAAU,CAAC,CAAC,CAAC,EAAE,GAAGC,WAAW;AAcnD,MAAMG,kBAAkB,GAAG;AAC3B,MAAMC,mBAAmB,GAAG;;;;"}
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,OAAO,EACR,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,aAAa,
|
|
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,GAAI,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAG,KAAK,IAAI,WACjC,CAAC;AAE9C,eAAO,MAAM,YAAY,GAAI,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAG,KAAK,IAAI,UAClC,CAAC;AAE5C,eAAO,MAAM,kBAAkB,GAC7B,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KACnC,KAAK,IAAI,gBAA4C,CAAC;AAEzD,eAAO,MAAM,gBAAgB,GAC3B,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EACpC,YAAY,UAAU,KACrB,UAAU,IAAI,cACqD,CAAC;AAEvE,eAAO,MAAM,iBAAiB,GAAI,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,YAAY,UAAU,WAc7F,CAAC"}
|
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\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
|
|
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;AAErC,MAAMG,YAAY,GAAIH,KAAoC,IAC/DI,kBAAW,CAACF,QAAQ,CAACF,KAAmB;AAEnC,MAAMK,kBAAkB,GAC7BL,KAAoC,IACNA,KAAK,KAAKI,kBAAW,CAAC,CAAC;MAE1CE,gBAAgB,GAAGA,CAC9BN,KAAoC,EACpCO,UAAsB,KAEtBR,aAAa,CAACC,KAAoB,CAAC,IAAIQ,kBAAW,CAAC,CAAC,CAAC,KAAKD;MAE/CE,iBAAiB,GAAGA,CAACT,KAAoC,EAAEO,UAAsB,KAAI;AAChG,EAAA,IAAI,CAACR,aAAa,CAACC,KAAK,CAAC,EAAE;AACzB,IAAA,OAAO,CAAYA,SAAAA,EAAAA,KAAK,IAAI,UAAU,CAAE,CAAA;AAC1C;EAEA,IAAIU,OAAO,GAAG,CAAmB,iBAAA,CAAA;AAEjC,EAAA,IAAIP,YAAY,CAACH,KAAK,CAAC,EAAE;AACvBU,IAAAA,OAAO,IAAI,CAAA,CAAA,EAAIA,OAAO,CAAA,EAAA,EAAKV,KAAK,CAAE,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;AACzC;AAEA,EAAA,OAAOG,OAAO;AAChB;;;;;;;;"}
|
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\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
|
|
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;AAErC,MAAMG,YAAY,GAAIH,KAAoC,IAC/DI,WAAW,CAACF,QAAQ,CAACF,KAAmB;AAEnC,MAAMK,kBAAkB,GAC7BL,KAAoC,IACNA,KAAK,KAAKI,WAAW,CAAC,CAAC;MAE1CE,gBAAgB,GAAGA,CAC9BN,KAAoC,EACpCO,UAAsB,KAEtBR,aAAa,CAACC,KAAoB,CAAC,IAAIQ,WAAW,CAAC,CAAC,CAAC,KAAKD;MAE/CE,iBAAiB,GAAGA,CAACT,KAAoC,EAAEO,UAAsB,KAAI;AAChG,EAAA,IAAI,CAACR,aAAa,CAACC,KAAK,CAAC,EAAE;AACzB,IAAA,OAAO,CAAYA,SAAAA,EAAAA,KAAK,IAAI,UAAU,CAAE,CAAA;AAC1C;EAEA,IAAIU,OAAO,GAAG,CAAmB,iBAAA,CAAA;AAEjC,EAAA,IAAIP,YAAY,CAACH,KAAK,CAAC,EAAE;AACvBU,IAAAA,OAAO,IAAI,CAAA,CAAA,EAAIA,OAAO,CAAA,EAAA,EAAKV,KAAK,CAAE,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;AACzC;AAEA,EAAA,OAAOG,OAAO;AAChB;;;;"}
|
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;CACJ;AAEV,MAAMC,eAAe,GAAGA,MAAK;EAC3B,IAAI;AACF,IAAA,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAACC,QAAQ,CAACC,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC;AACtE,GAAC,CAAC,MAAM;AACN,IAAA,OAAO,KAAK;AACd;AACF,CAAC;AAEYC,MAAAA,QAAQ,GAAGA,MAAqB;AAC3C,EAAA,MAAMC,OAAO,GAAGC,gBAAU,CAACC,iCAAY,CAAC;AAExC,EAAA,IAAI,CAACF,OAAO,IAAIN,eAAe,EAAE,EAAE;AACjC;AACAS,IAAAA,OAAO,CAACC,IAAI,CAAC,0CAA0C,CAAC;AAC1D;EAEA,MAAM;IAAEd,KAAK;AAAEE,IAAAA,UAAU,EAAEa;GAAmB,GAAGL,OAAO,IAAIX,eAAe;EAE3E,MAAMG,UAAU,GAAGF,KAAK,KAAKC,yBAAkB,GAAGE,0BAAmB,GAAGY,iBAAiB;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;AAC/C,GAAA,CAAC,EACF,CAACF,KAAK,EAAEE,UAAU,CAAC,CACpB;AACH;;;;"}
|
package/dist/useTheme.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useContext, useMemo } from 'react';
|
|
2
|
-
import { ThemeContext } from './
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { ThemeContext } from './ThemeProviderContext.mjs';
|
|
3
|
+
import { DEFAULT_SCREEN_MODE, DEFAULT_BASE_THEME } from './const.mjs';
|
|
4
|
+
import { getThemeClassName, isScreenModeDark, isForestGreenTheme, isThemeModern } from './helpers.mjs';
|
|
5
5
|
|
|
6
6
|
const FALLBACK_VALUES = {
|
|
7
7
|
theme: DEFAULT_BASE_THEME,
|
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;CACJ;AAEV,MAAMC,eAAe,GAAGA,MAAK;EAC3B,IAAI;AACF,IAAA,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAACC,QAAQ,CAACC,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC;AACtE,GAAC,CAAC,MAAM;AACN,IAAA,OAAO,KAAK;AACd;AACF,CAAC;AAEYC,MAAAA,QAAQ,GAAGA,MAAqB;AAC3C,EAAA,MAAMC,OAAO,GAAGC,UAAU,CAACC,YAAY,CAAC;AAExC,EAAA,IAAI,CAACF,OAAO,IAAIN,eAAe,EAAE,EAAE;AACjC;AACAS,IAAAA,OAAO,CAACC,IAAI,CAAC,0CAA0C,CAAC;AAC1D;EAEA,MAAM;IAAEd,KAAK;AAAEE,IAAAA,UAAU,EAAEa;GAAmB,GAAGL,OAAO,IAAIX,eAAe;EAE3E,MAAMG,UAAU,GAAGF,KAAK,KAAKC,kBAAkB,GAAGE,mBAAmB,GAAGY,iBAAiB;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;AAC/C,GAAA,CAAC,EACF,CAACF,KAAK,EAAEE,UAAU,CAAC,CACpB;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/components-theming",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "Provides theming support for the Wise Design system components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -12,29 +12,32 @@
|
|
|
12
12
|
"url": "git+https://github.com/transferwise/neptune-web.git"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@babel/runtime": "^7.
|
|
15
|
+
"@babel/runtime": "^7.27.3",
|
|
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.
|
|
22
|
-
"@babel/preset-react": "^7.
|
|
23
|
-
"@babel/preset-typescript": "^7.
|
|
19
|
+
"@babel/core": "^7.27.3",
|
|
20
|
+
"@babel/plugin-transform-runtime": "^7.27.3",
|
|
21
|
+
"@babel/preset-env": "^7.27.2",
|
|
22
|
+
"@babel/preset-react": "^7.27.1",
|
|
23
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
24
24
|
"@rollup/plugin-babel": "^6.0.4",
|
|
25
|
-
"@rollup/plugin-typescript": "^
|
|
26
|
-
"@testing-library/dom": "^10.
|
|
27
|
-
"@testing-library/jest-dom": "^6.
|
|
28
|
-
"@testing-library/react": "^16.
|
|
29
|
-
"@tsconfig/recommended": "^1.0.
|
|
25
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
26
|
+
"@testing-library/dom": "^10.4.0",
|
|
27
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
28
|
+
"@testing-library/react": "^16.3.0",
|
|
29
|
+
"@tsconfig/recommended": "^1.0.8",
|
|
30
30
|
"@types/babel__core": "^7.20.5",
|
|
31
|
-
"@types/jest": "^29.5.
|
|
31
|
+
"@types/jest": "^29.5.14",
|
|
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.27.0",
|
|
34
36
|
"jest": "^29.7.0",
|
|
35
37
|
"jest-environment-jsdom": "^29.7.0",
|
|
36
|
-
"rollup": "^4.
|
|
37
|
-
"rollup-preserve-directives": "^1.1.
|
|
38
|
+
"rollup": "^4.41.1",
|
|
39
|
+
"rollup-preserve-directives": "^1.1.3",
|
|
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,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren, useContext, useEffect, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
import { ThemedChildren } from './ThemedChildren';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Theming } from './const';
|
|
5
5
|
import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';
|
|
6
6
|
import { getThemeClassName } from './helpers';
|
|
7
|
-
|
|
8
|
-
export const ThemeContext = createContext<
|
|
9
|
-
| {
|
|
10
|
-
theme: NonNullable<Theming['theme']>;
|
|
11
|
-
screenMode: ScreenMode;
|
|
12
|
-
}
|
|
13
|
-
| undefined
|
|
14
|
-
>(undefined);
|
|
7
|
+
import { ThemeContext } from './ThemeProviderContext';
|
|
15
8
|
|
|
16
9
|
type ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };
|
|
17
10
|
|
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';
|