/** * Font Pairings tab — a library of heading/body font combinations. One * pairing is marked active and drives the site's actual heading/body fonts * (see Aureon\Core\Dynamic_CSS::build_css()), superseding the legacy * System/Serif/Monospace selects on the Headings/Body Text tabs. */ import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Button } from '@wordpress/components'; import { Plus, ArrowLeftRight } from 'lucide-react'; import SelectField from '../../controls/select-field'; import PairingCard from './pairing-card'; import type { FontPairing, FontPairingsSchema, FontPairingsSettings, SetPath, } from '../../types'; interface FontPairingsSectionProps { schema?: FontPairingsSchema; value: FontPairingsSettings; setPath: SetPath; } const FALLBACK_SLUG = 'system'; export default function FontPairingsSection( { schema, value, setPath, }: FontPairingsSectionProps ) { const [ newHeading, setNewHeading ] = useState( FALLBACK_SLUG ); const [ newBody, setNewBody ] = useState( FALLBACK_SLUG ); if ( ! schema ) { return null; } const fonts = schema.fonts; const items = value?.items ?? []; const active = value?.active ?? items[ 0 ]?.id; const atMax = items.length >= schema.maxPairings; const fontOptions = fonts.map( ( font ) => ( { value: font.value, label: font.label, } ) ); const writeItems = ( next: FontPairing[] ) => setPath( `${ schema.path }.items`, next ); const setActive = ( id: string ) => setPath( `${ schema.path }.active`, id ); const updatePairing = ( id: string, patch: FontPairing ) => writeItems( items.map( ( item ) => ( item.id === id ? patch : item ) ) ); const deletePairing = ( id: string ) => { const next = items.filter( ( item ) => item.id !== id ); writeItems( next ); if ( id === active && next.length > 0 ) { setActive( next[ 0 ].id ); } }; const createPairing = () => { if ( atMax ) { return; } const id = `pairing-${ Date.now().toString( 36 ) }`; writeItems( [ ...items, { id, heading: newHeading, body: newBody } ] ); setActive( id ); setNewHeading( FALLBACK_SLUG ); setNewBody( FALLBACK_SLUG ); }; const swapNewSelection = () => { setNewHeading( newBody ); setNewBody( newHeading ); }; return (

{ __( 'Typography Pairings', 'aureon' ) }

{ __( 'Create and manage font pairings used throughout your site.', 'aureon' ) }

{ items.map( ( pairing, index ) => ( setActive( pairing.id ) } onChange={ ( next ) => updatePairing( pairing.id, next ) } onDelete={ () => deletePairing( pairing.id ) } /> ) ) }

{ __( 'The active pairing is used across your site.', 'aureon' ) }

{ __( 'Add New Pairing', 'aureon' ) }

{ __( 'Choose fonts from Google Fonts to create a new typography pairing.', 'aureon' ) }

{ atMax && (

{ __( 'You’ve reached the maximum number of font pairings.', 'aureon' ) }

) }
); }