@wise/components-theming 0.1.1-next-74bd02ad78.0 → 0.1.1
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/CHANGELOG.md +11 -0
- package/dist/cjs/index.d.ts +1 -7
- package/dist/cjs/index.js +2 -22
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.ts +1 -7
- package/dist/es/index.js +3 -23
- package/dist/es/index.js.map +1 -1
- package/package.json +2 -2
- package/src/ThemeProvider.tsx +1 -5
- package/src/const.ts +0 -4
- package/src/useTheme.spec.tsx +2 -12
- package/src/useTheme.ts +3 -21
- package/src/helpers.ts +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.1.1](https://github.com/transferwise/neptune-web/compare/@wise/components-theming@0.1.0...@wise/components-theming@0.1.1) (2022-11-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **components-theming:** fix build ([#1747](https://github.com/transferwise/neptune-web/issues/1747)) ([f077c1a](https://github.com/transferwise/neptune-web/commit/f077c1aff760b8b65fa663a236cf168360ecdcf8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# 0.1.0 (2022-11-02)
|
|
7
18
|
|
|
8
19
|
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -9,12 +9,6 @@ type ThemeProviderProps = PropsWithChildren<{
|
|
|
9
9
|
theme: ComponentTheme | undefined;
|
|
10
10
|
}>;
|
|
11
11
|
declare const ThemeProvider: ({ theme, children }: ThemeProviderProps) => JSX.Element;
|
|
12
|
-
|
|
13
|
-
theme: ComponentTheme;
|
|
14
|
-
isModern: boolean;
|
|
15
|
-
isDark: boolean;
|
|
16
|
-
className: string;
|
|
17
|
-
}
|
|
18
|
-
declare const useTheme: () => ThemeHookValue;
|
|
12
|
+
declare const useTheme: () => ComponentTheme;
|
|
19
13
|
export type { ComponentTheme };
|
|
20
14
|
export { ThemeProvider, useTheme };
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,20 +3,8 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var react = require('react');
|
|
5
5
|
|
|
6
|
-
var modernThemes = ['personal'];
|
|
7
|
-
var darkThemes = [];
|
|
8
6
|
var DEFAULT_COMPONENT_THEME = 'light';
|
|
9
7
|
|
|
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
|
-
|
|
20
8
|
var ThemeContext = /*#__PURE__*/react.createContext(DEFAULT_COMPONENT_THEME);
|
|
21
9
|
var ThemeProvider = function ThemeProvider(_ref) {
|
|
22
10
|
var _ref$theme = _ref.theme,
|
|
@@ -35,7 +23,7 @@ var ThemeProvider = function ThemeProvider(_ref) {
|
|
|
35
23
|
} // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
36
24
|
|
|
37
25
|
|
|
38
|
-
var classNames = [
|
|
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(' ');
|
|
39
27
|
return /*#__PURE__*/react.cloneElement(child, {
|
|
40
28
|
className: classNames // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
29
|
|
|
@@ -50,15 +38,7 @@ var ThemeProvider = function ThemeProvider(_ref) {
|
|
|
50
38
|
var useTheme = function useTheme() {
|
|
51
39
|
var _useContext;
|
|
52
40
|
|
|
53
|
-
|
|
54
|
-
return react.useMemo(function () {
|
|
55
|
-
return {
|
|
56
|
-
theme: theme,
|
|
57
|
-
isModern: isThemeModern(theme),
|
|
58
|
-
isDark: isThemeDark(theme),
|
|
59
|
-
className: getThemeClassName(theme)
|
|
60
|
-
};
|
|
61
|
-
}, [theme]);
|
|
41
|
+
return (_useContext = react.useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
|
|
62
42
|
};
|
|
63
43
|
|
|
64
44
|
exports.ThemeProvider = ThemeProvider;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/
|
|
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 = [`np-theme-${theme}`, child?.props?.className].filter(Boolean).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 } from 'react';\n\nimport { ThemeContext } from './ThemeProvider';\nimport { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';\n\nexport const useTheme = (): ComponentTheme => {\n return useContext(ThemeContext) ?? DEFAULT_COMPONENT_THEME;\n};\n"],"names":["DEFAULT_COMPONENT_THEME","ThemeContext","createContext","ThemeProvider","theme","children","themedChildren","Children","map","child","isValidElement","process","env","NODE_ENV","console","warn","classNames","props","className","filter","Boolean","join","cloneElement","_jsx","Provider","value","useTheme","useContext"],"mappings":";;;;;AAIO,IAAMA,uBAAuB,GAAG,OAAhC;;ACAA,IAAMC,YAAY,gBAAGC,mBAAa,CAAiBF,uBAAjB,CAAlC,CAAA;AAMMG,IAAAA,aAAa,GAAG,SAAhBA,aAAgB,CAGJ,IAAA,EAAA;AAAA,EAAA,IAAA,UAAA,GAAA,IAAA,CAFvBC,KAEuB;MAFvBA,KAEuB,2BAFfJ,uBAEe,GAAA,UAAA;MADvBK,QACuB,QADvBA,QACuB,CAAA;EACvB,IAAMC,cAAc,GAAGC,cAAQ,CAACC,GAAT,CAAaH,QAAb,EAAuB,UAACI,KAAD,EAAU;AAAA,IAAA,IAAA,YAAA,CAAA;;AACtD,IAAA,IAAI,eAACC,oBAAc,CAACD,KAAD,CAAnB,EAA4B;AAC1B,MAAA,IAAIE,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;QACAC,OAAO,CAACC,IAAR,CACE,iGADF,CAAA,CAAA;AAGD,OAAA;;AACD,MAAA,OAAON,KAAP,CAAA;AACD,KATqD;;;IAYtD,IAAMO,UAAU,GAAG,CAAaZ,WAAAA,CAAAA,MAAAA,CAAAA,KAAb,GAAsBK,KAAtB,KAAA,IAAA,IAAsBA,KAAtB,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,CAAA,YAAA,GAAsBA,KAAK,CAAEQ,KAA7B,MAAsB,IAAA,IAAA,YAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,YAAA,CAAcC,SAApC,CAAA,CAA+CC,MAA/C,CAAsDC,OAAtD,CAA+DC,CAAAA,IAA/D,CAAoE,GAApE,CAAnB,CAAA;IAEA,oBAAOC,kBAAY,CAACb,KAAD,EAAQ;MACzBS,SAAS,EAAEF,UADc;;AAAA,KAAR,CAAnB,CAAA;AAID,GAlBsB,CAAvB,CAAA;AAoBA,EAAA,OAAOO,cAACtB,CAAAA,YAAY,CAACuB,QAAd,EAAsB;AAACC,IAAAA,KAAK,EAAErB,KAAR;IAAaC,QAAGC,EAAAA,cAAAA;AAAhB,GAAtB,CAAP,CAAA;AACD;;AC9BYoB,IAAAA,QAAQ,GAAG,SAAXA,QAAW,GAAqB;AAAA,EAAA,IAAA,WAAA,CAAA;;AAC3C,EAAA,OAAA,CAAA,WAAA,GAAOC,gBAAU,CAAC1B,YAAD,CAAjB,qDAAmCD,uBAAnC,CAAA;AACD;;;;;"}
|
package/dist/es/index.d.ts
CHANGED
|
@@ -9,12 +9,6 @@ type ThemeProviderProps = PropsWithChildren<{
|
|
|
9
9
|
theme: ComponentTheme | undefined;
|
|
10
10
|
}>;
|
|
11
11
|
declare const ThemeProvider: ({ theme, children }: ThemeProviderProps) => JSX.Element;
|
|
12
|
-
|
|
13
|
-
theme: ComponentTheme;
|
|
14
|
-
isModern: boolean;
|
|
15
|
-
isDark: boolean;
|
|
16
|
-
className: string;
|
|
17
|
-
}
|
|
18
|
-
declare const useTheme: () => ThemeHookValue;
|
|
12
|
+
declare const useTheme: () => ComponentTheme;
|
|
19
13
|
export type { ComponentTheme };
|
|
20
14
|
export { ThemeProvider, useTheme };
|
package/dist/es/index.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { Children, isValidElement, cloneElement, createContext, useContext
|
|
2
|
+
import { Children, isValidElement, cloneElement, createContext, useContext } from 'react';
|
|
3
3
|
|
|
4
|
-
var modernThemes = ['personal'];
|
|
5
|
-
var darkThemes = [];
|
|
6
4
|
var DEFAULT_COMPONENT_THEME = 'light';
|
|
7
5
|
|
|
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
|
-
|
|
18
6
|
var ThemeContext = /*#__PURE__*/createContext(DEFAULT_COMPONENT_THEME);
|
|
19
7
|
var ThemeProvider = function ThemeProvider(_ref) {
|
|
20
8
|
var _ref$theme = _ref.theme,
|
|
@@ -33,7 +21,7 @@ var ThemeProvider = function ThemeProvider(_ref) {
|
|
|
33
21
|
} // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
34
22
|
|
|
35
23
|
|
|
36
|
-
var classNames = [
|
|
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(' ');
|
|
37
25
|
return /*#__PURE__*/cloneElement(child, {
|
|
38
26
|
className: classNames // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
27
|
|
|
@@ -48,15 +36,7 @@ var ThemeProvider = function ThemeProvider(_ref) {
|
|
|
48
36
|
var useTheme = function useTheme() {
|
|
49
37
|
var _useContext;
|
|
50
38
|
|
|
51
|
-
|
|
52
|
-
return useMemo(function () {
|
|
53
|
-
return {
|
|
54
|
-
theme: theme,
|
|
55
|
-
isModern: isThemeModern(theme),
|
|
56
|
-
isDark: isThemeDark(theme),
|
|
57
|
-
className: getThemeClassName(theme)
|
|
58
|
-
};
|
|
59
|
-
}, [theme]);
|
|
39
|
+
return (_useContext = useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
|
|
60
40
|
};
|
|
61
41
|
|
|
62
42
|
export { ThemeProvider, useTheme };
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/
|
|
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 = [`np-theme-${theme}`, child?.props?.className].filter(Boolean).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 } from 'react';\n\nimport { ThemeContext } from './ThemeProvider';\nimport { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';\n\nexport const useTheme = (): ComponentTheme => {\n return useContext(ThemeContext) ?? DEFAULT_COMPONENT_THEME;\n};\n"],"names":["DEFAULT_COMPONENT_THEME","ThemeContext","createContext","ThemeProvider","theme","children","themedChildren","Children","map","child","isValidElement","process","env","NODE_ENV","console","warn","classNames","props","className","filter","Boolean","join","cloneElement","_jsx","Provider","value","useTheme","useContext"],"mappings":";;;AAIO,IAAMA,uBAAuB,GAAG,OAAhC;;ACAA,IAAMC,YAAY,gBAAGC,aAAa,CAAiBF,uBAAjB,CAAlC,CAAA;AAMMG,IAAAA,aAAa,GAAG,SAAhBA,aAAgB,CAGJ,IAAA,EAAA;AAAA,EAAA,IAAA,UAAA,GAAA,IAAA,CAFvBC,KAEuB;MAFvBA,KAEuB,2BAFfJ,uBAEe,GAAA,UAAA;MADvBK,QACuB,QADvBA,QACuB,CAAA;EACvB,IAAMC,cAAc,GAAGC,QAAQ,CAACC,GAAT,CAAaH,QAAb,EAAuB,UAACI,KAAD,EAAU;AAAA,IAAA,IAAA,YAAA,CAAA;;AACtD,IAAA,IAAI,eAACC,cAAc,CAACD,KAAD,CAAnB,EAA4B;AAC1B,MAAA,IAAIE,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;QACAC,OAAO,CAACC,IAAR,CACE,iGADF,CAAA,CAAA;AAGD,OAAA;;AACD,MAAA,OAAON,KAAP,CAAA;AACD,KATqD;;;IAYtD,IAAMO,UAAU,GAAG,CAAaZ,WAAAA,CAAAA,MAAAA,CAAAA,KAAb,GAAsBK,KAAtB,KAAA,IAAA,IAAsBA,KAAtB,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,CAAA,YAAA,GAAsBA,KAAK,CAAEQ,KAA7B,MAAsB,IAAA,IAAA,YAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,YAAA,CAAcC,SAApC,CAAA,CAA+CC,MAA/C,CAAsDC,OAAtD,CAA+DC,CAAAA,IAA/D,CAAoE,GAApE,CAAnB,CAAA;IAEA,oBAAOC,YAAY,CAACb,KAAD,EAAQ;MACzBS,SAAS,EAAEF,UADc;;AAAA,KAAR,CAAnB,CAAA;AAID,GAlBsB,CAAvB,CAAA;AAoBA,EAAA,OAAOO,GAACtB,CAAAA,YAAY,CAACuB,QAAd,EAAsB;AAACC,IAAAA,KAAK,EAAErB,KAAR;IAAaC,QAAGC,EAAAA,cAAAA;AAAhB,GAAtB,CAAP,CAAA;AACD;;AC9BYoB,IAAAA,QAAQ,GAAG,SAAXA,QAAW,GAAqB;AAAA,EAAA,IAAA,WAAA,CAAA;;AAC3C,EAAA,OAAA,CAAA,WAAA,GAAOC,UAAU,CAAC1B,YAAD,CAAjB,qDAAmCD,uBAAnC,CAAA;AACD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/components-theming",
|
|
3
|
-
"version": "0.1.1
|
|
3
|
+
"version": "0.1.1",
|
|
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": "6fdf7eae7b108f3744d768b79c59e04c68be1e5b"
|
|
47
47
|
}
|
package/src/ThemeProvider.tsx
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { Children, cloneElement, createContext, isValidElement, PropsWithChildren } from 'react';
|
|
3
2
|
|
|
4
3
|
import { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';
|
|
5
|
-
import { getThemeClassName } from './helpers';
|
|
6
4
|
|
|
7
5
|
export const ThemeContext = createContext<ComponentTheme>(DEFAULT_COMPONENT_THEME);
|
|
8
6
|
|
|
@@ -26,9 +24,7 @@ export const ThemeProvider = ({
|
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
29
|
-
const classNames = [
|
|
30
|
-
.filter(Boolean)
|
|
31
|
-
.join(' ');
|
|
27
|
+
const classNames = [`np-theme-${theme}`, child?.props?.className].filter(Boolean).join(' ');
|
|
32
28
|
|
|
33
29
|
return cloneElement(child, {
|
|
34
30
|
className: classNames,
|
package/src/const.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
export const componentThemes = ['light', 'personal'] as const;
|
|
2
|
-
export const modernThemes = ['personal'] as const;
|
|
3
|
-
export const darkThemes = [] as const;
|
|
4
2
|
|
|
5
3
|
export type ComponentTheme = typeof componentThemes[number];
|
|
6
|
-
export type ModernTheme = typeof modernThemes[number];
|
|
7
|
-
export type DarkTheme = typeof darkThemes[number];
|
|
8
4
|
|
|
9
5
|
export const DEFAULT_COMPONENT_THEME = 'light' as const;
|
package/src/useTheme.spec.tsx
CHANGED
|
@@ -9,12 +9,7 @@ describe('useTheme', () => {
|
|
|
9
9
|
result: { current },
|
|
10
10
|
} = renderHook(() => useTheme());
|
|
11
11
|
|
|
12
|
-
expect(current).toStrictEqual(
|
|
13
|
-
theme: 'light',
|
|
14
|
-
isModern: false,
|
|
15
|
-
isDark: false,
|
|
16
|
-
className: 'np-theme-light',
|
|
17
|
-
});
|
|
12
|
+
expect(current).toStrictEqual('light');
|
|
18
13
|
});
|
|
19
14
|
|
|
20
15
|
it('returns provided theme', () => {
|
|
@@ -27,11 +22,6 @@ describe('useTheme', () => {
|
|
|
27
22
|
},
|
|
28
23
|
});
|
|
29
24
|
|
|
30
|
-
expect(current).toStrictEqual(
|
|
31
|
-
className: 'np-theme-personal',
|
|
32
|
-
isDark: false,
|
|
33
|
-
isModern: true,
|
|
34
|
-
theme: 'personal',
|
|
35
|
-
});
|
|
25
|
+
expect(current).toStrictEqual('personal');
|
|
36
26
|
});
|
|
37
27
|
});
|
package/src/useTheme.ts
CHANGED
|
@@ -1,26 +1,8 @@
|
|
|
1
|
-
import { useContext
|
|
1
|
+
import { useContext } 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';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
);
|
|
6
|
+
export const useTheme = (): ComponentTheme => {
|
|
7
|
+
return useContext(ThemeContext) ?? DEFAULT_COMPONENT_THEME;
|
|
26
8
|
};
|
package/src/helpers.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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}`;
|