/** * Font pairing card — heading/body font preview ("Ag"), Google Fonts source * badge, active/default status, and move/edit/delete actions. Follows the * TypographyCard/ColorCard shell conventions (bordered surface, hover * border) and reuses the existing up/down-button reorder pattern from * ElementList rather than adding a drag-and-drop dependency. */ import { useState, useEffect } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Button } from '@wordpress/components'; import { Pencil, Trash2, Check } from 'lucide-react'; import SelectField from '../../controls/select-field'; import ConfirmDialog from '../../confirm-dialog'; import { loadGoogleFont } from './load-google-font'; import type { FontChoice, FontPairing } from '../../types'; // Google Fonts' brand mark (google-fonts-2021-logo.svg), inlined rather than // pulled in as an asset — it's a single small multi-color glyph used only // here, not a general-purpose icon worth adding to module-icons.ts. const GoogleFontsIcon = () => ( ); interface PairingCardProps { pairing: FontPairing; fonts: FontChoice[]; index: number; isActive: boolean; onSetActive: () => void; onChange: ( pairing: FontPairing ) => void; onDelete: () => void; } // Purely decorative tint for the "Ag" glyph swatch, cycled by list position // so pairings stay visually distinct at a glance. The protected "System UI" // pairing keeps its own neutral, un-tinted treatment (see isProtected below). const GLYPH_TINTS = [ 'violet', 'amber', 'teal', 'rose' ]; const fontLabel = ( fonts: FontChoice[], slug: string ): FontChoice | undefined => fonts.find( ( font ) => font.value === slug ); const cssFamilyFor = ( font?: FontChoice ): string | undefined => { if ( ! font ) { return undefined; } return 'google' === font.source ? `"${ font.label }", ${ font.category }` : font.category; }; export default function PairingCard( { pairing, fonts, index, isActive, onSetActive, onChange, onDelete, }: PairingCardProps ) { const [ editing, setEditing ] = useState( false ); const [ confirmingDelete, setConfirmingDelete ] = useState( false ); const [ draft, setDraft ] = useState( pairing ); // The seeded "System UI" pairing (Settings::defaults()' font_pairings.items[0]) // is the fallback every site always has — it can be made active, but never // edited or deleted, so the site can never end up with zero pairings. const isProtected = 'default' === pairing.id; const heading = fontLabel( fonts, pairing.heading ); const body = fontLabel( fonts, pairing.body ); useEffect( () => { if ( 'google' === heading?.source ) { loadGoogleFont( heading.label ); } }, [ heading?.source, heading?.label ] ); const fontOptions = fonts.map( ( font ) => ( { value: font.value, label: font.label, } ) ); const startEditing = () => { setDraft( pairing ); setEditing( true ); }; const saveEditing = () => { onChange( draft ); setEditing( false ); }; const glyphTint = isProtected ? 'neutral' : GLYPH_TINTS[ index % GLYPH_TINTS.length ]; return (
{ isActive && ! editing && ( ) }
{ ! editing && (
{ __( 'H', 'aureon' ) } { heading?.label ?? pairing.heading } { 'google' === heading?.source && ( ) }
{ __( 'B', 'aureon' ) } { body?.label ?? pairing.body } { 'google' === body?.source && ( ) }
) } { editing && (
setDraft( { ...draft, heading: value } ) } /> setDraft( { ...draft, body: value } ) } />
) }
{ editing ? ( <> ) : ( <> { isActive ? ( ) : ( ) } { ! isProtected && (
) } ) }
{ confirmingDelete && ( { onDelete(); setConfirmingDelete( false ); } } onCancel={ () => setConfirmingDelete( false ) } /> ) }
); }