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)
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:
JavaScript 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:
JavaScript < MethodStyleTag
clientId ={ clientId }
attributes ={ attributes }
selectorMap ={ cssMap }
/>
Core Extensions pass excludeBase={true} to avoid conflicting with WordPress core’s own base styling.