/** * Buttons section — border-radius scale plus the full global button style: * variant, size, alignment, padding, border, hover, and focus ring. Two tabs: * "Settings" for the higher-level defaults (Button Style, Border Radius, * Button Size, Button Alignment) and "Style" for the detailed styling * (Padding, Border, Hover Style, Focus Style, Button Preview), ending in the * existing "How it works" CSS-variables callout shared by both tabs. * * Every field here maps to a --aureon-btn-* / --aureon-radius-* custom property * consumed by .aureon-button (see src/frontend/style.scss) and emitted by * Aureon\Core\Dynamic_CSS::build_css() (the "Button box styling" section). */ import { useState } from '@wordpress/element'; import type { ReactNode } from 'react'; import { __ } from '@wordpress/i18n'; import { ToggleControl, Button, Tooltip } from '@wordpress/components'; import { Radius, Palette, Ruler, AlignCenter, AlignLeft, AlignRight, MoveHorizontal, SquareDashedBottom, MousePointer2, Focus, Eye, Square, RectangleHorizontal, Type, Link as LinkIcon, SlidersHorizontal, Paintbrush, Undo2, } from 'lucide-react'; import type { LucideIcon } from 'lucide-react'; import Tabs, { TabPanel } from '../controls/tabs'; import ScaleField from '../controls/scale-field'; import SelectField from '../controls/select-field'; import UnitField from '../controls/unit-field'; import ColorField from '../controls/color-field'; import BorderField from '../controls/border-field'; import BoxField from '../controls/box-field'; import CssVariablesCallout from '../controls/css-variables-callout'; import type { ButtonsSchema, ButtonOption, WorkingSettings, SetPath, } from '../types'; import SectionIntro from '../controls/section-intro'; const ID_PREFIX = 'aureon-buttons'; const LENGTH_UNITS = [ { value: 'px', label: 'px' }, { value: 'em', label: 'em' }, { value: 'rem', label: 'rem' }, ]; const SPEED_UNITS = [ { value: 's', label: 's' } ]; const STYLE_ICONS: Record< string, LucideIcon > = { filled: Square, outline: RectangleHorizontal, text: Type, link: LinkIcon, }; const ALIGNMENT_ICONS: Record< string, LucideIcon > = { left: AlignLeft, center: AlignCenter, right: AlignRight, }; interface ButtonsSectionProps { schema?: ButtonsSchema; defaults: Partial< WorkingSettings >; working: WorkingSettings; setPath: SetPath; } /** * FieldGroup — icon square + uppercase eyebrow label + description + its * fields, factoring out the repeated "Padding"/"Border"/"Hover Style"/"Focus * Style" header pattern the mockup shows for every group below Button Style. * Kept local to this file since nothing else needs it yet. * * `onReset` is optional: supply it (with `isDefault`) to show a "Reset to * default" icon button in the header, matching the Undo2 affordance * ColorCard/TypographyCard/ScaleField already use elsewhere in this admin — * every group here edits several settings keys at once, so one group-level * reset (rather than one per field) keeps the header from getting crowded. * @param root0 * @param root0.icon * @param root0.label * @param root0.description * @param root0.onReset * @param root0.isDefault * @param root0.plain * @param root0.children */ function FieldGroup( { icon: Icon, label, description, onReset, isDefault = true, plain = false, children, }: { icon: LucideIcon; label: string; description?: string; onReset?: () => void; isDefault?: boolean; /** * Skip the `.aureon-admin__grid` wrapper (its 220px-minmax columns and * 24px bottom margin are sized for a row of fields) — for content that * isn't a field row, like the Button Preview's plain flex row of sample * buttons, which otherwise inherited empty grid space it never used. */ plain?: boolean; children: ReactNode; } ) { return (

{ label }

{ description && (

{ description }

) }
{ onReset && ! isDefault && (
{ plain ? ( children ) : (
{ children }
) }
); } /** * ToggleGrid — a row of equal-width icon+label boxes for a "pick one" * choice, one column per option. Used for both Button Style (4 options) and * Button Alignment (3 options) so every "choose a look" field in this * section reads as the same affordance, rather than Style using bordered * boxes and Alignment using the shared pill-bar SegmentedControl — two * different controls for the same kind of decision. Any per-option * description surfaces as a native tooltip; the shared caption above (on the * FieldGroup) carries the field's own explanation. * @param root0 * @param root0.options * @param root0.value * @param root0.onChange * @param root0.icons */ function ToggleGrid( { options, value, onChange, icons, }: { options: ButtonOption[]; value: string; onChange: ( value: string ) => void; icons: Record< string, LucideIcon >; } ) { return (
{ options.map( ( option ) => { const Icon = icons[ option.key ] ?? Square; const selected = option.key === value; return ( ); } ) }
); } /** * Button Preview — a few sample buttons styled live from the in-progress * `working` values via inline --aureon-btn-* custom properties, so every group * above visibly updates the preview as it's edited, no new state needed. * @param root0 * @param root0.radius * @param root0.style */ function ButtonPreview( { radius, style, }: { radius: Record< string, string >; style: Record< string, any >; } ) { const isVariant = [ 'outline', 'text', 'link' ].includes( style.style ?? 'filled' ); const previewStyle: Record< string, string > = { '--aureon-radius-md': radius.md ?? '8px', '--aureon-btn-padding-top': style.padding_top || '12px', '--aureon-btn-padding-right': style.padding_right || '24px', '--aureon-btn-padding-bottom': style.padding_bottom || '12px', '--aureon-btn-padding-left': style.padding_left || '24px', '--aureon-btn-border-width': style.border_width || '2px', '--aureon-btn-border-style': style.border_style || 'solid', }; if ( style.border_color ) { previewStyle[ '--aureon-btn-border-color' ] = style.border_color; } if ( isVariant ) { previewStyle[ '--aureon-btn-bg' ] = 'transparent'; previewStyle[ '--aureon-btn-text' ] = 'var(--aureon-color-primary)'; if ( 'outline' === style.style && ! style.border_color ) { previewStyle[ '--aureon-btn-border-color' ] = 'var(--aureon-color-primary)'; } } // The variant class for the primary sample; filled buttons need none. const variantClass = ( { link: ' aureon-button--link', text: ' aureon-button--text', outline: ' aureon-button--outline', } as Record< string, string > )[ style.style ] ?? ''; // Plain spans, not links: these are visual samples with nothing to do, // so they shouldn't be focusable or announced as links. return (
{ __( 'Primary Button', 'aureon' ) } { __( 'Secondary Button', 'aureon' ) } { __( 'Text Button →', 'aureon' ) }
); } export default function ButtonsSection( { schema, defaults, working, setPath, }: ButtonsSectionProps ) { const [ activeTab, setActiveTab ] = useState( 'settings' ); if ( ! schema ) { return null; } const radius = working?.design?.radius ?? {}; const radiusDefaults = defaults?.design?.radius ?? {}; const stylePath = schema.style_path ?? 'design.buttons'; const style = ( ( working?.design as Record< string, any > )?.buttons ?? {} ) as Record< string, any >; const styleDefaults = ( ( defaults?.design as Record< string, any > ) ?.buttons ?? {} ) as Record< string, any >; const setStyle = ( key: string, value: unknown ) => setPath( `${ stylePath }.${ key }`, value ); // Whether every key in a group still matches its default — drives the // group's "Reset to default" button in FieldGroup. const isGroupDefault = ( keys: string[] ) => keys.every( ( key ) => String( style[ key ] ?? '' ) === String( styleDefaults[ key ] ?? '' ) ); const resetGroup = ( keys: string[] ) => keys.forEach( ( key ) => setStyle( key, styleDefaults[ key ] ) ); // BorderField stores width as a plain integer px; border_width here is a // css-length string (e.g. "2px") like every other length field in this // section, so coerce through it at the edges rather than changing its // storage shape. const borderWidthPx = parseInt( style.border_width ?? '2px', 10 ) || 0; const cssVariables = schema.fields.map( ( field ) => ( { name: `--aureon-radius-${ field.key }`, value: radius[ field.key ] ?? '—', } ) ); [ 'style', 'size', 'alignment', 'padding_top', 'padding_right', 'padding_bottom', 'padding_left', 'border_width', 'border_style', 'border_color', 'hover_bg', 'hover_text', 'hover_transform', 'transition_speed', 'focus_ring', 'focus_ring_color', ].forEach( ( key ) => { cssVariables.push( { name: `--aureon-btn-${ key.replace( /_/g, '-' ) }`, value: String( style[ key ] ?? '—' ) || '—', } ); } ); return (

{ schema.label }

{ __( 'Global button style: variant, size, alignment, radius, border, padding, hover, and focus ring — applied to every theme button.', 'aureon' ) }

resetGroup( [ 'style' ] ) } isDefault={ isGroupDefault( [ 'style' ] ) } > setStyle( 'style', value ) } icons={ STYLE_ICONS } /> { schema.fields.map( ( field ) => ( setPath( `${ schema.path }.${ field.key }`, value ) } /> ) ) } resetGroup( [ 'size' ] ) } isDefault={ isGroupDefault( [ 'size' ] ) } > ( { value: option.key, label: option.label, } ) ) } onChange={ ( value ) => setStyle( 'size', value ) } /> resetGroup( [ 'alignment' ] ) } isDefault={ isGroupDefault( [ 'alignment' ] ) } > setStyle( 'alignment', value ) } icons={ ALIGNMENT_ICONS } /> resetGroup( [ 'padding_top', 'padding_right', 'padding_bottom', 'padding_left', ] ) } isDefault={ isGroupDefault( [ 'padding_top', 'padding_right', 'padding_bottom', 'padding_left', ] ) } > { setStyle( 'padding_top', next.top ?? '' ); setStyle( 'padding_right', next.right ?? '' ); setStyle( 'padding_bottom', next.bottom ?? '' ); setStyle( 'padding_left', next.left ?? '' ); } } /> resetGroup( [ 'border_width', 'border_style', 'border_color', ] ) } isDefault={ isGroupDefault( [ 'border_width', 'border_style', 'border_color', ] ) } > setStyle( 'border_width', `${ width }px` ) } onColorChange={ ( color ) => setStyle( 'border_color', color ) } /> ( { value: option.key, label: option.label, } ) ) } onChange={ ( value ) => setStyle( 'border_style', value ) } /> resetGroup( [ 'hover_bg', 'hover_text', 'hover_transform', 'transition_speed', ] ) } isDefault={ isGroupDefault( [ 'hover_bg', 'hover_text', 'hover_transform', 'transition_speed', ] ) } > setStyle( 'hover_bg', value ) } /> setStyle( 'hover_text', value ) } /> ( { value: option.key, label: option.label, } ) ) } onChange={ ( value ) => setStyle( 'hover_transform', value ) } /> setStyle( 'transition_speed', value ) } /> resetGroup( [ 'focus_ring', 'focus_ring_color' ] ) } isDefault={ isGroupDefault( [ 'focus_ring', 'focus_ring_color', ] ) } > setStyle( 'focus_ring', checked ) } /> { style.focus_ring !== false && ( setStyle( 'focus_ring_color', value ) } /> ) }
); }