/** * Column settings — the trigger on each column plus its settings window: * General (alignment, width, element layout) and Style (background, border, padding), with * Delete in the footer. See BuilderModal for the window itself. */ import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Button } from '@wordpress/components'; import { AlignCenter, AlignLeft, AlignRight, Columns3, Settings2, Trash2, } from '../../icons'; import ColorField from '../../controls/color-field'; import BoxField from '../../controls/box-field'; import BorderField from '../../controls/border-field'; import RangeField from '../../controls/range-field'; import BuilderModal from './builder-modal'; import Segmented from './segmented'; import type { ColumnAlign, ColumnDesign, ColumnLayout, BoxValue, } from './canvas-model'; import type { ReactElement } from 'react'; /** Width a column gets when switched from Auto to Custom. */ const CUSTOM_WIDTH_START = 33; interface ColumnToolbarProps { align: ColumnAlign; width: number; design: ColumnDesign; canDelete: boolean; onAlign: ( align: ColumnAlign ) => void; onWidth: ( width: number ) => void; onDesign: ( patch: Partial< ColumnDesign > ) => void; onDelete: () => void; /** Where the column sits, e.g. "Main Header · Column 2". */ subtitle?: string; /** Trigger icon — defaults to the sliders glyph. */ icon?: ReactElement; /** * Replaces the default gear button — receives the opener. For a trigger * that carries text (core's icon Button fixes its width to the icon). */ renderTrigger?: ( open: () => void ) => ReactElement; } export default function ColumnToolbar( { align, width, design, canDelete, onAlign, onWidth, onDesign, onDelete, subtitle, icon, renderTrigger, }: ColumnToolbarProps ) { const [ open, setOpen ] = useState( false ); const [ tab, setTab ] = useState( 'general' ); return (
{ renderTrigger ? ( renderTrigger( () => setOpen( true ) ) ) : ( } footerEnd={ } > { 'general' === tab && ( <> label={ __( 'Content alignment', 'aureon' ) } value={ align } options={ [ { value: 'left', label: __( 'Left', 'aureon' ), icon: AlignLeft, }, { value: 'center', label: __( 'Center', 'aureon' ), icon: AlignCenter, }, { value: 'right', label: __( 'Right', 'aureon' ), icon: AlignRight, }, ] } onChange={ onAlign } /> label={ __( 'Elements', 'aureon' ) } value={ design.layout ?? 'row' } options={ [ { value: 'row', label: __( 'Side by side', 'aureon' ), }, { value: 'stack', label: __( 'Stacked', 'aureon' ), }, ] } onChange={ ( layout ) => onDesign( { layout } ) } /> label={ __( 'Width', 'aureon' ) } value={ width ? 'custom' : 'auto' } options={ [ { value: 'auto', label: __( 'Auto', 'aureon' ), }, { value: 'custom', label: __( 'Custom', 'aureon' ), }, ] } onChange={ ( mode ) => onWidth( 'custom' === mode ? width || CUSTOM_WIDTH_START : 0 ) } /> { width ? ( ) : (

{ __( 'Auto columns share the row’s remaining space evenly.', 'aureon' ) }

) } ) } { 'style' === tab && ( <> onDesign( { background } ) } /> onDesign( { border_width: next } ) } onColorChange={ ( color ) => onDesign( { border_color: color } ) } sides={ design.border_sides } onSidesChange={ ( sides ) => onDesign( { border_sides: sides } ) } /> onDesign( { padding } ) } /> ) } ) }
); }