-
-
Notifications
You must be signed in to change notification settings - Fork 85
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 #100 from albbus-stack/theme-toggle
Added ThemeToggle component
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useState } from "react"; | ||
import { useThemeSetting } from "@tamagui/next-theme"; | ||
import { Monitor, Sun, Moon } from "@tamagui/lucide-icons"; | ||
import type { ButtonProps } from "tamagui"; | ||
import { Button, useIsomorphicLayoutEffect } from "tamagui"; | ||
|
||
const icons = { | ||
system: Monitor, | ||
light: Sun, | ||
dark: Moon | ||
} | ||
export const ThemeToggle = (props: ButtonProps) => { | ||
const themeSetting = useThemeSetting()!; | ||
const [clientTheme, setClientTheme] = useState("system"); | ||
|
||
useIsomorphicLayoutEffect(() => { | ||
setClientTheme(themeSetting.current || "system"); | ||
}, [themeSetting.current]); | ||
|
||
return ( | ||
<Button | ||
size="$4" | ||
onPress={themeSetting.toggle} | ||
aria-label="Toggle color scheme" | ||
icon={icons[clientTheme]} | ||
{...props} | ||
/> | ||
); | ||
}; |
6c5a3b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔ EAS production build completed