| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var __ = wp.i18n.__; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var RichText = wp.blockEditor.RichText; |
| 7 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 8 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var ToggleControl = wp.components.ToggleControl; |
| 11 |
var RangeControl = wp.components.RangeControl; |
| 12 |
var SelectControl = wp.components.SelectControl; |
| 13 |
var TextControl = wp.components.TextControl; |
| 14 |
|
| 15 |
var _TypographyControl, _typoCssVars; |
| 16 |
function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); } |
| 17 |
function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); } |
| 18 |
|
| 19 |
registerBlockType('blockenberg/highlight-section', { |
| 20 |
edit: function (props) { |
| 21 |
var attr = props.attributes; |
| 22 |
var setAttr = props.setAttributes; |
| 23 |
|
| 24 |
var blockProps = useBlockProps({ className: 'bkbg-hs-editor' }); |
| 25 |
|
| 26 |
var _tv = getTypoCssVars(); |
| 27 |
var sectionStyle = { |
| 28 |
background: attr.bgColor || '#fff', |
| 29 |
paddingTop: attr.paddingTop + 'px', |
| 30 |
paddingBottom: attr.paddingBottom + 'px', |
| 31 |
position: 'relative', |
| 32 |
overflow: 'hidden', |
| 33 |
textAlign: attr.textAlign |
| 34 |
}; |
| 35 |
Object.assign(sectionStyle, _tv(attr.headingTypo || {}, '--bkbg-hs-h-')); |
| 36 |
Object.assign(sectionStyle, _tv(attr.subtextTypo || {}, '--bkbg-hs-st-')); |
| 37 |
Object.assign(sectionStyle, _tv(attr.ctaTypo || {}, '--bkbg-hs-cta-')); |
| 38 |
/* legacy fallback vars */ |
| 39 |
if (attr.headingSize && attr.headingSize !== 56) sectionStyle['--bkbg-hs-h-sz'] = attr.headingSize + 'px'; |
| 40 |
if (attr.headingFontWeight && attr.headingFontWeight !== '800') sectionStyle['--bkbg-hs-h-fw'] = attr.headingFontWeight; |
| 41 |
if (attr.headingLineHeight && attr.headingLineHeight !== 1.15) sectionStyle['--bkbg-hs-h-lh'] = String(attr.headingLineHeight); |
| 42 |
if (attr.subtextSize && attr.subtextSize !== 20) sectionStyle['--bkbg-hs-st-sz'] = attr.subtextSize + 'px'; |
| 43 |
if (attr.subtextFontWeight && attr.subtextFontWeight !== '400') sectionStyle['--bkbg-hs-st-fw'] = attr.subtextFontWeight; |
| 44 |
if (attr.subtextLineHeight && attr.subtextLineHeight !== 1.6) sectionStyle['--bkbg-hs-st-lh'] = String(attr.subtextLineHeight); |
| 45 |
if (attr.ctaFontSize && attr.ctaFontSize !== 16) sectionStyle['--bkbg-hs-cta-sz'] = attr.ctaFontSize + 'px'; |
| 46 |
if (attr.ctaFontWeight && attr.ctaFontWeight !== '600') sectionStyle['--bkbg-hs-cta-fw'] = attr.ctaFontWeight; |
| 47 |
|
| 48 |
var innerStyle = { |
| 49 |
maxWidth: attr.maxWidth + 'px', |
| 50 |
margin: '0 auto', |
| 51 |
position: 'relative', |
| 52 |
zIndex: 1 |
| 53 |
}; |
| 54 |
|
| 55 |
var controls = el(InspectorControls, {}, |
| 56 |
el(PanelBody, { title: __('Background Word', 'blockenberg'), initialOpen: true }, |
| 57 |
el(ToggleControl, { |
| 58 |
label: __('Show Background Word', 'blockenberg'), |
| 59 |
checked: attr.showBgWord, |
| 60 |
onChange: function (v) { setAttr({ showBgWord: v }); }, |
| 61 |
__nextHasNoMarginBottom: true |
| 62 |
}), |
| 63 |
attr.showBgWord && el(TextControl, { |
| 64 |
label: __('Background Word', 'blockenberg'), |
| 65 |
value: attr.bgWord, |
| 66 |
onChange: function (v) { setAttr({ bgWord: v }); }, |
| 67 |
__nextHasNoMarginBottom: true |
| 68 |
}), |
| 69 |
attr.showBgWord && el(RangeControl, { |
| 70 |
label: __('Background Word Size (px)', 'blockenberg'), |
| 71 |
value: attr.bgWordSize, |
| 72 |
min: 80, max: 600, |
| 73 |
onChange: function (v) { setAttr({ bgWordSize: v }); }, |
| 74 |
__nextHasNoMarginBottom: true |
| 75 |
}), |
| 76 |
attr.showBgWord && el(SelectControl, { |
| 77 |
label: __('Background Word Weight', 'blockenberg'), |
| 78 |
value: attr.bgWordWeight, |
| 79 |
options: [ |
| 80 |
{ label: 'Extra Bold (900)', value: '900' }, |
| 81 |
{ label: 'Bold (700)', value: '700' }, |
| 82 |
{ label: 'Normal (400)', value: '400' } |
| 83 |
], |
| 84 |
onChange: function (v) { setAttr({ bgWordWeight: v }); }, |
| 85 |
__nextHasNoMarginBottom: true |
| 86 |
}) |
| 87 |
), |
| 88 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: false }, |
| 89 |
el(ToggleControl, { |
| 90 |
label: __('Show Subtext', 'blockenberg'), |
| 91 |
checked: attr.showSubtext, |
| 92 |
onChange: function (v) { setAttr({ showSubtext: v }); }, |
| 93 |
__nextHasNoMarginBottom: true |
| 94 |
}), |
| 95 |
el(ToggleControl, { |
| 96 |
label: __('Show CTA Button', 'blockenberg'), |
| 97 |
checked: attr.showCta, |
| 98 |
onChange: function (v) { setAttr({ showCta: v }); }, |
| 99 |
__nextHasNoMarginBottom: true |
| 100 |
}), |
| 101 |
attr.showCta && el(TextControl, { |
| 102 |
label: __('CTA Label', 'blockenberg'), |
| 103 |
value: attr.ctaLabel, |
| 104 |
onChange: function (v) { setAttr({ ctaLabel: v }); }, |
| 105 |
__nextHasNoMarginBottom: true |
| 106 |
}), |
| 107 |
attr.showCta && el(TextControl, { |
| 108 |
label: __('CTA URL', 'blockenberg'), |
| 109 |
value: attr.ctaUrl, |
| 110 |
onChange: function (v) { setAttr({ ctaUrl: v }); }, |
| 111 |
__nextHasNoMarginBottom: true |
| 112 |
}), |
| 113 |
attr.showCta && el(ToggleControl, { |
| 114 |
label: __('Open in New Tab', 'blockenberg'), |
| 115 |
checked: attr.ctaOpenNewTab, |
| 116 |
onChange: function (v) { setAttr({ ctaOpenNewTab: v }); }, |
| 117 |
__nextHasNoMarginBottom: true |
| 118 |
}) |
| 119 |
), |
| 120 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 121 |
el(SelectControl, { |
| 122 |
label: __('Text Align', 'blockenberg'), |
| 123 |
value: attr.textAlign, |
| 124 |
options: [ |
| 125 |
{ label: 'Left', value: 'left' }, |
| 126 |
{ label: 'Center', value: 'center' }, |
| 127 |
{ label: 'Right', value: 'right' } |
| 128 |
], |
| 129 |
onChange: function (v) { setAttr({ textAlign: v }); }, |
| 130 |
__nextHasNoMarginBottom: true |
| 131 |
}), |
| 132 |
el(getTypographyControl(), { label: __('Heading Typography', 'blockenberg'), value: attr.headingTypo || {}, onChange: function (v) { setAttr({ headingTypo: v }); } }), |
| 133 |
el(getTypographyControl(), { label: __('Subtext Typography', 'blockenberg'), value: attr.subtextTypo || {}, onChange: function (v) { setAttr({ subtextTypo: v }); } }), |
| 134 |
el(getTypographyControl(), { label: __('CTA Typography', 'blockenberg'), value: attr.ctaTypo || {}, onChange: function (v) { setAttr({ ctaTypo: v }); } }) |
| 135 |
), |
| 136 |
el(PanelColorSettings, { |
| 137 |
title: __('Colors', 'blockenberg'), |
| 138 |
initialOpen: false, |
| 139 |
colorSettings: [ |
| 140 |
{ label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#fff' }); } }, |
| 141 |
{ label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); } }, |
| 142 |
{ label: __('Subtext', 'blockenberg'), value: attr.subtextColor, onChange: function (v) { setAttr({ subtextColor: v || '#4b5563' }); } }, |
| 143 |
{ label: __('CTA Background', 'blockenberg'), value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#7c3aed' }); } }, |
| 144 |
{ label: __('CTA Text', 'blockenberg'), value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#fff' }); } }, |
| 145 |
{ label: __('Background Word Color', 'blockenberg'), value: attr.bgWordColor, onChange: function (v) { setAttr({ bgWordColor: v || 'rgba(0,0,0,0.05)' }); } } |
| 146 |
] |
| 147 |
}), |
| 148 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false }, |
| 149 |
el(RangeControl, { |
| 150 |
label: __('Max Width (px)', 'blockenberg'), |
| 151 |
value: attr.maxWidth, |
| 152 |
min: 400, max: 1600, |
| 153 |
onChange: function (v) { setAttr({ maxWidth: v }); }, |
| 154 |
__nextHasNoMarginBottom: true |
| 155 |
}), |
| 156 |
el(RangeControl, { |
| 157 |
label: __('Padding Top (px)', 'blockenberg'), |
| 158 |
value: attr.paddingTop, |
| 159 |
min: 0, max: 300, |
| 160 |
onChange: function (v) { setAttr({ paddingTop: v }); }, |
| 161 |
__nextHasNoMarginBottom: true |
| 162 |
}), |
| 163 |
el(RangeControl, { |
| 164 |
label: __('Padding Bottom (px)', 'blockenberg'), |
| 165 |
value: attr.paddingBottom, |
| 166 |
min: 0, max: 300, |
| 167 |
onChange: function (v) { setAttr({ paddingBottom: v }); }, |
| 168 |
__nextHasNoMarginBottom: true |
| 169 |
}) |
| 170 |
) |
| 171 |
); |
| 172 |
|
| 173 |
return el('div', blockProps, controls, |
| 174 |
el('div', { className: 'bkbg-hs-wrap', style: sectionStyle }, |
| 175 |
attr.showBgWord && el('div', { |
| 176 |
className: 'bkbg-hs-bg-word', |
| 177 |
style: { |
| 178 |
position: 'absolute', |
| 179 |
top: '50%', |
| 180 |
left: '50%', |
| 181 |
transform: 'translate(-50%, -50%)', |
| 182 |
fontSize: attr.bgWordSize + 'px', |
| 183 |
fontWeight: attr.bgWordWeight, |
| 184 |
color: attr.bgWordColor, |
| 185 |
pointerEvents: 'none', |
| 186 |
userSelect: 'none', |
| 187 |
lineHeight: 1, |
| 188 |
whiteSpace: 'nowrap', |
| 189 |
zIndex: 0 |
| 190 |
} |
| 191 |
}, attr.bgWord), |
| 192 |
el('div', { style: innerStyle }, |
| 193 |
el(RichText, { |
| 194 |
tagName: 'h2', |
| 195 |
className: 'bkbg-hs-heading', |
| 196 |
style: { color: attr.headingColor, margin: '0 0 20px' }, |
| 197 |
value: attr.heading, |
| 198 |
onChange: function (v) { setAttr({ heading: v }); }, |
| 199 |
placeholder: __('Heading…', 'blockenberg') |
| 200 |
}), |
| 201 |
attr.showSubtext && el(RichText, { |
| 202 |
tagName: 'p', |
| 203 |
className: 'bkbg-hs-subtext', |
| 204 |
style: { color: attr.subtextColor, margin: '0 0 32px' }, |
| 205 |
value: attr.subtext, |
| 206 |
onChange: function (v) { setAttr({ subtext: v }); }, |
| 207 |
placeholder: __('Subtext…', 'blockenberg') |
| 208 |
}), |
| 209 |
attr.showCta && el('div', { className: 'bkbg-hs-cta-wrap' }, |
| 210 |
el('span', { |
| 211 |
className: 'bkbg-hs-cta-btn', |
| 212 |
style: { |
| 213 |
display: 'inline-block', |
| 214 |
background: attr.ctaBg, |
| 215 |
color: attr.ctaColor, |
| 216 |
padding: '14px 32px', |
| 217 |
borderRadius: '8px', |
| 218 |
cursor: 'default' |
| 219 |
} |
| 220 |
}, attr.ctaLabel) |
| 221 |
) |
| 222 |
) |
| 223 |
) |
| 224 |
); |
| 225 |
}, |
| 226 |
|
| 227 |
save: function (props) { |
| 228 |
var attr = props.attributes; |
| 229 |
var blockProps = wp.blockEditor.useBlockProps.save(); |
| 230 |
return el('div', blockProps, |
| 231 |
el('div', { |
| 232 |
className: 'bkbg-hs-app', |
| 233 |
'data-opts': JSON.stringify(attr) |
| 234 |
}) |
| 235 |
); |
| 236 |
} |
| 237 |
}); |
| 238 |
}() ); |
| 239 |
|