From 044c265423e71b9d0438251dc0d8c79facea0d0b Mon Sep 17 00:00:00 2001 From: Alex <33497058+bexsoft@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:33:05 -0600 Subject: [PATCH] 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 --- portal-ui/package.json | 2 +- portal-ui/src/StyleHandler.tsx | 6 +- .../DarkModeActivator/DarkModeActivator.tsx | 48 ++ .../PageHeaderWrapper/PageHeaderWrapper.tsx | 2 + .../screens/Console/License/LicensePlans.tsx | 500 +++++++++--------- .../src/screens/LoginPage/loginThunks.ts | 10 +- portal-ui/src/systemSlice.ts | 7 + portal-ui/src/utils/stylesUtils.ts | 16 + portal-ui/yarn.lock | 6 +- 9 files changed, 344 insertions(+), 253 deletions(-) create mode 100644 portal-ui/src/screens/Console/Common/DarkModeActivator/DarkModeActivator.tsx diff --git a/portal-ui/package.json b/portal-ui/package.json index cb73237a8..f7860a8c2 100644 --- a/portal-ui/package.json +++ b/portal-ui/package.json @@ -10,7 +10,7 @@ "local-storage-fallback": "^4.1.1", "lodash": "^4.17.21", "luxon": "^3.4.3", - "mds": "https://github.com/minio/mds.git#v0.12.1", + "mds": "https://github.com/minio/mds.git#v0.12.2", "react": "^18.1.0", "react-component-export-image": "^1.0.6", "react-copy-to-clipboard": "^5.0.2", diff --git a/portal-ui/src/StyleHandler.tsx b/portal-ui/src/StyleHandler.tsx index 5cf2fa4c2..90e0e84ae 100644 --- a/portal-ui/src/StyleHandler.tsx +++ b/portal-ui/src/StyleHandler.tsx @@ -31,6 +31,7 @@ const StyleHandler = ({ children }: IStyleHandler) => { const colorVariants = useSelector( (state: AppState) => state.system.overrideStyles, ); + const darkMode = useSelector((state: AppState) => state.system.darkMode); let thm = undefined; @@ -38,11 +39,12 @@ const StyleHandler = ({ children }: IStyleHandler) => { thm = generateOverrideTheme(colorVariants); } - // ThemeHandler is needed for MDS components theming. Eventually we will remove Theme Provider & use only mds themes. return ( - {children} + + {children} + ); }; diff --git a/portal-ui/src/screens/Console/Common/DarkModeActivator/DarkModeActivator.tsx b/portal-ui/src/screens/Console/Common/DarkModeActivator/DarkModeActivator.tsx new file mode 100644 index 000000000..2d4131c6d --- /dev/null +++ b/portal-ui/src/screens/Console/Common/DarkModeActivator/DarkModeActivator.tsx @@ -0,0 +1,48 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2023 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +import React from "react"; +import { Button, DarkModeIcon } from "mds"; +import TooltipWrapper from "../TooltipWrapper/TooltipWrapper"; +import { useSelector } from "react-redux"; +import { AppState, useAppDispatch } from "../../../../store"; +import { setDarkMode } from "../../../../systemSlice"; +import { storeDarkMode } from "../../../../utils/stylesUtils"; + +const DarkModeActivator = () => { + const dispatch = useAppDispatch(); + + const darkMode = useSelector((state: AppState) => state.system.darkMode); + + const darkModeActivator = () => { + const currentStatus = !!darkMode; + + dispatch(setDarkMode(!currentStatus)); + storeDarkMode(!currentStatus ? "on" : "off"); + }; + + return ( + +