"use client" import * as React from "react" import { LockButton } from "@/app/(create)/components/lock-button" import { Picker, PickerContent, PickerGroup, PickerLabel, PickerRadioGroup, PickerRadioItem, PickerSeparator, PickerTrigger, } from "@/app/(create)/components/picker" import { FONTS } from "@/app/(create)/lib/fonts" import { useDesignSystemSearchParams, type DesignSystemSearchParams, } from "@/app/(create)/lib/search-params" type FontPickerOption = { name: string value: string type: string font: { style: { fontFamily: string } } | null } export function FontPicker({ label, param, fonts, isMobile, anchorRef, }: { label: string param: "font" | "fontHeading" fonts: readonly FontPickerOption[] isMobile: boolean anchorRef: React.RefObject }) { const [params, setParams] = useDesignSystemSearchParams() const currentValue = param === "font" ? params.font : params.fontHeading const handleFontChange = React.useCallback( (value: string) => { setParams({ [param]: value, } as Partial) }, [param, setParams] ) const currentFont = React.useMemo( () => fonts.find((font) => font.value === currentValue), [fonts, currentValue] ) const currentBodyFont = React.useMemo( () => FONTS.find((font) => font.value === params.font), [params.font] ) const inheritsBodyFont = param === "fontHeading" && currentValue === "inherit" const displayFontName = inheritsBodyFont ? currentBodyFont?.name : currentFont?.name const inheritFontLabel = currentBodyFont ? currentBodyFont.name : "Body font" const groupedFonts = React.useMemo(() => { const pickerFonts = param === "fontHeading" ? fonts.filter((font) => font.value !== "inherit") : fonts const groups = new Map() for (const font of pickerFonts) { const existing = groups.get(font.type) if (existing) { existing.push(font) continue } groups.set(font.type, [font]) } return Array.from(groups.entries()).map(([type, items]) => ({ type, label: `${type.charAt(0).toUpperCase()}${type.slice(1)}`, items, })) }, [fonts, param]) return (
{label}
{displayFontName}
Aa
{param === "fontHeading" ? ( <> {inheritFontLabel} ) : null} {groupedFonts.map((group) => ( {group.label} {group.items.map((font) => ( {font.name} ))} ))}
) }