import { useEffect, useState } from "react" import { Check, Palette } from "lucide-react" import { Button } from "~/components/ui/button" import { Popover, PopoverContent, PopoverDescription, PopoverHeader, PopoverTitle, PopoverTrigger, } from "~/components/ui/popover" import { cn } from "~/lib/utils" export const backgrounds = [ { id: "none", label: "None" }, { id: "pearl", label: "Pearl" }, { id: "linen", label: "Linen" }, { id: "mist", label: "Mist" }, { id: "dawn", label: "Dawn" }, { id: "seafoam", label: "Seafoam" }, { id: "aurora", label: "Aurora" }, { id: "sunset", label: "Sunset" }, { id: "meadow", label: "Meadow" }, { id: "midnight", label: "Midnight" }, { id: "blush", label: "Blush" }, { id: "noir", label: "Noir" }, ] as const export type BackgroundId = (typeof backgrounds)[number]["id"] const STORAGE_KEY = "crema-bg" const DEFAULT_BG: BackgroundId = "none" function isBackgroundId(value: string | null): value is BackgroundId { return !!value && backgrounds.some((b) => b.id === value) } function applyBg(id: BackgroundId) { if (id === "none") { delete document.body.dataset.bg } else { document.body.dataset.bg = id } } export function BackgroundPicker() { const [current, setCurrent] = useState(DEFAULT_BG) useEffect(() => { const stored = localStorage.getItem(STORAGE_KEY) const next = isBackgroundId(stored) ? stored : DEFAULT_BG setCurrent(next) applyBg(next) }, []) const select = (id: BackgroundId) => { setCurrent(id) applyBg(id) localStorage.setItem(STORAGE_KEY, id) } return ( } /> Background Pick an atmosphere.
{backgrounds.map((bg) => { const active = current === bg.id return ( ) })}
) }