Skip to content

Commit 044c265

Browse files
authored
Enabled Dark Mode in Console (#3129)
- Dark mode will be tied to system settings if not set - Dark mode will be stored in Application storage once set Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 0053658 commit 044c265

File tree

9 files changed

+344
-253
lines changed

9 files changed

+344
-253
lines changed

portal-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"local-storage-fallback": "^4.1.1",
1111
"lodash": "^4.17.21",
1212
"luxon": "^3.4.3",
13-
"mds": "https://github.com/minio/mds.git#v0.12.1",
13+
"mds": "https://github.com/minio/mds.git#v0.12.2",
1414
"react": "^18.1.0",
1515
"react-component-export-image": "^1.0.6",
1616
"react-copy-to-clipboard": "^5.0.2",

portal-ui/src/StyleHandler.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ const StyleHandler = ({ children }: IStyleHandler) => {
3131
const colorVariants = useSelector(
3232
(state: AppState) => state.system.overrideStyles,
3333
);
34+
const darkMode = useSelector((state: AppState) => state.system.darkMode);
3435

3536
let thm = undefined;
3637

3738
if (colorVariants) {
3839
thm = generateOverrideTheme(colorVariants);
3940
}
4041

41-
// ThemeHandler is needed for MDS components theming. Eventually we will remove Theme Provider & use only mds themes.
4242
return (
4343
<Fragment>
4444
<GlobalStyles />
45-
<ThemeHandler customTheme={thm}>{children}</ThemeHandler>
45+
<ThemeHandler darkMode={darkMode} customTheme={thm}>
46+
{children}
47+
</ThemeHandler>
4648
</Fragment>
4749
);
4850
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2023 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import React from "react";
18+
import { Button, DarkModeIcon } from "mds";
19+
import TooltipWrapper from "../TooltipWrapper/TooltipWrapper";
20+
import { useSelector } from "react-redux";
21+
import { AppState, useAppDispatch } from "../../../../store";
22+
import { setDarkMode } from "../../../../systemSlice";
23+
import { storeDarkMode } from "../../../../utils/stylesUtils";
24+
25+
const DarkModeActivator = () => {
26+
const dispatch = useAppDispatch();
27+
28+
const darkMode = useSelector((state: AppState) => state.system.darkMode);
29+
30+
const darkModeActivator = () => {
31+
const currentStatus = !!darkMode;
32+
33+
dispatch(setDarkMode(!currentStatus));
34+
storeDarkMode(!currentStatus ? "on" : "off");
35+
};
36+
37+
return (
38+
<TooltipWrapper tooltip={`${darkMode ? "Light" : "Dark"} Mode`}>
39+
<Button
40+
id={"dark-mode-activator"}
41+
icon={<DarkModeIcon />}
42+
onClick={darkModeActivator}
43+
/>
44+
</TooltipWrapper>
45+
);
46+
};
47+
48+
export default DarkModeActivator;

portal-ui/src/screens/Console/Common/PageHeaderWrapper/PageHeaderWrapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import React, { Fragment } from "react";
1818
import { PageHeader } from "mds";
1919
import ObjectManagerButton from "../ObjectManager/ObjectManagerButton";
20+
import DarkModeActivator from "../DarkModeActivator/DarkModeActivator";
2021

2122
interface IPageHeaderWrapper {
2223
label: React.ReactNode;
@@ -35,6 +36,7 @@ const PageHeaderWrapper = ({
3536
actions={
3637
<Fragment>
3738
{actions}
39+
<DarkModeActivator />
3840
<ObjectManagerButton />
3941
</Fragment>
4042
}

0 commit comments

Comments
 (0)