| 1 |
/* ==================================================== |
| 2 |
Section Intro — editor (index.js) |
| 3 |
Block: blockenberg/section-intro |
| 4 |
==================================================== */ |
| 5 |
( function () { |
| 6 |
var el = wp.element.createElement; |
| 7 |
var Fragment = wp.element.Fragment; |
| 8 |
var RichText = wp.blockEditor.RichText; |
| 9 |
var registerBlockType = wp.blocks.registerBlockType; |
| 10 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 11 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 12 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 13 |
var PanelBody = wp.components.PanelBody; |
| 14 |
var RangeControl = wp.components.RangeControl; |
| 15 |
var SelectControl = wp.components.SelectControl; |
| 16 |
var ToggleControl = wp.components.ToggleControl; |
| 17 |
var TextControl = wp.components.TextControl; |
| 18 |
var __ = wp.i18n.__; |
| 19 |
|
| 20 |
var _TC, _tv; |
| 21 |
function getTC() { return _TC || (_TC = window.bkbgTypographyControl); } |
| 22 |
function getTV() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 23 |
|
| 24 |
function wrapStyle(a) { |
| 25 |
return { |
| 26 |
'--bkbg-si-pt': a.paddingTop + 'px', |
| 27 |
'--bkbg-si-pb': a.paddingBottom + 'px', |
| 28 |
'--bkbg-si-gap': a.gap + 'px', |
| 29 |
'--bkbg-si-mw': a.maxWidth + 'px', |
| 30 |
'--bkbg-si-hl-c': a.headingColor, |
| 31 |
'--bkbg-si-sub-c': a.subtitleColor, |
| 32 |
'--bkbg-si-ey-bg': a.eyebrowBg, |
| 33 |
'--bkbg-si-ey-c': a.eyebrowColor, |
| 34 |
'--bkbg-si-div-c': a.dividerColor, |
| 35 |
'--bkbg-si-cta-c': a.ctaColor, |
| 36 |
'--bkbg-si-hl-sz': a.headingSize + 'px', |
| 37 |
'--bkbg-si-sub-sz': a.subtitleSize + 'px', |
| 38 |
'--bkbg-si-ey-sz': a.eyebrowSize + 'px', |
| 39 |
'--bkbg-si-div-w': a.dividerWidth + 'px', |
| 40 |
'--bkbg-si-hl-wt': a.headingWeight, |
| 41 |
}; |
| 42 |
} |
| 43 |
|
| 44 |
registerBlockType('blockenberg/section-intro', { |
| 45 |
edit: function (props) { |
| 46 |
var a = props.attributes; |
| 47 |
var setAttr = props.setAttributes; |
| 48 |
|
| 49 |
var blockProps = useBlockProps((function () { |
| 50 |
var _tvFn = getTV(); |
| 51 |
var s = wrapStyle(a); |
| 52 |
Object.assign(s, _tvFn(a.headingTypo, '--bksi-ht-')); |
| 53 |
Object.assign(s, _tvFn(a.eyebrowTypo, '--bksi-et-')); |
| 54 |
Object.assign(s, _tvFn(a.subtitleTypo, '--bksi-st-')); |
| 55 |
return { className: 'bkbg-si-wrap bkbg-si-align--' + a.align, style: s }; |
| 56 |
})()); |
| 57 |
|
| 58 |
var inspector = el(InspectorControls, null, |
| 59 |
el(PanelBody, { title:__('Content','blockenberg'), initialOpen:true }, |
| 60 |
el(ToggleControl, { label:__('Show eyebrow','blockenberg'), checked:a.showEyebrow, onChange:function(v){ setAttr({showEyebrow:v}); } }), |
| 61 |
el(TextControl, { label:__('Eyebrow text','blockenberg'), value:a.eyebrow, onChange:function(v){ setAttr({eyebrow:v}); } }), |
| 62 |
el(SelectControl, { label:__('Eyebrow style','blockenberg'), value:a.eyebrowStyle, options:[{label:'Pill badge',value:'pill'},{label:'Line above',value:'line-above'},{label:'Plain text',value:'plain'},{label:'Dot separator',value:'dot'}], onChange:function(v){ setAttr({eyebrowStyle:v}); } }), |
| 63 |
el(SelectControl, { label:__('Heading tag','blockenberg'), value:a.headingTag, options:[{label:'H1',value:'h1'},{label:'H2',value:'h2'},{label:'H3',value:'h3'},{label:'H4',value:'h4'}], onChange:function(v){ setAttr({headingTag:v}); } }), |
| 64 |
el(ToggleControl, { label:__('Show subtitle','blockenberg'), checked:a.showSubtitle, onChange:function(v){ setAttr({showSubtitle:v}); } }), |
| 65 |
el(ToggleControl, { label:__('Show divider','blockenberg'), checked:a.showDivider, onChange:function(v){ setAttr({showDivider:v}); } }), |
| 66 |
a.showDivider ? el(RangeControl, { label:__('Divider width (px)','blockenberg'), value:a.dividerWidth, min:16, max:200, onChange:function(v){ setAttr({dividerWidth:v}); } }) : null, |
| 67 |
el(ToggleControl, { label:__('Show CTA link','blockenberg'), checked:a.showCta, onChange:function(v){ setAttr({showCta:v}); } }), |
| 68 |
a.showCta ? el(TextControl, { label:__('CTA label','blockenberg'), value:a.ctaLabel, onChange:function(v){ setAttr({ctaLabel:v}); } }) : null, |
| 69 |
a.showCta ? el(TextControl, { label:__('CTA URL','blockenberg'), value:a.ctaUrl, onChange:function(v){ setAttr({ctaUrl:v}); } }) : null, |
| 70 |
a.showCta ? el(SelectControl, { label:__('CTA style','blockenberg'), value:a.ctaStyle, options:[{label:'Link with arrow',value:'link-arrow'},{label:'Button filled',value:'button-filled'},{label:'Button outlined',value:'button-outlined'}], onChange:function(v){ setAttr({ctaStyle:v}); } }) : null |
| 71 |
), |
| 72 |
el(PanelBody, { title:__('Layout','blockenberg'), initialOpen:false }, |
| 73 |
el(SelectControl, { label:__('Alignment','blockenberg'), value:a.align, options:[{label:'Center',value:'center'},{label:'Left',value:'left'},{label:'Right',value:'right'}], onChange:function(v){ setAttr({align:v}); } }), |
| 74 |
el(RangeControl, { label:__('Max width (px)','blockenberg'), value:a.maxWidth, min:300, max:1000, onChange:function(v){ setAttr({maxWidth:v}); } }), |
| 75 |
el(RangeControl, { label:__('Inner gap (px)','blockenberg'), value:a.gap, min:4, max:48, onChange:function(v){ setAttr({gap:v}); } }) |
| 76 |
), |
| 77 |
el(PanelBody, { title:__('Typography','blockenberg'), initialOpen:false }, |
| 78 |
el(getTC(), { label: __('Heading', 'blockenberg'), value: a.headingTypo, onChange: function (v) { setAttr({ headingTypo: v }); } }), |
| 79 |
el(getTC(), { label: __('Eyebrow', 'blockenberg'), value: a.eyebrowTypo, onChange: function (v) { setAttr({ eyebrowTypo: v }); } }), |
| 80 |
el(getTC(), { label: __('Subtitle', 'blockenberg'), value: a.subtitleTypo, onChange: function (v) { setAttr({ subtitleTypo: v }); } }) |
| 81 |
), |
| 82 |
el(PanelBody, { title:__('Spacing','blockenberg'), initialOpen:false }, |
| 83 |
el(RangeControl, { label:__('Padding top (px)','blockenberg'), value:a.paddingTop, min:0, max:160, onChange:function(v){ setAttr({paddingTop:v}); } }), |
| 84 |
el(RangeControl, { label:__('Padding bottom (px)','blockenberg'), value:a.paddingBottom, min:0, max:160, onChange:function(v){ setAttr({paddingBottom:v}); } }) |
| 85 |
), |
| 86 |
el(PanelColorSettings, { title:__('Colors','blockenberg'), initialOpen:false, colorSettings:[ |
| 87 |
{label:__('Heading','blockenberg'), value:a.headingColor, onChange:function(v){ setAttr({headingColor:v||''}); }}, |
| 88 |
{label:__('Subtitle','blockenberg'), value:a.subtitleColor, onChange:function(v){ setAttr({subtitleColor:v||''}); }}, |
| 89 |
{label:__('Eyebrow bg','blockenberg'), value:a.eyebrowBg, onChange:function(v){ setAttr({eyebrowBg:v||''}); }}, |
| 90 |
{label:__('Eyebrow text','blockenberg'), value:a.eyebrowColor, onChange:function(v){ setAttr({eyebrowColor:v||''}); }}, |
| 91 |
{label:__('Divider','blockenberg'), value:a.dividerColor, onChange:function(v){ setAttr({dividerColor:v||''}); }}, |
| 92 |
{label:__('CTA color','blockenberg'), value:a.ctaColor, onChange:function(v){ setAttr({ctaColor:v||''}); }}, |
| 93 |
] }) |
| 94 |
); |
| 95 |
|
| 96 |
return el(Fragment, null, |
| 97 |
inspector, |
| 98 |
el('div', blockProps, |
| 99 |
el('div', { className:'bkbg-si-inner' }, |
| 100 |
a.showEyebrow ? el('span', { className:'bkbg-si-eyebrow bkbg-si-ey--' + a.eyebrowStyle }, a.eyebrow) : null, |
| 101 |
a.showDivider ? el('div', { className:'bkbg-si-divider' }) : null, |
| 102 |
el(RichText, { tagName:a.headingTag, className:'bkbg-si-heading', value:a.heading, onChange:function(v){ setAttr({heading:v}); }, placeholder:__('Section heading…','blockenberg') }), |
| 103 |
a.showSubtitle ? el(RichText, { tagName:'p', className:'bkbg-si-subtitle', value:a.subtitle, onChange:function(v){ setAttr({subtitle:v}); }, placeholder:__('Subtitle…','blockenberg') }) : null, |
| 104 |
a.showCta ? el('span', { className:'bkbg-si-cta bkbg-si-cta--' + a.ctaStyle }, a.ctaLabel, a.ctaStyle === 'link-arrow' ? el('span', { className:'bkbg-si-arrow' }, ' →') : null) : null |
| 105 |
) |
| 106 |
) |
| 107 |
); |
| 108 |
}, |
| 109 |
|
| 110 |
deprecated: [{ |
| 111 |
attributes: {"showEyebrow":{"type":"boolean","default":true},"eyebrow":{"type":"string","default":"Why choose us"},"eyebrowStyle":{"type":"string","default":"pill"},"heading":{"type":"string","default":"Everything you need to succeed"},"headingTag":{"type":"string","default":"h2"},"showSubtitle":{"type":"boolean","default":true},"subtitle":{"type":"string","default":"We\u2019ve built a platform that grows with you \u2014 from first launch to global scale."},"showCta":{"type":"boolean","default":false},"ctaLabel":{"type":"string","default":"Learn more"},"ctaUrl":{"type":"string","default":"#"},"ctaTarget":{"type":"string","default":"_self"},"ctaStyle":{"type":"string","default":"link-arrow"},"showDivider":{"type":"boolean","default":false},"dividerWidth":{"type":"number","default":48},"align":{"type":"string","default":"center"},"maxWidth":{"type":"number","default":680},"headingSize":{"type":"number","default":40},"headingWeight":{"type":"string","default":"800"},"subtitleSize":{"type":"number","default":18},"eyebrowSize":{"type":"number","default":12},"gap":{"type":"number","default":16},"paddingTop":{"type":"number","default":0},"paddingBottom":{"type":"number","default":0},"headingColor":{"type":"string","default":"#0f172a"},"subtitleColor":{"type":"string","default":"#475569"},"eyebrowBg":{"type":"string","default":"#f0ebff"},"eyebrowColor":{"type":"string","default":"#6c3fb5"},"dividerColor":{"type":"string","default":"#6c3fb5"},"ctaColor":{"type":"string","default":"#6c3fb5"}}, |
| 112 |
save: function (props) { |
| 113 |
var a = props.attributes; |
| 114 |
var blockProps = wp.blockEditor.useBlockProps.save({ |
| 115 |
className: 'bkbg-si-wrap bkbg-si-align--' + a.align, |
| 116 |
style: wrapStyle(a) |
| 117 |
}); |
| 118 |
return el('div', blockProps, |
| 119 |
el('div', { className:'bkbg-si-inner' }, |
| 120 |
a.showEyebrow ? el('span', { className:'bkbg-si-eyebrow bkbg-si-ey--' + a.eyebrowStyle }, a.eyebrow) : null, |
| 121 |
a.showDivider ? el('div', { className:'bkbg-si-divider' }) : null, |
| 122 |
el(RichText.Content, { tagName:a.headingTag, className:'bkbg-si-heading', value:a.heading }), |
| 123 |
a.showSubtitle ? el(RichText.Content, { tagName:'p', className:'bkbg-si-subtitle', value:a.subtitle }) : null, |
| 124 |
a.showCta ? el('a', { href:a.ctaUrl, className:'bkbg-si-cta bkbg-si-cta--' + a.ctaStyle, target:a.ctaTarget, rel:a.ctaTarget==='_blank'?'noopener noreferrer':undefined }, |
| 125 |
a.ctaLabel, a.ctaStyle === 'link-arrow' ? el('span', { className:'bkbg-si-arrow' }, ' →') : null |
| 126 |
) : null |
| 127 |
) |
| 128 |
); |
| 129 |
} |
| 130 |
}], |
| 131 |
|
| 132 |
save: function (props) { |
| 133 |
var a = props.attributes; |
| 134 |
var _tvFn = window.bkbgTypoCssVars; |
| 135 |
var s = wrapStyle(a); |
| 136 |
if (_tvFn) { |
| 137 |
Object.assign(s, _tvFn(a.headingTypo || {}, '--bksi-ht-')); |
| 138 |
Object.assign(s, _tvFn(a.eyebrowTypo || {}, '--bksi-et-')); |
| 139 |
Object.assign(s, _tvFn(a.subtitleTypo || {}, '--bksi-st-')); |
| 140 |
} |
| 141 |
var blockProps = wp.blockEditor.useBlockProps.save({ |
| 142 |
className: 'bkbg-si-wrap bkbg-si-align--' + a.align, |
| 143 |
style: s |
| 144 |
}); |
| 145 |
return el('div', blockProps, |
| 146 |
el('div', { className:'bkbg-si-inner' }, |
| 147 |
a.showEyebrow ? el('span', { className:'bkbg-si-eyebrow bkbg-si-ey--' + a.eyebrowStyle }, a.eyebrow) : null, |
| 148 |
a.showDivider ? el('div', { className:'bkbg-si-divider' }) : null, |
| 149 |
el(RichText.Content, { tagName:a.headingTag, className:'bkbg-si-heading', value:a.heading }), |
| 150 |
a.showSubtitle ? el(RichText.Content, { tagName:'p', className:'bkbg-si-subtitle', value:a.subtitle }) : null, |
| 151 |
a.showCta ? el('a', { href:a.ctaUrl, className:'bkbg-si-cta bkbg-si-cta--' + a.ctaStyle, target:a.ctaTarget, rel:a.ctaTarget==='_blank'?'noopener noreferrer':undefined }, |
| 152 |
a.ctaLabel, a.ctaStyle === 'link-arrow' ? el('span', { className:'bkbg-si-arrow' }, ' →') : null |
| 153 |
) : null |
| 154 |
) |
| 155 |
); |
| 156 |
} |
| 157 |
}); |
| 158 |
}() ); |
| 159 |
|