import { useEffect, useState } from "react" import { Check, Type } 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 fontSizes = [ { id: "sm", label: "Small", sample: "Aa" }, { id: "md", label: "Medium", sample: "Aa" }, { id: "lg", label: "Large", sample: "Aa" }, { id: "xl", label: "Extra large", sample: "Aa" }, ] as const export type FontSizeId = (typeof fontSizes)[number]["id"] const STORAGE_KEY = "crema-font-scale" const DEFAULT_SIZE: FontSizeId = "md" function isFontSizeId(value: string | null): value is FontSizeId { return !!value && fontSizes.some((f) => f.id === value) } const SAMPLE_PX: Record = { sm: 14, md: 16, lg: 18, xl: 20, } export function FontSizePicker() { const [current, setCurrent] = useState(DEFAULT_SIZE) useEffect(() => { const stored = localStorage.getItem(STORAGE_KEY) const next = isFontSizeId(stored) ? stored : DEFAULT_SIZE setCurrent(next) document.documentElement.dataset.fontScale = next }, []) const select = (id: FontSizeId) => { setCurrent(id) document.documentElement.dataset.fontScale = id localStorage.setItem(STORAGE_KEY, id) } return ( } /> Font size Scales the entire UI.
{fontSizes.map((f) => { const active = current === f.id return ( ) })}
) }