/** * The field groups behind Spacing's two tabs (Scale / Layout), kept apart * from the section component in `index.tsx`. */ import { __ } from '@wordpress/i18n'; import ScaleField from '../../controls/scale-field'; import SelectField from '../../controls/select-field'; import UnitField from '../../controls/unit-field'; import type { ScaleSchema, WorkingSettings, SetPath } from '../../types'; export const CONTAINER_PADDING_UNITS = [ { value: 'rem', label: 'rem' }, { value: 'px', label: 'px' }, { value: 'em', label: 'em' }, { value: '%', label: '%' }, ]; interface LayoutOption { value: string; label: string; } export interface LayoutSchemaSlice { spacings?: LayoutOption[]; } interface LayoutData { section_spacing?: string; } export interface SpacingSchema extends ScaleSchema { container_padding_path?: string; } /** * Everything derived from `schema`/`working` that both the hub and each * tab-section leaf need — computed once, passed down. * @param schema * @param layoutSchema * @param defaults * @param working */ export function getSpacingData( schema: SpacingSchema, layoutSchema: LayoutSchemaSlice | undefined, defaults: Partial< WorkingSettings >, working: WorkingSettings ) { const spacing = working?.design?.spacing ?? {}; const spacingDefaults = defaults?.design?.spacing ?? {}; const layout = ( working?.layout ?? {} ) as LayoutData; const sectionSpacingOptions = layoutSchema?.spacings ?? []; const containerPaddingPath = schema.container_padding_path ?? 'design.container_padding'; const containerPadding = ( ( working?.design as Record< string, any > ) ?.container_padding as string ) ?? ''; const cssVariables = schema.fields.map( ( field ) => ( { name: `--aureon-space-${ field.key }`, value: spacing[ field.key ] ?? '—', } ) ); cssVariables.push( { name: '--aureon-section-spacing', value: `var(--aureon-space-${ layout.section_spacing ?? 'md' })`, } ); cssVariables.push( { name: '--aureon-container-padding', value: containerPadding || 'var(--aureon-space-md)', } ); return { spacing, spacingDefaults, layout, sectionSpacingOptions, containerPaddingPath, containerPadding, cssVariables, }; } interface ScaleFieldsProps { schema: SpacingSchema; spacing: Record< string, string >; spacingDefaults: Record< string, string >; setPath: SetPath; } export function ScaleFields( { schema, spacing, spacingDefaults, setPath, }: ScaleFieldsProps ) { return (
{ __( 'How much vertical breathing room sections get by default — drawn from this scale. Also editable from the Layout section.', 'aureon' ) }
{ __( 'Horizontal gutter inside the boxed container. Leave empty to use the medium spacing token.', 'aureon' ) }