@wise/components-theming 0.1.0 → 0.1.1-next-3a766caf8e.2444
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 +7 -1
- package/dist/cjs/index.js +29 -12
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.ts +7 -1
- package/dist/es/index.js +30 -13
- package/dist/es/index.js.map +1 -1
- package/package.json +2 -2
- package/src/ThemeProvider.tsx +5 -1
- package/src/const.ts +4 -0
- package/src/helpers.ts +9 -0
- package/src/useTheme.spec.tsx +12 -2
- package/src/useTheme.ts +21 -3
package/dist/cjs/index.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ type ThemeProviderProps = PropsWithChildren<{
|
|
|
9
9
|
theme: ComponentTheme | undefined;
|
|
10
10
|
}>;
|
|
11
11
|
declare const ThemeProvider: ({ theme, children }: ThemeProviderProps) => JSX.Element;
|
|
12
|
-
|
|
12
|
+
interface ThemeHookValue {
|
|
13
|
+
theme: ComponentTheme;
|
|
14
|
+
isModern: boolean;
|
|
15
|
+
isDark: boolean;
|
|
16
|
+
className: string;
|
|
17
|
+
}
|
|
18
|
+
declare const useTheme: () => ThemeHookValue;
|
|
13
19
|
export type { ComponentTheme };
|
|
14
20
|
export { ThemeProvider, useTheme };
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,32 +3,42 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var react = require('react');
|
|
5
5
|
|
|
6
|
+
var modernThemes = ['personal'];
|
|
7
|
+
var darkThemes = [];
|
|
6
8
|
var DEFAULT_COMPONENT_THEME = 'light';
|
|
7
9
|
|
|
10
|
+
var isThemeModern = function isThemeModern(theme) {
|
|
11
|
+
return modernThemes.includes(theme);
|
|
12
|
+
};
|
|
13
|
+
var isThemeDark = function isThemeDark(theme) {
|
|
14
|
+
return darkThemes.includes(theme);
|
|
15
|
+
};
|
|
16
|
+
var getThemeClassName = function getThemeClassName(theme) {
|
|
17
|
+
return "np-theme-".concat(theme);
|
|
18
|
+
};
|
|
19
|
+
|
|
8
20
|
var ThemeContext = /*#__PURE__*/react.createContext(DEFAULT_COMPONENT_THEME);
|
|
9
21
|
var ThemeProvider = function ThemeProvider(_ref) {
|
|
10
22
|
var _ref$theme = _ref.theme,
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
theme = _ref$theme === void 0 ? DEFAULT_COMPONENT_THEME : _ref$theme,
|
|
24
|
+
children = _ref.children;
|
|
13
25
|
var themedChildren = react.Children.map(children, function (child) {
|
|
14
26
|
var _child$props;
|
|
15
|
-
|
|
16
27
|
if (! /*#__PURE__*/react.isValidElement(child)) {
|
|
17
28
|
if (process.env.NODE_ENV !== 'production') {
|
|
18
29
|
// eslint-disable-next-line no-console
|
|
19
30
|
console.warn('[ThemeProvider] Trying to inject `className` to an invalid React element, this will be skipped!');
|
|
20
31
|
}
|
|
21
|
-
|
|
22
32
|
return child;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var classNames = ["np-theme-".concat(theme), child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.className].filter(Boolean).join(' ');
|
|
33
|
+
}
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
35
|
+
var classNames = [getThemeClassName(theme), child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.className].filter(Boolean).join(' ');
|
|
27
36
|
return /*#__PURE__*/react.cloneElement(child, {
|
|
28
|
-
className: classNames
|
|
29
|
-
|
|
37
|
+
className: classNames
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
39
|
});
|
|
31
40
|
});
|
|
41
|
+
|
|
32
42
|
return jsxRuntime.jsx(ThemeContext.Provider, {
|
|
33
43
|
value: theme,
|
|
34
44
|
children: themedChildren
|
|
@@ -37,8 +47,15 @@ var ThemeProvider = function ThemeProvider(_ref) {
|
|
|
37
47
|
|
|
38
48
|
var useTheme = function useTheme() {
|
|
39
49
|
var _useContext;
|
|
40
|
-
|
|
41
|
-
return
|
|
50
|
+
var theme = (_useContext = react.useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
|
|
51
|
+
return react.useMemo(function () {
|
|
52
|
+
return {
|
|
53
|
+
theme: theme,
|
|
54
|
+
isModern: isThemeModern(theme),
|
|
55
|
+
isDark: isThemeDark(theme),
|
|
56
|
+
className: getThemeClassName(theme)
|
|
57
|
+
};
|
|
58
|
+
}, [theme]);
|
|
42
59
|
};
|
|
43
60
|
|
|
44
61
|
exports.ThemeProvider = ThemeProvider;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/ThemeProvider.tsx","../../src/useTheme.ts"],"sourcesContent":["export const componentThemes = ['light', 'personal'] as const;\n\nexport type ComponentTheme = typeof componentThemes[number];\n\nexport const DEFAULT_COMPONENT_THEME = 'light' as const;\n","import { Children, cloneElement, createContext, isValidElement, PropsWithChildren } from 'react';\n\nimport { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';\n\nexport const ThemeContext = createContext<ComponentTheme>(DEFAULT_COMPONENT_THEME);\n\ntype ThemeProviderProps = PropsWithChildren<{\n theme: ComponentTheme | undefined;\n}>;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_COMPONENT_THEME,\n children,\n}: ThemeProviderProps) => {\n const themedChildren = Children.map(children, (child) => {\n if (!isValidElement(child)) {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(\n '[ThemeProvider] Trying to inject `className` to an invalid React element, this will be skipped!',\n );\n }\n return child;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const classNames = [
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/helpers.ts","../../src/ThemeProvider.tsx","../../src/useTheme.ts"],"sourcesContent":["export const componentThemes = ['light', 'personal'] as const;\nexport const modernThemes = ['personal'] as const;\nexport const darkThemes = [] as const;\n\nexport type ComponentTheme = typeof componentThemes[number];\nexport type ModernTheme = typeof modernThemes[number];\nexport type DarkTheme = typeof darkThemes[number];\n\nexport const DEFAULT_COMPONENT_THEME = 'light' as const;\n","import { ComponentTheme, DarkTheme, ModernTheme, modernThemes, darkThemes } from './const';\n\nexport const isThemeModern = (theme: ComponentTheme): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isThemeDark = (theme: ComponentTheme): theme is DarkTheme =>\n darkThemes.includes(theme as DarkTheme);\n\nexport const getThemeClassName = (theme: ComponentTheme) => `np-theme-${theme}`;\n","import React from 'react';\nimport { Children, cloneElement, createContext, isValidElement, PropsWithChildren } from 'react';\n\nimport { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';\nimport { getThemeClassName } from './helpers';\n\nexport const ThemeContext = createContext<ComponentTheme>(DEFAULT_COMPONENT_THEME);\n\ntype ThemeProviderProps = PropsWithChildren<{\n theme: ComponentTheme | undefined;\n}>;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_COMPONENT_THEME,\n children,\n}: ThemeProviderProps) => {\n const themedChildren = Children.map(children, (child) => {\n if (!isValidElement(child)) {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(\n '[ThemeProvider] Trying to inject `className` to an invalid React element, this will be skipped!',\n );\n }\n return child;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const classNames = [getThemeClassName(theme), child?.props?.className]\n .filter(Boolean)\n .join(' ');\n\n return cloneElement(child, {\n className: classNames,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any);\n });\n\n return <ThemeContext.Provider value={theme}>{themedChildren}</ThemeContext.Provider>;\n};\n","import { useContext, useMemo } from 'react';\n\nimport { ThemeContext } from './ThemeProvider';\nimport { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';\nimport { getThemeClassName, isThemeDark, isThemeModern } from './helpers';\n\ninterface ThemeHookValue {\n theme: ComponentTheme;\n isModern: boolean;\n isDark: boolean;\n className: string;\n}\n\nexport const useTheme = (): ThemeHookValue => {\n const theme = useContext(ThemeContext) ?? DEFAULT_COMPONENT_THEME;\n\n return useMemo(\n () => ({\n theme,\n isModern: isThemeModern(theme),\n isDark: isThemeDark(theme),\n className: getThemeClassName(theme),\n }),\n [theme],\n );\n};\n"],"names":["modernThemes","darkThemes","DEFAULT_COMPONENT_THEME","isThemeModern","theme","includes","isThemeDark","getThemeClassName","ThemeContext","createContext","ThemeProvider","children","themedChildren","Children","map","child","isValidElement","process","env","NODE_ENV","console","warn","classNames","props","className","filter","Boolean","join","cloneElement","_jsx","Provider","value","useTheme","useContext","useMemo","isModern","isDark"],"mappings":";;;;;AACO,IAAMA,YAAY,GAAG,CAAC,UAAU,CAAU,CAAA;AAC1C,IAAMC,UAAU,GAAG,EAAW,CAAA;AAM9B,IAAMC,uBAAuB,GAAG,OAAgB;;ACNhD,IAAMC,aAAa,GAAG,SAAhBA,aAAa,CAAIC,KAAqB,EAAA;AAAA,EAAA,OACjDJ,YAAY,CAACK,QAAQ,CAACD,KAAoB,CAAC,CAAA;AAAA,CAAA,CAAA;AAEtC,IAAME,WAAW,GAAG,SAAdA,WAAW,CAAIF,KAAqB,EAAA;AAAA,EAAA,OAC/CH,UAAU,CAACI,QAAQ,CAACD,KAAkB,CAAC,CAAA;AAAA,CAAA,CAAA;AAElC,IAAMG,iBAAiB,GAAG,SAApBA,iBAAiB,CAAIH,KAAqB,EAAA;AAAA,EAAA,OAAA,WAAA,CAAA,MAAA,CAAiBA,KAAK,CAAA,CAAA;AAAA,CAAE;;ACFxE,IAAMI,YAAY,gBAAGC,mBAAa,CAAiBP,uBAAuB,CAAC,CAAA;AAMrEQ,IAAAA,aAAa,GAAG,SAAhBA,aAAa,CAGD,IAAA,EAAA;AAAA,EAAA,IAAA,UAAA,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IN,uBAAuB,CAAA;AAEjE,EAAA,OAAOgC,aAAO,CACZ,YAAA;IAAA,OAAO;AACL9B,MAAAA,KAAK,EAALA,KAAK;AACL+B,MAAAA,QAAQ,EAAEhC,aAAa,CAACC,KAAK,CAAC;AAC9BgC,MAAAA,MAAM,EAAE9B,WAAW,CAACF,KAAK,CAAC;MAC1BoB,SAAS,EAAEjB,iBAAiB,CAACH,KAAK,CAAA;AACnC,KAAA,CAAA;AAAA,GAAC,EACF,CAACA,KAAK,CAAC,CACR,CAAA;AACH;;;;;"}
|
package/dist/es/index.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ type ThemeProviderProps = PropsWithChildren<{
|
|
|
9
9
|
theme: ComponentTheme | undefined;
|
|
10
10
|
}>;
|
|
11
11
|
declare const ThemeProvider: ({ theme, children }: ThemeProviderProps) => JSX.Element;
|
|
12
|
-
|
|
12
|
+
interface ThemeHookValue {
|
|
13
|
+
theme: ComponentTheme;
|
|
14
|
+
isModern: boolean;
|
|
15
|
+
isDark: boolean;
|
|
16
|
+
className: string;
|
|
17
|
+
}
|
|
18
|
+
declare const useTheme: () => ThemeHookValue;
|
|
13
19
|
export type { ComponentTheme };
|
|
14
20
|
export { ThemeProvider, useTheme };
|
package/dist/es/index.js
CHANGED
|
@@ -1,32 +1,42 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { Children, isValidElement, cloneElement, createContext, useContext } from 'react';
|
|
2
|
+
import { Children, isValidElement, cloneElement, createContext, useContext, useMemo } from 'react';
|
|
3
3
|
|
|
4
|
+
var modernThemes = ['personal'];
|
|
5
|
+
var darkThemes = [];
|
|
4
6
|
var DEFAULT_COMPONENT_THEME = 'light';
|
|
5
7
|
|
|
8
|
+
var isThemeModern = function isThemeModern(theme) {
|
|
9
|
+
return modernThemes.includes(theme);
|
|
10
|
+
};
|
|
11
|
+
var isThemeDark = function isThemeDark(theme) {
|
|
12
|
+
return darkThemes.includes(theme);
|
|
13
|
+
};
|
|
14
|
+
var getThemeClassName = function getThemeClassName(theme) {
|
|
15
|
+
return "np-theme-".concat(theme);
|
|
16
|
+
};
|
|
17
|
+
|
|
6
18
|
var ThemeContext = /*#__PURE__*/createContext(DEFAULT_COMPONENT_THEME);
|
|
7
19
|
var ThemeProvider = function ThemeProvider(_ref) {
|
|
8
20
|
var _ref$theme = _ref.theme,
|
|
9
|
-
|
|
10
|
-
|
|
21
|
+
theme = _ref$theme === void 0 ? DEFAULT_COMPONENT_THEME : _ref$theme,
|
|
22
|
+
children = _ref.children;
|
|
11
23
|
var themedChildren = Children.map(children, function (child) {
|
|
12
24
|
var _child$props;
|
|
13
|
-
|
|
14
25
|
if (! /*#__PURE__*/isValidElement(child)) {
|
|
15
26
|
if (process.env.NODE_ENV !== 'production') {
|
|
16
27
|
// eslint-disable-next-line no-console
|
|
17
28
|
console.warn('[ThemeProvider] Trying to inject `className` to an invalid React element, this will be skipped!');
|
|
18
29
|
}
|
|
19
|
-
|
|
20
30
|
return child;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var classNames = ["np-theme-".concat(theme), child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.className].filter(Boolean).join(' ');
|
|
31
|
+
}
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
33
|
+
var classNames = [getThemeClassName(theme), child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.className].filter(Boolean).join(' ');
|
|
25
34
|
return /*#__PURE__*/cloneElement(child, {
|
|
26
|
-
className: classNames
|
|
27
|
-
|
|
35
|
+
className: classNames
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
37
|
});
|
|
29
38
|
});
|
|
39
|
+
|
|
30
40
|
return jsx(ThemeContext.Provider, {
|
|
31
41
|
value: theme,
|
|
32
42
|
children: themedChildren
|
|
@@ -35,8 +45,15 @@ var ThemeProvider = function ThemeProvider(_ref) {
|
|
|
35
45
|
|
|
36
46
|
var useTheme = function useTheme() {
|
|
37
47
|
var _useContext;
|
|
38
|
-
|
|
39
|
-
return (
|
|
48
|
+
var theme = (_useContext = useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
|
|
49
|
+
return useMemo(function () {
|
|
50
|
+
return {
|
|
51
|
+
theme: theme,
|
|
52
|
+
isModern: isThemeModern(theme),
|
|
53
|
+
isDark: isThemeDark(theme),
|
|
54
|
+
className: getThemeClassName(theme)
|
|
55
|
+
};
|
|
56
|
+
}, [theme]);
|
|
40
57
|
};
|
|
41
58
|
|
|
42
59
|
export { ThemeProvider, useTheme };
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/ThemeProvider.tsx","../../src/useTheme.ts"],"sourcesContent":["export const componentThemes = ['light', 'personal'] as const;\n\nexport type ComponentTheme = typeof componentThemes[number];\n\nexport const DEFAULT_COMPONENT_THEME = 'light' as const;\n","import { Children, cloneElement, createContext, isValidElement, PropsWithChildren } from 'react';\n\nimport { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';\n\nexport const ThemeContext = createContext<ComponentTheme>(DEFAULT_COMPONENT_THEME);\n\ntype ThemeProviderProps = PropsWithChildren<{\n theme: ComponentTheme | undefined;\n}>;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_COMPONENT_THEME,\n children,\n}: ThemeProviderProps) => {\n const themedChildren = Children.map(children, (child) => {\n if (!isValidElement(child)) {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(\n '[ThemeProvider] Trying to inject `className` to an invalid React element, this will be skipped!',\n );\n }\n return child;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const classNames = [
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/helpers.ts","../../src/ThemeProvider.tsx","../../src/useTheme.ts"],"sourcesContent":["export const componentThemes = ['light', 'personal'] as const;\nexport const modernThemes = ['personal'] as const;\nexport const darkThemes = [] as const;\n\nexport type ComponentTheme = typeof componentThemes[number];\nexport type ModernTheme = typeof modernThemes[number];\nexport type DarkTheme = typeof darkThemes[number];\n\nexport const DEFAULT_COMPONENT_THEME = 'light' as const;\n","import { ComponentTheme, DarkTheme, ModernTheme, modernThemes, darkThemes } from './const';\n\nexport const isThemeModern = (theme: ComponentTheme): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isThemeDark = (theme: ComponentTheme): theme is DarkTheme =>\n darkThemes.includes(theme as DarkTheme);\n\nexport const getThemeClassName = (theme: ComponentTheme) => `np-theme-${theme}`;\n","import React from 'react';\nimport { Children, cloneElement, createContext, isValidElement, PropsWithChildren } from 'react';\n\nimport { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';\nimport { getThemeClassName } from './helpers';\n\nexport const ThemeContext = createContext<ComponentTheme>(DEFAULT_COMPONENT_THEME);\n\ntype ThemeProviderProps = PropsWithChildren<{\n theme: ComponentTheme | undefined;\n}>;\n\nexport const ThemeProvider = ({\n theme = DEFAULT_COMPONENT_THEME,\n children,\n}: ThemeProviderProps) => {\n const themedChildren = Children.map(children, (child) => {\n if (!isValidElement(child)) {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(\n '[ThemeProvider] Trying to inject `className` to an invalid React element, this will be skipped!',\n );\n }\n return child;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const classNames = [getThemeClassName(theme), child?.props?.className]\n .filter(Boolean)\n .join(' ');\n\n return cloneElement(child, {\n className: classNames,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any);\n });\n\n return <ThemeContext.Provider value={theme}>{themedChildren}</ThemeContext.Provider>;\n};\n","import { useContext, useMemo } from 'react';\n\nimport { ThemeContext } from './ThemeProvider';\nimport { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';\nimport { getThemeClassName, isThemeDark, isThemeModern } from './helpers';\n\ninterface ThemeHookValue {\n theme: ComponentTheme;\n isModern: boolean;\n isDark: boolean;\n className: string;\n}\n\nexport const useTheme = (): ThemeHookValue => {\n const theme = useContext(ThemeContext) ?? DEFAULT_COMPONENT_THEME;\n\n return useMemo(\n () => ({\n theme,\n isModern: isThemeModern(theme),\n isDark: isThemeDark(theme),\n className: getThemeClassName(theme),\n }),\n [theme],\n );\n};\n"],"names":["modernThemes","darkThemes","DEFAULT_COMPONENT_THEME","isThemeModern","theme","includes","isThemeDark","getThemeClassName","ThemeContext","createContext","ThemeProvider","children","themedChildren","Children","map","child","isValidElement","process","env","NODE_ENV","console","warn","classNames","props","className","filter","Boolean","join","cloneElement","_jsx","Provider","value","useTheme","useContext","useMemo","isModern","isDark"],"mappings":";;;AACO,IAAMA,YAAY,GAAG,CAAC,UAAU,CAAU,CAAA;AAC1C,IAAMC,UAAU,GAAG,EAAW,CAAA;AAM9B,IAAMC,uBAAuB,GAAG,OAAgB;;ACNhD,IAAMC,aAAa,GAAG,SAAhBA,aAAa,CAAIC,KAAqB,EAAA;AAAA,EAAA,OACjDJ,YAAY,CAACK,QAAQ,CAACD,KAAoB,CAAC,CAAA;AAAA,CAAA,CAAA;AAEtC,IAAME,WAAW,GAAG,SAAdA,WAAW,CAAIF,KAAqB,EAAA;AAAA,EAAA,OAC/CH,UAAU,CAACI,QAAQ,CAACD,KAAkB,CAAC,CAAA;AAAA,CAAA,CAAA;AAElC,IAAMG,iBAAiB,GAAG,SAApBA,iBAAiB,CAAIH,KAAqB,EAAA;AAAA,EAAA,OAAA,WAAA,CAAA,MAAA,CAAiBA,KAAK,CAAA,CAAA;AAAA,CAAE;;ACFxE,IAAMI,YAAY,gBAAGC,aAAa,CAAiBP,uBAAuB,CAAC,CAAA;AAMrEQ,IAAAA,aAAa,GAAG,SAAhBA,aAAa,CAGD,IAAA,EAAA;AAAA,EAAA,IAAA,UAAA,GAAA,IAAA,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A;AAEjE,EAAA,OAAOgC,OAAO,CACZ,YAAA;IAAA,OAAO;AACL9B,MAAAA,KAAK,EAALA,KAAK;AACL+B,MAAAA,QAAQ,EAAEhC,aAAa,CAACC,KAAK,CAAC;AAC9BgC,MAAAA,MAAM,EAAE9B,WAAW,CAACF,KAAK,CAAC;MAC1BoB,SAAS,EAAEjB,iBAAiB,CAACH,KAAK,CAAA;AACnC,KAAA,CAAA;AAAA,GAAC,EACF,CAACA,KAAK,CAAC,CACR,CAAA;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/components-theming",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-next-3a766caf8e.2444+3a766caf8e",
|
|
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": "3a766caf8e66ce724ef128c99cbf11cbc890c3b3"
|
|
47
47
|
}
|
package/src/ThemeProvider.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { Children, cloneElement, createContext, isValidElement, PropsWithChildren } from 'react';
|
|
2
3
|
|
|
3
4
|
import { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';
|
|
5
|
+
import { getThemeClassName } from './helpers';
|
|
4
6
|
|
|
5
7
|
export const ThemeContext = createContext<ComponentTheme>(DEFAULT_COMPONENT_THEME);
|
|
6
8
|
|
|
@@ -24,7 +26,9 @@ export const ThemeProvider = ({
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
27
|
-
const classNames = [
|
|
29
|
+
const classNames = [getThemeClassName(theme), child?.props?.className]
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.join(' ');
|
|
28
32
|
|
|
29
33
|
return cloneElement(child, {
|
|
30
34
|
className: classNames,
|
package/src/const.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export const componentThemes = ['light', 'personal'] as const;
|
|
2
|
+
export const modernThemes = ['personal'] as const;
|
|
3
|
+
export const darkThemes = [] as const;
|
|
2
4
|
|
|
3
5
|
export type ComponentTheme = typeof componentThemes[number];
|
|
6
|
+
export type ModernTheme = typeof modernThemes[number];
|
|
7
|
+
export type DarkTheme = typeof darkThemes[number];
|
|
4
8
|
|
|
5
9
|
export const DEFAULT_COMPONENT_THEME = 'light' as const;
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ComponentTheme, DarkTheme, ModernTheme, modernThemes, darkThemes } from './const';
|
|
2
|
+
|
|
3
|
+
export const isThemeModern = (theme: ComponentTheme): theme is ModernTheme =>
|
|
4
|
+
modernThemes.includes(theme as ModernTheme);
|
|
5
|
+
|
|
6
|
+
export const isThemeDark = (theme: ComponentTheme): theme is DarkTheme =>
|
|
7
|
+
darkThemes.includes(theme as DarkTheme);
|
|
8
|
+
|
|
9
|
+
export const getThemeClassName = (theme: ComponentTheme) => `np-theme-${theme}`;
|
package/src/useTheme.spec.tsx
CHANGED
|
@@ -9,7 +9,12 @@ describe('useTheme', () => {
|
|
|
9
9
|
result: { current },
|
|
10
10
|
} = renderHook(() => useTheme());
|
|
11
11
|
|
|
12
|
-
expect(current).toStrictEqual(
|
|
12
|
+
expect(current).toStrictEqual({
|
|
13
|
+
theme: 'light',
|
|
14
|
+
isModern: false,
|
|
15
|
+
isDark: false,
|
|
16
|
+
className: 'np-theme-light',
|
|
17
|
+
});
|
|
13
18
|
});
|
|
14
19
|
|
|
15
20
|
it('returns provided theme', () => {
|
|
@@ -22,6 +27,11 @@ describe('useTheme', () => {
|
|
|
22
27
|
},
|
|
23
28
|
});
|
|
24
29
|
|
|
25
|
-
expect(current).toStrictEqual(
|
|
30
|
+
expect(current).toStrictEqual({
|
|
31
|
+
className: 'np-theme-personal',
|
|
32
|
+
isDark: false,
|
|
33
|
+
isModern: true,
|
|
34
|
+
theme: 'personal',
|
|
35
|
+
});
|
|
26
36
|
});
|
|
27
37
|
});
|
package/src/useTheme.ts
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
import { ThemeContext } from './ThemeProvider';
|
|
4
4
|
import { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';
|
|
5
|
+
import { getThemeClassName, isThemeDark, isThemeModern } from './helpers';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
interface ThemeHookValue {
|
|
8
|
+
theme: ComponentTheme;
|
|
9
|
+
isModern: boolean;
|
|
10
|
+
isDark: boolean;
|
|
11
|
+
className: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const useTheme = (): ThemeHookValue => {
|
|
15
|
+
const theme = useContext(ThemeContext) ?? DEFAULT_COMPONENT_THEME;
|
|
16
|
+
|
|
17
|
+
return useMemo(
|
|
18
|
+
() => ({
|
|
19
|
+
theme,
|
|
20
|
+
isModern: isThemeModern(theme),
|
|
21
|
+
isDark: isThemeDark(theme),
|
|
22
|
+
className: getThemeClassName(theme),
|
|
23
|
+
}),
|
|
24
|
+
[theme],
|
|
25
|
+
);
|
|
8
26
|
};
|