| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var __ = wp.i18n.__; |
| 4 |
var useState = wp.element.useState; |
| 5 |
var registerBlockType = wp.blocks.registerBlockType; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 8 |
var MediaUploadCheck = wp.blockEditor.MediaUploadCheck; |
| 9 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 10 |
var RichText = wp.blockEditor.RichText; |
| 11 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 12 |
var PanelBody = wp.components.PanelBody; |
| 13 |
var ToggleControl = wp.components.ToggleControl; |
| 14 |
var RangeControl = wp.components.RangeControl; |
| 15 |
var SelectControl = wp.components.SelectControl; |
| 16 |
var TextControl = wp.components.TextControl; |
| 17 |
var Button = wp.components.Button; |
| 18 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 19 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 20 |
|
| 21 |
registerBlockType('blockenberg/results-section', { |
| 22 |
edit: function (props) { |
| 23 |
var attributes = props.attributes; |
| 24 |
var setAttributes = props.setAttributes; |
| 25 |
var a = attributes; |
| 26 |
|
| 27 |
var TC = getTypoControl(); |
| 28 |
|
| 29 |
var blockProps = useBlockProps((function () { |
| 30 |
var _tvFn = getTypoCssVars(); |
| 31 |
var s = { backgroundColor: a.bgColor, paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px' }; |
| 32 |
if (_tvFn) { |
| 33 |
Object.assign(s, _tvFn(a.headingTypo || {}, '--bkrs-ht-')); |
| 34 |
Object.assign(s, _tvFn(a.bodyTypo || {}, '--bkrs-bt-')); |
| 35 |
} |
| 36 |
return { className: 'bkbg-rss-wrap', style: s }; |
| 37 |
})()); |
| 38 |
|
| 39 |
function updateMetric(idx, key, val) { |
| 40 |
var updated = a.metrics.map(function (m, i) { |
| 41 |
return i === idx ? Object.assign({}, m, { [key]: val }) : m; |
| 42 |
}); |
| 43 |
setAttributes({ metrics: updated }); |
| 44 |
} |
| 45 |
|
| 46 |
function addMetric() { |
| 47 |
setAttributes({ metrics: a.metrics.concat([{ label: 'New Metric', before: '0', after: '0', change: '+0%', description: '', direction: 'up' }]) }); |
| 48 |
} |
| 49 |
|
| 50 |
function removeMetric(idx) { |
| 51 |
setAttributes({ metrics: a.metrics.filter(function (_, i) { return i !== idx; }) }); |
| 52 |
} |
| 53 |
|
| 54 |
var changeColor = function (m) { |
| 55 |
return m.direction === 'down' ? a.changeDownColor : a.changeUpColor; |
| 56 |
}; |
| 57 |
var changeBg = function (m) { |
| 58 |
return m.direction === 'down' ? a.changeDownBg : a.changeUpBg; |
| 59 |
}; |
| 60 |
|
| 61 |
var innerStyle = { |
| 62 |
maxWidth: a.maxWidth + 'px', |
| 63 |
margin: '0 auto', |
| 64 |
padding: '0 24px' |
| 65 |
}; |
| 66 |
|
| 67 |
return el('div', blockProps, |
| 68 |
// Inspector |
| 69 |
el(InspectorControls, null, |
| 70 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true }, |
| 71 |
el(ToggleControl, { label: __('Show Eyebrow', 'blockenberg'), checked: a.showEyebrow, onChange: function (v) { setAttributes({ showEyebrow: v }); }, __nextHasNoMarginBottom: true }), |
| 72 |
a.showEyebrow && el(TextControl, { label: __('Eyebrow Text', 'blockenberg'), value: a.eyebrow, onChange: function (v) { setAttributes({ eyebrow: v }); }, __nextHasNoMarginBottom: true }), |
| 73 |
el(ToggleControl, { label: __('Show Subtext', 'blockenberg'), checked: a.showSubtext, onChange: function (v) { setAttributes({ showSubtext: v }); }, __nextHasNoMarginBottom: true }), |
| 74 |
el(ToggleControl, { label: __('Show Case Study', 'blockenberg'), checked: a.showCaseStudy, onChange: function (v) { setAttributes({ showCaseStudy: v }); }, __nextHasNoMarginBottom: true }), |
| 75 |
el(ToggleControl, { label: __('Show CTA', 'blockenberg'), checked: a.showCtaRow, onChange: function (v) { setAttributes({ showCtaRow: v }); }, __nextHasNoMarginBottom: true }), |
| 76 |
a.showCtaRow && el(TextControl, { label: __('CTA Label', 'blockenberg'), value: a.ctaLabel, onChange: function (v) { setAttributes({ ctaLabel: v }); }, __nextHasNoMarginBottom: true }), |
| 77 |
a.showCtaRow && el(TextControl, { label: __('CTA URL', 'blockenberg'), value: a.ctaUrl, onChange: function (v) { setAttributes({ ctaUrl: v }); }, __nextHasNoMarginBottom: true }) |
| 78 |
), |
| 79 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false }, |
| 80 |
el(SelectControl, { label: __('Layout', 'blockenberg'), value: a.layout, options: [{ label: 'Metrics Top', value: 'metrics-top' }, { label: 'Metrics Bottom', value: 'metrics-bottom' }, { label: 'Split (metrics + case)', value: 'split' }], onChange: function (v) { setAttributes({ layout: v }); }, __nextHasNoMarginBottom: true }), |
| 81 |
el(SelectControl, { label: __('Metric Style', 'blockenberg'), value: a.metricStyle, options: [{ label: 'Cards', value: 'cards' }, { label: 'Borderless', value: 'borderless' }, { label: 'Dark cards', value: 'dark' }], onChange: function (v) { setAttributes({ metricStyle: v }); }, __nextHasNoMarginBottom: true }), |
| 82 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: a.maxWidth, min: 600, max: 1400, onChange: function (v) { setAttributes({ maxWidth: v }); }, __nextHasNoMarginBottom: true }), |
| 83 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: a.paddingTop, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingTop: v }); }, __nextHasNoMarginBottom: true }), |
| 84 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: a.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingBottom: v }); }, __nextHasNoMarginBottom: true }) |
| 85 |
), |
| 86 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 87 |
TC && el(TC, { label: __('Heading', 'blockenberg'), value: a.headingTypo || {}, onChange: function (v) { setAttributes({ headingTypo: v }); } }), |
| 88 |
TC && el(TC, { label: __('Body Text', 'blockenberg'), value: a.bodyTypo || {}, onChange: function (v) { setAttributes({ bodyTypo: v }); } }), |
| 89 |
el(RangeControl, { label: __('Metric After Size (px)', 'blockenberg'), value: a.metricAfterSize, min: 18, max: 64, onChange: function (v) { setAttributes({ metricAfterSize: v }); }, __nextHasNoMarginBottom: true }), |
| 90 |
el(RangeControl, { label: __('Eyebrow Size (px)', 'blockenberg'), value: attributes.eyebrowSize, min: 10, max: 24, __nextHasNoMarginBottom: true, onChange: function (v) { setAttributes({ eyebrowSize: v }); } }), |
| 91 |
el(RangeControl, { label: __('Case Name Size (px)', 'blockenberg'), value: a.caseNameSize, min: 12, max: 32, __nextHasNoMarginBottom: true, onChange: function (v) { setAttributes({ caseNameSize: v }); } }) |
| 92 |
), |
| 93 |
el(PanelBody, { title: __('Case Study', 'blockenberg'), initialOpen: false }, |
| 94 |
el(TextControl, { label: __('Client Name', 'blockenberg'), value: a.caseStudyName, onChange: function (v) { setAttributes({ caseStudyName: v }); }, __nextHasNoMarginBottom: true }), |
| 95 |
el(TextControl, { label: __('Attribution', 'blockenberg'), value: a.clientName, onChange: function (v) { setAttributes({ clientName: v }); }, __nextHasNoMarginBottom: true }), |
| 96 |
el('p', { style: { margin: '8px 0 4px', fontSize: 11, color: '#6b7280', fontWeight: 600, textTransform: 'uppercase' } }, __('Client Logo', 'blockenberg')), |
| 97 |
el(MediaUploadCheck, null, |
| 98 |
el(MediaUpload, { |
| 99 |
onSelect: function (media) { setAttributes({ clientLogoUrl: media.url, clientLogoId: media.id, clientLogoAlt: media.alt || '' }); }, |
| 100 |
allowedTypes: ['image'], |
| 101 |
value: a.clientLogoId, |
| 102 |
render: function (ref) { |
| 103 |
return el('div', null, |
| 104 |
a.clientLogoUrl && el('img', { src: a.clientLogoUrl, style: { maxHeight: 40, display: 'block', marginBottom: 8, borderRadius: 4 } }), |
| 105 |
el(Button, { variant: 'secondary', size: 'small', onClick: ref.open, __nextHasNoMarginBottom: true }, a.clientLogoUrl ? __('Replace Logo', 'blockenberg') : __('Upload Logo', 'blockenberg')) |
| 106 |
); |
| 107 |
} |
| 108 |
}) |
| 109 |
) |
| 110 |
), |
| 111 |
el(PanelColorSettings, { |
| 112 |
title: __('Colors', 'blockenberg'), |
| 113 |
initialOpen: false, |
| 114 |
colorSettings: [ |
| 115 |
{ label: __('Background', 'blockenberg'), value: a.bgColor, onChange: function (v) { setAttributes({ bgColor: v || '#ffffff' }); } }, |
| 116 |
{ label: __('Eyebrow Color', 'blockenberg'), value: a.eyebrowColor, onChange: function (v) { setAttributes({ eyebrowColor: v || '#7c3aed' }); } }, |
| 117 |
{ label: __('Heading Color', 'blockenberg'), value: a.headingColor, onChange: function (v) { setAttributes({ headingColor: v || '#111827' }); } }, |
| 118 |
{ label: __('Metric Card BG', 'blockenberg'), value: a.metricCardBg, onChange: function (v) { setAttributes({ metricCardBg: v || '#f9fafb' }); } }, |
| 119 |
{ label: __('After Value Color', 'blockenberg'), value: a.metricAfterColor, onChange: function (v) { setAttributes({ metricAfterColor: v || '#111827' }); } }, |
| 120 |
{ label: __('Change Up Color', 'blockenberg'), value: a.changeUpColor, onChange: function (v) { setAttributes({ changeUpColor: v || '#15803d' }); } }, |
| 121 |
{ label: __('Change Down Color', 'blockenberg'), value: a.changeDownColor, onChange: function (v) { setAttributes({ changeDownColor: v || '#b45309' }); } }, |
| 122 |
{ label: __('Case Study BG', 'blockenberg'), value: a.caseBg, onChange: function (v) { setAttributes({ caseBg: v || '#f8f5ff' }); } }, |
| 123 |
{ label: __('Accent Color', 'blockenberg'), value: a.accentColor, onChange: function (v) { setAttributes({ accentColor: v || '#7c3aed' }); } }, |
| 124 |
{ label: __('CTA Button BG', 'blockenberg'), value: a.ctaBg, onChange: function (v) { setAttributes({ ctaBg: v || '#7c3aed' }); } } |
| 125 |
] |
| 126 |
}) |
| 127 |
), |
| 128 |
|
| 129 |
// Editor preview |
| 130 |
el('div', { style: innerStyle }, |
| 131 |
// Header |
| 132 |
el('div', { style: { textAlign: 'center', marginBottom: 48 } }, |
| 133 |
a.showEyebrow && el('span', { style: { display: 'inline-block', background: a.eyebrowBg, color: a.eyebrowColor, fontWeight: 700, fontSize: (a.eyebrowSize || 12), letterSpacing: '0.08em', textTransform: 'uppercase', padding: '5px 14px', borderRadius: 999, marginBottom: 16 } }, a.eyebrow), |
| 134 |
el(RichText, { tagName: 'h2', className: 'bkbg-rss-heading', value: a.heading, onChange: function (v) { setAttributes({ heading: v }); }, placeholder: __('Heading…', 'blockenberg'), style: { color: a.headingColor, margin: '0 0 16px' } }), |
| 135 |
a.showSubtext && el(RichText, { tagName: 'p', className: 'bkbg-rss-subtext', value: a.subtext, onChange: function (v) { setAttributes({ subtext: v }); }, placeholder: __('Subtext…', 'blockenberg'), style: { color: a.subtextColor, margin: '0 auto', maxWidth: 680 } }) |
| 136 |
), |
| 137 |
|
| 138 |
// Metrics grid |
| 139 |
el('div', { className: 'bkbg-rss-metrics bkbg-rss-metrics--' + a.metricStyle, style: { display: 'grid', gridTemplateColumns: 'repeat(' + Math.min(a.metrics.length, 3) + ', 1fr)', gap: 24, marginBottom: a.showCaseStudy ? 40 : 0 } }, |
| 140 |
a.metrics.map(function (m, idx) { |
| 141 |
var isDarkCard = a.metricStyle === 'dark'; |
| 142 |
var cardBgVal = isDarkCard ? '#1f2937' : (a.metricStyle === 'cards' ? a.metricCardBg : 'transparent'); |
| 143 |
var borderW = a.metricStyle === 'borderless' ? 0 : 1; |
| 144 |
return el('div', { key: idx, style: { background: cardBgVal, border: borderW + 'px solid ' + a.metricCardBorder, borderRadius: 14, padding: 28, position: 'relative' } }, |
| 145 |
// Remove button |
| 146 |
el(Button, { isDestructive: true, size: 'small', onClick: function () { removeMetric(idx); }, style: { position: 'absolute', top: 10, right: 10, fontSize: 10 } }, '✕'), |
| 147 |
// Change badge |
| 148 |
el('span', { style: { display: 'inline-block', background: changeBg(m), color: changeColor(m), fontWeight: 700, fontSize: 12, padding: '3px 10px', borderRadius: 999, marginBottom: 12 } }, |
| 149 |
m.direction === 'down' ? '▼ ' : '▲ ', m.change |
| 150 |
), |
| 151 |
// Before → After |
| 152 |
el('div', { style: { display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 6 } }, |
| 153 |
el('span', { style: { fontSize: 16, color: a.metricBeforeColor, textDecoration: 'line-through' } }, |
| 154 |
el(RichText, { tagName: 'span', value: m.before, onChange: function (v) { updateMetric(idx, 'before', v); }, placeholder: 'Before' }) |
| 155 |
), |
| 156 |
el('span', { style: { fontSize: 13, color: a.metricBeforeColor } }, '→'), |
| 157 |
el('span', { style: { fontSize: a.metricAfterSize + 'px', fontWeight: 800, color: isDarkCard ? '#ffffff' : a.metricAfterColor, lineHeight: 1 } }, |
| 158 |
el(RichText, { tagName: 'span', value: m.after, onChange: function (v) { updateMetric(idx, 'after', v); }, placeholder: 'After' }) |
| 159 |
) |
| 160 |
), |
| 161 |
el('p', { style: { fontWeight: 700, fontSize: 15, color: isDarkCard ? '#d1d5db' : a.metricLabelColor, margin: '0 0 4px' } }, |
| 162 |
el(RichText, { tagName: 'span', value: m.label, onChange: function (v) { updateMetric(idx, 'label', v); }, placeholder: 'Label' }) |
| 163 |
), |
| 164 |
el('p', { style: { fontSize: 13, color: isDarkCard ? '#9ca3af' : a.subtextColor, margin: 0 } }, |
| 165 |
el(RichText, { tagName: 'span', value: m.description, onChange: function (v) { updateMetric(idx, 'description', v); }, placeholder: 'Description' }) |
| 166 |
), |
| 167 |
el('div', { style: { marginTop: 10, display: 'flex', gap: 8 } }, |
| 168 |
el(SelectControl, { label: __('Direction', 'blockenberg'), value: m.direction, options: [{ label: '▲ Up', value: 'up' }, { label: '▼ Down', value: 'down' }], onChange: function (v) { updateMetric(idx, 'direction', v); }, __nextHasNoMarginBottom: true }) |
| 169 |
) |
| 170 |
); |
| 171 |
}), |
| 172 |
el('div', { style: { display: 'flex', justifyContent: 'center', alignItems: 'center', border: '2px dashed #d1d5db', borderRadius: 14, minHeight: 60, cursor: 'pointer' }, onClick: addMetric }, |
| 173 |
el('span', { style: { fontSize: 13, color: '#9ca3af' } }, '+ Add Metric') |
| 174 |
) |
| 175 |
), |
| 176 |
|
| 177 |
// Case study card |
| 178 |
a.showCaseStudy && el('div', { style: { background: a.caseBg, borderRadius: 16, padding: 36, borderLeft: '4px solid ' + a.accentColor } }, |
| 179 |
el('div', { style: { display: 'flex', alignItems: 'center', gap: 14, marginBottom: 16 } }, |
| 180 |
a.clientLogoUrl && el('img', { src: a.clientLogoUrl, style: { height: 36, objectFit: 'contain' } }), |
| 181 |
el('span', { style: { fontWeight: 800, fontSize: a.caseNameSize || 18, color: a.caseNameColor } }, a.caseStudyName) |
| 182 |
), |
| 183 |
el(RichText, { tagName: 'p', value: a.caseStudySummary, onChange: function (v) { setAttributes({ caseStudySummary: v }); }, placeholder: __('Case study summary…', 'blockenberg'), style: { color: a.caseSummaryColor, fontSize: 16, lineHeight: 1.7, margin: '0 0 16px' } }), |
| 184 |
el('span', { style: { fontSize: 14, color: a.subtextColor } }, '— ', a.clientName) |
| 185 |
), |
| 186 |
|
| 187 |
// CTA |
| 188 |
a.showCtaRow && el('div', { style: { textAlign: 'center', marginTop: 36 } }, |
| 189 |
el('a', { href: '#', style: { display: 'inline-block', background: a.ctaBg, color: a.ctaColor, fontWeight: 700, fontSize: 15, padding: '14px 32px', borderRadius: 8, textDecoration: 'none' } }, a.ctaLabel) |
| 190 |
) |
| 191 |
) |
| 192 |
); |
| 193 |
}, |
| 194 |
save: function (props) { |
| 195 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 196 |
return el('div', useBlockProps.save(), |
| 197 |
el('div', { className: 'bkbg-rss-app', 'data-opts': JSON.stringify(props.attributes) }) |
| 198 |
); |
| 199 |
} |
| 200 |
}); |
| 201 |
}() ); |
| 202 |
|