@wise/components-theming 0.5.2 → 0.5.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/cjs/index.d.ts +21 -11
- package/dist/cjs/index.js +7 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.ts +21 -11
- package/dist/es/index.js +7 -4
- package/dist/es/index.js.map +1 -1
- package/package.json +2 -2
- package/src/ThemeProvider.tsx +3 -2
- package/src/const.ts +10 -5
- package/src/helpers.ts +12 -8
- package/src/index.ts +1 -1
- package/src/useTheme.ts +4 -3
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PropsWithChildren } from "react";
|
|
3
|
-
// TODO: Change 'light' with 'legacy' in future
|
|
4
|
-
declare const baseThemes:
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
// TODO: Change 'light' with 'legacy' in the future
|
|
4
|
+
declare const baseThemes: readonly [
|
|
5
|
+
"light",
|
|
6
|
+
"personal"
|
|
7
|
+
];
|
|
8
|
+
declare const extraThemes: readonly [
|
|
9
|
+
"forest-green"
|
|
10
|
+
];
|
|
11
|
+
declare const screenModes: readonly [
|
|
12
|
+
"light",
|
|
13
|
+
"dark"
|
|
14
|
+
];
|
|
15
|
+
// TODO: componentThemes returned back for backward compatibility, refactor this place in the future
|
|
16
|
+
type ComponentTheme = (typeof baseThemes)[number];
|
|
7
17
|
type BaseTheme = (typeof baseThemes)[number];
|
|
8
18
|
type ExtraTheme = (typeof extraThemes)[number];
|
|
9
19
|
type ScreenMode = (typeof screenModes)[number];
|
|
10
20
|
type Theming = {
|
|
11
|
-
theme?: BaseTheme | ExtraTheme;
|
|
21
|
+
theme?: ComponentTheme | BaseTheme | ExtraTheme;
|
|
12
22
|
screenMode?: ScreenMode;
|
|
13
23
|
};
|
|
14
|
-
declare const isThemeModern: (theme: BaseTheme | ExtraTheme) =>
|
|
15
|
-
declare const isExtraTheme: (theme: ExtraTheme) => theme is
|
|
16
|
-
declare const isScreenModeDark: (theme: BaseTheme, screenMode: ScreenMode) =>
|
|
17
|
-
declare const getThemeClassName: (theme: BaseTheme | ExtraTheme, screenMode: ScreenMode) => string;
|
|
24
|
+
declare const isThemeModern: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "personal" | "forest-green";
|
|
25
|
+
declare const isExtraTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green";
|
|
26
|
+
declare const isScreenModeDark: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => screenMode is "dark";
|
|
27
|
+
declare const getThemeClassName: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => string;
|
|
18
28
|
type ThemeProviderProps = PropsWithChildren<Theming>;
|
|
19
29
|
declare const ThemeProvider: ({ theme, screenMode, children }: ThemeProviderProps) => JSX.Element;
|
|
20
30
|
interface ThemeHookValue {
|
|
21
|
-
theme: BaseTheme | ExtraTheme;
|
|
31
|
+
theme: ComponentTheme | BaseTheme | ExtraTheme;
|
|
22
32
|
screenMode: ScreenMode;
|
|
23
33
|
isModern: boolean;
|
|
24
34
|
isScreenModeDark: boolean;
|
|
25
35
|
className: string;
|
|
26
36
|
}
|
|
27
37
|
declare const useTheme: () => ThemeHookValue;
|
|
28
|
-
export type { BaseTheme, ExtraTheme, ScreenMode, Theming };
|
|
38
|
+
export type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming };
|
|
29
39
|
export { isThemeModern, isExtraTheme, isScreenModeDark, getThemeClassName, ThemeProvider, useTheme };
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,19 +3,22 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var react = require('react');
|
|
5
5
|
|
|
6
|
-
// TODO: Change 'light' with 'legacy' in future
|
|
6
|
+
// TODO: Change 'light' with 'legacy' in the future
|
|
7
|
+
var baseThemes = ['light', 'personal'];
|
|
7
8
|
var extraThemes = ['forest-green'];
|
|
9
|
+
var screenModes = ['light', 'dark'];
|
|
10
|
+
var modernThemes = [baseThemes[1]].concat(extraThemes);
|
|
8
11
|
var DEFAULT_BASE_THEME = 'light';
|
|
9
12
|
var DEFAULT_SCREEN_MODE = 'light';
|
|
10
13
|
|
|
11
14
|
var isThemeModern = function isThemeModern(theme) {
|
|
12
|
-
return
|
|
15
|
+
return modernThemes.includes(theme);
|
|
13
16
|
};
|
|
14
17
|
var isExtraTheme = function isExtraTheme(theme) {
|
|
15
18
|
return extraThemes.includes(theme);
|
|
16
19
|
};
|
|
17
20
|
var isScreenModeDark = function isScreenModeDark(theme, screenMode) {
|
|
18
|
-
return theme
|
|
21
|
+
return isThemeModern(theme) && screenModes[1] === screenMode;
|
|
19
22
|
};
|
|
20
23
|
var getThemeClassName = function getThemeClassName(theme, screenMode) {
|
|
21
24
|
if (!isThemeModern(theme)) {
|
|
@@ -26,7 +29,7 @@ var getThemeClassName = function getThemeClassName(theme, screenMode) {
|
|
|
26
29
|
|
|
27
30
|
if (isExtraTheme(theme)) {
|
|
28
31
|
classes += " ".concat(classes, "--").concat(theme);
|
|
29
|
-
} else if (
|
|
32
|
+
} else if (screenModes[1] === screenMode) {
|
|
30
33
|
classes += " ".concat(classes, "--").concat(screenMode);
|
|
31
34
|
}
|
|
32
35
|
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/helpers.ts","../../src/useTheme.ts","../../src/ThemedChildren.tsx","../../src/ThemeProvider.tsx"],"sourcesContent":["// TODO: Change 'light' with 'legacy' in future\nexport const baseThemes = ['light', 'personal'];\nexport const extraThemes = ['forest-green'];\nexport const screenModes = ['light', 'dark'];\n\nexport type BaseTheme = typeof baseThemes[number];\nexport type ExtraTheme = typeof extraThemes[number];\nexport type ScreenMode = typeof screenModes[number];\n\nexport const DEFAULT_BASE_THEME = 'light' as const;\nexport const DEFAULT_SCREEN_MODE = 'light' as const;\n\nexport type Theming = {\n theme?: BaseTheme | ExtraTheme;\n screenMode?: ScreenMode;\n};\n","import {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/helpers.ts","../../src/useTheme.ts","../../src/ThemedChildren.tsx","../../src/ThemeProvider.tsx"],"sourcesContent":["// TODO: Change 'light' with 'legacy' in the future\nexport const baseThemes = ['light', 'personal'] as const;\nexport const extraThemes = ['forest-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], ...extraThemes] 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 ScreenMode = typeof screenModes[number];\nexport type ScreenModeDark = typeof screenModes[1];\n\nexport const DEFAULT_BASE_THEME = 'light' as const;\nexport const DEFAULT_SCREEN_MODE = 'light' as const;\n\nexport type Theming = {\n theme?: ComponentTheme | BaseTheme | ExtraTheme;\n screenMode?: ScreenMode;\n};\n","import type { ComponentTheme, ModernTheme, BaseTheme, ExtraTheme, ScreenMode, ScreenModeDark } from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (theme: ComponentTheme | BaseTheme | ExtraTheme): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isExtraTheme = (theme: ComponentTheme | BaseTheme | ExtraTheme): theme is ExtraTheme =>\n extraThemes.includes(theme as ExtraTheme);\n\nexport const isScreenModeDark = (\n theme: ComponentTheme | BaseTheme | ExtraTheme,\n screenMode: ScreenMode\n): screenMode is ScreenModeDark =>\n isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;\n\nexport const getThemeClassName = (\n theme: ComponentTheme | BaseTheme | ExtraTheme,\n screenMode: ScreenMode,\n) => {\n if (!isThemeModern(theme)) {\n return `np-theme-${theme}`;\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","import { useContext, useMemo } from 'react';\n\nimport { ThemeContext } from './ThemeProvider';\nimport type { ComponentTheme, BaseTheme, ScreenMode, ExtraTheme } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { isThemeModern, isScreenModeDark, getThemeClassName } from './helpers';\n\ninterface ThemeHookValue {\n theme: ComponentTheme | BaseTheme | ExtraTheme;\n screenMode: ScreenMode;\n isModern: boolean;\n isScreenModeDark: boolean;\n className: string;\n}\n\nexport const useTheme = (): ThemeHookValue => {\n const theme: ComponentTheme | BaseTheme | ExtraTheme = useContext(ThemeContext).theme ?? DEFAULT_BASE_THEME;\n const screenMode: ScreenMode = theme !== DEFAULT_BASE_THEME\n ? useContext(ThemeContext).screenMode ?? DEFAULT_SCREEN_MODE\n : DEFAULT_SCREEN_MODE;\n\n return useMemo(\n () => ({\n theme,\n screenMode,\n isModern: isThemeModern(theme),\n isScreenModeDark: isScreenModeDark(theme, screenMode),\n className: getThemeClassName(theme, screenMode),\n }),\n [theme, screenMode],\n );\n};\n","import { ReactNode } from 'react';\n\nimport { useTheme } from './useTheme';\n\ntype ThemedChildrenProps = { children: ReactNode };\n\nexport const ThemedChildren = ({ children }: ThemedChildrenProps) => {\n const { className } = useTheme();\n\n return <div className={className}>{children}</div>;\n};\n","import { createContext, PropsWithChildren, useContext, useEffect } from 'react';\n\nimport { ThemedChildren } from './ThemedChildren';\nimport type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { getThemeClassName } from './helpers';\n\nexport const ThemeContext = createContext<{\n theme: ComponentTheme | BaseTheme | ExtraTheme | undefined,\n screenMode: ScreenMode | undefined,\n}>({ theme: undefined, screenMode: undefined });\n\ntype ThemeProviderProps = PropsWithChildren<Theming>;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_BASE_THEME,\n screenMode = DEFAULT_SCREEN_MODE,\n children,\n}: ThemeProviderProps) => {\n const isRootProvider = useContext(ThemeContext).theme === undefined;\n\n // RegEx to check for `np-theme-` class name\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const themeClass = new RegExp(/\\bnp-theme-[a-z-]+\\b/, 'g');\n\n // useEffect hook used to apply the theme class to the HTML element\n useEffect(() => {\n if (isRootProvider) {\n // Remove all the theme classes from the documentElement\n document.documentElement.className.match(themeClass)?.map((item) => {\n document.documentElement.classList.remove(item);\n });\n getThemeClassName(theme, screenMode).split(' ').forEach(item => {\n document.documentElement.classList.add(item);\n })\n }\n }, [isRootProvider, theme, screenMode]);\n\n return (\n <ThemeContext.Provider value={{ theme, screenMode }}>\n <ThemedChildren>{children}</ThemedChildren>\n </ThemeContext.Provider>\n );\n};\n"],"names":["baseThemes","extraThemes","screenModes","modernThemes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE","isThemeModern","theme","includes","isExtraTheme","isScreenModeDark","screenMode","getThemeClassName","classes","useTheme","useContext","ThemeContext","useMemo","isModern","className","ThemedChildren","children","_jsx","createContext","undefined","ThemeProvider","isRootProvider","themeClass","RegExp","useEffect","documentElement","match","map","item","document","classList","remove","split","forEach","add","Provider","value"],"mappings":";;;;;AAAA;AACO,IAAMA,UAAU,GAAG,CAAC,OAAD,EAAU,UAAV,CAAnB,CAAA;AACA,IAAMC,WAAW,GAAG,CAAC,cAAD,CAApB,CAAA;AACA,IAAMC,WAAW,GAAG,CAAC,OAAD,EAAU,MAAV,CAApB,CAAA;AACA,IAAMC,YAAY,GAAIH,CAAAA,UAAU,CAAC,CAAD,CAAd,CAAsBC,CAAAA,MAAAA,CAAAA,WAAtB,CAAlB,CAAA;AAUA,IAAMG,kBAAkB,GAAG,OAA3B,CAAA;AACA,IAAMC,mBAAmB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CAAA;AAYA,EAAA,OACEW,cAACN,CAAAA,YAAY,CAACwB,QAAd,EAAsB;AAACC,IAAAA,KAAK,EAAE;AAAElC,MAAAA,KAAK,EAALA,KAAF;AAASI,MAAAA,UAAU,EAAVA,UAAAA;KAAjB;IAA6BU,QACjDC,EAAAA,cAAAA,CAACF,cAAD,EAAe;MAAAC,QAAEA,EAAAA,QAAAA;KAAjB,CAAA;AADoB,GAAtB,CADF,CAAA;AAKD;;;;;;;;;"}
|
package/dist/es/index.d.ts
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PropsWithChildren } from "react";
|
|
3
|
-
// TODO: Change 'light' with 'legacy' in future
|
|
4
|
-
declare const baseThemes:
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
// TODO: Change 'light' with 'legacy' in the future
|
|
4
|
+
declare const baseThemes: readonly [
|
|
5
|
+
"light",
|
|
6
|
+
"personal"
|
|
7
|
+
];
|
|
8
|
+
declare const extraThemes: readonly [
|
|
9
|
+
"forest-green"
|
|
10
|
+
];
|
|
11
|
+
declare const screenModes: readonly [
|
|
12
|
+
"light",
|
|
13
|
+
"dark"
|
|
14
|
+
];
|
|
15
|
+
// TODO: componentThemes returned back for backward compatibility, refactor this place in the future
|
|
16
|
+
type ComponentTheme = (typeof baseThemes)[number];
|
|
7
17
|
type BaseTheme = (typeof baseThemes)[number];
|
|
8
18
|
type ExtraTheme = (typeof extraThemes)[number];
|
|
9
19
|
type ScreenMode = (typeof screenModes)[number];
|
|
10
20
|
type Theming = {
|
|
11
|
-
theme?: BaseTheme | ExtraTheme;
|
|
21
|
+
theme?: ComponentTheme | BaseTheme | ExtraTheme;
|
|
12
22
|
screenMode?: ScreenMode;
|
|
13
23
|
};
|
|
14
|
-
declare const isThemeModern: (theme: BaseTheme | ExtraTheme) =>
|
|
15
|
-
declare const isExtraTheme: (theme: ExtraTheme) => theme is
|
|
16
|
-
declare const isScreenModeDark: (theme: BaseTheme, screenMode: ScreenMode) =>
|
|
17
|
-
declare const getThemeClassName: (theme: BaseTheme | ExtraTheme, screenMode: ScreenMode) => string;
|
|
24
|
+
declare const isThemeModern: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "personal" | "forest-green";
|
|
25
|
+
declare const isExtraTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green";
|
|
26
|
+
declare const isScreenModeDark: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => screenMode is "dark";
|
|
27
|
+
declare const getThemeClassName: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => string;
|
|
18
28
|
type ThemeProviderProps = PropsWithChildren<Theming>;
|
|
19
29
|
declare const ThemeProvider: ({ theme, screenMode, children }: ThemeProviderProps) => JSX.Element;
|
|
20
30
|
interface ThemeHookValue {
|
|
21
|
-
theme: BaseTheme | ExtraTheme;
|
|
31
|
+
theme: ComponentTheme | BaseTheme | ExtraTheme;
|
|
22
32
|
screenMode: ScreenMode;
|
|
23
33
|
isModern: boolean;
|
|
24
34
|
isScreenModeDark: boolean;
|
|
25
35
|
className: string;
|
|
26
36
|
}
|
|
27
37
|
declare const useTheme: () => ThemeHookValue;
|
|
28
|
-
export type { BaseTheme, ExtraTheme, ScreenMode, Theming };
|
|
38
|
+
export type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming };
|
|
29
39
|
export { isThemeModern, isExtraTheme, isScreenModeDark, getThemeClassName, ThemeProvider, useTheme };
|
package/dist/es/index.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useContext, useMemo, createContext, useEffect } from 'react';
|
|
3
3
|
|
|
4
|
-
// TODO: Change 'light' with 'legacy' in future
|
|
4
|
+
// TODO: Change 'light' with 'legacy' in the future
|
|
5
|
+
var baseThemes = ['light', 'personal'];
|
|
5
6
|
var extraThemes = ['forest-green'];
|
|
7
|
+
var screenModes = ['light', 'dark'];
|
|
8
|
+
var modernThemes = [baseThemes[1]].concat(extraThemes);
|
|
6
9
|
var DEFAULT_BASE_THEME = 'light';
|
|
7
10
|
var DEFAULT_SCREEN_MODE = 'light';
|
|
8
11
|
|
|
9
12
|
var isThemeModern = function isThemeModern(theme) {
|
|
10
|
-
return
|
|
13
|
+
return modernThemes.includes(theme);
|
|
11
14
|
};
|
|
12
15
|
var isExtraTheme = function isExtraTheme(theme) {
|
|
13
16
|
return extraThemes.includes(theme);
|
|
14
17
|
};
|
|
15
18
|
var isScreenModeDark = function isScreenModeDark(theme, screenMode) {
|
|
16
|
-
return theme
|
|
19
|
+
return isThemeModern(theme) && screenModes[1] === screenMode;
|
|
17
20
|
};
|
|
18
21
|
var getThemeClassName = function getThemeClassName(theme, screenMode) {
|
|
19
22
|
if (!isThemeModern(theme)) {
|
|
@@ -24,7 +27,7 @@ var getThemeClassName = function getThemeClassName(theme, screenMode) {
|
|
|
24
27
|
|
|
25
28
|
if (isExtraTheme(theme)) {
|
|
26
29
|
classes += " ".concat(classes, "--").concat(theme);
|
|
27
|
-
} else if (
|
|
30
|
+
} else if (screenModes[1] === screenMode) {
|
|
28
31
|
classes += " ".concat(classes, "--").concat(screenMode);
|
|
29
32
|
}
|
|
30
33
|
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/helpers.ts","../../src/useTheme.ts","../../src/ThemedChildren.tsx","../../src/ThemeProvider.tsx"],"sourcesContent":["// TODO: Change 'light' with 'legacy' in future\nexport const baseThemes = ['light', 'personal'];\nexport const extraThemes = ['forest-green'];\nexport const screenModes = ['light', 'dark'];\n\nexport type BaseTheme = typeof baseThemes[number];\nexport type ExtraTheme = typeof extraThemes[number];\nexport type ScreenMode = typeof screenModes[number];\n\nexport const DEFAULT_BASE_THEME = 'light' as const;\nexport const DEFAULT_SCREEN_MODE = 'light' as const;\n\nexport type Theming = {\n theme?: BaseTheme | ExtraTheme;\n screenMode?: ScreenMode;\n};\n","import {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/helpers.ts","../../src/useTheme.ts","../../src/ThemedChildren.tsx","../../src/ThemeProvider.tsx"],"sourcesContent":["// TODO: Change 'light' with 'legacy' in the future\nexport const baseThemes = ['light', 'personal'] as const;\nexport const extraThemes = ['forest-green'] as const;\nexport const screenModes = ['light', 'dark'] as const;\nexport const modernThemes = [baseThemes[1], ...extraThemes] 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 ScreenMode = typeof screenModes[number];\nexport type ScreenModeDark = typeof screenModes[1];\n\nexport const DEFAULT_BASE_THEME = 'light' as const;\nexport const DEFAULT_SCREEN_MODE = 'light' as const;\n\nexport type Theming = {\n theme?: ComponentTheme | BaseTheme | ExtraTheme;\n screenMode?: ScreenMode;\n};\n","import type { ComponentTheme, ModernTheme, BaseTheme, ExtraTheme, ScreenMode, ScreenModeDark } from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (theme: ComponentTheme | BaseTheme | ExtraTheme): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isExtraTheme = (theme: ComponentTheme | BaseTheme | ExtraTheme): theme is ExtraTheme =>\n extraThemes.includes(theme as ExtraTheme);\n\nexport const isScreenModeDark = (\n theme: ComponentTheme | BaseTheme | ExtraTheme,\n screenMode: ScreenMode\n): screenMode is ScreenModeDark =>\n isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;\n\nexport const getThemeClassName = (\n theme: ComponentTheme | BaseTheme | ExtraTheme,\n screenMode: ScreenMode,\n) => {\n if (!isThemeModern(theme)) {\n return `np-theme-${theme}`;\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","import { useContext, useMemo } from 'react';\n\nimport { ThemeContext } from './ThemeProvider';\nimport type { ComponentTheme, BaseTheme, ScreenMode, ExtraTheme } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { isThemeModern, isScreenModeDark, getThemeClassName } from './helpers';\n\ninterface ThemeHookValue {\n theme: ComponentTheme | BaseTheme | ExtraTheme;\n screenMode: ScreenMode;\n isModern: boolean;\n isScreenModeDark: boolean;\n className: string;\n}\n\nexport const useTheme = (): ThemeHookValue => {\n const theme: ComponentTheme | BaseTheme | ExtraTheme = useContext(ThemeContext).theme ?? DEFAULT_BASE_THEME;\n const screenMode: ScreenMode = theme !== DEFAULT_BASE_THEME\n ? useContext(ThemeContext).screenMode ?? DEFAULT_SCREEN_MODE\n : DEFAULT_SCREEN_MODE;\n\n return useMemo(\n () => ({\n theme,\n screenMode,\n isModern: isThemeModern(theme),\n isScreenModeDark: isScreenModeDark(theme, screenMode),\n className: getThemeClassName(theme, screenMode),\n }),\n [theme, screenMode],\n );\n};\n","import { ReactNode } from 'react';\n\nimport { useTheme } from './useTheme';\n\ntype ThemedChildrenProps = { children: ReactNode };\n\nexport const ThemedChildren = ({ children }: ThemedChildrenProps) => {\n const { className } = useTheme();\n\n return <div className={className}>{children}</div>;\n};\n","import { createContext, PropsWithChildren, useContext, useEffect } from 'react';\n\nimport { ThemedChildren } from './ThemedChildren';\nimport type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { getThemeClassName } from './helpers';\n\nexport const ThemeContext = createContext<{\n theme: ComponentTheme | BaseTheme | ExtraTheme | undefined,\n screenMode: ScreenMode | undefined,\n}>({ theme: undefined, screenMode: undefined });\n\ntype ThemeProviderProps = PropsWithChildren<Theming>;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_BASE_THEME,\n screenMode = DEFAULT_SCREEN_MODE,\n children,\n}: ThemeProviderProps) => {\n const isRootProvider = useContext(ThemeContext).theme === undefined;\n\n // RegEx to check for `np-theme-` class name\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const themeClass = new RegExp(/\\bnp-theme-[a-z-]+\\b/, 'g');\n\n // useEffect hook used to apply the theme class to the HTML element\n useEffect(() => {\n if (isRootProvider) {\n // Remove all the theme classes from the documentElement\n document.documentElement.className.match(themeClass)?.map((item) => {\n document.documentElement.classList.remove(item);\n });\n getThemeClassName(theme, screenMode).split(' ').forEach(item => {\n document.documentElement.classList.add(item);\n })\n }\n }, [isRootProvider, theme, screenMode]);\n\n return (\n <ThemeContext.Provider value={{ theme, screenMode }}>\n <ThemedChildren>{children}</ThemedChildren>\n </ThemeContext.Provider>\n );\n};\n"],"names":["baseThemes","extraThemes","screenModes","modernThemes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE","isThemeModern","theme","includes","isExtraTheme","isScreenModeDark","screenMode","getThemeClassName","classes","useTheme","useContext","ThemeContext","useMemo","isModern","className","ThemedChildren","children","_jsx","createContext","undefined","ThemeProvider","isRootProvider","themeClass","RegExp","useEffect","documentElement","match","map","item","document","classList","remove","split","forEach","add","Provider","value"],"mappings":";;;AAAA;AACO,IAAMA,UAAU,GAAG,CAAC,OAAD,EAAU,UAAV,CAAnB,CAAA;AACA,IAAMC,WAAW,GAAG,CAAC,cAAD,CAApB,CAAA;AACA,IAAMC,WAAW,GAAG,CAAC,OAAD,EAAU,MAAV,CAApB,CAAA;AACA,IAAMC,YAAY,GAAIH,CAAAA,UAAU,CAAC,CAAD,CAAd,CAAsBC,CAAAA,MAAAA,CAAAA,WAAtB,CAAlB,CAAA;AAUA,IAAMG,kBAAkB,GAAG,OAA3B,CAAA;AACA,IAAMC,mBAAmB,GAAG,OAA5B;;ICZMC,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,E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,IAAAA,KAAK,EAAE;AAAElC,MAAAA,KAAK,EAALA,KAAF;AAASI,MAAAA,UAAU,EAAVA,UAAAA;KAAjB;IAA6BU,QACjDC,EAAAA,GAAAA,CAACF,cAAD,EAAe;MAAAC,QAAEA,EAAAA,QAAAA;KAAjB,CAAA;AADoB,GAAtB,CADF,CAAA;AAKD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/components-theming",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Provides theming support for the Wise Design system components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"dist/",
|
|
44
44
|
"src/"
|
|
45
45
|
],
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "9d9da4cbd46a75706cce774bf4c341629d80fd22"
|
|
47
47
|
}
|
package/src/ThemeProvider.tsx
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createContext, PropsWithChildren, useContext, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
import { ThemedChildren } from './ThemedChildren';
|
|
4
|
-
import { BaseTheme, ExtraTheme, ScreenMode, Theming
|
|
4
|
+
import type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';
|
|
5
|
+
import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';
|
|
5
6
|
import { getThemeClassName } from './helpers';
|
|
6
7
|
|
|
7
8
|
export const ThemeContext = createContext<{
|
|
8
|
-
theme: BaseTheme | ExtraTheme | undefined,
|
|
9
|
+
theme: ComponentTheme | BaseTheme | ExtraTheme | undefined,
|
|
9
10
|
screenMode: ScreenMode | undefined,
|
|
10
11
|
}>({ theme: undefined, screenMode: undefined });
|
|
11
12
|
|
package/src/const.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
// TODO: Change 'light' with 'legacy' in future
|
|
2
|
-
export const baseThemes = ['light', 'personal'];
|
|
3
|
-
export const extraThemes = ['forest-green'];
|
|
4
|
-
export const screenModes = ['light', 'dark'];
|
|
1
|
+
// TODO: Change 'light' with 'legacy' in the future
|
|
2
|
+
export const baseThemes = ['light', 'personal'] as const;
|
|
3
|
+
export const extraThemes = ['forest-green'] as const;
|
|
4
|
+
export const screenModes = ['light', 'dark'] as const;
|
|
5
|
+
export const modernThemes = [baseThemes[1], ...extraThemes] as const;
|
|
5
6
|
|
|
7
|
+
// TODO: componentThemes returned back for backward compatibility, refactor this place in the future
|
|
8
|
+
export type ComponentTheme = typeof baseThemes[number];
|
|
9
|
+
export type ModernTheme = typeof modernThemes[number];
|
|
6
10
|
export type BaseTheme = typeof baseThemes[number];
|
|
7
11
|
export type ExtraTheme = typeof extraThemes[number];
|
|
8
12
|
export type ScreenMode = typeof screenModes[number];
|
|
13
|
+
export type ScreenModeDark = typeof screenModes[1];
|
|
9
14
|
|
|
10
15
|
export const DEFAULT_BASE_THEME = 'light' as const;
|
|
11
16
|
export const DEFAULT_SCREEN_MODE = 'light' as const;
|
|
12
17
|
|
|
13
18
|
export type Theming = {
|
|
14
|
-
theme?: BaseTheme | ExtraTheme;
|
|
19
|
+
theme?: ComponentTheme | BaseTheme | ExtraTheme;
|
|
15
20
|
screenMode?: ScreenMode;
|
|
16
21
|
};
|
package/src/helpers.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ComponentTheme, ModernTheme, BaseTheme, ExtraTheme, ScreenMode, ScreenModeDark } from './const';
|
|
2
|
+
import { extraThemes, screenModes, modernThemes } from './const';
|
|
2
3
|
|
|
3
|
-
export const isThemeModern = (theme: BaseTheme | ExtraTheme):
|
|
4
|
-
|
|
4
|
+
export const isThemeModern = (theme: ComponentTheme | BaseTheme | ExtraTheme): theme is ModernTheme =>
|
|
5
|
+
modernThemes.includes(theme as ModernTheme);
|
|
5
6
|
|
|
6
|
-
export const isExtraTheme = (theme: ExtraTheme): theme is ExtraTheme =>
|
|
7
|
+
export const isExtraTheme = (theme: ComponentTheme | BaseTheme | ExtraTheme): theme is ExtraTheme =>
|
|
7
8
|
extraThemes.includes(theme as ExtraTheme);
|
|
8
9
|
|
|
9
|
-
export const isScreenModeDark = (
|
|
10
|
-
theme
|
|
10
|
+
export const isScreenModeDark = (
|
|
11
|
+
theme: ComponentTheme | BaseTheme | ExtraTheme,
|
|
12
|
+
screenMode: ScreenMode
|
|
13
|
+
): screenMode is ScreenModeDark =>
|
|
14
|
+
isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;
|
|
11
15
|
|
|
12
16
|
export const getThemeClassName = (
|
|
13
|
-
theme: BaseTheme | ExtraTheme,
|
|
17
|
+
theme: ComponentTheme | BaseTheme | ExtraTheme,
|
|
14
18
|
screenMode: ScreenMode,
|
|
15
19
|
) => {
|
|
16
20
|
if (!isThemeModern(theme)) {
|
|
@@ -21,7 +25,7 @@ export const getThemeClassName = (
|
|
|
21
25
|
|
|
22
26
|
if (isExtraTheme(theme)) {
|
|
23
27
|
classes += ` ${classes}--${theme}`;
|
|
24
|
-
} else if (
|
|
28
|
+
} else if (screenModes[1] === screenMode) {
|
|
25
29
|
classes += ` ${classes}--${screenMode}`;
|
|
26
30
|
}
|
|
27
31
|
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';
|
|
1
|
+
export type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';
|
|
2
2
|
export { isThemeModern, isExtraTheme, isScreenModeDark, getThemeClassName } from './helpers';
|
|
3
3
|
|
|
4
4
|
export { ThemeProvider } from './ThemeProvider';
|
package/src/useTheme.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useContext, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
import { ThemeContext } from './ThemeProvider';
|
|
4
|
-
import { BaseTheme, ScreenMode, ExtraTheme
|
|
4
|
+
import type { ComponentTheme, BaseTheme, ScreenMode, ExtraTheme } from './const';
|
|
5
|
+
import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';
|
|
5
6
|
import { isThemeModern, isScreenModeDark, getThemeClassName } from './helpers';
|
|
6
7
|
|
|
7
8
|
interface ThemeHookValue {
|
|
8
|
-
theme: BaseTheme | ExtraTheme;
|
|
9
|
+
theme: ComponentTheme | BaseTheme | ExtraTheme;
|
|
9
10
|
screenMode: ScreenMode;
|
|
10
11
|
isModern: boolean;
|
|
11
12
|
isScreenModeDark: boolean;
|
|
@@ -13,7 +14,7 @@ interface ThemeHookValue {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export const useTheme = (): ThemeHookValue => {
|
|
16
|
-
const theme: BaseTheme | ExtraTheme = useContext(ThemeContext).theme ?? DEFAULT_BASE_THEME;
|
|
17
|
+
const theme: ComponentTheme | BaseTheme | ExtraTheme = useContext(ThemeContext).theme ?? DEFAULT_BASE_THEME;
|
|
17
18
|
const screenMode: ScreenMode = theme !== DEFAULT_BASE_THEME
|
|
18
19
|
? useContext(ThemeContext).screenMode ?? DEFAULT_SCREEN_MODE
|
|
19
20
|
: DEFAULT_SCREEN_MODE;
|