-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43f3e59
commit 76235de
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
apps/azkaban-admin-ui/src/features/shared/components/layout/dashboard/theme-toggle.tsx
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,32 @@ | ||
import { useTheme } from '../../../hooks'; | ||
import { useCallback } from 'react'; | ||
import { ThemeToggleIcon } from './themetoggle/icon'; | ||
|
||
export function ThemeToggle() { | ||
const { theme, setTheme } = useTheme(); | ||
|
||
const switchTheme = useCallback(() => { | ||
const newTheme = theme === 'light' ? 'dark' : 'light'; | ||
setTheme(newTheme); | ||
}, [theme, setTheme]); | ||
|
||
return ( | ||
<div> | ||
<input | ||
type="checkbox" | ||
name="light-switch" | ||
id="light-switch" | ||
className="light-switch sr-only" | ||
checked={theme === 'light'} | ||
onChange={() => switchTheme()} | ||
/> | ||
<label | ||
className="flex items-center justify-center cursor-pointer w-8 h-8 bg-slate-100 hover:bg-slate-200 dark:bg-slate-700 dark:hover:bg-slate-600/80 rounded-full" | ||
htmlFor="light-switch" | ||
> | ||
<ThemeToggleIcon theme={theme} /> | ||
<span className="sr-only">Switch to light / dark version</span> | ||
</label> | ||
</div> | ||
); | ||
} |
21 changes: 21 additions & 0 deletions
21
apps/azkaban-admin-ui/src/features/shared/components/layout/dashboard/themetoggle/icon.tsx
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,21 @@ | ||
import { Show } from '../../../../widgets'; | ||
import { MoonIcon, SunIcon } from '@radix-ui/react-icons'; | ||
|
||
interface Props { | ||
theme: string; | ||
} | ||
|
||
export function ThemeToggleIcon(props: Props) { | ||
const { theme } = props; | ||
|
||
return ( | ||
<> | ||
<Show show={theme === 'light'}> | ||
<MoonIcon /> | ||
</Show> | ||
<Show show={theme === 'dark'}> | ||
<SunIcon /> | ||
</Show> | ||
</> | ||
); | ||
} |