Overview
Generates scoped <style> elements for live editor preview by converting block attributes and responsive settings into CSS, with full support for media queries.
File: lib/blocks/components/MethodStyleTag.jsx
Type: Utility component (renders a <style> element, no visible UI)
Props
Prop Type Default Description clientIdstring(required) The block’s WordPress clientId; used as data-method-id on the style tag attributesobject(required) The block’s full attributes object selectorMapobject(required) Maps CSS selectors to arrays of property keys to generate excludeBasebooleanfalseWhen true, skips base breakpoint CSS (used by Core Extensions) postIdnumbernullWith postType, lets the tag resolve the post’s featured image per breakpoint (useFeaturedImageSizes) for blocks with useFeaturedImage postTypestringnullSee postId isImportantbooleanfalseAppend !important to every declaration — used by the core extensions so overrides beat core / theme.json specificity in the canvas
How It Works
MethodStyleTag is the bridge between block attributes and live editor styling. It renders a <style> element whose innerHTML is rebuilt via useEffect whenever attributes changes.
Selector Map
The selectorMap is an object where keys are CSS selectors and values are arrays of property keys to resolve:
const cssMap = {
[`#block-${clientId}`]: ['borderRadius', 'margin-top', 'margin-bottom', 'boxShadow'],
[`#block-${clientId} > .content`]: ['textColor', 'bgColor', 'padding-top', 'padding-bottom'],
[`#block-${clientId} a`]: ['linkColor'],
};
CSS Generation Pipeline
Base styles (unless excludeBase): Processes responsiveSettings.base and top‑level color attributes
Mobile styles: Wrapped in @media(max-width: {mobile_max})
Tablet styles: Wrapped in @media(min-width: {tablet_min}) and (max-width: {tablet_max})
Wide styles: Wrapped in @media(min-width: {wide_min})
Breakpoint values come from window.methodGlobalData.breakpoints.
Property Key Reference
The component supports a comprehensive set of property keys that map attribute data to CSS output:
Spacing Properties
Key Source CSS Output padding-topsettings.padding.toppadding-top: {value}padding-bottomsettings.padding.bottompadding-bottom: {value}padding-leftsettings.padding.leftpadding-left: {value}padding-rightsettings.padding.rightpadding-right: {value}margin-topsettings.margin.topmargin-top: {value}margin-bottomsettings.margin.bottommargin-bottom: {value}margin-leftsettings.margin.leftmargin-left: {value} (skipped if starts with 0)margin-rightsettings.margin.rightmargin-right: {value} (skipped if starts with 0)gapsettings.gaprow-gap from .top; column-gap from .left/.rightgapAsVarssettings.gap--bs-gutter-y from .top; --bs-gutter-x from .left/.right
Typography Properties
Key Source CSS Output fontSizesettings.fontSizefont-size: {value}lineHeightsettings.lineHeightline-height: {value}textAlignsettings.textAligntext-align: {value}
Color Properties (base breakpoint only)
Key Source CSS Output textColorattributes.textColorcolor: {value}linkColorattributes.linkColorcolor: {value}bgColorattributes.bgGradient \|\| attributes.bgColorbackground: {value}bgShadeattributes.bgShadeGradient \|\| attributes.bgShadeColorbackground: {value}
Dimension Controls
Key Source CSS Output heightsettings.heightheight: {value} (skipped if starts with 0)minHeightsettings.minHeightmin-height: {value} (skipped if starts with 0)widthsettings.widthwidth: {value} (skipped if starts with 0)minWidthsettings.minWidthmin-width: {value} (skipped if starts with 0)
Border Properties
Key Source CSS Output bordersettings.borderUniform: border: {width} {style} {color}. Per‑side: individual border-top, etc. borderRadiussettings.borderRadiusObject: per‑corner properties. String: single border-radius
Layout Properties
Key Source CSS Output alignItemssettings.alignItemsalign-items: {value}justifyContentsettings.justifyContentjustify-content: {value}flexDirectionsettings.flexDirectionflex-direction: {value} (defaults to row)ordersettings.orderorder: {value} (skipped if starts with 0)
Background Properties (base or customBg breakpoints)
Key Source CSS Output bgImgattributes.bgImg[settings.bgImgSize].urlbackground-image: url(...)bgPositionsettings.bgImgAlign + offsetsbackground-position: {x} {xOffset} {y} {yOffset}bgSizesettings.bgDisplaySizebackground-size: cover\|contain\|{w} {h}bgRepeatsettings.bgRepeatbackground-repeat: {value} (defaults to no-repeat)
Special Properties
Key Source CSS Output boxShadowsettings.shadows arraybox-shadow: {layer1}, {layer2}, ... (base only)aspectRatiosettings.aspectUses + sub‑keysHeight mode: height + padding-top: 0. Percentage mode: padding-top + height: 0 equalDimensionssettings.dimensionswidth: {value}; height: {value}
Usage
Every Method block that uses responsive styling includes a MethodStyleTag:
<MethodStyleTag
clientId={clientId}
attributes={attributes}
selectorMap={cssMap}
/>
Core Extensions pass excludeBase={true} to avoid conflicting with WordPress core’s own base styling.
Changelog
Version Description 2.0.0-alpha4 Introduced (121d149 ). 2.0.0-beta5 overflow and zIndex (1a17d90 ).2.0.0-beta6 flexGrow, flexShrink, flexBasis; zIndex checked with !== undefined so z-index: 0 renders; postId / postType props and per-breakpoint featured-image backgrounds (09cc16b ).2.0.0-beta7 zeroHeight (5afb83a ).2.0.0-beta8 aspectRatioDimension from aspectRatioX / aspectRatioY (bd7d2f4 ).2.0.0-beta14 linkHoverColor, so hover colors preview in the editor (ba36676 ).2.0.0-beta15 hide (a67fd5b ).2.0.0-beta17 fontFamily, fontStyle, fontWeight, textTransform, letterSpacing; textColor accepted as an alias of the color map key (8db7ce9 ).2.0.0-beta18 isImportant prop (3064cd9 ).2.0.0-beta20 backdrop (as backdrop-filter) and order (ae61c10 ).2.0.0-beta21 background-size: unset for the new Image Size background option (75910d2 ).2.0.0-beta24 flexWrap (a3a3034 ).