@wise/components-theming 1.2.0 → 1.2.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.
@@ -1,7 +1,7 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import type { ScreenMode, Theming } from './const';
3
3
  export declare const ThemeContext: import("react").Context<{
4
- theme: Theming['theme'];
4
+ theme: NonNullable<Theming['theme']>;
5
5
  screenMode: ScreenMode;
6
6
  } | undefined>;
7
7
  type ThemeProviderProps = PropsWithChildren<Theming> & {
@@ -1 +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,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAInD,eAAO,MAAM,YAAY;WAEZ,OAAO,CAAC,OAAO,CAAC;gBACX,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"}
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,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAInD,eAAO,MAAM,YAAY;WAEZ,YAAY,OAAO,CAAC,OAAO,CAAC,CAAC;gBACxB,UAAU;cAGhB,CAAC;AAEb,KAAK,kBAAkB,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAK9E,eAAO,MAAM,aAAa,mEAMvB,kBAAkB,gCAyBpB,CAAC"}
package/dist/index.js CHANGED
@@ -79,6 +79,8 @@ const ThemedChildren = ({
79
79
  };
80
80
 
81
81
  const ThemeContext = /*#__PURE__*/react.createContext(undefined);
82
+ // RegEx to check for `np-theme-` class name
83
+ const themeClass = /\bnp-theme-[a-z-]+\b/g;
82
84
  const ThemeProvider = ({
83
85
  theme = DEFAULT_BASE_THEME,
84
86
  screenMode = DEFAULT_SCREEN_MODE,
@@ -87,9 +89,6 @@ const ThemeProvider = ({
87
89
  className = undefined
88
90
  }) => {
89
91
  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
92
  // useEffect hook used to apply the theme class to the HTML element
94
93
  react.useEffect(() => {
95
94
  if (!isNotRootProvider && isContextRoot) {
@@ -101,7 +100,7 @@ const ThemeProvider = ({
101
100
  document.documentElement.classList.add(item);
102
101
  });
103
102
  }
104
- }, [isNotRootProvider, isContextRoot, theme, screenMode, themeClass]);
103
+ }, [isNotRootProvider, isContextRoot, theme, screenMode]);
105
104
  const contextValue = react.useMemo(() => ({
106
105
  theme,
107
106
  screenMode
package/dist/index.js.map CHANGED
@@ -1 +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","isExtraTheme","isForestGreenTheme","theme","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,CA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AAAO,CAAA;AAAAf,EAAAA,KAAA,GAAAN,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
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;\nexport const platformThemes = ['platform', 'platform--forest-green'] 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];\nexport type PlatformTheme = (typeof platformThemes)[0];\nexport type PlatformForestGreenTheme = (typeof platformThemes)[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 | PlatformTheme | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\n isNotRootProvider?: boolean | undefined;\n};\n","import type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (theme: Theming['theme']): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isExtraTheme = (theme: Theming['theme']): theme is ExtraTheme =>\n extraThemes.includes(theme as ExtraTheme);\n\nexport const isForestGreenTheme = (theme: Theming['theme']): theme is ForestGreenTheme =>\n theme === extraThemes[0];\n\nexport const isScreenModeDark = (\n theme: Theming['theme'],\n screenMode: ScreenMode,\n): screenMode is ScreenModeDark =>\n isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;\n\nexport const getThemeClassName = (theme: Theming['theme'], screenMode: ScreenMode) => {\n if (!isThemeModern(theme)) {\n return `np-theme-${theme || 'personal'}`;\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 { ScreenMode, Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { isThemeModern, isForestGreenTheme, isScreenModeDark, getThemeClassName } from './helpers';\n\ninterface ThemeHookValue {\n theme: Theming['theme'];\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 { 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: NonNullable<Theming['theme']>;\n screenMode: ScreenMode;\n }\n | undefined\n>(undefined);\n\ntype ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };\n\n// RegEx to check for `np-theme-` class name\nconst themeClass = /\\bnp-theme-[a-z-]+\\b/g;\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 // 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]);\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","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE","isThemeModern","theme","includes","isExtraTheme","isForestGreenTheme","isScreenModeDark","screenMode","getThemeClassName","classes","FALLBACK_VALUES","isNotProduction","window","location","hostname","useTheme","theming","useContext","ThemeContext","console","warn","contextScreenMode","useMemo","isModern","className","ThemedChildren","undefined","children","themeClass","_jsx","classNames","createContext","ThemeProvider","isNotRootProvider","isContextRoot","useEffect","document","documentElement","match","forEach","item","classList","remove","split","add","contextValue","Provider","value"],"mappings":";;;;;;;;;;AAAA;AACO,MAAMA,UAAU,GAAG,CAAC,OAAO,EAAE,UAAU,CAAU,CAAA;AACjD,MAAMC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc,CAAU,CAAA;AAC7D,MAAMC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,CAAU,CAAA;AAC9C,MAAMC,YAAY,GAAG,CAACH,UAAU,CAAC,CAAC,CAAC,EAAE,GAAGC,WAAW,CAAU,CAAA;AAc7D,MAAMG,kBAAkB,GAAG,OAAgB,CAAA;AAC3C,MAAMC,mBAAmB,GAAG,OAAgB;;ACT5C,MAAMC,aAAa,GAAIC,KAAuB,IACnDJ,YAAY,CAACK,QAAQ,CAACD,KAAoB,EAAC;AAEtC,MAAME,YAAY,GAAIF,KAAuB,IAClDN,WAAW,CAACO,QAAQ,CAACD,KAAmB,EAAC;AAEpC,MAAMG,kBAAkB,GAAIH,KAAuB,IACxDA,KAAK,KAAKN,WAAW,CAAC,CAAC,EAAC;MAEbU,gBAAgB,GAAGA,CAC9BJ,KAAuB,EACvBK,UAAsB,KAEtBN,aAAa,CAACC,KAAoB,CAAC,IAAIL,WAAW,CAAC,CAA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egEx to check for `np-theme-` class name
77
+ const themeClass = /\bnp-theme-[a-z-]+\b/g;
76
78
  const ThemeProvider = ({
77
79
  theme = DEFAULT_BASE_THEME,
78
80
  screenMode = DEFAULT_SCREEN_MODE,
@@ -81,9 +83,6 @@ const ThemeProvider = ({
81
83
  className = undefined
82
84
  }) => {
83
85
  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
86
  // useEffect hook used to apply the theme class to the HTML element
88
87
  useEffect(() => {
89
88
  if (!isNotRootProvider && isContextRoot) {
@@ -95,7 +94,7 @@ const ThemeProvider = ({
95
94
  document.documentElement.classList.add(item);
96
95
  });
97
96
  }
98
- }, [isNotRootProvider, isContextRoot, theme, screenMode, themeClass]);
97
+ }, [isNotRootProvider, isContextRoot, theme, screenMode]);
99
98
  const contextValue = useMemo(() => ({
100
99
  theme,
101
100
  screenMode
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","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","isExtraTheme","isForestGreenTheme","theme","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;AAClB,MAAAC,YA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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","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;\nexport const platformThemes = ['platform', 'platform--forest-green'] 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];\nexport type PlatformTheme = (typeof platformThemes)[0];\nexport type PlatformForestGreenTheme = (typeof platformThemes)[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 | PlatformTheme | PlatformForestGreenTheme;\n screenMode?: ScreenMode;\n isNotRootProvider?: boolean | undefined;\n};\n","import type {\n ModernTheme,\n ExtraTheme,\n ForestGreenTheme,\n ScreenMode,\n ScreenModeDark,\n Theming,\n} from './const';\nimport { extraThemes, screenModes, modernThemes } from './const';\n\nexport const isThemeModern = (theme: Theming['theme']): theme is ModernTheme =>\n modernThemes.includes(theme as ModernTheme);\n\nexport const isExtraTheme = (theme: Theming['theme']): theme is ExtraTheme =>\n extraThemes.includes(theme as ExtraTheme);\n\nexport const isForestGreenTheme = (theme: Theming['theme']): theme is ForestGreenTheme =>\n theme === extraThemes[0];\n\nexport const isScreenModeDark = (\n theme: Theming['theme'],\n screenMode: ScreenMode,\n): screenMode is ScreenModeDark =>\n isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;\n\nexport const getThemeClassName = (theme: Theming['theme'], screenMode: ScreenMode) => {\n if (!isThemeModern(theme)) {\n return `np-theme-${theme || 'personal'}`;\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 { ScreenMode, Theming } from './const';\nimport { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';\nimport { isThemeModern, isForestGreenTheme, isScreenModeDark, getThemeClassName } from './helpers';\n\ninterface ThemeHookValue {\n theme: Theming['theme'];\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 { 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: NonNullable<Theming['theme']>;\n screenMode: ScreenMode;\n }\n | undefined\n>(undefined);\n\ntype ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };\n\n// RegEx to check for `np-theme-` class name\nconst themeClass = /\\bnp-theme-[a-z-]+\\b/g;\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 // 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]);\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","DEFAULT_BASE_THEME","DEFAULT_SCREEN_MODE","isThemeModern","theme","includes","isExtraTheme","isForestGreenTheme","isScreenModeDark","screenMode","getThemeClassName","classes","FALLBACK_VALUES","isNotProduction","window","location","hostname","useTheme","theming","useContext","ThemeContext","console","warn","contextScreenMode","useMemo","isModern","className","ThemedChildren","undefined","children","themeClass","_jsx","classNames","createContext","ThemeProvider","isNotRootProvider","isContextRoot","useEffect","document","documentElement","match","forEach","item","classList","remove","split","add","contextValue","Provider","value"],"mappings":";;;;AAAA;AACO,MAAMA,UAAU,GAAG,CAAC,OAAO,EAAE,UAAU,CAAU,CAAA;AACjD,MAAMC,WAAW,GAAG,CAAC,cAAc,EAAE,cAAc,CAAU,CAAA;AAC7D,MAAMC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,CAAU,CAAA;AAC9C,MAAMC,YAAY,GAAG,CAACH,UAAU,CAAC,CAAC,CAAC,EAAE,GAAGC,WAAW,CAAU,CAAA;AAc7D,MAAMG,kBAAkB,GAAG,OAAgB,CAAA;AAC3C,MAAMC,mBAAmB,GAAG,OAAgB;;ACT5C,MAAMC,aAAa,GAAIC,KAAuB,IACnDJ,YAAY,CAACK,QAAQ,CAACD,KAAoB,EAAC;AAEtC,MAAME,YAAY,GAAIF,KAAuB,IAClDN,WAAW,CAACO,QAAQ,CAACD,KAAmB,EAAC;AAEpC,MAAMG,kBAAkB,GAAIH,KAAuB,IACxDA,KAAK,KAAKN,WAAW,CAAC,CAAC,EAAC;MAEbU,gBAAgB,GAAGA,CAC9BJ,KAAuB,EACvBK,UAAsB,KAEtBN,aAAa,CAACC,KAAoB,CAAC,IAAIL,WAAW,CAAC,CAAC,CAAC,KAAKU,WAAU;MAEzDC,iBAAiB,GAAGA,CAACN,KAAuB,EAAEK,UAAsB,KAAI;AACnF,EAAA,IAAI,CAACN,aAAa,CAACC,KAAK,CAAC,EAAE;AACzB,IAAA,OAAmB,CAAAA,SAAAA,EAAAA,KAAK,IAAI,WAA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eAAe,CAACb,SAAS,CAACc,KAAK,CAACV,UAAU,CAAC,EAAEW,OAAO,CAAEC,IAAI,IAAI;QACrEJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACC,MAAM,CAACF,IAAI,CAAC,CAAA;AACjD,OAAC,CAAC,CAAA;AACFhC,MAAAA,iBAAiB,CAACN,KAAK,EAAEK,UAAU,CAAC,CACjCoC,KAAK,CAAC,GAAG,CAAC,CACVJ,OAAO,CAAEC,IAAI,IAAI;QAChBJ,QAAQ,CAACC,eAAe,CAACI,SAAS,CAACG,GAAG,CAACJ,IAAI,CAAC,CAAA;AAC9C,OAAC,CAAC,CAAA;AACL,KAAA;GACF,EAAE,CAACP,iBAAiB,EAAEC,aAAa,EAAEhC,KAAK,EAAEK,UAAU,CAAC,CAAC,CAAA;AAEzD,EAAA,MAAMsC,YAAY,GAAGvB,OAAO,CAAC,OAAO;IAAEpB,KAAK;AAAEK,IAAAA,UAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEL,KAAK,CAAC,CAAC,CAAA;AAEhF,EAAA,oBACE2B,GAAA,CAACX,YAAY,CAAC4B,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAEF,YAAa;IAAAlB,QAAA,eACzCE,GAAA,CAACJ,cAAc,EAAA;AAACD,MAAAA,SAAS,EAAEA,SAAU;AAAAG,MAAAA,QAAA,EAAEA,QAAAA;KAAyB,CAAA;AAClE,GAAuB,CAAC,CAAA;AAE5B;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/components-theming",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Provides theming support for the Wise Design system components",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -12,32 +12,31 @@
12
12
  "url": "git+https://github.com/transferwise/neptune-web.git"
13
13
  },
14
14
  "dependencies": {
15
- "@babel/runtime": "^7.22.15",
16
- "classnames": "^2.3.2"
15
+ "@babel/runtime": "^7.24.5",
16
+ "classnames": "^2.5.1"
17
17
  },
18
18
  "devDependencies": {
19
- "@babel/core": "^7.23.9",
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",
26
- "@testing-library/jest-dom": "^5.14.1",
27
- "@testing-library/react": "^12.0.0",
28
- "@testing-library/react-hooks": "^8.0.0",
29
- "@tsconfig/recommended": "^1.0.2",
30
- "@types/babel__core": "^7.20.1",
19
+ "@babel/core": "^7.24.5",
20
+ "@babel/plugin-transform-runtime": "^7.24.3",
21
+ "@babel/preset-env": "^7.24.5",
22
+ "@babel/preset-react": "^7.24.1",
23
+ "@babel/preset-typescript": "^7.24.1",
24
+ "@rollup/plugin-babel": "^6.0.4",
25
+ "@rollup/plugin-typescript": "^11.1.6",
26
+ "@testing-library/jest-dom": "^5.17.0",
27
+ "@testing-library/react": "^12.1.5",
28
+ "@testing-library/react-hooks": "^8.0.1",
29
+ "@tsconfig/recommended": "^1.0.6",
30
+ "@types/babel__core": "^7.20.5",
31
31
  "@types/jest": "^29.5.12",
32
- "@types/node": "^18.15.12",
33
- "@types/react": "^17.0.65",
34
- "@types/react-dom": "^17.0.20",
35
- "@types/testing-library__jest-dom": "^5.14.5",
36
- "classnames": "^2.3.2",
32
+ "@types/react": "^17.0.80",
33
+ "@types/react-dom": "^17.0.25",
34
+ "@types/testing-library__jest-dom": "^5.14.9",
35
+ "classnames": "^2.5.1",
37
36
  "jest": "^29.7.0",
38
37
  "jest-environment-jsdom": "^29.7.0",
39
- "rollup": "^3.28.1",
40
- "typescript": "4.9.4"
38
+ "rollup": "^4.17.2",
39
+ "typescript": "4.9.5"
41
40
  },
42
41
  "peerDependencies": {
43
42
  "react": ">=16.14",
@@ -7,7 +7,7 @@ import { getThemeClassName } from './helpers';
7
7
 
8
8
  export const ThemeContext = createContext<
9
9
  | {
10
- theme: Theming['theme'];
10
+ theme: NonNullable<Theming['theme']>;
11
11
  screenMode: ScreenMode;
12
12
  }
13
13
  | undefined
@@ -15,6 +15,9 @@ export const ThemeContext = createContext<
15
15
 
16
16
  type ThemeProviderProps = PropsWithChildren<Theming> & { className?: string };
17
17
 
18
+ // RegEx to check for `np-theme-` class name
19
+ const themeClass = /\bnp-theme-[a-z-]+\b/g;
20
+
18
21
  export const ThemeProvider = ({
19
22
  theme = DEFAULT_BASE_THEME,
20
23
  screenMode = DEFAULT_SCREEN_MODE,
@@ -24,10 +27,6 @@ export const ThemeProvider = ({
24
27
  }: ThemeProviderProps) => {
25
28
  const isContextRoot = useContext(ThemeContext) === undefined;
26
29
 
27
- // RegEx to check for `np-theme-` class name
28
- // eslint-disable-next-line react-hooks/exhaustive-deps
29
- const themeClass = new RegExp(/\bnp-theme-[a-z-]+\b/, 'g');
30
-
31
30
  // useEffect hook used to apply the theme class to the HTML element
32
31
  useEffect(() => {
33
32
  if (!isNotRootProvider && isContextRoot) {
@@ -41,7 +40,7 @@ export const ThemeProvider = ({
41
40
  document.documentElement.classList.add(item);
42
41
  });
43
42
  }
44
- }, [isNotRootProvider, isContextRoot, theme, screenMode, themeClass]);
43
+ }, [isNotRootProvider, isContextRoot, theme, screenMode]);
45
44
 
46
45
  const contextValue = useMemo(() => ({ theme, screenMode }), [screenMode, theme]);
47
46