mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
6818a82cd1
* feat: add dark mode theme * fix: feature metrics * fix: add color * styling * fix: add switch * fix: form sidebar * fix: remove console log * fix: add properties * fix: strategy container * feat: feature flag * fix: tests * fix: build * fix: logo * fix: icon * fix: update snapshots * fix: CES operator * fix: typography * fix: input styling * fix: remove initial load * fix: change flag name * fix: refactor to custom hook * fix: remove unused import * fix: dialog headers * fix: use uiConfig flags instead of flags
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import UIContext, { themeMode } from 'contexts/UIContext';
|
|
import { useContext } from 'react';
|
|
import { setLocalStorageItem } from 'utils/storage';
|
|
import mainTheme from 'themes/theme';
|
|
import darkTheme from 'themes/dark-theme';
|
|
import { Theme } from '@emotion/react';
|
|
|
|
interface IUseThemeModeOutput {
|
|
resolveTheme: () => Theme;
|
|
onSetThemeMode: () => void;
|
|
themeMode: themeMode;
|
|
}
|
|
|
|
export const useThemeMode = (): IUseThemeModeOutput => {
|
|
const { themeMode, setThemeMode } = useContext(UIContext);
|
|
|
|
const resolveTheme = () => {
|
|
if (themeMode === 'light') {
|
|
return mainTheme;
|
|
}
|
|
|
|
return darkTheme;
|
|
};
|
|
|
|
const onSetThemeMode = () => {
|
|
setThemeMode((prev: themeMode) => {
|
|
if (prev === 'light') {
|
|
setLocalStorageItem('unleash-theme', 'dark');
|
|
return 'dark';
|
|
}
|
|
setLocalStorageItem('unleash-theme', 'light');
|
|
return 'light';
|
|
});
|
|
};
|
|
|
|
return { resolveTheme, onSetThemeMode, themeMode };
|
|
};
|