2024-11-12 19:15:13 +07:00
|
|
|
import React, { useId } from "react";
|
|
|
|
import { Switch, GetProps, XStack, Label } from "tamagui";
|
2024-11-10 18:49:18 +07:00
|
|
|
import useThemeStore from "@/stores/theme";
|
2024-11-12 19:15:13 +07:00
|
|
|
import { Ionicons } from "../ui/icons";
|
2024-11-10 18:49:18 +07:00
|
|
|
|
2024-11-12 19:15:13 +07:00
|
|
|
type Props = GetProps<typeof XStack> & {
|
2024-11-10 18:49:18 +07:00
|
|
|
iconSize?: number;
|
|
|
|
};
|
|
|
|
|
2024-11-12 19:15:13 +07:00
|
|
|
const ThemeSwitcher = ({ iconSize = 18, ...props }: Props) => {
|
2024-11-10 18:49:18 +07:00
|
|
|
const { theme, toggle } = useThemeStore();
|
2024-11-12 19:15:13 +07:00
|
|
|
const id = useId();
|
2024-11-10 18:49:18 +07:00
|
|
|
|
|
|
|
return (
|
2024-11-15 09:39:35 +00:00
|
|
|
<XStack
|
|
|
|
alignItems="center"
|
|
|
|
gap="$4"
|
|
|
|
w="auto"
|
|
|
|
justifyContent="space-between"
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
<XStack alignItems="center" gap="$2">
|
|
|
|
<Ionicons
|
|
|
|
name={theme === "light" ? "moon-outline" : "sunny-outline"}
|
|
|
|
size={iconSize}
|
|
|
|
/>
|
|
|
|
<Label htmlFor={id} cursor="pointer">
|
|
|
|
Dark Mode
|
|
|
|
</Label>
|
|
|
|
</XStack>
|
2024-11-12 19:15:13 +07:00
|
|
|
<Switch
|
|
|
|
id={id}
|
|
|
|
onPress={toggle}
|
|
|
|
checked={theme === "dark"}
|
|
|
|
size="$2"
|
|
|
|
cursor="pointer"
|
|
|
|
>
|
|
|
|
<Switch.Thumb animation="quicker" />
|
|
|
|
</Switch>
|
|
|
|
</XStack>
|
2024-11-10 18:49:18 +07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ThemeSwitcher;
|