@wise/components-theming 0.1.1 → 0.1.2-next-b582ce3e07.2570

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 CHANGED
@@ -3,6 +3,7 @@
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
+
6
7
  ## [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
 
8
9
 
@@ -14,6 +15,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
14
15
 
15
16
 
16
17
 
18
+
17
19
  # 0.1.0 (2022-11-02)
18
20
 
19
21
 
@@ -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
- declare const useTheme: () => ComponentTheme;
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,6 +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 = [];
6
8
  var DEFAULT_COMPONENT_THEME = 'light';
7
9
 
8
10
  var ThemeContext = /*#__PURE__*/react.createContext(DEFAULT_COMPONENT_THEME);
@@ -35,10 +37,28 @@ var ThemeProvider = function ThemeProvider(_ref) {
35
37
  });
36
38
  };
37
39
 
40
+ var isThemeModern = function isThemeModern(theme) {
41
+ return modernThemes.includes(theme);
42
+ };
43
+ var isThemeDark = function isThemeDark(theme) {
44
+ return darkThemes.includes(theme);
45
+ };
46
+ var getThemeClassName = function getThemeClassName(theme) {
47
+ return "np-theme-".concat(theme);
48
+ };
49
+
38
50
  var useTheme = function useTheme() {
39
51
  var _useContext;
40
52
 
41
- return (_useContext = react.useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
53
+ var theme = (_useContext = react.useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
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]);
42
62
  };
43
63
 
44
64
  exports.ThemeProvider = ThemeProvider;
@@ -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 = [`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;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/ThemeProvider.tsx","../../src/helpers.ts","../../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 { 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 = [`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 { 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 { 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","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","isThemeModern","includes","isThemeDark","getThemeClassName","useTheme","useContext","useMemo","isModern","isDark"],"mappings":";;;;;AACO,IAAMA,YAAY,GAAG,CAAC,UA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AACuB,QAAd,EAAsB;AAACC,IAAAA,KAAK,EAAErB,KAAR;IAAaC,QAAGC,EAAAA,cAAAA;AAAhB,GAAtB,CAAP,CAAA;AACD;;AClCM,IAAMoB,aAAa,GAAG,SAAhBA,aAAgB,CAACtB,KAAD,EAAA;AAAA,EAAA,OAC3BN,YAAY,CAAC6B,QAAb,CAAsBvB,KAAtB,CAD2B,CAAA;AAAA,CAAtB,CAAA;AAGA,IAAMwB,WAAW,GAAG,SAAdA,WAAc,CAACxB,KAAD,EAAA;AAAA,EAAA,OACzBL,UAAU,CAAC4B,QAAX,CAAoBvB,KAApB,CADyB,CAAA;AAAA,CAApB,CAAA;AAGA,IAAMyB,iBAAiB,GAAG,SAApBA,iBAAoB,CAACzB,KAAD,EAAA;AAAA,EAAA,OAAA,WAAA,CAAA,MAAA,CAAuCA,KAAvC,CAAA,CAAA;AAAA,CAA1B;;ACKM0B,IAAAA,QAAQ,GAAG,SAAXA,QAAW,GAAqB;AAAA,EAAA,IAAA,WAAA,CAAA;;AAC3C,EAAA,IAAM1B,KAAK,GAAG2B,CAAAA,WAAAA,GAAAA,gBAAU,CAAC9B,YAAD,CAAb,qDAA+BD,uBAA1C,CAAA;AAEA,EAAA,OAAOgC,aAAO,CACZ,YAAA;IAAA,OAAO;AACL5B,MAAAA,KAAK,EAALA,KADK;AAEL6B,MAAAA,QAAQ,EAAEP,aAAa,CAACtB,KAAD,CAFlB;AAGL8B,MAAAA,MAAM,EAAEN,WAAW,CAACxB,KAAD,CAHd;MAILc,SAAS,EAAEW,iBAAiB,CAACzB,KAAD,CAAA;KAJ9B,CAAA;AAAA,GADY,EAOZ,CAACA,KAAD,CAPY,CAAd,CAAA;AASD;;;;;"}
@@ -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
- declare const useTheme: () => ComponentTheme;
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,6 +1,8 @@
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
 
6
8
  var ThemeContext = /*#__PURE__*/createContext(DEFAULT_COMPONENT_THEME);
@@ -33,10 +35,28 @@ var ThemeProvider = function ThemeProvider(_ref) {
33
35
  });
34
36
  };
35
37
 
38
+ var isThemeModern = function isThemeModern(theme) {
39
+ return modernThemes.includes(theme);
40
+ };
41
+ var isThemeDark = function isThemeDark(theme) {
42
+ return darkThemes.includes(theme);
43
+ };
44
+ var getThemeClassName = function getThemeClassName(theme) {
45
+ return "np-theme-".concat(theme);
46
+ };
47
+
36
48
  var useTheme = function useTheme() {
37
49
  var _useContext;
38
50
 
39
- return (_useContext = useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
51
+ var theme = (_useContext = useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
52
+ return useMemo(function () {
53
+ return {
54
+ theme: theme,
55
+ isModern: isThemeModern(theme),
56
+ isDark: isThemeDark(theme),
57
+ className: getThemeClassName(theme)
58
+ };
59
+ }, [theme]);
40
60
  };
41
61
 
42
62
  export { ThemeProvider, useTheme };
@@ -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 = [`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,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,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/ThemeProvider.tsx","../../src/helpers.ts","../../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 { 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 = [`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 { 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 { 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","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","isThemeModern","includes","isThemeDark","getThemeClassName","useTheme","useContext","useMemo","isModern","isDark"],"mappings":";;;AACO,IAAMA,YAAY,GAAG,CAAC,UAAD,CAArB,CAAA;AACA,IAAMC,UAAU,GAAG,EAAnB,CAAA;AAMA,IAAMC,uBAAuB,GAAG,OAAhC;;ACHA,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,OA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AAA,IAAA,WAAA,CAAA;;AAC3C,EAAA,IAAM1B,KAAK,GAAG2B,CAAAA,WAAAA,GAAAA,UAAU,CAAC9B,YAAD,CAAb,qDAA+BD,uBAA1C,CAAA;AAEA,EAAA,OAAOgC,OAAO,CACZ,YAAA;IAAA,OAAO;AACL5B,MAAAA,KAAK,EAALA,KADK;AAEL6B,MAAAA,QAAQ,EAAEP,aAAa,CAACtB,KAAD,CAFlB;AAGL8B,MAAAA,MAAM,EAAEN,WAAW,CAACxB,KAAD,CAHd;MAILc,SAAS,EAAEW,iBAAiB,CAACzB,KAAD,CAAA;KAJ9B,CAAA;AAAA,GADY,EAOZ,CAACA,KAAD,CAPY,CAAd,CAAA;AASD;;;;"}
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.2-next-b582ce3e07.2570+b582ce3e07",
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": "6fdf7eae7b108f3744d768b79c59e04c68be1e5b"
46
+ "gitHead": "b582ce3e07402bfc8387a141d6a77bf6f3539ba2"
47
47
  }
@@ -1,6 +1,7 @@
1
1
  import { Children, cloneElement, createContext, isValidElement, PropsWithChildren } from 'react';
2
2
 
3
3
  import { ComponentTheme, DEFAULT_COMPONENT_THEME } from './const';
4
+ import { getThemeClassName } from './helpers';
4
5
 
5
6
  export const ThemeContext = createContext<ComponentTheme>(DEFAULT_COMPONENT_THEME);
6
7
 
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}`;
@@ -9,7 +9,12 @@ describe('useTheme', () => {
9
9
  result: { current },
10
10
  } = renderHook(() => useTheme());
11
11
 
12
- expect(current).toStrictEqual('light');
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('personal');
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
- export const useTheme = (): ComponentTheme => {
7
- return useContext(ThemeContext) ?? DEFAULT_COMPONENT_THEME;
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
  };