Expose the Vite/React website source under dashboard/ (with node_modules still ignored) so the full dashboard can be built and maintained from this repo.
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
import { useEffect } from "react";
|
|
import type { ConfigField } from "@/lib/config-schemas";
|
|
import {
|
|
GOOGLE_FONTS,
|
|
SYSTEM_FONT_ID,
|
|
fontFamilyCss,
|
|
injectGoogleFontsStylesheet,
|
|
normalizeGoogleFontValue,
|
|
} from "@/lib/google-fonts";
|
|
import { Label } from "@/components/ui/label";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
|
|
interface GoogleFontPickerProps {
|
|
field: ConfigField;
|
|
value: unknown;
|
|
onChange: (value: unknown) => void;
|
|
readOnly?: boolean;
|
|
}
|
|
|
|
export function GoogleFontPicker({
|
|
field,
|
|
value,
|
|
onChange,
|
|
readOnly,
|
|
}: GoogleFontPickerProps) {
|
|
const id = field.path.replace(/\./g, "-");
|
|
const selected = normalizeGoogleFontValue(value);
|
|
|
|
useEffect(() => {
|
|
injectGoogleFontsStylesheet();
|
|
}, []);
|
|
|
|
return (
|
|
<div className="space-y-2">
|
|
<Label htmlFor={id}>{field.label}</Label>
|
|
{field.description ? (
|
|
<p className="text-xs text-muted-foreground">{field.description}</p>
|
|
) : null}
|
|
<Select
|
|
value={selected}
|
|
disabled={readOnly}
|
|
onValueChange={onChange}
|
|
>
|
|
<SelectTrigger
|
|
id={id}
|
|
className="border-border bg-secondary/30"
|
|
style={{ fontFamily: fontFamilyCss(selected) }}
|
|
>
|
|
<SelectValue placeholder="Choose a font…" />
|
|
</SelectTrigger>
|
|
<SelectContent className="max-h-[min(320px,50vh)]">
|
|
<SelectItem value={SYSTEM_FONT_ID} style={{ fontFamily: fontFamilyCss(SYSTEM_FONT_ID) }}>
|
|
System default
|
|
</SelectItem>
|
|
{GOOGLE_FONTS.map((font) => (
|
|
<SelectItem
|
|
key={font.id}
|
|
value={font.id}
|
|
style={{ fontFamily: fontFamilyCss(font.id) }}
|
|
>
|
|
{font.label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
);
|
|
}
|