@wise/components-theming 0.8.2 → 0.8.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.
@@ -0,0 +1,12 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';
3
+ export declare const ThemeContext: import("react").Context<{
4
+ theme: ComponentTheme | BaseTheme | ExtraTheme;
5
+ screenMode: ScreenMode;
6
+ } | undefined>;
7
+ type ThemeProviderProps = PropsWithChildren<Theming> & {
8
+ className?: string;
9
+ };
10
+ export declare const ThemeProvider: ({ theme, screenMode, isNotRootProvider, children, className, }: ThemeProviderProps) => import("react").JSX.Element;
11
+ export {};
12
+ //# sourceMappingURL=ThemeProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../src/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAkC,MAAM,OAAO,CAAC;AAGzF,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAI1F,eAAO,MAAM,YAAY;WAEZ,cAAc,GAAG,SAAS,GAAG,UAAU;gBAClC,UAAU;cAGhB,CAAC;AAEb,KAAK,kBAAkB,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E,eAAO,MAAM,aAAa,mEAMvB,kBAAkB,gCA6BpB,CAAC"}
@@ -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"}
@@ -0,0 +1,19 @@
1
+ export declare const baseThemes: readonly ["light", "personal"];
2
+ export declare const extraThemes: readonly ["forest-green", "bright-green"];
3
+ export declare const screenModes: readonly ["light", "dark"];
4
+ export declare const modernThemes: readonly ["personal", "forest-green", "bright-green"];
5
+ export type ComponentTheme = (typeof baseThemes)[number];
6
+ export type ModernTheme = (typeof modernThemes)[number];
7
+ export type BaseTheme = (typeof baseThemes)[number];
8
+ export type ExtraTheme = (typeof extraThemes)[number];
9
+ export type ForestGreenTheme = (typeof extraThemes)[0];
10
+ export type ScreenMode = (typeof screenModes)[number];
11
+ export type ScreenModeDark = (typeof screenModes)[1];
12
+ export declare const DEFAULT_BASE_THEME: "light";
13
+ export declare const DEFAULT_SCREEN_MODE: "light";
14
+ export type Theming = {
15
+ theme?: ComponentTheme | BaseTheme | ExtraTheme;
16
+ screenMode?: ScreenMode;
17
+ isNotRootProvider?: boolean | undefined;
18
+ };
19
+ //# sourceMappingURL=const.d.ts.map
@@ -0,0 +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;AAGrE,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;AAErD,eAAO,MAAM,kBAAkB,SAAmB,CAAC;AACnD,eAAO,MAAM,mBAAmB,SAAmB,CAAC;AAEpD,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,GAAG,UAAU,CAAC;IAChD,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACzC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode } from './const';
2
+ export declare const isThemeModern: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "personal" | "forest-green" | "bright-green";
3
+ export declare const isExtraTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green" | "bright-green";
4
+ export declare const isForestGreenTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green";
5
+ export declare const isScreenModeDark: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => screenMode is "dark";
6
+ export declare const getThemeClassName: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => string;
7
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,SAAS,EACT,UAAU,EAEV,UAAU,EAEX,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,aAAa,UACjB,cAAc,GAAG,SAAS,GAAG,UAAU,0DACsB,CAAC;AAEvE,eAAO,MAAM,YAAY,UAAW,cAAc,GAAG,SAAS,GAAG,UAAU,6CAChC,CAAC;AAE5C,eAAO,MAAM,kBAAkB,UACtB,cAAc,GAAG,SAAS,GAAG,UAAU,4BACQ,CAAC;AAEzD,eAAO,MAAM,gBAAgB,UACpB,cAAc,GAAG,SAAS,GAAG,UAAU,cAClC,UAAU,yBAE8C,CAAC;AAEvE,eAAO,MAAM,iBAAiB,UACrB,cAAc,GAAG,SAAS,GAAG,UAAU,cAClC,UAAU,WAevB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';
2
+ export { isThemeModern, isExtraTheme, isForestGreenTheme, isScreenModeDark, getThemeClassName, } from './helpers';
3
+ export { ThemeProvider } from './ThemeProvider';
4
+ export { useTheme } from './useTheme';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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"}
@@ -0,0 +1,113 @@
1
+ import { useContext, useMemo, createContext, useEffect } from 'react';
2
+ import classNames from 'classnames';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ // TODO: Change 'light' with 'legacy' in the future
6
+ const baseThemes = ['light', 'personal'];
7
+ const extraThemes = ['forest-green', 'bright-green'];
8
+ const screenModes = ['light', 'dark'];
9
+ const modernThemes = [baseThemes[1], ...extraThemes];
10
+ const DEFAULT_BASE_THEME = 'light';
11
+ const DEFAULT_SCREEN_MODE = 'light';
12
+
13
+ const isThemeModern = theme => modernThemes.includes(theme);
14
+ const isExtraTheme = theme => extraThemes.includes(theme);
15
+ const isForestGreenTheme = theme => theme === extraThemes[0];
16
+ const isScreenModeDark = (theme, screenMode) => isThemeModern(theme) && screenModes[1] === screenMode;
17
+ const getThemeClassName = (theme, screenMode) => {
18
+ if (!isThemeModern(theme)) {
19
+ return `np-theme-${theme}`;
20
+ }
21
+ let classes = `np-theme-personal`;
22
+ if (isExtraTheme(theme)) {
23
+ classes += ` ${classes}--${theme}`;
24
+ } else if (screenModes[1] === screenMode) {
25
+ classes += ` ${classes}--${screenMode}`;
26
+ }
27
+ return classes;
28
+ };
29
+
30
+ const FALLBACK_VALUES = {
31
+ theme: DEFAULT_BASE_THEME,
32
+ screenMode: DEFAULT_SCREEN_MODE
33
+ };
34
+ const isNotProduction = () => {
35
+ try {
36
+ return ['localhost', 'dev-wi.se'].includes(window.location.hostname);
37
+ } catch {
38
+ return false;
39
+ }
40
+ };
41
+ const useTheme = () => {
42
+ const theming = useContext(ThemeContext);
43
+ if (!theming && isNotProduction()) {
44
+ // eslint-disable-next-line no-console
45
+ console.warn('Call to useTheme outside a ThemeProvider');
46
+ }
47
+ const {
48
+ theme,
49
+ screenMode: contextScreenMode
50
+ } = theming ?? FALLBACK_VALUES;
51
+ const screenMode = theme === DEFAULT_BASE_THEME ? DEFAULT_SCREEN_MODE : contextScreenMode;
52
+ return useMemo(() => ({
53
+ theme,
54
+ screenMode,
55
+ isModern: isThemeModern(theme),
56
+ isForestGreenTheme: isForestGreenTheme(theme),
57
+ isScreenModeDark: isScreenModeDark(theme, screenMode),
58
+ className: getThemeClassName(theme, screenMode)
59
+ }), [theme, screenMode]);
60
+ };
61
+
62
+ const ThemedChildren = ({
63
+ className = undefined,
64
+ children
65
+ }) => {
66
+ const {
67
+ className: themeClass
68
+ } = useTheme();
69
+ return /*#__PURE__*/jsx("div", {
70
+ className: classNames(themeClass, className),
71
+ children: children
72
+ });
73
+ };
74
+
75
+ const ThemeContext = /*#__PURE__*/createContext(undefined);
76
+ const ThemeProvider = ({
77
+ theme = DEFAULT_BASE_THEME,
78
+ screenMode = DEFAULT_SCREEN_MODE,
79
+ isNotRootProvider = false,
80
+ children,
81
+ className = undefined
82
+ }) => {
83
+ const isContextRoot = useContext(ThemeContext) === undefined;
84
+ // RegEx to check for `np-theme-` class name
85
+ // eslint-disable-next-line react-hooks/exhaustive-deps
86
+ const themeClass = new RegExp(/\bnp-theme-[a-z-]+\b/, 'g');
87
+ // useEffect hook used to apply the theme class to the HTML element
88
+ useEffect(() => {
89
+ if (!isNotRootProvider && isContextRoot) {
90
+ // Remove all the theme classes from the documentElement
91
+ document.documentElement.className.match(themeClass)?.forEach(item => {
92
+ document.documentElement.classList.remove(item);
93
+ });
94
+ getThemeClassName(theme, screenMode).split(' ').forEach(item => {
95
+ document.documentElement.classList.add(item);
96
+ });
97
+ }
98
+ }, [isNotRootProvider, isContextRoot, theme, screenMode, themeClass]);
99
+ const contextValue = useMemo(() => ({
100
+ theme,
101
+ screenMode
102
+ }), [screenMode, theme]);
103
+ return /*#__PURE__*/jsx(ThemeContext.Provider, {
104
+ value: contextValue,
105
+ children: /*#__PURE__*/jsx(ThemedChildren, {
106
+ className: className,
107
+ children: children
108
+ })
109
+ });
110
+ };
111
+
112
+ export { ThemeProvider, getThemeClassName, isExtraTheme, isForestGreenTheme, isScreenModeDark, isThemeModern, useTheme };
113
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/const.ts","../src/helpers.ts","../src/useTheme.ts","../src/ThemedChildren.tsx","../src/ThemeProvider.tsx"],"sourcesContent":[null,null,null,null,null],"names":["baseThemes","extraThemes","screenModes","modernThemes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE","isThemeModern","includes","theme","isExtraTheme","isForestGreenTheme","isScreenModeDark","screenMode","getThemeClassName","FALLBACK_VALUES","isNotProduction","ThemedChildren","className","undefined","children","themeClass","useTheme","_jsx","classNames","createContext","ThemeProvider","isNotRootProvider","useContext","ThemeContext","RegExp"],"mappings":";;;;AACA;AACO,MAAAA,UAAiB,GAAA,CAAA,OAAA,EAAA,UAAA,CAAA,CAAA;AACjB,MAAAC,WAAiB,GAAA,CAAA,cAAA,EAAA,cAAA,CAAA,CAAA;AACjB,MAAAC,WAAkB,GAAA,CAAA,OAAA,EAAA,MAAA,CAAA,CAAA;AAGnB,MAAoBC,YAAA,GAAA,CAAGH,kBAAkBC,WAAU,CAAA,CAAA;AACnD,MAAiBG,kBAAI,GAAO;AAC5B,MAAeC,mBAAW,UAAU;;ACEnC,MAAAC,qBACE,IAAAH,YAAA,CAAAI,QAAiB,CAASC,KAAA,EAAA;AAG5B,MAAAC,oBAA6B,IAAAR,WAAA,CAAAM,SAAiBC,KAAS,EAAA;AAGvD,MAAAE,0BACE,IAAAF,KAAA,KAAAP,WAAiB,CAAS,CAAA,EAAA;MAG5BU,gBAAsB,GAAAA,CAAAH,KAAA,EAAAI,UACN,KAAAN,aAAY,CAAAE,KAAA,CAAA,IAAaN,WAAA,CAAA,CAAA,CAAA,KAAAU,WACxB;MAIjBC,iBAAuB,GAAAA,CAAAL,KAAA,EAAAI,UACP,KAAA;;;;;;;;;;;;;MCnBbE,eAAS,GAAC;AAClBN,EAAAA,KAAkB,EAAAJ;AAClBQ,EAAAA,UAAgB,EAAAP,mBAAAA;;AAEjB,MAAAU,eAAA,GAAAA,MAAA;EAeD,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;ACxBsC,MAAAC,cAAU,GAAAA,CAAA;AAAAC,EAAAA,SAAA,GAAAC,SAAA;AAAAC,EAAAA,QAAAA;AAAA,CAAA,KAAA;EAAC,MAAQ;AAAAF,IAAAA,WAAWG,UAAAA;GAAA,GAAAC,QAAA,EAAA,CAAA;AAAG,EAAA,oBAAAC,GAAA,CAAA,KAAA,EAAA;AAAAL,IAAAA,SAAA,EAAAM,UAAA,CAAAH,UAAA,EAAAH,SAAA,CAAA;AAAAE,IAAAA,QAAA,EAAAA,QAAAA;AAAA,GAAA,CAAA,CAAA;AAEvE,CAAA;;kBCG4B,gBAAAK,aAAA,CAAAN,SAAA,CAAA,CAAA;mBAGf,GAAAO,CAAA;AAAAjB,EAAAA,KAAA,GAAAJ,kBAAA;AAAAQ,EAAAA,UAAA,GAAAP,mBAAA;AAAAqB,EAAAA,iBAAA,GAAA,KAAA;EAAAP,QAAA;AAAAF,EAAAA,SAAA,GAAAC,SAAAA;AAAA,CAAA,KAAA;AAEb,EAAA,mBAAuB,GAAGS,UAAA,CAAAC,YAAkB,CAAA,KAAWV,SAAA,CAAA;AAAE;AAAqB;EAE9E,MAAAE,UAAa,GAAA,IAAAS,MAAA,CAAa,sBAMvB,EAAA,GAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var classNames = require('classnames');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var classNames__default = /*#__PURE__*/_interopDefault(classNames);
10
+
11
+ // TODO: Change 'light' with 'legacy' in the future
12
+ const baseThemes = ['light', 'personal'];
13
+ const extraThemes = ['forest-green', 'bright-green'];
14
+ const screenModes = ['light', 'dark'];
15
+ const modernThemes = [baseThemes[1], ...extraThemes];
16
+ const DEFAULT_BASE_THEME = 'light';
17
+ const DEFAULT_SCREEN_MODE = 'light';
18
+
19
+ const isThemeModern = theme => modernThemes.includes(theme);
20
+ const isExtraTheme = theme => extraThemes.includes(theme);
21
+ const isForestGreenTheme = theme => theme === extraThemes[0];
22
+ const isScreenModeDark = (theme, screenMode) => isThemeModern(theme) && screenModes[1] === screenMode;
23
+ const getThemeClassName = (theme, screenMode) => {
24
+ if (!isThemeModern(theme)) {
25
+ return `np-theme-${theme}`;
26
+ }
27
+ let classes = `np-theme-personal`;
28
+ if (isExtraTheme(theme)) {
29
+ classes += ` ${classes}--${theme}`;
30
+ } else if (screenModes[1] === screenMode) {
31
+ classes += ` ${classes}--${screenMode}`;
32
+ }
33
+ return classes;
34
+ };
35
+
36
+ const FALLBACK_VALUES = {
37
+ theme: DEFAULT_BASE_THEME,
38
+ screenMode: DEFAULT_SCREEN_MODE
39
+ };
40
+ const isNotProduction = () => {
41
+ try {
42
+ return ['localhost', 'dev-wi.se'].includes(window.location.hostname);
43
+ } catch {
44
+ return false;
45
+ }
46
+ };
47
+ const useTheme = () => {
48
+ const theming = react.useContext(ThemeContext);
49
+ if (!theming && isNotProduction()) {
50
+ // eslint-disable-next-line no-console
51
+ console.warn('Call to useTheme outside a ThemeProvider');
52
+ }
53
+ const {
54
+ theme,
55
+ screenMode: contextScreenMode
56
+ } = theming ?? FALLBACK_VALUES;
57
+ const screenMode = theme === DEFAULT_BASE_THEME ? DEFAULT_SCREEN_MODE : contextScreenMode;
58
+ return react.useMemo(() => ({
59
+ theme,
60
+ screenMode,
61
+ isModern: isThemeModern(theme),
62
+ isForestGreenTheme: isForestGreenTheme(theme),
63
+ isScreenModeDark: isScreenModeDark(theme, screenMode),
64
+ className: getThemeClassName(theme, screenMode)
65
+ }), [theme, screenMode]);
66
+ };
67
+
68
+ const ThemedChildren = ({
69
+ className = undefined,
70
+ children
71
+ }) => {
72
+ const {
73
+ className: themeClass
74
+ } = useTheme();
75
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
76
+ className: classNames__default.default(themeClass, className),
77
+ children: children
78
+ });
79
+ };
80
+
81
+ const ThemeContext = /*#__PURE__*/react.createContext(undefined);
82
+ const ThemeProvider = ({
83
+ theme = DEFAULT_BASE_THEME,
84
+ screenMode = DEFAULT_SCREEN_MODE,
85
+ isNotRootProvider = false,
86
+ children,
87
+ className = undefined
88
+ }) => {
89
+ const isContextRoot = react.useContext(ThemeContext) === undefined;
90
+ // RegEx to check for `np-theme-` class name
91
+ // eslint-disable-next-line react-hooks/exhaustive-deps
92
+ const themeClass = new RegExp(/\bnp-theme-[a-z-]+\b/, 'g');
93
+ // useEffect hook used to apply the theme class to the HTML element
94
+ react.useEffect(() => {
95
+ if (!isNotRootProvider && isContextRoot) {
96
+ // Remove all the theme classes from the documentElement
97
+ document.documentElement.className.match(themeClass)?.forEach(item => {
98
+ document.documentElement.classList.remove(item);
99
+ });
100
+ getThemeClassName(theme, screenMode).split(' ').forEach(item => {
101
+ document.documentElement.classList.add(item);
102
+ });
103
+ }
104
+ }, [isNotRootProvider, isContextRoot, theme, screenMode, themeClass]);
105
+ const contextValue = react.useMemo(() => ({
106
+ theme,
107
+ screenMode
108
+ }), [screenMode, theme]);
109
+ return /*#__PURE__*/jsxRuntime.jsx(ThemeContext.Provider, {
110
+ value: contextValue,
111
+ children: /*#__PURE__*/jsxRuntime.jsx(ThemedChildren, {
112
+ className: className,
113
+ children: children
114
+ })
115
+ });
116
+ };
117
+
118
+ exports.ThemeProvider = ThemeProvider;
119
+ exports.getThemeClassName = getThemeClassName;
120
+ exports.isExtraTheme = isExtraTheme;
121
+ exports.isForestGreenTheme = isForestGreenTheme;
122
+ exports.isScreenModeDark = isScreenModeDark;
123
+ exports.isThemeModern = isThemeModern;
124
+ exports.useTheme = useTheme;
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/const.ts","../src/helpers.ts","../src/useTheme.ts","../src/ThemedChildren.tsx","../src/ThemeProvider.tsx"],"sourcesContent":[null,null,null,null,null],"names":["baseThemes","extraThemes","screenModes","modernThemes","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE","isThemeModern","includes","theme","isExtraTheme","isForestGreenTheme","isScreenModeDark","screenMode","getThemeClassName","FALLBACK_VALUES","isNotProduction","ThemedChildren","className","undefined","children","themeClass","useTheme","_jsx","classNames","createContext","ThemeProvider","isNotRootProvider","useContext","ThemeContext","RegExp"],"mappings":";;;;;;;;;;AACA;AACO,MAAAA,UAAiB,GAAA,CAAA,OAAA,EAAA,UAAA,CAAA,CAAA;AACjB,MAAAC,WAAiB,GAAA,CAAA,cAAA,EAAA,cAAA,CAAA,CAAA;AACjB,MAAAC,WAAkB,GAAA,CAAA,OAAA,EAAA,MAAA,CAAA,CAAA;AAGnB,MAAoBC,YAAA,GAAA,CAAGH,kBAAkBC,WAAU,CAAA,CAAA;AACnD,MAAiBG,kBAAI,GAAO;AAC5B,MAAeC,mBAAW,UAAU;;ACEnC,MAAAC,qBACE,IAAAH,YAAA,CAAAI,QAAiB,CAASC,KAAA,EAAA;AAG5B,MAAAC,oBAA6B,IAAAR,WAAA,CAAAM,SAAiBC,KAAS,EAAA;AAGvD,MAAAE,0BACE,IAAAF,KAAA,KAAAP,WAAiB,CAAS,CAAA,EAAA;MAG5BU,gBAAsB,GAAAA,CAAAH,KAAA,EAAAI,UACN,KAAAN,aAAY,CAAAE,KAAA,CAAA,IAAaN,WAAA,CAAA,CAAA,CAAA,KAAAU,WACxB;MAIjBC,iBAAuB,GAAAA,CAAAL,KAAA,EAAAI,UACP,KAAA;;;;;;;;;;;;;MCnBbE,eAAS,GAAC;AAClBN,EAAAA,KAAkB,EAAAJ;AAClBQ,EAAAA,UAAgB,EAAAP,mBAAAA;;AAEjB,MAAAU,eAAA,GAAAA,MAAA;EAeD,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;ACxBsC,MAAAC,cAAU,GAAAA,CAAA;AAAAC,EAAAA,SAAA,GAAAC,SAAA;AAAAC,EAAAA,QAAAA;AAAA,CAAA,KAAA;EAAC,MAAQ;AAAAF,IAAAA,WAAWG,UAAAA;GAAA,GAAAC,QAAA,EAAA,CAAA;AAAG,EAAA,oBAAAC,cAAA,CAAA,KAAA,EAAA;AAAAL,IAAAA,SAAA,EAAAM,2BAAA,CAAAH,UAAA,EAAAH,SAAA,CAAA;AAAAE,IAAAA,QAAA,EAAAA,QAAAA;AAAA,GAAA,CAAA,CAAA;AAEvE,CAAA;;kBCG4B,gBAAAK,mBAAA,CAAAN,SAAA,CAAA,CAAA;mBAGf,GAAAO,CAAA;AAAAjB,EAAAA,KAAA,GAAAJ,kBAAA;AAAAQ,EAAAA,UAAA,GAAAP,mBAAA;AAAAqB,EAAAA,iBAAA,GAAA,KAAA;EAAAP,QAAA;AAAAF,EAAAA,SAAA,GAAAC,SAAAA;AAAA,CAAA,KAAA;AAEb,EAAA,mBAAuB,GAAGS,gBAAA,CAAAC,YAAkB,CAAA,KAAWV,SAAA,CAAA;AAAE;AAAqB;EAE9E,MAAAE,UAAa,GAAA,IAAAS,MAAA,CAAa,sBAMvB,EAAA,GAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,12 @@
1
+ import type { ComponentTheme, BaseTheme, ScreenMode, ExtraTheme } from './const';
2
+ interface ThemeHookValue {
3
+ theme: ComponentTheme | BaseTheme | ExtraTheme;
4
+ screenMode: ScreenMode;
5
+ isModern: boolean;
6
+ isForestGreenTheme: boolean;
7
+ isScreenModeDark: boolean;
8
+ className: string;
9
+ }
10
+ export declare const useTheme: () => ThemeHookValue;
11
+ export {};
12
+ //# sourceMappingURL=useTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../src/useTheme.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIjF,UAAU,cAAc;IACtB,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,UAAU,CAAC;IAC/C,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/components-theming",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Provides theming support for the Wise Design system components",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -12,16 +12,24 @@
12
12
  "url": "git+https://github.com/transferwise/neptune-web.git"
13
13
  },
14
14
  "dependencies": {
15
+ "@babel/runtime": "^7.22.15",
15
16
  "classnames": "^2.3.2"
16
17
  },
17
18
  "devDependencies": {
18
- "@babel/plugin-syntax-import-assertions": "7.20.0",
19
- "@rollup/plugin-typescript": "11.0.0",
19
+ "@babel/core": "^7.22.15",
20
+ "@babel/plugin-transform-runtime": "^7.22.15",
21
+ "@babel/preset-env": "^7.22.15",
22
+ "@babel/preset-react": "^7.22.15",
23
+ "@babel/preset-typescript": "^7.22.15",
24
+ "@rollup/plugin-babel": "^6.0.3",
25
+ "@rollup/plugin-typescript": "^11.1.3",
20
26
  "@testing-library/jest-dom": "^5.14.1",
21
27
  "@testing-library/react": "^12.0.0",
22
28
  "@testing-library/react-hooks": "^8.0.0",
23
29
  "@transferwise/eslint-config": "^7.4.0",
24
30
  "@transferwise/test-config": "^5.0.2",
31
+ "@tsconfig/recommended": "^1.0.2",
32
+ "@types/babel__core": "^7.20.1",
25
33
  "@types/jest": "^27.5.2",
26
34
  "@types/node": "^18.15.12",
27
35
  "@types/react": "^17.0.59",
@@ -29,26 +37,23 @@
29
37
  "@types/testing-library__jest-dom": "^5.14.5",
30
38
  "classnames": "^2.3.2",
31
39
  "jest": "^27.0.6",
32
- "rollup": "3.2.3",
33
- "rollup-plugin-ts": "3.0.2",
40
+ "rollup": "^3.28.1",
34
41
  "typescript": "4.9.4"
35
42
  },
36
43
  "peerDependencies": {
37
44
  "react": ">=16.14",
38
45
  "react-dom": ">=16.14"
39
46
  },
40
- "exports": {
41
- ".": {
42
- "import": "./dist/es/index.js",
43
- "require": "./dist/cjs/index.js"
44
- }
45
- },
46
- "main": "./dist/cjs/index.js",
47
- "module": "./dist/es/index.js",
48
- "types": "./dist/es/index.d.ts",
47
+ "sideEffects": [
48
+ "*.css"
49
+ ],
50
+ "main": "./dist/index.js",
51
+ "module": "./dist/index.esm.js",
52
+ "types": "./dist/index.d.ts",
49
53
  "files": [
50
54
  "dist/",
51
- "src/"
55
+ "src/",
56
+ "!**/*.tsbuildinfo"
52
57
  ],
53
58
  "publishConfig": {
54
59
  "access": "public"
@@ -1,44 +0,0 @@
1
- import { PropsWithChildren } from "react";
2
- // TODO: Change 'light' with 'legacy' in the future
3
- declare const baseThemes: readonly [
4
- "light",
5
- "personal"
6
- ];
7
- declare const extraThemes: readonly [
8
- "forest-green",
9
- "bright-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];
17
- type BaseTheme = (typeof baseThemes)[number];
18
- type ExtraTheme = (typeof extraThemes)[number];
19
- type ScreenMode = (typeof screenModes)[number];
20
- type Theming = {
21
- theme?: ComponentTheme | BaseTheme | ExtraTheme;
22
- screenMode?: ScreenMode;
23
- isNotRootProvider?: boolean | undefined;
24
- };
25
- declare const isThemeModern: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "personal" | "forest-green" | "bright-green";
26
- declare const isExtraTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green" | "bright-green";
27
- declare const isForestGreenTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green";
28
- declare const isScreenModeDark: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => screenMode is "dark";
29
- declare const getThemeClassName: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => string;
30
- type ThemeProviderProps = PropsWithChildren<Theming> & {
31
- className?: string;
32
- };
33
- declare const ThemeProvider: ({ theme, screenMode, isNotRootProvider, children, className }: ThemeProviderProps) => JSX.Element;
34
- interface ThemeHookValue {
35
- theme: ComponentTheme | BaseTheme | ExtraTheme;
36
- screenMode: ScreenMode;
37
- isModern: boolean;
38
- isForestGreenTheme: boolean;
39
- isScreenModeDark: boolean;
40
- className: string;
41
- }
42
- declare const useTheme: () => ThemeHookValue;
43
- export type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming };
44
- export { isThemeModern, isExtraTheme, isForestGreenTheme, isScreenModeDark, getThemeClassName, ThemeProvider, useTheme };
package/dist/cjs/index.js DELETED
@@ -1,135 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var react = require('react');
5
- var classNames = require('classnames');
6
-
7
- // TODO: Change 'light' with 'legacy' in the future
8
- var baseThemes = ['light', 'personal'];
9
- var extraThemes = ['forest-green', 'bright-green'];
10
- var screenModes = ['light', 'dark'];
11
- var modernThemes = [baseThemes[1]].concat(extraThemes);
12
- var DEFAULT_BASE_THEME = 'light';
13
- var DEFAULT_SCREEN_MODE = 'light';
14
-
15
- var isThemeModern = function isThemeModern(theme) {
16
- return modernThemes.includes(theme);
17
- };
18
- var isExtraTheme = function isExtraTheme(theme) {
19
- return extraThemes.includes(theme);
20
- };
21
- var isForestGreenTheme = function isForestGreenTheme(theme) {
22
- return theme === extraThemes[0];
23
- };
24
- var isScreenModeDark = function isScreenModeDark(theme, screenMode) {
25
- return isThemeModern(theme) && screenModes[1] === screenMode;
26
- };
27
- var getThemeClassName = function getThemeClassName(theme, screenMode) {
28
- if (!isThemeModern(theme)) {
29
- return "np-theme-".concat(theme);
30
- }
31
- var classes = "np-theme-personal";
32
- if (isExtraTheme(theme)) {
33
- classes += " ".concat(classes, "--").concat(theme);
34
- } else if (screenModes[1] === screenMode) {
35
- classes += " ".concat(classes, "--").concat(screenMode);
36
- }
37
- return classes;
38
- };
39
-
40
- var FALLBACK_VALUES = {
41
- theme: DEFAULT_BASE_THEME,
42
- screenMode: DEFAULT_SCREEN_MODE
43
- };
44
- var isNotProduction = function isNotProduction() {
45
- try {
46
- return ['localhost', 'dev-wi.se'].includes(window.location.hostname);
47
- } catch (_unused) {
48
- return false;
49
- }
50
- };
51
- var useTheme = function useTheme() {
52
- var theming = react.useContext(ThemeContext);
53
- if (!theming && isNotProduction()) {
54
- // eslint-disable-next-line no-console
55
- console.warn('Call to useTheme outside a ThemeProvider');
56
- }
57
- var _ref = theming !== null && theming !== void 0 ? theming : FALLBACK_VALUES,
58
- theme = _ref.theme,
59
- contextScreenMode = _ref.screenMode;
60
- var screenMode = theme === DEFAULT_BASE_THEME ? DEFAULT_SCREEN_MODE : contextScreenMode;
61
- return react.useMemo(function () {
62
- return {
63
- theme: theme,
64
- screenMode: screenMode,
65
- isModern: isThemeModern(theme),
66
- isForestGreenTheme: isForestGreenTheme(theme),
67
- isScreenModeDark: isScreenModeDark(theme, screenMode),
68
- className: getThemeClassName(theme, screenMode)
69
- };
70
- }, [theme, screenMode]);
71
- };
72
-
73
- var ThemedChildren = function ThemedChildren(_ref) {
74
- var _ref$className = _ref.className,
75
- className = _ref$className === void 0 ? undefined : _ref$className,
76
- children = _ref.children;
77
- var _useTheme = useTheme(),
78
- themeClass = _useTheme.className;
79
- return jsxRuntime.jsx("div", {
80
- className: classNames.default(themeClass, className),
81
- children: children
82
- });
83
- };
84
-
85
- var ThemeContext = /*#__PURE__*/react.createContext(undefined);
86
- var ThemeProvider = function ThemeProvider(_ref) {
87
- var _ref$theme = _ref.theme,
88
- theme = _ref$theme === void 0 ? DEFAULT_BASE_THEME : _ref$theme,
89
- _ref$screenMode = _ref.screenMode,
90
- screenMode = _ref$screenMode === void 0 ? DEFAULT_SCREEN_MODE : _ref$screenMode,
91
- _ref$isNotRootProvide = _ref.isNotRootProvider,
92
- isNotRootProvider = _ref$isNotRootProvide === void 0 ? false : _ref$isNotRootProvide,
93
- children = _ref.children,
94
- _ref$className = _ref.className,
95
- className = _ref$className === void 0 ? undefined : _ref$className;
96
- var isContextRoot = react.useContext(ThemeContext) === undefined;
97
- // RegEx to check for `np-theme-` class name
98
- // eslint-disable-next-line react-hooks/exhaustive-deps
99
- var themeClass = new RegExp(/\bnp-theme-[a-z-]+\b/, 'g');
100
- // useEffect hook used to apply the theme class to the HTML element
101
- react.useEffect(function () {
102
- if (!isNotRootProvider && isContextRoot) {
103
- var _document$documentEle;
104
- // Remove all the theme classes from the documentElement
105
- (_document$documentEle = document.documentElement.className.match(themeClass)) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.forEach(function (item) {
106
- document.documentElement.classList.remove(item);
107
- });
108
- getThemeClassName(theme, screenMode).split(' ').forEach(function (item) {
109
- document.documentElement.classList.add(item);
110
- });
111
- }
112
- }, [isNotRootProvider, isContextRoot, theme, screenMode, themeClass]);
113
- var contextValue = react.useMemo(function () {
114
- return {
115
- theme: theme,
116
- screenMode: screenMode
117
- };
118
- }, [screenMode, theme]);
119
- return jsxRuntime.jsx(ThemeContext.Provider, {
120
- value: contextValue,
121
- children: jsxRuntime.jsx(ThemedChildren, {
122
- className: className,
123
- children: children
124
- })
125
- });
126
- };
127
-
128
- exports.ThemeProvider = ThemeProvider;
129
- exports.getThemeClassName = getThemeClassName;
130
- exports.isExtraTheme = isExtraTheme;
131
- exports.isForestGreenTheme = isForestGreenTheme;
132
- exports.isScreenModeDark = isScreenModeDark;
133
- exports.isThemeModern = isThemeModern;
134
- exports.useTheme = useTheme;
135
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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', 'bright-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 ForestGreenTheme = (typeof extraThemes)[0];\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 isNotRootProvider?: boolean | undefined;\n};\n","import type {\n ComponentTheme,\n ModernTheme,\n BaseTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (\n theme: ComponentTheme | BaseTheme | ExtraTheme,\n): theme is ModernTheme => 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 isForestGreenTheme = (\n theme: ComponentTheme | BaseTheme | ExtraTheme,\n): theme is ForestGreenTheme => theme === extraThemes[0];\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, isForestGreenTheme, isScreenModeDark, getThemeClassName } from './helpers';\n\ninterface ThemeHookValue {\n theme: ComponentTheme | BaseTheme | ExtraTheme;\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};\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","import classNames from 'classnames';\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={classNames(themeClass, className)}>{children}</div>;\n};\n","import { createContext, PropsWithChildren, useContext, useEffect, useMemo } 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 | {\n theme: ComponentTheme | BaseTheme | ExtraTheme;\n screenMode: ScreenMode;\n }\n | undefined\n>(undefined);\n\ntype ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };\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 // 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 (!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, themeClass]);\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":["baseThemes","extraThemes","screenModes","modernThemes","concat","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE","isThemeModern","theme","includes","isExtraTheme","isForestGreenTheme","isScreenModeDark","screenMode","getThemeClassName","classes","FALLBACK_VALUES","isNotProduction","window","location","hostname","_unused","useTheme","theming","useContext","ThemeContext","console","warn","_ref","contextScreenMode","useMemo","isModern","className","ThemedChildren","_ref$className","undefined","children","_useTheme","themeClass","_jsx","classNames","createContext","ThemeProvider","_ref$theme","_ref$screenMode","_ref$isNotRootProvide","isNotRootProvider","isContextRoot","RegExp","useEffect","_document$documentEle","document","documentElement","match","forEach","item","classList","remove","split","add","contextValue","Provider","value"],"mappings":";;;;;;AAAA;AACO,IAAMA,UAAU,GAAG,CAAC,OAAO,EAAE,UAAU,CAAU,CAAA;AACjD,IAAMC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc,CAAU,CAAA;AAC7D,IAAMC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,CAAU,CAAA;AAC9C,IAAMC,YAAY,GAAA,CAAIH,UAAU,CAAC,CAAC,CAAC,CAAAI,CAAAA,MAAA,CAAKH,WAAW,CAAU,CAAA;AAW7D,IAAMI,kBAAkB,GAAG,OAAgB,CAAA;AAC3C,IAAMC,mBAAmB,GAAG,OAAgB;;ICLtCC,aAAa,GAAG,SAAhBA,aAAaA,CACxBC,KAA8C,EAAA;AAAA,EAAA,OACrBL,YAAY,CAACM,QAAQ,CAACD,KAAoB,CAAC,CAAA;AAAA,EAAA;IAEzDE,YAAY,GAAG,SAAfA,YAAYA,CAAIF,KAA8C,EAAA;AAAA,EAAA,OACzEP,WAAW,CAACQ,QAAQ,CAACD,KAAmB,CAAC,CAAA;AAAA,EAAA;IAE9BG,kBAAkB,GAAG,SAArBA,kBAAkBA,CAC7BH,KAA8C,EAAA;AAAA,EAAA,OAChBA,KAAK,KAAKP,WAAW,CAAC,CAAC,CAAC,CAAA;AAAA,EAAA;AAEjD,IAAMW,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAC3BJ,KAA8C,EAC9CK,UAAsB,EAAA;EAAA,OAEtBN,aAAa,CAACC,KAAoB,CAAC,IAAIN,WAAW,CAAC,CAAC,CAAC,KAAKW,UAAU,CAAA;AAAA,EAAA;AAE/D,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAC5BN,KAA8C,EAC9CK,UAAsB,EACpB;AACF,EAAA,IAAI,CAACN,aAAa,CAACC,KAAK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,OAAO,CAAC,UAACC,IAAI,EAAI;QAChBJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACG,GAAG,CAACJ,IAAI,CAAC,CAAA;AAC9C,OAAC,CAAC,CAAA;;AAER,GAAC,EAAE,CAACT,iBAAiB,EAAEC,aAAa,EAAEvC,KAAK,EAAEK,UAAU,EAAEyB,UAAU,CAAC,CAAC,CAAA;EAErE,IAAMsB,YAAY,GAAG9B,aAAO,CAAC,YAAA;IAAA,OAAO;AAAEtB,MAAAA,KAAK,EAALA,KAAK;AAAEK,MAAAA,UAAU,EAAVA,UAAAA;KAAY,CAAA;AAAA,GAAC,EAAE,CAACA,UAAU,EAAEL,KAAK,CAAC,CAAC,CAAA;AAEhF,EAAA,OACE+B,cAAA,CAACd,YAAY,CAACoC,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAEF,YAAY;IAAAxB,QAAA,EACxCG,cAAA,CAACN,cAAc,EAAA;AAACD,MAAAA,SAAS,EAAEA,SAAS;AAAAI,MAAAA,QAAA,EAAGA,QAAAA;AAAQ,KAAA,CAAA;GACzB,CAAA,CAAA;AAE5B;;;;;;;;;;"}
@@ -1,44 +0,0 @@
1
- import { PropsWithChildren } from "react";
2
- // TODO: Change 'light' with 'legacy' in the future
3
- declare const baseThemes: readonly [
4
- "light",
5
- "personal"
6
- ];
7
- declare const extraThemes: readonly [
8
- "forest-green",
9
- "bright-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];
17
- type BaseTheme = (typeof baseThemes)[number];
18
- type ExtraTheme = (typeof extraThemes)[number];
19
- type ScreenMode = (typeof screenModes)[number];
20
- type Theming = {
21
- theme?: ComponentTheme | BaseTheme | ExtraTheme;
22
- screenMode?: ScreenMode;
23
- isNotRootProvider?: boolean | undefined;
24
- };
25
- declare const isThemeModern: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "personal" | "forest-green" | "bright-green";
26
- declare const isExtraTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green" | "bright-green";
27
- declare const isForestGreenTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green";
28
- declare const isScreenModeDark: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => screenMode is "dark";
29
- declare const getThemeClassName: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => string;
30
- type ThemeProviderProps = PropsWithChildren<Theming> & {
31
- className?: string;
32
- };
33
- declare const ThemeProvider: ({ theme, screenMode, isNotRootProvider, children, className }: ThemeProviderProps) => JSX.Element;
34
- interface ThemeHookValue {
35
- theme: ComponentTheme | BaseTheme | ExtraTheme;
36
- screenMode: ScreenMode;
37
- isModern: boolean;
38
- isForestGreenTheme: boolean;
39
- isScreenModeDark: boolean;
40
- className: string;
41
- }
42
- declare const useTheme: () => ThemeHookValue;
43
- export type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming };
44
- export { isThemeModern, isExtraTheme, isForestGreenTheme, isScreenModeDark, getThemeClassName, ThemeProvider, useTheme };
package/dist/es/index.js DELETED
@@ -1,127 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { useContext, useMemo, createContext, useEffect } from 'react';
3
- import classNames from 'classnames';
4
-
5
- // TODO: Change 'light' with 'legacy' in the future
6
- var baseThemes = ['light', 'personal'];
7
- var extraThemes = ['forest-green', 'bright-green'];
8
- var screenModes = ['light', 'dark'];
9
- var modernThemes = [baseThemes[1]].concat(extraThemes);
10
- var DEFAULT_BASE_THEME = 'light';
11
- var DEFAULT_SCREEN_MODE = 'light';
12
-
13
- var isThemeModern = function isThemeModern(theme) {
14
- return modernThemes.includes(theme);
15
- };
16
- var isExtraTheme = function isExtraTheme(theme) {
17
- return extraThemes.includes(theme);
18
- };
19
- var isForestGreenTheme = function isForestGreenTheme(theme) {
20
- return theme === extraThemes[0];
21
- };
22
- var isScreenModeDark = function isScreenModeDark(theme, screenMode) {
23
- return isThemeModern(theme) && screenModes[1] === screenMode;
24
- };
25
- var getThemeClassName = function getThemeClassName(theme, screenMode) {
26
- if (!isThemeModern(theme)) {
27
- return "np-theme-".concat(theme);
28
- }
29
- var classes = "np-theme-personal";
30
- if (isExtraTheme(theme)) {
31
- classes += " ".concat(classes, "--").concat(theme);
32
- } else if (screenModes[1] === screenMode) {
33
- classes += " ".concat(classes, "--").concat(screenMode);
34
- }
35
- return classes;
36
- };
37
-
38
- var FALLBACK_VALUES = {
39
- theme: DEFAULT_BASE_THEME,
40
- screenMode: DEFAULT_SCREEN_MODE
41
- };
42
- var isNotProduction = function isNotProduction() {
43
- try {
44
- return ['localhost', 'dev-wi.se'].includes(window.location.hostname);
45
- } catch (_unused) {
46
- return false;
47
- }
48
- };
49
- var useTheme = function useTheme() {
50
- var theming = useContext(ThemeContext);
51
- if (!theming && isNotProduction()) {
52
- // eslint-disable-next-line no-console
53
- console.warn('Call to useTheme outside a ThemeProvider');
54
- }
55
- var _ref = theming !== null && theming !== void 0 ? theming : FALLBACK_VALUES,
56
- theme = _ref.theme,
57
- contextScreenMode = _ref.screenMode;
58
- var screenMode = theme === DEFAULT_BASE_THEME ? DEFAULT_SCREEN_MODE : contextScreenMode;
59
- return useMemo(function () {
60
- return {
61
- theme: theme,
62
- screenMode: screenMode,
63
- isModern: isThemeModern(theme),
64
- isForestGreenTheme: isForestGreenTheme(theme),
65
- isScreenModeDark: isScreenModeDark(theme, screenMode),
66
- className: getThemeClassName(theme, screenMode)
67
- };
68
- }, [theme, screenMode]);
69
- };
70
-
71
- var ThemedChildren = function ThemedChildren(_ref) {
72
- var _ref$className = _ref.className,
73
- className = _ref$className === void 0 ? undefined : _ref$className,
74
- children = _ref.children;
75
- var _useTheme = useTheme(),
76
- themeClass = _useTheme.className;
77
- return jsx("div", {
78
- className: classNames(themeClass, className),
79
- children: children
80
- });
81
- };
82
-
83
- var ThemeContext = /*#__PURE__*/createContext(undefined);
84
- var ThemeProvider = function ThemeProvider(_ref) {
85
- var _ref$theme = _ref.theme,
86
- theme = _ref$theme === void 0 ? DEFAULT_BASE_THEME : _ref$theme,
87
- _ref$screenMode = _ref.screenMode,
88
- screenMode = _ref$screenMode === void 0 ? DEFAULT_SCREEN_MODE : _ref$screenMode,
89
- _ref$isNotRootProvide = _ref.isNotRootProvider,
90
- isNotRootProvider = _ref$isNotRootProvide === void 0 ? false : _ref$isNotRootProvide,
91
- children = _ref.children,
92
- _ref$className = _ref.className,
93
- className = _ref$className === void 0 ? undefined : _ref$className;
94
- var isContextRoot = useContext(ThemeContext) === undefined;
95
- // RegEx to check for `np-theme-` class name
96
- // eslint-disable-next-line react-hooks/exhaustive-deps
97
- var themeClass = new RegExp(/\bnp-theme-[a-z-]+\b/, 'g');
98
- // useEffect hook used to apply the theme class to the HTML element
99
- useEffect(function () {
100
- if (!isNotRootProvider && isContextRoot) {
101
- var _document$documentEle;
102
- // Remove all the theme classes from the documentElement
103
- (_document$documentEle = document.documentElement.className.match(themeClass)) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.forEach(function (item) {
104
- document.documentElement.classList.remove(item);
105
- });
106
- getThemeClassName(theme, screenMode).split(' ').forEach(function (item) {
107
- document.documentElement.classList.add(item);
108
- });
109
- }
110
- }, [isNotRootProvider, isContextRoot, theme, screenMode, themeClass]);
111
- var contextValue = useMemo(function () {
112
- return {
113
- theme: theme,
114
- screenMode: screenMode
115
- };
116
- }, [screenMode, theme]);
117
- return jsx(ThemeContext.Provider, {
118
- value: contextValue,
119
- children: jsx(ThemedChildren, {
120
- className: className,
121
- children: children
122
- })
123
- });
124
- };
125
-
126
- export { ThemeProvider, getThemeClassName, isExtraTheme, isForestGreenTheme, isScreenModeDark, isThemeModern, useTheme };
127
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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', 'bright-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 ForestGreenTheme = (typeof extraThemes)[0];\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 isNotRootProvider?: boolean | undefined;\n};\n","import type {\n ComponentTheme,\n ModernTheme,\n BaseTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (\n theme: ComponentTheme | BaseTheme | ExtraTheme,\n): theme is ModernTheme => 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 isForestGreenTheme = (\n theme: ComponentTheme | BaseTheme | ExtraTheme,\n): theme is ForestGreenTheme => theme === extraThemes[0];\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, isForestGreenTheme, isScreenModeDark, getThemeClassName } from './helpers';\n\ninterface ThemeHookValue {\n theme: ComponentTheme | BaseTheme | ExtraTheme;\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};\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","import classNames from 'classnames';\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={classNames(themeClass, className)}>{children}</div>;\n};\n","import { createContext, PropsWithChildren, useContext, useEffect, useMemo } 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 | {\n theme: ComponentTheme | BaseTheme | ExtraTheme;\n screenMode: ScreenMode;\n }\n | undefined\n>(undefined);\n\ntype ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };\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 // 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 (!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, themeClass]);\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":["baseThemes","extraThemes","screenModes","modernThemes","concat","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE","isThemeModern","theme","includes","isExtraTheme","isForestGreenTheme","isScreenModeDark","screenMode","getThemeClassName","classes","FALLBACK_VALUES","isNotProduction","window","location","hostname","_unused","useTheme","theming","useContext","ThemeContext","console","warn","_ref","contextScreenMode","useMemo","isModern","className","ThemedChildren","_ref$className","undefined","children","_useTheme","themeClass","_jsx","classNames","createContext","ThemeProvider","_ref$theme","_ref$screenMode","_ref$isNotRootProvide","isNotRootProvider","isContextRoot","RegExp","useEffect","_document$documentEle","document","documentElement","match","forEach","item","classList","remove","split","add","contextValue","Provider","value"],"mappings":";;;;AAAA;AACO,IAAMA,UAAU,GAAG,CAAC,OAAO,EAAE,UAAU,CAAU,CAAA;AACjD,IAAMC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc,CAAU,CAAA;AAC7D,IAAMC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,CAAU,CAAA;AAC9C,IAAMC,YAAY,GAAA,CAAIH,UAAU,CAAC,CAAC,CAAC,CAAAI,CAAAA,MAAA,CAAKH,WAAW,CAAU,CAAA;AAW7D,IAAMI,kBAAkB,GAAG,OAAgB,CAAA;AAC3C,IAAMC,mBAAmB,GAAG,OAAgB;;ICLtCC,aAAa,GAAG,SAAhBA,aAAaA,CACxBC,KAA8C,EAAA;AAAA,EAAA,OACrBL,YAAY,CAACM,QAAQ,CAACD,KAAoB,CAAC,CAAA;AAAA,EAAA;IAEzDE,YAAY,GAAG,SAAfA,YAAYA,CAAIF,KAA8C,EAAA;AAAA,EAAA,OACzEP,WAAW,CAACQ,QAAQ,CAACD,KAAmB,CAAC,CAAA;AAAA,EAAA;IAE9BG,kBAAkB,GAAG,SAArBA,kBAAkBA,CAC7BH,KAA8C,EAAA;AAAA,EAAA,OAChBA,KAAK,KAAKP,WAAW,CAAC,CAAC,CAAC,CAAA;AAAA,EAAA;AAEjD,IAAMW,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAC3BJ,KAA8C,EAC9CK,UAAsB,EAAA;EAAA,OAEtBN,aAAa,CAACC,KAAoB,CAAC,IAAIN,WAAW,CAAC,CAAC,CAAC,KAAKW,UAAU,CAAA;AAAA,EAAA;AAE/D,IAAMC,iBAAiB,GAAG,SAApBA,iB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