| 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 useBlockProps = wp.blockEditor.useBlockProps; |
| 7 |
var RichText = wp.blockEditor.RichText; |
| 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 |
var Button = wp.components.Button; |
| 15 |
var Fragment = wp.element.Fragment; |
| 16 |
|
| 17 |
// Lazy lookup so the typography control is resolved at render time |
| 18 |
function getTypographyControl() { |
| 19 |
return (typeof window.bkbgTypographyControl !== 'undefined') ? window.bkbgTypographyControl : null; |
| 20 |
} |
| 21 |
function getTypoCssVars() { |
| 22 |
return (typeof window.bkbgTypoCssVars !== 'undefined') ? window.bkbgTypoCssVars : function() { return {}; }; |
| 23 |
} |
| 24 |
|
| 25 |
registerBlockType('blockenberg/affiliate-section', { |
| 26 |
edit: function (props) { |
| 27 |
var attr = props.attributes; |
| 28 |
var setAttr = props.setAttributes; |
| 29 |
|
| 30 |
/* ── Inspector ── */ |
| 31 |
var inspector = el(InspectorControls, null, |
| 32 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true }, |
| 33 |
el(SelectControl, { |
| 34 |
__nextHasNoMarginBottom: true, |
| 35 |
label: __('Layout', 'blockenberg'), |
| 36 |
value: attr.layout, |
| 37 |
options: [ |
| 38 |
{ label: 'Split (Commission + Steps)', value: 'split' }, |
| 39 |
{ label: 'Centered', value: 'centered' }, |
| 40 |
{ label: 'Steps Focus', value: 'steps-focus' } |
| 41 |
], |
| 42 |
onChange: function (v) { setAttr({ layout: v }); } |
| 43 |
}), |
| 44 |
el(RangeControl, { |
| 45 |
__nextHasNoMarginBottom: true, |
| 46 |
label: __('Max Width (px)', 'blockenberg'), |
| 47 |
value: attr.maxWidth, |
| 48 |
min: 600, max: 1400, |
| 49 |
onChange: function (v) { setAttr({ maxWidth: v }); } |
| 50 |
}), |
| 51 |
el(RangeControl, { |
| 52 |
__nextHasNoMarginBottom: true, |
| 53 |
label: __('Padding Top (px)', 'blockenberg'), |
| 54 |
value: attr.paddingTop, |
| 55 |
min: 0, max: 200, |
| 56 |
onChange: function (v) { setAttr({ paddingTop: v }); } |
| 57 |
}), |
| 58 |
el(RangeControl, { |
| 59 |
__nextHasNoMarginBottom: true, |
| 60 |
label: __('Padding Bottom (px)', 'blockenberg'), |
| 61 |
value: attr.paddingBottom, |
| 62 |
min: 0, max: 200, |
| 63 |
onChange: function (v) { setAttr({ paddingBottom: v }); } |
| 64 |
}) |
| 65 |
), |
| 66 |
el(PanelBody, { title: __('Commission Badge', 'blockenberg'), initialOpen: false }, |
| 67 |
el(TextControl, { |
| 68 |
__nextHasNoMarginBottom: true, |
| 69 |
label: __('Commission Value', 'blockenberg'), |
| 70 |
value: attr.commission, |
| 71 |
onChange: function (v) { setAttr({ commission: v }); } |
| 72 |
}), |
| 73 |
el(TextControl, { |
| 74 |
__nextHasNoMarginBottom: true, |
| 75 |
label: __('Commission Label', 'blockenberg'), |
| 76 |
value: attr.commissionLabel, |
| 77 |
onChange: function (v) { setAttr({ commissionLabel: v }); } |
| 78 |
}), |
| 79 |
el(TextControl, { |
| 80 |
__nextHasNoMarginBottom: true, |
| 81 |
label: __('Commission Note', 'blockenberg'), |
| 82 |
value: attr.commissionNote, |
| 83 |
onChange: function (v) { setAttr({ commissionNote: v }); } |
| 84 |
}) |
| 85 |
), |
| 86 |
el(PanelBody, { title: __('Benefits & Stats', 'blockenberg'), initialOpen: false }, |
| 87 |
el(ToggleControl, { |
| 88 |
__nextHasNoMarginBottom: true, |
| 89 |
label: __('Show Benefits List', 'blockenberg'), |
| 90 |
checked: attr.showBenefits, |
| 91 |
onChange: function (v) { setAttr({ showBenefits: v }); } |
| 92 |
}), |
| 93 |
el(ToggleControl, { |
| 94 |
__nextHasNoMarginBottom: true, |
| 95 |
label: __('Show Stats', 'blockenberg'), |
| 96 |
checked: attr.showStats, |
| 97 |
onChange: function (v) { setAttr({ showStats: v }); } |
| 98 |
}) |
| 99 |
), |
| 100 |
el(PanelBody, { title: __('CTA Buttons', 'blockenberg'), initialOpen: false }, |
| 101 |
el(TextControl, { |
| 102 |
__nextHasNoMarginBottom: true, |
| 103 |
label: __('Primary CTA Label', 'blockenberg'), |
| 104 |
value: attr.ctaLabel, |
| 105 |
onChange: function (v) { setAttr({ ctaLabel: v }); } |
| 106 |
}), |
| 107 |
el(TextControl, { |
| 108 |
__nextHasNoMarginBottom: true, |
| 109 |
label: __('Primary CTA URL', 'blockenberg'), |
| 110 |
value: attr.ctaUrl, |
| 111 |
onChange: function (v) { setAttr({ ctaUrl: v }); } |
| 112 |
}), |
| 113 |
el(ToggleControl, { |
| 114 |
__nextHasNoMarginBottom: true, |
| 115 |
label: __('Show Secondary CTA', 'blockenberg'), |
| 116 |
checked: attr.showSecondary, |
| 117 |
onChange: function (v) { setAttr({ showSecondary: v }); } |
| 118 |
}), |
| 119 |
attr.showSecondary && el(TextControl, { |
| 120 |
__nextHasNoMarginBottom: true, |
| 121 |
label: __('Secondary CTA Label', 'blockenberg'), |
| 122 |
value: attr.ctaSecondaryLabel, |
| 123 |
onChange: function (v) { setAttr({ ctaSecondaryLabel: v }); } |
| 124 |
}), |
| 125 |
attr.showSecondary && el(TextControl, { |
| 126 |
__nextHasNoMarginBottom: true, |
| 127 |
label: __('Secondary CTA URL', 'blockenberg'), |
| 128 |
value: attr.ctaSecondaryUrl, |
| 129 |
onChange: function (v) { setAttr({ ctaSecondaryUrl: v }); } |
| 130 |
}) |
| 131 |
), |
| 132 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 133 |
(function () { |
| 134 |
var TC = getTypographyControl(); |
| 135 |
if (!TC) return el('p', null, 'Typography control not loaded.'); |
| 136 |
return el(Fragment, null, |
| 137 |
el(TC, { label: __('Eyebrow Typography', 'blockenberg'), value: attr.eyebrowTypo || {}, onChange: function (v) { setAttr({ eyebrowTypo: v }); } }), |
| 138 |
el(TC, { label: __('Heading Typography', 'blockenberg'), value: attr.headingTypo || {}, onChange: function (v) { setAttr({ headingTypo: v }); } }), |
| 139 |
el(TC, { label: __('Subtext Typography', 'blockenberg'), value: attr.subtextTypo || {}, onChange: function (v) { setAttr({ subtextTypo: v }); } }) |
| 140 |
); |
| 141 |
})() |
| 142 |
), |
| 143 |
el(PanelColorSettings, { |
| 144 |
title: __('Colors', 'blockenberg'), |
| 145 |
initialOpen: false, |
| 146 |
colorSettings: [ |
| 147 |
{ label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#0f172a' }); } }, |
| 148 |
{ label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#6366f1' }); } }, |
| 149 |
{ label: __('Commission Badge BG', 'blockenberg'), value: attr.commissionBg, onChange: function (v) { setAttr({ commissionBg: v || '#6366f1' }); } }, |
| 150 |
{ label: __('Commission Badge Text', 'blockenberg'), value: attr.commissionColor, onChange: function (v) { setAttr({ commissionColor: v || '#ffffff' }); } }, |
| 151 |
{ label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#ffffff' }); } }, |
| 152 |
{ label: __('Subtext', 'blockenberg'), value: attr.subColor, onChange: function (v) { setAttr({ subColor: v || '#94a3b8' }); } }, |
| 153 |
{ label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowColor, onChange: function (v) { setAttr({ eyebrowColor: v || '#a5b4fc' }); } }, |
| 154 |
{ label: __('Step Card BG', 'blockenberg'), value: attr.stepCardBg, onChange: function (v) { setAttr({ stepCardBg: v || '#1e293b' }); } }, |
| 155 |
{ label: __('Stat Number', 'blockenberg'), value: attr.statNumColor, onChange: function (v) { setAttr({ statNumColor: v || '#6366f1' }); } }, |
| 156 |
{ label: __('CTA BG', 'blockenberg'), value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#6366f1' }); } }, |
| 157 |
{ label: __('CTA Text', 'blockenberg'), value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#ffffff' }); } } |
| 158 |
] |
| 159 |
}) |
| 160 |
); |
| 161 |
|
| 162 |
/* ── Preview ── */ |
| 163 |
var blockProps = useBlockProps({ className: 'bkbg-aff-editor bkbg-aff-layout-' + attr.layout }); |
| 164 |
|
| 165 |
/* Build editor wrapper style with typography CSS vars */ |
| 166 |
var _tv = getTypoCssVars(); |
| 167 |
var previewStyle = Object.assign( |
| 168 |
{ background: attr.bgColor, padding: '40px', borderRadius: '8px', fontFamily: 'sans-serif' }, |
| 169 |
_tv(attr.eyebrowTypo || {}, '--bkbg-aff-eyebrow-'), |
| 170 |
_tv(attr.headingTypo || {}, '--bkbg-aff-heading-'), |
| 171 |
_tv(attr.subtextTypo || {}, '--bkbg-aff-subtext-') |
| 172 |
); |
| 173 |
previewStyle['--bkbg-aff-eyebrow-sz'] = (attr.eyebrowFontSize || 13) + 'px'; |
| 174 |
previewStyle['--bkbg-aff-heading-sz'] = (attr.headingFontSize || 38) + 'px'; |
| 175 |
previewStyle['--bkbg-aff-subtext-sz'] = (attr.subtextFontSize || 18) + 'px'; |
| 176 |
|
| 177 |
return el('div', blockProps, |
| 178 |
inspector, |
| 179 |
el('div', { className: 'bkbg-aff-preview', style: previewStyle }, |
| 180 |
el('div', { style: { textAlign: 'center', marginBottom: '32px' } }, |
| 181 |
el(RichText, { |
| 182 |
tagName: 'p', |
| 183 |
className: 'bkbg-aff-eyebrow', |
| 184 |
value: attr.eyebrow, |
| 185 |
onChange: function (v) { setAttr({ eyebrow: v }); }, |
| 186 |
placeholder: __('Eyebrow text…', 'blockenberg'), |
| 187 |
style: { color: attr.eyebrowColor, marginBottom: '8px' } |
| 188 |
}), |
| 189 |
el(RichText, { |
| 190 |
tagName: 'h2', |
| 191 |
className: 'bkbg-aff-heading', |
| 192 |
value: attr.heading, |
| 193 |
onChange: function (v) { setAttr({ heading: v }); }, |
| 194 |
placeholder: __('Section heading…', 'blockenberg'), |
| 195 |
style: { color: attr.headingColor, margin: '0 0 16px' } |
| 196 |
}), |
| 197 |
el(RichText, { |
| 198 |
tagName: 'p', |
| 199 |
className: 'bkbg-aff-sub', |
| 200 |
value: attr.subtext, |
| 201 |
onChange: function (v) { setAttr({ subtext: v }); }, |
| 202 |
placeholder: __('Subtext…', 'blockenberg'), |
| 203 |
style: { color: attr.subColor, maxWidth: '600px', margin: '0 auto' } |
| 204 |
}) |
| 205 |
), |
| 206 |
/* Commission badge */ |
| 207 |
el('div', { style: { textAlign: 'center', marginBottom: '40px' } }, |
| 208 |
el('div', { style: { display: 'inline-block', background: attr.commissionBg, color: attr.commissionColor, borderRadius: '16px', padding: '24px 48px' } }, |
| 209 |
el('div', { style: { fontSize: '64px', fontWeight: 800, lineHeight: 1 } }, attr.commission), |
| 210 |
el('div', { style: { fontSize: '16px', fontWeight: 600, marginTop: '4px' } }, attr.commissionLabel), |
| 211 |
el('div', { style: { fontSize: '13px', opacity: 0.8, marginTop: '4px' } }, attr.commissionNote) |
| 212 |
) |
| 213 |
), |
| 214 |
/* Steps */ |
| 215 |
el('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: '20px', marginBottom: '40px' } }, |
| 216 |
(attr.steps || []).map(function (step, i) { |
| 217 |
return el('div', { key: i, style: { background: attr.stepCardBg, borderRadius: '12px', padding: '24px', textAlign: 'center' } }, |
| 218 |
el('div', { style: { fontSize: '40px', marginBottom: '12px' } }, step.icon), |
| 219 |
el('div', { style: { color: attr.stepTitleColor, fontWeight: 700, fontSize: '18px', marginBottom: '8px' } }, step.title), |
| 220 |
el('div', { style: { color: attr.stepDescColor, fontSize: '14px' } }, step.description) |
| 221 |
); |
| 222 |
}) |
| 223 |
), |
| 224 |
/* Benefits */ |
| 225 |
attr.showBenefits && el('div', { style: { textAlign: 'center', marginBottom: '32px' } }, |
| 226 |
el('div', { style: { display: 'inline-flex', flexWrap: 'wrap', gap: '12px', justifyContent: 'center' } }, |
| 227 |
(attr.benefits || []).map(function (b, i) { |
| 228 |
return el('span', { key: i, style: { color: attr.benefitColor, display: 'flex', alignItems: 'center', gap: '6px', fontSize: '15px' } }, |
| 229 |
el('span', { style: { color: attr.accentColor } }, '✓'), |
| 230 |
b.text |
| 231 |
); |
| 232 |
}) |
| 233 |
) |
| 234 |
), |
| 235 |
/* Stats */ |
| 236 |
attr.showStats && el('div', { style: { display: 'flex', justifyContent: 'center', gap: '40px', marginBottom: '40px' } }, |
| 237 |
(attr.stats || []).map(function (s, i) { |
| 238 |
return el('div', { key: i, style: { textAlign: 'center' } }, |
| 239 |
el('div', { style: { color: attr.statNumColor, fontSize: '32px', fontWeight: 800 } }, s.number), |
| 240 |
el('div', { style: { color: attr.statLabelColor, fontSize: '14px' } }, s.label) |
| 241 |
); |
| 242 |
}) |
| 243 |
), |
| 244 |
/* CTAs */ |
| 245 |
el('div', { style: { textAlign: 'center', display: 'flex', justifyContent: 'center', gap: '16px' } }, |
| 246 |
el('a', { href: attr.ctaUrl, style: { background: attr.ctaBg, color: attr.ctaColor, padding: '14px 32px', borderRadius: '8px', fontWeight: 700, textDecoration: 'none', fontSize: '16px' } }, attr.ctaLabel), |
| 247 |
attr.showSecondary && el('a', { href: attr.ctaSecondaryUrl, style: { color: attr.accentColor, padding: '14px 32px', border: '2px solid ' + attr.accentColor, borderRadius: '8px', fontWeight: 600, textDecoration: 'none', fontSize: '16px' } }, attr.ctaSecondaryLabel) |
| 248 |
) |
| 249 |
) |
| 250 |
); |
| 251 |
}, |
| 252 |
|
| 253 |
save: function (props) { |
| 254 |
var attr = props.attributes; |
| 255 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 256 |
return el('div', useBlockProps.save(), |
| 257 |
el('div', { |
| 258 |
className: 'bkbg-aff-app', |
| 259 |
'data-opts': JSON.stringify(attr) |
| 260 |
}) |
| 261 |
); |
| 262 |
} |
| 263 |
}); |
| 264 |
}() ); |
| 265 |
|