/** * Colors section. * * Preset-first: a gallery of ready-made palettes (plus a Custom card) is the * whole surface — clicking a card opens the palette editor modal where colours * are tweaked and applied. Applying writes into the working settings tree via * setPath and maps to the --aureon-color-* custom properties the dynamic CSS * pipeline emits. * * Preset cards carry a full bundle (see Aureon\Modules\Site\Style_Presets): * palette + radius scale + font pairing. Applying one writes all three, so the * card matches what the description promises. The Custom modal only ever * touches colours. */ import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Palette, Pipette } from '../icons'; import Tabs, { TabPanel } from '../controls/tabs'; import PaletteGallery from '../controls/palette-gallery'; import type { Palette as PaletteType } from '../controls/palette-gallery'; import ColorCard from '../controls/color-card'; import CssVariablesCallout from '../controls/css-variables-callout'; import type { ColorsSchema, WorkingSettings, SetPath } from '../types'; import SectionIntro from '../controls/section-intro'; const ID_PREFIX = 'aureon-colors'; const TABS = [ { key: 'presets', label: __( 'Presets', 'aureon' ), icon: Palette }, { key: 'custom', label: __( 'Custom', 'aureon' ), icon: Pipette }, ]; interface PresetsSchema { label: string; items?: PaletteType[]; } // Where the non-colour halves of a preset bundle live in the settings tree. // Mirrors the Spacing (design.radius) and Font Pairings schema paths. const RADIUS_PATH = 'design.radius'; const PAIRING_ACTIVE_PATH = 'font_pairings.active'; interface ColorsSectionProps { schema?: ColorsSchema; presets?: PresetsSchema; defaults?: Partial< WorkingSettings >; working: WorkingSettings; setPath: SetPath; } export default function ColorsSection( { schema, presets, defaults, working, setPath, }: ColorsSectionProps ) { const [ activeTab, setActiveTab ] = useState( 'presets' ); if ( ! schema ) { return null; } const colors = working?.design?.colors ?? {}; const colorDefaults = defaults?.design?.colors ?? {}; const radius = working?.design?.radius ?? {}; const pairings = working?.font_pairings; const palettes = presets?.items ?? []; // Apply a palette, plus the preset's radius scale and font pairing when the // card carries them. The pairing is only switched if the id still exists in // the working library — the admin may have deleted that pairing. const applyBundle = ( next: Record< string, string >, palette?: PaletteType ) => { setPath( schema.path, { ...colors, ...next } ); if ( palette?.radius ) { setPath( RADIUS_PATH, { ...radius, ...palette.radius } ); } const pairing = palette?.pairing; if ( pairing && ( pairings?.items ?? [] ).some( ( item ) => item.id === pairing ) ) { setPath( PAIRING_ACTIVE_PATH, pairing ); } }; const cssVariables = schema.fields.map( ( field ) => ( { name: `--aureon-color-${ field.key }`, value: colors[ field.key ] ?? '—', } ) ); return (

{ schema.label }

{ __( 'Pick a palette or build your own. These map to the CSS variables used across your site and Aureon Blocks.', 'aureon' ) }

{ __( 'Fine-tune any colour individually — changes here become your applied palette.', 'aureon' ) }

{ schema.fields.map( ( field ) => ( setPath( `${ schema.path }.${ field.key }`, hex ) } /> ) ) }
); }