| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var __ = wp.i18n.__; |
| 5 |
var registerBlockType = wp.blocks.registerBlockType; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 8 |
var RichText = wp.blockEditor.RichText; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 11 |
var ToggleControl = wp.components.ToggleControl; |
| 12 |
var RangeControl = wp.components.RangeControl; |
| 13 |
var SelectControl = wp.components.SelectControl; |
| 14 |
var TextControl = wp.components.TextControl; |
| 15 |
var Button = wp.components.Button; |
| 16 |
|
| 17 |
/* ── typography lazy-getters ── */ |
| 18 |
function _tc() { return window.bkbgTypographyControl || null; } |
| 19 |
function _tv() { return window.bkbgTypoCssVars || function () { return {}; }; } |
| 20 |
|
| 21 |
var IP = function () { return window.bkbgIconPicker; }; |
| 22 |
|
| 23 |
registerBlockType('blockenberg/guarantee-section', { |
| 24 |
edit: function (props) { |
| 25 |
var attr = props.attributes; |
| 26 |
var setAttr = props.setAttributes; |
| 27 |
var blockProps = useBlockProps({ className: 'bkbg-gs-editor', style: Object.assign({}, _tv()(attr.typoHeading, '--bkbg-guar-hl-'), _tv()(attr.typoBody, '--bkbg-guar-bd-')) }); |
| 28 |
|
| 29 |
function updateBullet(i, val) { |
| 30 |
var next = attr.bullets.map(function (b, j) { return j === i ? val : b; }); |
| 31 |
setAttr({ bullets: next }); |
| 32 |
} |
| 33 |
|
| 34 |
var previewStyle = { background: attr.bgColor, padding: attr.paddingTop + 'px 40px ' + attr.paddingBottom + 'px' }; |
| 35 |
var innerStyle = { maxWidth: attr.maxWidth + 'px', margin: '0 auto', display: 'flex', flexDirection: attr.layout === 'centered' ? 'column' : 'row', alignItems: 'center', gap: 64, justifyContent: 'center' }; |
| 36 |
|
| 37 |
var sealStyle = { |
| 38 |
width: attr.sealSize + 'px', height: attr.sealSize + 'px', |
| 39 |
borderRadius: '50%', background: attr.sealBg, |
| 40 |
display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', |
| 41 |
color: attr.sealColor, flexShrink: 0, boxShadow: '0 0 0 12px rgba(124,58,237,.15)', |
| 42 |
textAlign: 'center', gap: 4 |
| 43 |
}; |
| 44 |
|
| 45 |
return el(Fragment, null, |
| 46 |
el(InspectorControls, null, |
| 47 |
el(PanelBody, { title: __('Seal', 'blockenberg'), initialOpen: true }, |
| 48 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, setAttr, { charAttr: 'sealIcon', typeAttr: 'sealIconType', dashiconAttr: 'sealIconDashicon', imageUrlAttr: 'sealIconImageUrl', colorAttr: 'sealIconDashiconColor' })), |
| 49 |
el(TextControl, { label: __('Large Label (e.g. 30-Day)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.sealLabel, onChange: function (v) { setAttr({ sealLabel: v }); } }), |
| 50 |
el(TextControl, { label: __('Sub Label (2 lines)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.sealSub, onChange: function (v) { setAttr({ sealSub: v }); } }), |
| 51 |
el(RangeControl, { label: __('Seal Size (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.sealSize, min: 100, max: 320, onChange: function (v) { setAttr({ sealSize: v }); } }) |
| 52 |
), |
| 53 |
el(PanelBody, { title: __('Bullet Points', 'blockenberg'), initialOpen: false }, |
| 54 |
attr.bullets.map(function (b, i) { |
| 55 |
return el('div', { key: i, style: { display: 'flex', gap: 8, marginBottom: 8, alignItems: 'flex-start' } }, |
| 56 |
el(TextControl, { label: null, __nextHasNoMarginBottom: true, value: b, onChange: function (v) { updateBullet(i, v); }, style: { flex: 1 } }), |
| 57 |
attr.bullets.length > 1 && el(Button, { onClick: function () { setAttr({ bullets: attr.bullets.filter(function (_, j) { return j !== i; }) }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, '✕') |
| 58 |
); |
| 59 |
}), |
| 60 |
el(Button, { onClick: function () { setAttr({ bullets: attr.bullets.concat(['New guarantee point']) }); }, variant: 'secondary', __nextHasNoMarginBottom: true }, __('+ Add Point', 'blockenberg')) |
| 61 |
), |
| 62 |
el(PanelBody, { title: __('CTA', 'blockenberg'), initialOpen: false }, |
| 63 |
el(ToggleControl, { label: __('Show CTA', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showCta, onChange: function (v) { setAttr({ showCta: v }); } }), |
| 64 |
attr.showCta && el(TextControl, { label: __('CTA Label', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ctaLabel, onChange: function (v) { setAttr({ ctaLabel: v }); } }), |
| 65 |
attr.showCta && el(TextControl, { label: __('CTA URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ctaUrl, onChange: function (v) { setAttr({ ctaUrl: v }); } }) |
| 66 |
), |
| 67 |
el(PanelBody, { title: __('Layout & Sizing', 'blockenberg'), initialOpen: false }, |
| 68 |
el(SelectControl, { label: __('Layout', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.layout, |
| 69 |
options: [{ label: 'Split (seal + text)', value: 'split' }, { label: 'Centered', value: 'centered' }], |
| 70 |
onChange: function (v) { setAttr({ layout: v }); } }), |
| 71 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 400, max: 1400, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }), |
| 72 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }), |
| 73 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } }) |
| 74 |
), |
| 75 |
|
| 76 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 77 |
_tc() && el(_tc(), { label:__('Heading','blockenberg'), value:attr.typoHeading, onChange:function(v){ setAttr({typoHeading:v}); } }), |
| 78 |
_tc() && el(_tc(), { label:__('Body','blockenberg'), value:attr.typoBody, onChange:function(v){ setAttr({typoBody:v}); } }) |
| 79 |
), |
| 80 |
el(PanelColorSettings, { |
| 81 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 82 |
colorSettings: [ |
| 83 |
{ value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#f5f3ff' }); }, label: __('Background', 'blockenberg') }, |
| 84 |
{ value: attr.sealBg, onChange: function (v) { setAttr({ sealBg: v || '#7c3aed' }); }, label: __('Seal Background', 'blockenberg') }, |
| 85 |
{ value: attr.sealColor, onChange: function (v) { setAttr({ sealColor: v || '#ffffff' }); }, label: __('Seal Text', 'blockenberg') }, |
| 86 |
{ value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); }, label: __('Heading', 'blockenberg') }, |
| 87 |
{ value: attr.textColor, onChange: function (v) { setAttr({ textColor: v || '#374151' }); }, label: __('Body Text', 'blockenberg') }, |
| 88 |
{ value: attr.bulletColor, onChange: function (v) { setAttr({ bulletColor: v || '#16a34a' }); }, label: __('Bullet Checkmark', 'blockenberg') }, |
| 89 |
{ value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#7c3aed' }); }, label: __('CTA Background', 'blockenberg') }, |
| 90 |
{ value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#ffffff' }); }, label: __('CTA Text', 'blockenberg') } |
| 91 |
] |
| 92 |
}) |
| 93 |
), |
| 94 |
el('div', blockProps, |
| 95 |
el('div', { style: previewStyle }, |
| 96 |
el('div', { style: innerStyle }, |
| 97 |
// Seal |
| 98 |
el('div', { style: sealStyle }, |
| 99 |
el('div', { style: { fontSize: attr.sealSize * 0.2 + 'px', lineHeight: 1 }, className: 'bkbg-gs-seal-icon' }, IP().buildEditorIcon(attr.sealIconType, attr.sealIcon, attr.sealIconDashicon, attr.sealIconImageUrl, attr.sealIconDashiconColor)), |
| 100 |
el('div', { style: { fontSize: attr.sealSize * 0.17 + 'px', fontWeight: 800, lineHeight: 1.1 } }, attr.sealLabel), |
| 101 |
el('div', { style: { fontSize: attr.sealSize * 0.1 + 'px', lineHeight: 1.3, whiteSpace: 'pre-line', opacity: .9 } }, attr.sealSub) |
| 102 |
), |
| 103 |
// Text |
| 104 |
el('div', { style: { display: 'flex', flexDirection: 'column', gap: 20, maxWidth: 560 } }, |
| 105 |
el(RichText, { tagName: 'h2', className: 'bkbg-gs-heading', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, style: { color: attr.headingColor, margin: 0 }, placeholder: __('Guarantee heading…', 'blockenberg') }), |
| 106 |
el(RichText, { tagName: 'p', className: 'bkbg-gs-body', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, style: { color: attr.textColor, margin: 0 }, placeholder: __('Description…', 'blockenberg') }), |
| 107 |
el('ul', { style: { listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 10 } }, |
| 108 |
attr.bullets.map(function (b, i) { |
| 109 |
return el('li', { key: i, className: 'bkbg-gs-bullet', style: { display: 'flex', alignItems: 'flex-start', gap: 10, color: attr.textColor } }, |
| 110 |
el('span', { className: 'bkbg-gs-check', style: { color: attr.bulletColor } }, '✓'), |
| 111 |
el('span', null, b) |
| 112 |
); |
| 113 |
}) |
| 114 |
), |
| 115 |
attr.showCta && el('a', { href: '#', className: 'bkbg-gs-cta', style: { background: attr.ctaBg, color: attr.ctaColor, textDecoration: 'none' } }, attr.ctaLabel, el('span', null, '→')) |
| 116 |
) |
| 117 |
) |
| 118 |
) |
| 119 |
) |
| 120 |
); |
| 121 |
}, |
| 122 |
save: function (props) { |
| 123 |
var attr = props.attributes; |
| 124 |
return el('div', useBlockProps.save(), |
| 125 |
el('div', { className: 'bkbg-guarantee-section-app', 'data-opts': JSON.stringify(attr) }) |
| 126 |
); |
| 127 |
} |
| 128 |
}); |
| 129 |
}() ); |
| 130 |
|