-
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.
Lag knapp for å bytte mellom ny & originale modia
- Loading branch information
Showing
6 changed files
with
52 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ArrowUndoIcon, SparklesIcon } from '@navikt/aksel-icons'; | ||
import { Box, Button } from '@navikt/ds-react'; | ||
import { useLocation, useNavigate } from '@tanstack/react-router'; | ||
import { useAtom } from 'jotai'; | ||
import { atomWithStorage } from 'jotai/utils'; | ||
import { useCallback } from 'react'; | ||
import { FeatureToggles } from './featureToggle/toggleIDs'; | ||
import useFeatureToggle from './featureToggle/useFeatureToggle'; | ||
|
||
export const nyModiaAtom = atomWithStorage('ny-modia', false); | ||
|
||
export const NyModia = () => { | ||
const { isOn } = useFeatureToggle(FeatureToggles.NyModiaKnapp); | ||
const [nyModia, setNyModia] = useAtom(nyModiaAtom); | ||
|
||
const { href } = useLocation(); | ||
const navigate = useNavigate(); | ||
|
||
const handleClick = useCallback(() => { | ||
setNyModia((v) => !v); | ||
|
||
if (!nyModia) { | ||
navigate({ to: `/new/${href}` }); | ||
} else { | ||
navigate({ to: href.replace('/new', '') }); | ||
} | ||
}, [navigate, setNyModia, nyModia, href]); | ||
|
||
if (!isOn) return; | ||
|
||
return ( | ||
<Box className="absolute bottom-0 right-0 m-12 overflow-hidden" borderRadius="xlarge"> | ||
<Button icon={nyModia ? <ArrowUndoIcon /> : <SparklesIcon />} variant="primary" onClick={handleClick}> | ||
{nyModia ? 'Gamle modia' : 'Ny!'} | ||
</Button> | ||
</Box> | ||
); | ||
}; |
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
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