MethodSpacingControls
Overview
Padding, margin, and gap controls using WordPress’s BoxControl, wrapped in a ToolsPanel with per‑item opt‑in and configurable side constraints.
- File:
lib/blocks/components/MethodSpacingControls.js - Panel label: “Block Spacing”
Props
| Prop | Type | Default | Description |
|---|---|---|---|
breakpoint | string | (required) | The responsive breakpoint: base, mobile, tablet, or wide |
attributes | object | (required) | The block’s full attributes object |
setAttributes | function | (required) | WordPress setAttributes function |
include | string[] | ['padding', 'margin', 'gap'] | Which spacing types to render |
sides | object | (see below) | Which sides to expose for each spacing type |
resetDefaults | object | (auto‑generated) | Custom reset values; overrides the built‑in defaults |
Default sides
{
padding: ['top', 'bottom', 'left', 'right'],
margin: ['top', 'bottom'],
gap: ['horizontal', 'vertical'],
}Controls
Padding
- UI:
BoxControlwith configurable sides. - Settings key:
responsiveSettings.{breakpoint}.padding - Value shape:
{ top: '0rem', bottom: '0rem', left: '0rem', right: '0rem' }
The sides prop determines which sides are editable. Commonly limited to top/bottom for certain blocks.
Margin
- UI:
BoxControlwith configurable sides + “Allow Negative Values” checkbox. - Settings key:
responsiveSettings.{breakpoint}.margin - Value shape:
{ top: '0rem', bottom: '0rem', left: '0rem', right: '0rem' }
Full‑width awareness: When attributes.align === 'full', left/right margin sides are automatically filtered out, leaving only top/bottom. This prevents full‑width blocks from receiving horizontal margins that would break the layout.
Negative margins: When the allowNegative checkbox is enabled (responsiveSettings.{breakpoint}.allowNegative), the BoxControl’s input range expands from the default to -999 through 999. This is stored as a separate key and is removed when the margin control is deselected.
Gap
- UI:
BoxControlwithsplitOnAxis={true}for horizontal/vertical gap. - Settings key:
responsiveSettings.{breakpoint}.gap - Value shape:
{ top: '1.5rem', bottom: '1.5rem', left: '1.5rem', right: '1.5rem' }
Gap uses BoxControl’s axis splitting — top/bottom map to row‑gap and left/right map to column‑gap. The sides prop controls which axes are available (e.g., ['horizontal', 'vertical'] for both, or ['horizontal'] for column‑gap only).
ToolsPanel Behavior
- Padding onDeselect: Removes
paddingkey entirely from the breakpoint settings - Margin onDeselect: Removes both
marginandallowNegativekeys simultaneously viaupdateMultipleSettings - Gap onDeselect: Removes
gapkey - resetAll: Removes
padding,margin,gap, andallowNegativefrom the breakpoint
Default reset values are auto‑generated based on the include prop:
- Padding resets to
0remon all sides - Margin resets to
0remon all sides - Gap resets to
1.5remon applicable axes
CSS Output
The spacing values are consumed by MethodStyleTag which maps them to CSS properties:
| Settings Key | CSS Properties |
|---|---|
padding.top | padding-top |
margin.left | margin-left |
gap.top / gap.bottom | row-gap (standard) or --bs-gutter-y (grid variant) |
gap.left / gap.right | column-gap (standard) or --bs-gutter-x (grid variant) |
The distinction between gap and gapAsVars in the selector map determines whether standard CSS gap or Bootstrap CSS custom properties are used.
Usage by Blocks
Used by nearly every Method block. Common configurations:
| Block | Include | Notes |
|---|---|---|
| Section | padding, margin | All 4 sides each |
| Container | padding, margin | All 4 sides each |
| Advanced Grid | padding, margin | Grid: all sides; Row adds gap |
| Basic Grid | padding, margin, gap | — |
| Flex Container | padding, margin, gap | Gap with horizontal/vertical |
| Buttons | padding, margin, gap | Gap with horizontal/vertical |
| Breadcrumb | padding, margin, gap | Gap with horizontal/vertical |
| Button (child) | padding only | — |
| Basic Grid Item | padding only | — |