MethodBackgroundControls
Overview
Image and video background management with media upload, resolution selection, position alignment, display sizing, repeat options, and parallax toggle.
- File:
lib/blocks/components/MethodBackgroundControls.js - Panel context: Typically rendered inside a “Background Media” PanelBody
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 |
isImg | boolean | false | When true, switches to image‑fitting mode (cover/contain only, no position/repeat/parallax) |
includeVideo | boolean | false | When true, shows the background video URL field |
Controls
Image Selection (base breakpoint only)
- UI:
MediaUploadwith Select/Change/Reset buttons and image thumbnail preview. - Attribute:
bgImg(top‑level object, not insideresponsiveSettings)
When an image is selected, the component builds a bgImg object containing all available WordPress image sizes with their URLs and dimensions:
{
id: 123,
full: { url: '...', width: 1920, height: 1080 },
large: { url: '...', width: 1024, height: 576 },
medium: { url: '...', width: 300, height: 169 },
// ...additional registered sizes
}Size variants that are the same dimensions or URL as full are excluded. After selection, bgImgSize is auto‑set to large if available, otherwise full.
Image Resolution
- UI:
CustomSelectControlshowing available size names with dimensions as hints (e.g., “Large — 1024×576”). - Settings key:
responsiveSettings.{breakpoint}.bgImgSize - Visibility: Shown when
bgImghas been selected and the current breakpoint is enabled.
Available sizes are dynamically computed from the bgImg attribute cross‑referenced with the editor’s registered imageSizes.
Image Alignment
- UI:
AlignmentMatrixControl(3×3 grid) + text label showing the current value. - Settings key:
responsiveSettings.{breakpoint}.bgImgAlign - Default:
"center center" - Visibility: Base breakpoint only; hidden when parallax or video is active; hidden in
isImgmode.
Position Offset
- UI: Two
UnitControlfields for X and Y offset. - Settings keys:
responsiveSettings.{breakpoint}.bgOffsetX,responsiveSettings.{breakpoint}.bgOffsetY - Visibility: Same conditions as Image Alignment.
Display Size
- UI:
SelectControldropdown. - Settings key:
responsiveSettings.{breakpoint}.bgDisplaySize
In standard background mode (isImg=false):
| Option | Value |
|---|---|
| Image Size | "" (empty) |
| Cover | cover |
| Contain | contain |
| Custom | custom |
In image‑fitting mode (isImg=true):
| Option | Value |
|---|---|
| Cover | "" (empty) |
| Contain | "-contain" |
When “Custom” is selected, additional Width and Height UnitControl fields appear.
Repeat
- UI:
SelectControldropdown. - Settings key:
responsiveSettings.{breakpoint}.bgRepeat - Visibility: Hidden in
isImgmode and when parallax/video is active.
| Option | Value |
|---|---|
| No Repeat | "" (empty) |
| Repeat | repeat |
| Repeat X | repeat-x |
| Repeat Y | repeat-y |
| Space | space |
Parallax Toggle
- UI:
CheckboxControl. - Attribute:
useParallax(top‑level attribute, not inresponsiveSettings) - Visibility: Hidden in
isImgmode.
The checkbox label includes a help note: “If enabled, Jarallax will be used to add parallax scrolling. Automatically enabled for background video.” When bgVideo has a value, the checkbox is forced to checked.
Background Video URL
- UI:
TextControl. - Attribute:
bgVideo(top‑level attribute) - Visibility: Only when
includeVideo=true, not inisImgmode, and breakpoint is enabled.
Accepts URLs from YouTube, Vimeo, or direct video sources. Processed by Jarallax’s video extension.
Responsive Override
For non‑base breakpoints, a “Custom Background” checkbox (responsiveSettings.{breakpoint}.customBg) gates all controls. When unchecked, the breakpoint inherits from base.
Usage by Blocks
| Block | isImg | includeVideo | Breakpoints |
|---|---|---|---|
| Section | false | true (base) | base, mobile, tablet, wide |
| Container | false | true (base) | base, mobile, tablet, wide |
| Fitted Image | true | false | base only |
| Swiper Gallery | — | — | (uses its own MediaUpload) |