import { GripVertical, Plus, Trash2 } from 'lucide-react'; import { useState, type CSSProperties, type DragEvent, type ReactNode } from 'react'; import { zhCN } from '../../i18n/zh-CN'; import { IconButton } from '../common/IconButton'; import styles from './settings.module.css'; // 字体链编辑器:增删、拖动排序并实时预览。 interface FontChainEditorProps { label: string; value: string[]; onChange: (fonts: string[]) => void; previewStyle: CSSProperties; children?: ReactNode } export function FontChainEditor({ label, value, onChange, previewStyle, children }: FontChainEditorProps) { const [dragged, setDragged] = useState(); const move = (event: DragEvent, target: number) => { event.preventDefault(); if (dragged === undefined || dragged === target) return; const next = [...value]; const [font] = next.splice(dragged, 1); next.splice(target, 0, font); onChange(next); setDragged(target); }; return
{label}
{value.map((font, index) =>
move(event, index)}> setDragged(index)} onDragEnd={() => setDragged(undefined)} title={zhCN.moveFont}> onChange(value.map((item, itemIndex) => itemIndex === index ? event.target.value : item))} />} compact label={zhCN.removeFont(font)} disabled={value.length === 1} onClick={() => onChange(value.filter((_, itemIndex) => itemIndex !== index))} />
)}
} label={zhCN.addFallback} onClick={() => onChange([...value, ''])} /> {children}
{zhCN.preview}{zhCN.previewText}
; }