Skip to content

Commit

Permalink
Cleaned up theme toggle component
Browse files Browse the repository at this point in the history
  • Loading branch information
albbus-stack committed Nov 1, 2023
1 parent 3563f54 commit 99b0ac2
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions packages/ui/src/ThemeToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,19 @@ const icons = {
}
export const ThemeToggle = (props: ButtonProps) => {
const themeSetting = useThemeSetting()!;
const [clientTheme, setClientTheme] = useState<string>("system");
const [clientTheme, setClientTheme] = useState("system");

useIsomorphicLayoutEffect(() => {
if (themeSetting.resolvedTheme !== "system") {
document
.querySelector("#theme-color")
?.setAttribute(
"content",
themeSetting.resolvedTheme === "light" ? "#fff" : "#050505"
);
}

setClientTheme(themeSetting.current || "system");
}, [themeSetting.current, themeSetting.resolvedTheme]);
}, [themeSetting.current]);

return (
<Button
size="$4"
onPress={themeSetting.toggle}
{...props}
aria-label="Toggle color scheme"
icon={icons[clientTheme]}
{...props}
/>
);
};

0 comments on commit 99b0ac2

Please sign in to comment.