Skip to content

Commit

Permalink
refactor: add ui provider component
Browse files Browse the repository at this point in the history
  • Loading branch information
jonyw4 committed Nov 24, 2021
1 parent a0e6548 commit dcfdefd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions webapp/src/components/global/UIProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import { Theme } from "../../domain";
import { Locale, LocaleContext } from "./locale";
import { ThemeDataContext } from "./theme";

export interface UIProviderProps {
locale: Locale;
children: React.ReactNode;
themeData: {
initialTheme: Theme;
callback: (theme: Theme) => void;
};
}

export function UIProvider({ locale, children, themeData }: UIProviderProps) {
const [theme, setTheme] = React.useState<Theme>(themeData.initialTheme);

const changeTheme = (newTheme: Theme) => {
themeData.callback(newTheme);
setTheme(newTheme);
}

return (
<LocaleContext.Provider value={locale}>
<ThemeDataContext.Provider value={{ theme, changeTheme }}>
{children}
</ThemeDataContext.Provider>
</LocaleContext.Provider>
);
}
2 changes: 2 additions & 0 deletions webapp/src/components/global/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './UIProvider';
export * from './formatDate';
export * from './locale';
export * from './theme';

0 comments on commit dcfdefd

Please sign in to comment.