Skip to content

Commit

Permalink
feat: enable dark mode for all (#3614)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Apr 25, 2023
1 parent ae60cf0 commit 545e231
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 56 deletions.
40 changes: 15 additions & 25 deletions frontend/src/component/menu/Header/Header.tsx
Expand Up @@ -239,32 +239,22 @@ const Header: VFC = () => {
/>
</StyledLinks>
<StyledUserContainer>
<ConditionallyRender
condition={Boolean(
uiConfig.flags.ENABLE_DARK_MODE_SUPPORT
)}
show={
<Tooltip
title={
themeMode === 'dark'
? 'Switch to light theme'
: 'Switch to dark theme'
}
arrow
>
<IconButton
onClick={onSetThemeMode}
sx={focusable}
>
<ConditionallyRender
condition={themeMode === 'dark'}
show={<DarkModeOutlined />}
elseShow={<LightModeOutlined />}
/>
</IconButton>
</Tooltip>
<Tooltip
title={
themeMode === 'dark'
? 'Switch to light theme'
: 'Switch to dark theme'
}
/>
arrow
>
<IconButton onClick={onSetThemeMode} sx={focusable}>
<ConditionallyRender
condition={themeMode === 'dark'}
show={<DarkModeOutlined />}
elseShow={<LightModeOutlined />}
/>
</IconButton>
</Tooltip>{' '}
<ConditionallyRender
condition={!isOss()}
show={<Notifications />}
Expand Down
20 changes: 6 additions & 14 deletions frontend/src/component/providers/UIProvider/UIProvider.tsx
Expand Up @@ -3,34 +3,26 @@ import UIContext, { createEmptyToast, themeMode } from 'contexts/UIContext';
import { IToast } from 'interfaces/toast';
import { getLocalStorageItem } from 'utils/storage';

const resolveMode = (darkmode: boolean): themeMode => {
const resolveMode = (): themeMode => {
const value = getLocalStorageItem('unleash-theme');
if (value) {
return value as themeMode;
}

let osDark;
if (darkmode) {
osDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
}
const osDark =
window.matchMedia &&
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 UIProvider: React.FC = ({ children }) => {
const [toastData, setToast] = useState<IToast>(createEmptyToast());
const [showFeedback, setShowFeedback] = useState(false);
const [themeMode, setThemeMode] = useState(resolveMode(darkmode));
const [themeMode, setThemeMode] = useState(resolveMode());

const context = React.useMemo(
() => ({
Expand Down
Expand Up @@ -8,9 +8,5 @@ export const UIProviderContainer: React.FC = ({ children }) => {
return null;
}

return (
<UIProvider darkmode={uiConfig.flags.ENABLE_DARK_MODE_SUPPORT || false}>
{children}
</UIProvider>
);
return <UIProvider>{children}</UIProvider>;
};
Expand Up @@ -13,7 +13,7 @@ test('renders an empty list correctly', () => {
<MemoryRouter>
<ThemeProvider>
<AnnouncerProvider>
<UIProvider darkmode={false}>
<UIProvider>
<AccessProviderMock
permissions={[{ permission: ADMIN }]}
>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/interfaces/uiConfig.ts
Expand Up @@ -36,7 +36,6 @@ export interface IFlags {
T?: boolean;
UNLEASH_CLOUD?: boolean;
UG?: boolean;
ENABLE_DARK_MODE_SUPPORT?: boolean;
embedProxyFrontend?: boolean;
maintenanceMode?: boolean;
messageBanner?: boolean;
Expand Down
5 changes: 0 additions & 5 deletions src/lib/__snapshots__/create-config.test.ts.snap
Expand Up @@ -66,7 +66,6 @@ exports[`should create default config 1`] = `
"isEnabled": [Function],
},
"flags": {
"ENABLE_DARK_MODE_SUPPORT": false,
"anonymiseEventLog": false,
"bulkOperations": false,
"caseInsensitiveInOperators": false,
Expand All @@ -93,7 +92,6 @@ exports[`should create default config 1`] = `
},
"flagResolver": FlagResolver {
"experiments": {
"ENABLE_DARK_MODE_SUPPORT": false,
"anonymiseEventLog": false,
"bulkOperations": false,
"caseInsensitiveInOperators": false,
Expand Down Expand Up @@ -168,9 +166,6 @@ exports[`should create default config 1`] = `
"strategySegmentsLimit": 5,
"ui": {
"environment": "Open Source",
"flags": {
"ENABLE_DARK_MODE_SUPPORT": false,
},
},
"versionCheck": {
"enable": true,
Expand Down
3 changes: 0 additions & 3 deletions src/lib/create-config.ts
Expand Up @@ -105,9 +105,6 @@ function loadUI(options: IUnleashOptions): IUIConfig {
environment: 'Open Source',
};

ui.flags = {
ENABLE_DARK_MODE_SUPPORT: false,
};
return mergeAll([ui, uiO]);
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/types/experimental.ts
Expand Up @@ -4,7 +4,6 @@ export type IFlags = Partial<typeof flags>;
export type IFlagKey = keyof IFlags;

const flags = {
ENABLE_DARK_MODE_SUPPORT: false,
anonymiseEventLog: false,
embedProxy: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_EMBED_PROXY,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/util/flag-resolver.test.ts
Expand Up @@ -7,7 +7,7 @@ test('should produce empty exposed flags', () => {

const result = resolver.getAll();

expect(result.ENABLE_DARK_MODE_SUPPORT).toBe(false);
expect(result.anonymiseEventLog).toBe(false);
});

test('should produce UI flags with extra dynamic flags', () => {
Expand Down

0 comments on commit 545e231

Please sign in to comment.