/** * Typography section — a top-of-content tab bar (Overview / Font Pairings / * Headings / Body Text / Links / Buttons / Misc), following the same layout * as the Colors section for the section head. Font Pairings drives the * heading/body font families (see FontPairingsSection); Links/Buttons/Misc * keep the legacy System/Serif/Monospace family select. Every other role * property writes into design.typography.*, mapping to * --aureon-font-* / --aureon-link-* / --aureon-button-* / --aureon-misc-* custom * properties emitted by the dynamic CSS pipeline. */ import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Type, CaseSensitive, Heading, AlignLeft, Link as LinkIcon, MousePointerClick, SlidersHorizontal, } from 'lucide-react'; import type { LucideIcon } from 'lucide-react'; import Tabs, { TabPanel } from '../../controls/tabs'; import CssVariablesCallout from '../../controls/css-variables-callout'; import FontPairingsSection from '../font-pairings'; import FontLibrarySection from '../font-library'; import SectionFields from './section-fields'; import { useTypographyHelpers, isSectionDefault, } from './use-typography-helpers'; import { buildTypographyCssVariables } from './css-variables'; import { ID_PREFIX } from './constants'; import type { TypographySchema, FontPairingsSchema, FontLibrarySchema, WorkingSettings, SetPath, } from '../../types'; import SectionIntro from '../../controls/section-intro'; interface TypographySectionProps { schema?: TypographySchema; fontPairingsSchema?: FontPairingsSchema; fontLibrarySchema?: FontLibrarySchema; defaults: Partial< WorkingSettings >; working: WorkingSettings; setPath: SetPath; /** * The Customizer host gives every tab here a real native section of its * own (`aureon_font_pairings`, `aureon_typography_headings`, …), each * reached via `wp.customize.section(…).focus()` for a genuine * "Customizing ▸ Aureon ▸ Typography ▸ …" breadcrumb — so there this * hub navigates away instead of opening a tab in place, and renders * nothing below its own row list. The standalone theme options page has * no such sections to navigate to, so it leaves this unset and keeps * every tab inline here, exactly as before. */ onNavigateTab?: ( key: string ) => void; } /** * The tab named in `?tab=`, if it names a real one. Nothing otherwise: the * section's landing screen is the sub-navigation itself (see `SubNav`), so no tab * is open until one is picked. * * @param validKeys Keys the section actually renders. */ const getInitialTab = ( validKeys: string[] ): string => { const requested = new URLSearchParams( window.location.search ).get( 'tab' ); return requested && validKeys.includes( requested ) ? requested : ''; }; export default function TypographySection( { schema, fontPairingsSchema, fontLibrarySchema, defaults, working, setPath, onNavigateTab, }: TypographySectionProps ) { const [ activeTab, setActiveTabState ] = useState( () => getInitialTab( [ ...( schema?.tabs.map( ( tab ) => tab.key ) ?? [] ), ...( fontPairingsSchema && ! onNavigateTab ? [ 'font_pairings' ] : [] ), ] ) ); const setActiveTab = ( key: string ) => { setActiveTabState( key ); const url = new URL( window.location.href ); // Going back drops the parameter rather than setting it empty, so a // reloaded URL lands on the list the same way a fresh one does. if ( key ) { url.searchParams.set( 'tab', key ); } else { url.searchParams.delete( 'tab' ); } window.history.replaceState( {}, '', url ); }; const { families, familyDefaults, typography, typographyDefaults, pairings, familyLabel, familyOptions, pairingFamilyOptions, weightOptions, transformOptions, decorationOptions, scaleOptions, activePairingFontLabel, familyCssFor, } = useTypographyHelpers( { schema, fontPairingsSchema, defaults, working, } ); if ( ! schema ) { return null; } // Leading icon and one-line summary per tab, for the sub-navigation's // cards — what each screen holds, so the list explains itself. const TAB_ICONS: Record< string, LucideIcon > = { font_pairings: CaseSensitive, headings: Heading, body: AlignLeft, links: LinkIcon, buttons: MousePointerClick, misc: SlidersHorizontal, }; const TAB_DESCRIPTIONS: Record< string, string > = { headings: __( 'H1, H2, H3, H4, H5, H6 styles, size, weight and line height.', 'aureon' ), body: __( 'Base font, size, weight, line height and paragraph spacing.', 'aureon' ), links: __( 'Link color, hover color and text decoration.', 'aureon' ), buttons: __( 'Button typography, text transform and letter spacing.', 'aureon' ), misc: __( 'Form inputs, blockquotes, code, captions and more.', 'aureon' ), font_pairings: __( 'Predefined font combinations for a consistent design.', 'aureon' ), }; const tabs = [ ...schema.tabs, ...( fontPairingsSchema ? [ { key: 'font_pairings', label: __( 'Font Pairings', 'aureon' ), }, ] : [] ), ].map( ( tab ) => ( { ...tab, icon: TAB_ICONS[ tab.key ], description: TAB_DESCRIPTIONS[ tab.key ], } ) ); const sections = Object.values( schema.sections ).filter( ( section ) => section.tab === activeTab ); const cssVariables = buildTypographyCssVariables( { schema, typography, familyLabel, } ); const openTab = ( key: string ) => { if ( onNavigateTab ) { onNavigateTab( key ); return; } setActiveTab( key ); }; const goToFontPairings = () => openTab( 'font_pairings' ); return (

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

{ __( 'Manage fonts and typography settings across your site. These settings apply to the theme and Aureon Blocks.', 'aureon' ) }

{ ! onNavigateTab && fontPairingsSchema && pairings && ( { fontLibrarySchema && ( ) } ) } { ! onNavigateTab && sections.map( ( section ) => { const values = typography[ section.key ] ?? {}; const defaultValues = typographyDefaults[ section.key ] ?? {}; const familyValue = families[ section.family_role ] ?? 'system'; return ( { if ( undefined !== familyDefaults[ section.family_role ] ) { setPath( `${ schema.family_path }.${ section.family_role }`, familyDefaults[ section.family_role ] ); } setPath( section.path, defaultValues ); } } onChangeFamily={ ( value ) => setPath( `${ schema.family_path }.${ section.family_role }`, value ) } setPath={ setPath } onManagePairings={ goToFontPairings } showHeadingPreview={ 'headings' === section.key && Boolean( typography.headings ) } /> ); } ) } { ! onNavigateTab && ( ) }
); }