@wise/components-theming 0.1.1-next-3a766caf8e.2444 → 0.1.1-next-e4db433fcd.2433

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.js CHANGED
@@ -7,46 +7,49 @@ var modernThemes = ['personal'];
7
7
  var darkThemes = [];
8
8
  var DEFAULT_COMPONENT_THEME = 'light';
9
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
-
20
10
  var ThemeContext = /*#__PURE__*/react.createContext(DEFAULT_COMPONENT_THEME);
21
11
  var ThemeProvider = function ThemeProvider(_ref) {
22
12
  var _ref$theme = _ref.theme,
23
- theme = _ref$theme === void 0 ? DEFAULT_COMPONENT_THEME : _ref$theme,
24
- children = _ref.children;
13
+ theme = _ref$theme === void 0 ? DEFAULT_COMPONENT_THEME : _ref$theme,
14
+ children = _ref.children;
25
15
  var themedChildren = react.Children.map(children, function (child) {
26
16
  var _child$props;
17
+
27
18
  if (! /*#__PURE__*/react.isValidElement(child)) {
28
19
  if (process.env.NODE_ENV !== 'production') {
29
20
  // eslint-disable-next-line no-console
30
21
  console.warn('[ThemeProvider] Trying to inject `className` to an invalid React element, this will be skipped!');
31
22
  }
23
+
32
24
  return child;
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(' ');
25
+ } // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
26
+
27
+
28
+ 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(' ');
36
29
  return /*#__PURE__*/react.cloneElement(child, {
37
- className: classNames
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ className: classNames // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+
39
32
  });
40
33
  });
41
-
42
34
  return jsxRuntime.jsx(ThemeContext.Provider, {
43
35
  value: theme,
44
36
  children: themedChildren
45
37
  });
46
38
  };
47
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
+
48
50
  var useTheme = function useTheme() {
49
51
  var _useContext;
52
+
50
53
  var theme = (_useContext = react.useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
51
54
  return react.useMemo(function () {
52
55
  return {
@@ -1 +1 @@
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,C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AA,KAAA,CAAA,GAAA,CAAA,YAAA,GAALA,KAAK,CAAEQ,KAAK,MAAA,IAAA,IAAA,YAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAZ,YAAcC,CAAAA,SAAS,CAAC,CACnEC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,GAAG,CAAC,CAAA;IAEZ,oBAAOC,kBAAY,CAACb,KAAK,EAAE;AACzBS,MAAAA,SAAS,EAAEF,UAAAA;AACX;KACM,CAAC,CAAA;AACX,GAAC,CAAC,CAAA;;EAEF,OAAOO,cAAAA,CAACrB,YAAY,CAACsB,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAE3B,KAAK;IAAAO,QAAGC,EAAAA,cAAAA;GAAuC,CAAA,CAAA;AACtF;;AC1BaoB,IAAAA,QAAQ,GAAG,SAAXA,QAAQ,GAAwB;AAAA,EAAA,IAAA,WAAA,CAAA;AAC3C,EAAA,IAAM5B,KAAK,GAAG6B,CAAAA,WAAAA,GAAAA,gBAAU,CAACzB,YAAY,CAAC,qDAAIN,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;;;;;"}
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,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,C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a,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/dist/es/index.js CHANGED
@@ -5,46 +5,49 @@ var modernThemes = ['personal'];
5
5
  var darkThemes = [];
6
6
  var DEFAULT_COMPONENT_THEME = 'light';
7
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
-
18
8
  var ThemeContext = /*#__PURE__*/createContext(DEFAULT_COMPONENT_THEME);
19
9
  var ThemeProvider = function ThemeProvider(_ref) {
20
10
  var _ref$theme = _ref.theme,
21
- theme = _ref$theme === void 0 ? DEFAULT_COMPONENT_THEME : _ref$theme,
22
- children = _ref.children;
11
+ theme = _ref$theme === void 0 ? DEFAULT_COMPONENT_THEME : _ref$theme,
12
+ children = _ref.children;
23
13
  var themedChildren = Children.map(children, function (child) {
24
14
  var _child$props;
15
+
25
16
  if (! /*#__PURE__*/isValidElement(child)) {
26
17
  if (process.env.NODE_ENV !== 'production') {
27
18
  // eslint-disable-next-line no-console
28
19
  console.warn('[ThemeProvider] Trying to inject `className` to an invalid React element, this will be skipped!');
29
20
  }
21
+
30
22
  return child;
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(' ');
23
+ } // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
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(' ');
34
27
  return /*#__PURE__*/cloneElement(child, {
35
- className: classNames
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ className: classNames // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+
37
30
  });
38
31
  });
39
-
40
32
  return jsx(ThemeContext.Provider, {
41
33
  value: theme,
42
34
  children: themedChildren
43
35
  });
44
36
  };
45
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
+
46
48
  var useTheme = function useTheme() {
47
49
  var _useContext;
50
+
48
51
  var theme = (_useContext = useContext(ThemeContext)) !== null && _useContext !== void 0 ? _useContext : DEFAULT_COMPONENT_THEME;
49
52
  return useMemo(function () {
50
53
  return {
@@ -1 +1 @@
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,YA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KAAK,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,CAAA,YAAA,GAALA,KAAK,CAAEQ,KAAK,MAAA,IAAA,IAAA,YAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAZ,YAAcC,CAAAA,SAAS,CAAC,CACnEC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,GAAG,CAAC,CAAA;IAEZ,oBAAOC,YAAY,CAACb,KAAK,EAAE;AACzBS,MAAAA,SAAS,EAAEF,UAAAA;AACX;KACM,CAAC,CAAA;AACX,GAAC,CAAC,CAAA;;EAEF,OAAOO,GAAAA,CAACrB,YAAY,CAACsB,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAE3B,KAAK;IAAAO,QAAGC,EAAAA,cAAAA;GAAuC,CAAA,CAAA;AACtF;;AC1BaoB,IAAAA,QAAQ,GAAG,SAAXA,QAAQ,GAAwB;AAAA,EAAA,IAAA,WAAA,CAAA;AAC3C,EAAA,IAAM5B,KAAK,GAAG6B,CAAAA,WAAAA,GAAAA,UAAU,CAACzB,YAAY,CAAC,qDAAIN,uBAAuB,CAAA;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;;;;"}
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,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,K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AQ,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-next-3a766caf8e.2444+3a766caf8e",
3
+ "version": "0.1.1-next-e4db433fcd.2433+e4db433fcd",
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": "3a766caf8e66ce724ef128c99cbf11cbc890c3b3"
46
+ "gitHead": "e4db433fcd77d4458ac255860df2945983800984"
47
47
  }
@@ -1,4 +1,3 @@
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';
@@ -26,9 +25,7 @@ export const ThemeProvider = ({
26
25
  }
27
26
 
28
27
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
29
- const classNames = [getThemeClassName(theme), child?.props?.className]
30
- .filter(Boolean)
31
- .join(' ');
28
+ const classNames = [`np-theme-${theme}`, child?.props?.className].filter(Boolean).join(' ');
32
29
 
33
30
  return cloneElement(child, {
34
31
  className: classNames,