@wise/components-theming 1.1.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
- import type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';
2
+ import type { ScreenMode, Theming } from './const';
3
3
  export declare const ThemeContext: import("react").Context<{
4
- theme: ComponentTheme | BaseTheme | ExtraTheme;
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,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAI1F,eAAO,MAAM,YAAY;WAEZ,cAAc,GAAG,SAAS,GAAG,UAAU;gBAClC,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/const.d.ts CHANGED
@@ -2,6 +2,7 @@ export declare const baseThemes: readonly ["light", "personal"];
2
2
  export declare const extraThemes: readonly ["forest-green", "bright-green"];
3
3
  export declare const screenModes: readonly ["light", "dark"];
4
4
  export declare const modernThemes: readonly ["personal", "forest-green", "bright-green"];
5
+ export declare const platformThemes: readonly ["platform", "platform--forest-green"];
5
6
  export type ComponentTheme = (typeof baseThemes)[number];
6
7
  export type ModernTheme = (typeof modernThemes)[number];
7
8
  export type BaseTheme = (typeof baseThemes)[number];
@@ -9,10 +10,12 @@ export type ExtraTheme = (typeof extraThemes)[number];
9
10
  export type ForestGreenTheme = (typeof extraThemes)[0];
10
11
  export type ScreenMode = (typeof screenModes)[number];
11
12
  export type ScreenModeDark = (typeof screenModes)[1];
13
+ export type PlatformTheme = (typeof platformThemes)[0];
14
+ export type PlatformForestGreenTheme = (typeof platformThemes)[1];
12
15
  export declare const DEFAULT_BASE_THEME: "light";
13
16
  export declare const DEFAULT_SCREEN_MODE: "light";
14
17
  export type Theming = {
15
- theme?: ComponentTheme | BaseTheme | ExtraTheme;
18
+ theme?: ComponentTheme | BaseTheme | ExtraTheme | PlatformTheme | PlatformForestGreenTheme;
16
19
  screenMode?: ScreenMode;
17
20
  isNotRootProvider?: boolean | undefined;
18
21
  };
@@ -1 +1 @@
1
- {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,gCAAiC,CAAC;AACzD,eAAO,MAAM,WAAW,2CAA4C,CAAC;AACrE,eAAO,MAAM,WAAW,4BAA6B,CAAC;AACtD,eAAO,MAAM,YAAY,uDAA2C,CAAC;AAGrE,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,UAAU,CAAC,CA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,CAAC,MAAM,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAElE,eAAO,MAAM,kBAAkB,SAAmB,CAAC;AACnD,eAAO,MAAM,mBAAmB,SAAmB,CAAC;AAEpD,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,aAAa,GAAG,wBAAwB,CAAC;IAC3F,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACzC,CAAC"}
package/dist/helpers.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode } from './const';
2
- export declare const isThemeModern: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "personal" | "forest-green" | "bright-green";
3
- export declare const isExtraTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green" | "bright-green";
4
- export declare const isForestGreenTheme: (theme: ComponentTheme | BaseTheme | ExtraTheme) => theme is "forest-green";
5
- export declare const isScreenModeDark: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => screenMode is "dark";
6
- export declare const getThemeClassName: (theme: ComponentTheme | BaseTheme | ExtraTheme, screenMode: ScreenMode) => string;
1
+ import type { ScreenMode, Theming } from './const';
2
+ export declare const isThemeModern: (theme: Theming['theme']) => theme is "personal" | "forest-green" | "bright-green";
3
+ export declare const isExtraTheme: (theme: Theming['theme']) => theme is "forest-green" | "bright-green";
4
+ export declare const isForestGreenTheme: (theme: Theming['theme']) => theme is "forest-green";
5
+ export declare const isScreenModeDark: (theme: Theming['theme'], screenMode: ScreenMode) => screenMode is "dark";
6
+ export declare const getThemeClassName: (theme: Theming['theme'], screenMode: ScreenMode) => string;
7
7
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,SAAS,EACT,UAAU,EAEV,UAAU,EAEX,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,aAAa,UACjB,cAAc,GAAG,SAAS,GAAG,UAAU,0DACsB,CAAC;AAEvE,eAAO,MAAM,YAAY,UAAW,cAAc,GAAG,SAAS,GAAG,UAAU,6CAChC,CAAC;AAE5C,eAAO,MAAM,kBAAkB,UACtB,cAAc,GAAG,SAAS,GAAG,UAAU,4BACQ,CAAC;AAEzD,eAAO,MAAM,gBAAgB,UACpB,cAAc,GAAG,SAAS,GAAG,UAAU,cAClC,UAAU,yBAE8C,CAAC;AAEvE,eAAO,MAAM,iBAAiB,UACrB,cAAc,GAAG,SAAS,GAAG,UAAU,cAClC,UAAU,WAevB,CAAC"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,UAAU,EAEV,OAAO,EACR,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,aAAa,UAAW,OAAO,CAAC,OAAO,CAAC,0DACR,CAAC;AAE9C,eAAO,MAAM,YAAY,UAAW,OAAO,CAAC,OAAO,CAAC,6CACT,CAAC;AAE5C,eAAO,MAAM,kBAAkB,UAAW,OAAO,CAAC,OAAO,CAAC,4BAChC,CAAC;AAE3B,eAAO,MAAM,gBAAgB,UACpB,OAAO,CAAC,OAAO,CAAC,cACX,UAAU,yBAE8C,CAAC;AAEvE,eAAO,MAAM,iBAAiB,UAAW,OAAO,CAAC,OAAO,CAAC,cAAc,UAAU,WAchF,CAAC"}
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ const isForestGreenTheme = theme => theme === extraThemes[0];
22
22
  const isScreenModeDark = (theme, screenMode) => isThemeModern(theme) && screenModes[1] === screenMode;
23
23
  const getThemeClassName = (theme, screenMode) => {
24
24
  if (!isThemeModern(theme)) {
25
- return `np-theme-${theme}`;
25
+ return `np-theme-${theme || 'personal'}`;
26
26
  }
27
27
  let classes = `np-theme-personal`;
28
28
  if (isExtraTheme(theme)) {
@@ -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","theme","isExtraTheme","isForestGreenTheme","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;AAGnB,MAAoBC,YAAA,GAAA,CAAGH,kBAAkBC,WAAU,CAAA,CAAA;AACnD,MAAiBG,kBAAI,GAAO;AAC5B,MAAeC,mBAAW,UAAU;;ACEnC,MAAAC,qBACE,IAAAH,YAAA,CAAAI,QAAiB,CAASC,KAAA,EAAA;AAG5B,MAAAC,oBAA6B,IAAAR,WAAA,CAAAM,SAAiBC,KAAS,EAAA;AAGvD,MAAAE,0BACE,IAAAF,KAAA,KAAAP,WAAiB,CAAS,CAAA,EAAA;MAG5BU,gBAAsB,GAAAA,CAAAH,KAAA,EAAAI,UACN,KAAAN,aAAY,CAAAE,KAAA,CAAA,IAAaN,WAAA,CAAA,CAAA,CAAA,KAAAU,WACxB;MAIjBC,iBAAuB,GAAAA,CAAAL,KAAA,EAAAI,UACP,KAAA;;;;;;;;;;;;;MCnBbE,eAAS,GAAC;AAClBN,EAAAA,KAAkB,EAAAJ;AAClBQ,EAAAA,UAAgB,EAAAP,mBAAAA;;AAEjB,MAAAU,eAAA,GAAAA,MAAA;EAeD,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;ACxBsC,MAAAC,cAAU,GAAAA,CAAA;AAAAC,EAAAA,SAAA,GAAAC,SAAA;AAAAC,EAAAA,QAAAA;AAAA,CAAA,KAAA;EAAC,MAAQ;AAAAF,IAAAA,WAAWG,UAAAA;GAAA,GAAAC,QAAA,EAAA,CAAA;AAAG,EAAA,oBAAAC,cAAA,CAAA,KAAA,EAAA;AAAAL,IAAAA,SAAA,EAAAM,2BAAA,CAAAH,UAAA,EAAAH,SAAA,CAAA;AAAAE,IAAAA,QAAA,EAAAA,QAAAA;AAAA,GAAA,CAAA,CAAA;AAEvE,CAAA;;kBCG4B,gBAAAK,mBAAA,CAAAN,SAAA,CAAA,CAAA;mBAGf,GAAAO,CAAA;AAAAjB,EAAAA,KAAA,GAAAJ,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,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C,OAAO;IAAEpB,KAAK;AAAEK,IAAAA,UAAAA;AAAU,GAAE,CAAC,EAAE,CAACA,UAAU,EAAEL,KAAK,CAAC,CAAC,CAAA;AAEhF,EAAA,oBACE2B,cAAA,CAACX,YAAY,CAAC4B,QAAQ,EAAA;AAACC,IAAAA,KAAK,EAAEF,YAAa;IAAAlB,QAAA,eACzCE,cAAA,CAACJ,cAAc,EAAA;AAACD,MAAAA,SAAS,EAAEA,SAAU;AAAAG,MAAAA,QAAA,EAAEA,QAAAA;KAAyB,CAAA;AAClE,GAAuB,CAAC,CAAA;AAE5B;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -16,7 +16,7 @@ const isForestGreenTheme = theme => theme === extraThemes[0];
16
16
  const isScreenModeDark = (theme, screenMode) => isThemeModern(theme) && screenModes[1] === screenMode;
17
17
  const getThemeClassName = (theme, screenMode) => {
18
18
  if (!isThemeModern(theme)) {
19
- return `np-theme-${theme}`;
19
+ return `np-theme-${theme || 'personal'}`;
20
20
  }
21
21
  let classes = `np-theme-personal`;
22
22
  if (isExtraTheme(theme)) {
@@ -73,6 +73,8 @@ const ThemedChildren = ({
73
73
  };
74
74
 
75
75
  const ThemeContext = /*#__PURE__*/createContext(undefined);
76
+ // RegEx 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","theme","isExtraTheme","isForestGreenTheme","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;AAGnB,MAAoBC,YAAA,GAAA,CAAGH,kBAAkBC,WAAU,CAAA,CAAA;AACnD,MAAiBG,kBAAI,GAAO;AAC5B,MAAeC,mBAAW,UAAU;;ACEnC,MAAAC,qBACE,IAAAH,YAAA,CAAAI,QAAiB,CAASC,KAAA,EAAA;AAG5B,MAAAC,oBAA6B,IAAAR,WAAA,CAAAM,SAAiBC,KAAS,EAAA;AAGvD,MAAAE,0BACE,IAAAF,KAAA,KAAAP,WAAiB,CAAS,CAAA,EAAA;MAG5BU,gBAAsB,GAAAA,CAAAH,KAAA,EAAAI,UACN,KAAAN,aAAY,CAAAE,KAAA,CAAA,IAAaN,WAAA,CAAA,CAAA,CAAA,KAAAU,WACxB;MAIjBC,iBAAuB,GAAAA,CAAAL,KAAA,EAAAI,UACP,KAAA;;;;;;;;;;;;;MCnBbE,eAAS,GAAC;AAClBN,EAAAA,KAAkB,EAAAJ;AAClBQ,EAAAA,UAAgB,EAAAP,mBAAAA;;AAEjB,MAAAU,eAAA,GAAAA,MAAA;EAeD,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;ACxBsC,MAAAC,cAAU,GAAAA,CAAA;AAAAC,EAAAA,SAAA,GAAAC,SAAA;AAAAC,EAAAA,QAAAA;AAAA,CAAA,KAAA;EAAC,MAAQ;AAAAF,IAAAA,WAAWG,UAAAA;GAAA,GAAAC,QAAA,EAAA,CAAA;AAAG,EAAA,oBAAAC,GAAA,CAAA,KAAA,EAAA;AAAAL,IAAAA,SAAA,EAAAM,UAAA,CAAAH,UAAA,EAAAH,SAAA,CAAA;AAAAE,IAAAA,QAAA,EAAAA,QAAAA;AAAA,GAAA,CAAA,CAAA;AAEvE,CAAA;;kBCG4B,gBAAAK,aAAA,CAAAN,SAAA,CAAA,CAAA;mBAGf,GAAAO,CAAA;AAAAjB,EAAAA,KAAA,GAAAJ,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,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,cA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BAAiB,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;;;;"}
@@ -1,6 +1,6 @@
1
- import type { ComponentTheme, BaseTheme, ScreenMode, ExtraTheme } from './const';
1
+ import type { ScreenMode, Theming } from './const';
2
2
  interface ThemeHookValue {
3
- theme: ComponentTheme | BaseTheme | ExtraTheme;
3
+ theme: Theming['theme'];
4
4
  screenMode: ScreenMode;
5
5
  isModern: boolean;
6
6
  isForestGreenTheme: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../src/useTheme.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIjF,UAAU,cAAc;IACtB,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,UAAU,CAAC;IAC/C,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAeD,eAAO,MAAM,QAAQ,QAAO,cAuB3B,CAAC"}
1
+ {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../src/useTheme.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAInD,UAAU,cAAc;IACtB,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACxB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAeD,eAAO,MAAM,QAAQ,QAAO,cAuB3B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/components-theming",
3
- "version": "1.1.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,33 +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
- "@transferwise/eslint-config": "^7.4.0",
30
- "@tsconfig/recommended": "^1.0.2",
31
- "@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",
32
31
  "@types/jest": "^29.5.12",
33
- "@types/node": "^18.15.12",
34
- "@types/react": "^17.0.65",
35
- "@types/react-dom": "^17.0.20",
36
- "@types/testing-library__jest-dom": "^5.14.5",
37
- "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",
38
36
  "jest": "^29.7.0",
39
37
  "jest-environment-jsdom": "^29.7.0",
40
- "rollup": "^3.28.1",
41
- "typescript": "4.9.4"
38
+ "rollup": "^4.17.2",
39
+ "typescript": "4.9.5"
42
40
  },
43
41
  "peerDependencies": {
44
42
  "react": ">=16.14",
@@ -72,7 +70,7 @@
72
70
  "lint": "pnpm run lint:check",
73
71
  "lint:check": "npm-run-all --parallel lint:check:*",
74
72
  "lint:check:format": "prettier --check --ignore-path ../../.prettierignore .",
75
- "lint:check:js+ts": "eslint --ext .js,.jsx,.mjs,.ts,.tsx,.mts --ignore-path ../../.gitignore .",
73
+ "lint:check:js+ts": "eslint --ext .js,.jsx,.mjs,.cjs,.ts,.tsx,.mts,.cts --ignore-path ../../.gitignore .",
76
74
  "lint:check:types": "tsc --noEmit --emitDeclarationOnly false",
77
75
  "lint:fix": "npm-run-all --serial lint:fix:*",
78
76
  "lint:fix:format": "prettier --write --ignore-path ../../.prettierignore .",
@@ -26,6 +26,29 @@ describe('ThemeProvider', () => {
26
26
  expect(screen.getAllByText('light')[1].parentElement).toHaveClass('np-theme-light');
27
27
  });
28
28
 
29
+ it('sets platform themes', () => {
30
+ render(
31
+ <ThemeProvider theme="personal">
32
+ <div>personal</div>
33
+ <ThemeProvider theme="platform">
34
+ <div>platform</div>
35
+ </ThemeProvider>
36
+ <ThemeProvider theme="platform--forest-green">
37
+ <div>platform--forest-green</div>
38
+ </ThemeProvider>
39
+ </ThemeProvider>,
40
+ );
41
+
42
+ // eslint-disable-next-line testing-library/no-node-access
43
+ expect(screen.getByText('personal').parentElement).toHaveClass('np-theme-personal');
44
+ // eslint-disable-next-line testing-library/no-node-access
45
+ expect(screen.getByText('platform').parentElement).toHaveClass('np-theme-platform');
46
+ // eslint-disable-next-line testing-library/no-node-access
47
+ expect(screen.getByText('platform--forest-green').parentElement).toHaveClass(
48
+ 'np-theme-platform--forest-green',
49
+ );
50
+ });
51
+
29
52
  it('matches snapshot', () => {
30
53
  const { asFragment } = render(
31
54
  <ThemeProvider theme="light">
@@ -1,13 +1,13 @@
1
1
  import { createContext, PropsWithChildren, useContext, useEffect, useMemo } from 'react';
2
2
 
3
3
  import { ThemedChildren } from './ThemedChildren';
4
- import type { ComponentTheme, BaseTheme, ExtraTheme, ScreenMode, Theming } from './const';
4
+ import type { ScreenMode, Theming } from './const';
5
5
  import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';
6
6
  import { getThemeClassName } from './helpers';
7
7
 
8
8
  export const ThemeContext = createContext<
9
9
  | {
10
- theme: ComponentTheme | BaseTheme | ExtraTheme;
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
 
package/src/const.ts CHANGED
@@ -3,6 +3,7 @@ export const baseThemes = ['light', 'personal'] as const;
3
3
  export const extraThemes = ['forest-green', 'bright-green'] as const;
4
4
  export const screenModes = ['light', 'dark'] as const;
5
5
  export const modernThemes = [baseThemes[1], ...extraThemes] as const;
6
+ export const platformThemes = ['platform', 'platform--forest-green'] as const;
6
7
 
7
8
  // TODO: componentThemes returned back for backward compatibility, refactor this place in the future
8
9
  export type ComponentTheme = (typeof baseThemes)[number];
@@ -12,12 +13,14 @@ export type ExtraTheme = (typeof extraThemes)[number];
12
13
  export type ForestGreenTheme = (typeof extraThemes)[0];
13
14
  export type ScreenMode = (typeof screenModes)[number];
14
15
  export type ScreenModeDark = (typeof screenModes)[1];
16
+ export type PlatformTheme = (typeof platformThemes)[0];
17
+ export type PlatformForestGreenTheme = (typeof platformThemes)[1];
15
18
 
16
19
  export const DEFAULT_BASE_THEME = 'light' as const;
17
20
  export const DEFAULT_SCREEN_MODE = 'light' as const;
18
21
 
19
22
  export type Theming = {
20
- theme?: ComponentTheme | BaseTheme | ExtraTheme;
23
+ theme?: ComponentTheme | BaseTheme | ExtraTheme | PlatformTheme | PlatformForestGreenTheme;
21
24
  screenMode?: ScreenMode;
22
25
  isNotRootProvider?: boolean | undefined;
23
26
  };
package/src/helpers.ts CHANGED
@@ -1,37 +1,31 @@
1
1
  import type {
2
- ComponentTheme,
3
2
  ModernTheme,
4
- BaseTheme,
5
3
  ExtraTheme,
6
4
  ForestGreenTheme,
7
5
  ScreenMode,
8
6
  ScreenModeDark,
7
+ Theming,
9
8
  } from './const';
10
9
  import { extraThemes, screenModes, modernThemes } from './const';
11
10
 
12
- export const isThemeModern = (
13
- theme: ComponentTheme | BaseTheme | ExtraTheme,
14
- ): theme is ModernTheme => modernThemes.includes(theme as ModernTheme);
11
+ export const isThemeModern = (theme: Theming['theme']): theme is ModernTheme =>
12
+ modernThemes.includes(theme as ModernTheme);
15
13
 
16
- export const isExtraTheme = (theme: ComponentTheme | BaseTheme | ExtraTheme): theme is ExtraTheme =>
14
+ export const isExtraTheme = (theme: Theming['theme']): theme is ExtraTheme =>
17
15
  extraThemes.includes(theme as ExtraTheme);
18
16
 
19
- export const isForestGreenTheme = (
20
- theme: ComponentTheme | BaseTheme | ExtraTheme,
21
- ): theme is ForestGreenTheme => theme === extraThemes[0];
17
+ export const isForestGreenTheme = (theme: Theming['theme']): theme is ForestGreenTheme =>
18
+ theme === extraThemes[0];
22
19
 
23
20
  export const isScreenModeDark = (
24
- theme: ComponentTheme | BaseTheme | ExtraTheme,
21
+ theme: Theming['theme'],
25
22
  screenMode: ScreenMode,
26
23
  ): screenMode is ScreenModeDark =>
27
24
  isThemeModern(theme as ModernTheme) && screenModes[1] === screenMode;
28
25
 
29
- export const getThemeClassName = (
30
- theme: ComponentTheme | BaseTheme | ExtraTheme,
31
- screenMode: ScreenMode,
32
- ) => {
26
+ export const getThemeClassName = (theme: Theming['theme'], screenMode: ScreenMode) => {
33
27
  if (!isThemeModern(theme)) {
34
- return `np-theme-${theme}`;
28
+ return `np-theme-${theme || 'personal'}`;
35
29
  }
36
30
 
37
31
  let classes = `np-theme-personal`;
package/src/useTheme.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { useContext, useMemo } from 'react';
2
2
 
3
3
  import { ThemeContext } from './ThemeProvider';
4
- import type { ComponentTheme, BaseTheme, ScreenMode, ExtraTheme } from './const';
4
+ import type { ScreenMode, Theming } from './const';
5
5
  import { DEFAULT_BASE_THEME, DEFAULT_SCREEN_MODE } from './const';
6
6
  import { isThemeModern, isForestGreenTheme, isScreenModeDark, getThemeClassName } from './helpers';
7
7
 
8
8
  interface ThemeHookValue {
9
- theme: ComponentTheme | BaseTheme | ExtraTheme;
9
+ theme: Theming['theme'];
10
10
  screenMode: ScreenMode;
11
11
  isModern: boolean;
12
12
  isForestGreenTheme: boolean;