add catpucchin theme and nuqs for url state

This commit is contained in:
Aman Varshney
2025-04-21 06:43:10 +05:30
parent 0253195969
commit 9f0798d8b6
14 changed files with 347 additions and 170 deletions

View File

@@ -0,0 +1,62 @@
"use client";
import { cn } from "@/lib/utils"; // Make sure you have this utility
import * as SwitchPrimitives from "@radix-ui/react-switch";
import { Moon, Sun } from "lucide-react";
import { useTheme } from "next-themes";
import * as React from "react";
export function ThemeToggle({ className }: { className?: string }) {
const { theme, setTheme } = useTheme();
const [mounted, setMounted] = React.useState(false);
React.useEffect(() => {
setMounted(true);
}, []);
const isChecked = mounted ? theme === "dark" : false;
const handleCheckedChange = (checked: boolean) => {
setTheme(checked ? "dark" : "light");
};
if (!mounted) {
return (
<button
type="button"
className={cn(
"inline-flex h-5 w-10 shrink-0 cursor-not-allowed items-center rounded-full border-2 border-transparent bg-input opacity-50",
className,
)}
disabled
aria-label="Toggle theme (loading)"
>
<span className="block h-4 w-4 rounded-full bg-background shadow-lg ring-0" />
</button>
);
}
return (
<SwitchPrimitives.Root
checked={isChecked}
onCheckedChange={handleCheckedChange}
className={cn(
"peer inline-flex h-4 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
className,
)}
aria-label="Toggle theme between light and dark"
>
<SwitchPrimitives.Thumb
className={cn(
"pointer-events-none flex h-3 w-3 items-center justify-center rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0",
)}
>
{isChecked ? (
<Moon className="size-2 text-foreground" />
) : (
<Sun className="size-2 text-foreground" />
)}
</SwitchPrimitives.Thumb>
</SwitchPrimitives.Root>
);
}

View File

@@ -0,0 +1,31 @@
"use client";
import * as SwitchPrimitive from "@radix-ui/react-switch";
import type * as React from "react";
import { cn } from "@/lib/utils";
function Switch({
className,
...props
}: React.ComponentProps<typeof SwitchPrimitive.Root>) {
return (
<SwitchPrimitive.Root
data-slot="switch"
className={cn(
"peer inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs outline-none transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80",
className,
)}
{...props}
>
<SwitchPrimitive.Thumb
data-slot="switch-thumb"
className={cn(
"pointer-events-none block size-4 rounded-full bg-background ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground",
)}
/>
</SwitchPrimitive.Root>
);
}
export { Switch };