@monolith-forensics/monolith-ui 1.2.37 → 1.2.38

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.
@@ -3,7 +3,7 @@ import merge from "deepmerge";
3
3
  import { ThemeProvider } from "styled-components";
4
4
  export * from "styled-components";
5
5
  import { Themes, getTheme } from "../theme";
6
- import { createContext, useState } from "react";
6
+ import { createContext, useEffect, useState } from "react";
7
7
  import GlobalStyle from "./GlobalStyle";
8
8
  const LocalStorageTheme = "Monolith Theme";
9
9
  export const MonolithUIContext = createContext(undefined);
@@ -11,16 +11,15 @@ export const MonolithUIProvider = ({ children, theme, defaultColorScheme = local
11
11
  Themes.DARK, colorScheme, }) => {
12
12
  const [colorSchemeState, setColorSchemeState] = useState(defaultColorScheme);
13
13
  const toggleColorScheme = () => {
14
- setColorSchemeState((prev) => {
15
- const newState = prev === Themes.LIGHT ? Themes.DARK : Themes.LIGHT;
16
- localStorage.setItem(LocalStorageTheme, newState);
17
- return newState;
18
- });
14
+ setColorSchemeState((prev) => prev === Themes.LIGHT ? Themes.DARK : Themes.LIGHT);
19
15
  };
20
16
  const _scheme = colorScheme || colorSchemeState;
21
17
  const defaultTheme = getTheme(_scheme);
22
18
  // override default theme with the provided theme
23
19
  const _theme = merge(defaultTheme, theme || {});
20
+ useEffect(() => {
21
+ localStorage.setItem(LocalStorageTheme, _scheme);
22
+ }, [_scheme]);
24
23
  return (_jsx(MonolithUIContext.Provider, { value: {
25
24
  theme: _theme,
26
25
  Themes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.2.37",
3
+ "version": "1.2.38",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",