diff --git a/public/index.html b/public/index.html index 2370780a..f86d761e 100644 --- a/public/index.html +++ b/public/index.html @@ -1,5 +1,5 @@ - + diff --git a/src/layout/Header.tsx b/src/layout/Header.tsx index cc065d4f..e9eb52fe 100644 --- a/src/layout/Header.tsx +++ b/src/layout/Header.tsx @@ -1,3 +1,5 @@ +import { FormEvent, useEffect, useState } from 'react'; + import { Brand, Masthead, @@ -6,13 +8,46 @@ import { MastheadMain, MastheadToggle, PageToggleButton, - Title + Switch, + Title, + Toolbar, + ToolbarContent, + ToolbarGroup, + ToolbarItem } from '@patternfly/react-core'; import { BarsIcon } from '@patternfly/react-icons'; import { brandLogo, brandName } from '@config/config'; +const storageKey = 'theme-preference'; +const DARK_THEME_CLASS = 'pf-v5-theme-dark'; + const SkHeader = function () { + const [isChecked, setIsChecked] = useState(false); + + const handleChange = (_event: FormEvent, checked: boolean) => { + const htmlElement = document.querySelector('html') as HTMLElement; + + checked ? htmlElement.classList.add(DARK_THEME_CLASS) : htmlElement.classList.remove(DARK_THEME_CLASS); + checked ? localStorage.setItem(storageKey, DARK_THEME_CLASS) : localStorage.removeItem(storageKey); + + setIsChecked(checked); + }; + + useEffect(() => { + const themePreference = localStorage.getItem(storageKey); + + if (themePreference) { + const htmlElement = document.querySelector('html') as HTMLElement; + htmlElement.classList.add(themePreference); + setIsChecked(true); + + return; + } + + setIsChecked(false); + }, []); + return ( @@ -27,7 +62,24 @@ const SkHeader = function () { - {brandName && {brandName}} + + {brandName && {'brandName'}} + + + + + + + + + + ); }; diff --git a/src/layout/MainContainer.tsx b/src/layout/MainContainer.tsx index b5e40307..5ad02626 100644 --- a/src/layout/MainContainer.tsx +++ b/src/layout/MainContainer.tsx @@ -19,6 +19,7 @@ import NavigationViewLink from '../core/components/NavigationViewLink'; import TransitionPage from '../core/components/TransitionPages/Fade'; import '@patternfly/patternfly/patternfly-addons.css'; +import '@patternfly/patternfly/patternfly-charts-theme-dark.css'; interface MainContainerProps { dataTestId?: string;