-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2527 from navikt/modia-new-layout
Legg til dark mode & litt tweaks i personmeny
- Loading branch information
Showing
9 changed files
with
166 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { LightBulbIcon, MoonIcon, SunIcon } from '@navikt/aksel-icons'; | ||
import { HStack, Label, ToggleGroup } from '@navikt/ds-react'; | ||
import { useAtom } from 'jotai'; | ||
import { useCallback } from 'react'; | ||
import { themeAtom } from 'src/lib/state/theme'; | ||
|
||
export const ThemeToggle = () => { | ||
const [theme, setTheme] = useAtom(themeAtom); | ||
|
||
const changeTheme = useCallback( | ||
(v: string) => { | ||
if (v === 'light' || v === 'dark') { | ||
setTheme(v); | ||
} | ||
}, | ||
[setTheme] | ||
); | ||
|
||
return ( | ||
<HStack justify="space-between"> | ||
<HStack align="center" gap="2"> | ||
<LightBulbIcon /> | ||
<Label size="small">Bytt modus</Label> | ||
</HStack> | ||
<ToggleGroup onChange={changeTheme} value={theme} size="small"> | ||
<ToggleGroup.Item icon={<SunIcon />} value="light" /> | ||
<ToggleGroup.Item icon={<MoonIcon />} value="dark" /> | ||
</ToggleGroup> | ||
</HStack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { atom, useAtom, useAtomValue } from 'jotai'; | ||
import { type PropsWithChildren, useEffect } from 'react'; | ||
|
||
const localTheme = localStorage.getItem('theme'); | ||
|
||
export const themeAtom = atom<'light' | 'dark'>(localTheme === 'light' || localTheme === 'dark' ? localTheme : 'light'); | ||
|
||
export const useTheme = () => useAtomValue(themeAtom); | ||
|
||
export const ThemeProvider = ({ children }: PropsWithChildren) => { | ||
const [theme] = useAtom(themeAtom); | ||
|
||
useEffect(() => { | ||
document.documentElement.setAttribute('data-theme', theme); | ||
localStorage.setItem('theme', theme); | ||
}, [theme]); | ||
|
||
return children; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters