mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-28 17:55:15 +02:00
* 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
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import React, { useState } from 'react';
|
|
import UIContext, { createEmptyToast, themeMode } from 'contexts/UIContext';
|
|
import { IToast } from 'interfaces/toast';
|
|
import { getLocalStorageItem } from 'utils/storage';
|
|
|
|
const resolveMode = (darkmode: boolean): themeMode => {
|
|
const value = getLocalStorageItem('unleash-theme');
|
|
if (value) {
|
|
return value as themeMode;
|
|
}
|
|
|
|
let osDark;
|
|
if (darkmode) {
|
|
osDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
}
|
|
|
|
if (osDark) {
|
|
return 'dark';
|
|
}
|
|
return 'light';
|
|
};
|
|
|
|
interface IUiProviderProps {
|
|
darkmode: boolean;
|
|
}
|
|
|
|
const UIProvider: React.FC<IUiProviderProps> = ({
|
|
children,
|
|
darkmode = false,
|
|
}) => {
|
|
const [toastData, setToast] = useState<IToast>(createEmptyToast());
|
|
const [showFeedback, setShowFeedback] = useState(false);
|
|
const [themeMode, setThemeMode] = useState(resolveMode(darkmode));
|
|
|
|
const context = React.useMemo(
|
|
() => ({
|
|
setToast,
|
|
toastData,
|
|
showFeedback,
|
|
setShowFeedback,
|
|
themeMode,
|
|
setThemeMode,
|
|
}),
|
|
[toastData, showFeedback, themeMode]
|
|
);
|
|
|
|
return <UIContext.Provider value={context}>{children}</UIContext.Provider>;
|
|
};
|
|
|
|
export default UIProvider;
|