| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var useState = wp.element.useState; |
| 5 |
var __ = wp.i18n.__; |
| 6 |
var registerBlockType = wp.blocks.registerBlockType; |
| 7 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 8 |
var RichText = wp.blockEditor.RichText; |
| 9 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 10 |
var MediaUploadCheck = wp.blockEditor.MediaUploadCheck; |
| 11 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 12 |
var PanelBody = wp.components.PanelBody; |
| 13 |
var Button = wp.components.Button; |
| 14 |
var ToggleControl = wp.components.ToggleControl; |
| 15 |
var RangeControl = wp.components.RangeControl; |
| 16 |
var SelectControl = wp.components.SelectControl; |
| 17 |
var TextControl = wp.components.TextControl; |
| 18 |
var ColorPicker = wp.components.ColorPicker; |
| 19 |
var Popover = wp.components.Popover; |
| 20 |
|
| 21 |
var _bkbgCSWgetTC, _bkbgCSWgetTV; |
| 22 |
function getTC() { return _bkbgCSWgetTC || (_bkbgCSWgetTC = window.bkbgTypographyControl); } |
| 23 |
function getTV() { return _bkbgCSWgetTV || (_bkbgCSWgetTV = window.bkbgTypoCssVars); } |
| 24 |
function _tv(obj, prefix) { var fn = getTV(); return fn ? fn(obj, prefix) : {}; } |
| 25 |
|
| 26 |
var SWITCH_STYLE_OPTIONS = [ |
| 27 |
{ label: __('Pill slider', 'blockenberg'), value: 'pill' }, |
| 28 |
{ label: __('Tabs', 'blockenberg'), value: 'tabs' }, |
| 29 |
{ label: __('Buttons', 'blockenberg'), value: 'buttons' }, |
| 30 |
]; |
| 31 |
var ALIGN_OPTIONS = [ |
| 32 |
{ label: __('Left', 'blockenberg'), value: 'left' }, |
| 33 |
{ label: __('Center', 'blockenberg'), value: 'center' }, |
| 34 |
{ label: __('Right', 'blockenberg'), value: 'right' }, |
| 35 |
]; |
| 36 |
var LAYOUT_OPTIONS = [ |
| 37 |
{ label: __('Image right', 'blockenberg'), value: 'image-right' }, |
| 38 |
{ label: __('Image left', 'blockenberg'), value: 'image-left' }, |
| 39 |
{ label: __('Image top', 'blockenberg'), value: 'image-top' }, |
| 40 |
{ label: __('Text only', 'blockenberg'), value: 'text-only' }, |
| 41 |
]; |
| 42 |
var RATIO_OPTIONS = [ |
| 43 |
{ label: '16/9', value: '16/9' }, |
| 44 |
{ label: '4/3', value: '4/3' }, |
| 45 |
{ label: '1/1', value: '1/1' }, |
| 46 |
{ label: '3/4', value: '3/4' }, |
| 47 |
]; |
| 48 |
var BULLET_OPTIONS = [ |
| 49 |
{ label: __('Check ✓', 'blockenberg'), value: 'check' }, |
| 50 |
{ label: __('Arrow →', 'blockenberg'), value: 'arrow' }, |
| 51 |
{ label: __('Dot', 'blockenberg'), value: 'dot' }, |
| 52 |
]; |
| 53 |
|
| 54 |
function bulletChar(type) { return type === 'arrow' ? '→' : type === 'dot' ? '•' : '✓'; } |
| 55 |
|
| 56 |
function buildWrapStyle(a) { |
| 57 |
return Object.assign({ |
| 58 |
'--bkbg-csw-accent': a.accentColor, |
| 59 |
'--bkbg-csw-switch-bg': a.switchBg, |
| 60 |
'--bkbg-csw-active-text': a.switchActiveText, |
| 61 |
'--bkbg-csw-headline': a.headlineColor, |
| 62 |
'--bkbg-csw-body': a.bodyColor, |
| 63 |
'--bkbg-csw-bullet': a.bulletColor, |
| 64 |
'--bkbg-csw-bullet-icon': a.bulletIconColor, |
| 65 |
'--bkbg-csw-cta-bg': a.ctaBg, |
| 66 |
'--bkbg-csw-cta-color': a.ctaColor, |
| 67 |
'--bkbg-csw-switch-r': a.switchRadius + 'px', |
| 68 |
'--bkbg-csw-cta-r': a.ctaRadius + 'px', |
| 69 |
'--bkbg-csw-headline-sz': a.headlineSize + 'px', |
| 70 |
'--bkbg-csw-body-sz': a.bodySize + 'px', |
| 71 |
'--bkbg-csw-bullet-sz': a.bulletSize + 'px', |
| 72 |
'--bkbg-csw-badge-sz': a.badgeSize + 'px', |
| 73 |
'--bkbg-csw-switch-sz': a.switchSize + 'px', |
| 74 |
paddingTop: a.paddingTop + 'px', |
| 75 |
paddingBottom: a.paddingBottom + 'px', |
| 76 |
backgroundColor: a.bgColor || undefined, |
| 77 |
}, _tv(a.typoHeadline, '--bkcsw-head-'), _tv(a.typoBody, '--bkcsw-body-')); |
| 78 |
} |
| 79 |
|
| 80 |
function renderColorControl(key, label, value, onChange, openKey, setOpenKey) { |
| 81 |
var isOpen = openKey === key; |
| 82 |
return el('div', { key: key, style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 0', gap: '8px' } }, |
| 83 |
el('span', { style: { fontSize: '12px', color: '#1e1e1e', flex: 1, lineHeight: 1.4 } }, label), |
| 84 |
el('div', { style: { position: 'relative', flexShrink: 0 } }, |
| 85 |
el('button', { type: 'button', title: value || 'default', onClick: function () { setOpenKey(isOpen ? null : key); }, |
| 86 |
style: { width: '28px', height: '28px', borderRadius: '4px', border: isOpen ? '2px solid #007cba' : '2px solid #ddd', cursor: 'pointer', padding: 0, background: value || '#cccccc' } |
| 87 |
}), |
| 88 |
isOpen && el(Popover, { position: 'bottom left', onClose: function () { setOpenKey(null); } }, |
| 89 |
el('div', { style: { padding: '8px' } }, |
| 90 |
el(ColorPicker, { color: value, enableAlpha: true, onChange: onChange }) |
| 91 |
) |
| 92 |
) |
| 93 |
) |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
/* ── Panel preview ─────────────────────────────────────────────────── */ |
| 98 |
function PanelPreview(props) { |
| 99 |
var panel = props.panel; |
| 100 |
var a = props.a; |
| 101 |
var isLeft = a.panelLayout === 'image-left'; |
| 102 |
var isTop = a.panelLayout === 'image-top'; |
| 103 |
var isTextOnly = a.panelLayout === 'text-only'; |
| 104 |
|
| 105 |
var ratioParts = a.imageRatio.split('/'); |
| 106 |
var ratioVal = parseInt(ratioParts[1], 10) / parseInt(ratioParts[0], 10); |
| 107 |
|
| 108 |
var imgBox = !isTextOnly ? el('div', { className: 'bkbg-csw-img-col', style: { |
| 109 |
flex: isTop ? undefined : '0 0 45%', |
| 110 |
width: isTop ? '100%' : undefined, |
| 111 |
position: 'relative', |
| 112 |
borderRadius: a.imageRadius + 'px', |
| 113 |
overflow: 'hidden', |
| 114 |
boxShadow: a.imageShadow ? '0 16px 48px rgba(0,0,0,0.12)' : 'none', |
| 115 |
background: '#f3f4f6', |
| 116 |
} }, |
| 117 |
el('div', { style: { paddingBottom: (ratioVal * 100) + '%' } }), |
| 118 |
panel.imageUrl |
| 119 |
? el('img', { src: panel.imageUrl, alt: '', style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } }) |
| 120 |
: el('div', { style: { position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#9ca3af', fontSize: '13px' } }, __('Upload image for this panel', 'blockenberg')) |
| 121 |
) : null; |
| 122 |
|
| 123 |
var textBox = el('div', { className: 'bkbg-csw-text-col', style: { flex: '1 1 0', minWidth: 0 } }, |
| 124 |
panel.showBadge && panel.badge && el('span', { className: 'bkbg-csw-badge', style: { display: 'inline-block', background: a.accentColor + '18', color: a.accentColor, padding: '4px 14px', borderRadius: '99px', marginBottom: '14px' } }, panel.badge), |
| 125 |
el(RichText, { tagName: 'h2', className: 'bkbg-csw-headline', value: panel.headline, onChange: props.onHeadlineChange, placeholder: __('Panel headline…', 'blockenberg'), style: { color: a.headlineColor, margin: '0 0 14px' } }), |
| 126 |
el(RichText, { tagName: 'p', className: 'bkbg-csw-body', value: panel.body, onChange: props.onBodyChange, placeholder: __('Body text…', 'blockenberg'), style: { color: a.bodyColor, margin: '0 0 18px' } }), |
| 127 |
a.showBullets && panel.bullets && panel.bullets.length > 0 && el('ul', { style: { listStyle: 'none', margin: '0 0 22px', padding: 0, display: 'flex', flexDirection: 'column', gap: '8px' } }, |
| 128 |
panel.bullets.map(function (b) { |
| 129 |
return el('li', { key: b.id, className: 'bkbg-csw-bullet', style: { color: a.bulletColor } }, |
| 130 |
el('span', { style: { color: a.bulletIconColor, fontWeight: 700, flexShrink: 0 } }, bulletChar(a.bulletIcon)), |
| 131 |
el('span', null, b.text) |
| 132 |
); |
| 133 |
}) |
| 134 |
), |
| 135 |
panel.ctaLabel && el('a', { href: panel.ctaUrl || '#', className: 'bkbg-csw-cta', style: { background: a.ctaBg, color: a.ctaColor, borderRadius: a.ctaRadius + 'px' } }, panel.ctaLabel) |
| 136 |
); |
| 137 |
|
| 138 |
var flexDir = isTop ? 'column' : isLeft ? 'row-reverse' : 'row'; |
| 139 |
return el('div', { className: 'bkbg-csw-panel' + (a.animate ? ' bkbg-csw-anim' : ''), style: { display: 'flex', flexDirection: flexDir, gap: '48px', alignItems: 'center' } }, |
| 140 |
imgBox, textBox |
| 141 |
); |
| 142 |
} |
| 143 |
|
| 144 |
/* ── Switch bar ────────────────────────────────────────────────────── */ |
| 145 |
function SwitchBar(props) { |
| 146 |
var panels = props.panels; |
| 147 |
var active = props.active; |
| 148 |
var a = props.a; |
| 149 |
var wrapStyle = { display: 'inline-flex', background: a.switchStyle === 'pill' ? a.switchBg : 'transparent', borderRadius: a.switchRadius + 'px', padding: a.switchStyle === 'pill' ? '4px' : '0', gap: a.switchStyle === 'tabs' ? '0' : '4px' }; |
| 150 |
return el('div', { style: { textAlign: a.switchAlign, marginBottom: '40px' } }, |
| 151 |
el('div', { style: wrapStyle }, |
| 152 |
panels.map(function (panel, i) { |
| 153 |
var isActive = i === active; |
| 154 |
var btnStyle = { |
| 155 |
padding: '10px 22px', borderRadius: a.switchRadius + 'px', border: a.switchStyle === 'buttons' ? '1.5px solid ' + a.accentColor : 'none', |
| 156 |
background: isActive ? a.accentColor : 'transparent', |
| 157 |
color: isActive ? a.switchActiveText : a.accentColor, |
| 158 |
fontWeight: 600, cursor: 'pointer', fontSize: a.switchSize + 'px', transition: 'all 0.18s ease', |
| 159 |
}; |
| 160 |
return el('button', { key: i, type: 'button', style: btnStyle, onClick: function () { props.onSwitch(i); } }, panel.switchLabel || ('Panel ' + (i + 1))); |
| 161 |
}) |
| 162 |
) |
| 163 |
); |
| 164 |
} |
| 165 |
|
| 166 |
registerBlockType('blockenberg/content-switcher', { |
| 167 |
title: __('Content Switcher', 'blockenberg'), |
| 168 |
icon: 'controls-repeat', |
| 169 |
category: 'bkbg-content', |
| 170 |
|
| 171 |
edit: function (props) { |
| 172 |
var a = props.attributes; |
| 173 |
var setAttributes = props.setAttributes; |
| 174 |
|
| 175 |
var openColorKeyState = useState(null); |
| 176 |
var openColorKey = openColorKeyState[0]; |
| 177 |
var setOpenColorKey = openColorKeyState[1]; |
| 178 |
|
| 179 |
var activeState = useState(a.defaultActive || 0); |
| 180 |
var active = activeState[0]; |
| 181 |
var setActive = activeState[1]; |
| 182 |
|
| 183 |
var blockProps = useBlockProps({ style: buildWrapStyle(a) }); |
| 184 |
|
| 185 |
function cc(key, label, attrKey) { |
| 186 |
return renderColorControl(key, label, a[attrKey], function (val) { |
| 187 |
var upd = {}; upd[attrKey] = val; setAttributes(upd); |
| 188 |
}, openColorKey, setOpenColorKey); |
| 189 |
} |
| 190 |
|
| 191 |
function updatePanel(id, key, val) { |
| 192 |
setAttributes({ panels: a.panels.map(function (p) { if (p.id !== id) return p; var u = Object.assign({}, p); u[key] = val; return u; }) }); |
| 193 |
} |
| 194 |
function addBullet(panelId) { |
| 195 |
var panel = a.panels.find(function (p) { return p.id === panelId; }); |
| 196 |
var bullets = (panel.bullets || []).concat([{ id: 'b' + Math.random().toString(36).substr(2,4), text: __('New bullet point', 'blockenberg') }]); |
| 197 |
updatePanel(panelId, 'bullets', bullets); |
| 198 |
} |
| 199 |
function updateBullet(panelId, bulletId, val) { |
| 200 |
var panel = a.panels.find(function (p) { return p.id === panelId; }); |
| 201 |
updatePanel(panelId, 'bullets', (panel.bullets || []).map(function (b) { if (b.id !== bulletId) return b; return Object.assign({}, b, { text: val }); })); |
| 202 |
} |
| 203 |
function removeBullet(panelId, bulletId) { |
| 204 |
var panel = a.panels.find(function (p) { return p.id === panelId; }); |
| 205 |
updatePanel(panelId, 'bullets', (panel.bullets || []).filter(function (b) { return b.id !== bulletId; })); |
| 206 |
} |
| 207 |
|
| 208 |
var currentPanel = a.panels[active] || a.panels[0]; |
| 209 |
|
| 210 |
return el(Fragment, null, |
| 211 |
el(InspectorControls, null, |
| 212 |
el(PanelBody, { title: __('Switch Control', 'blockenberg'), initialOpen: true }, |
| 213 |
el(SelectControl, { label: __('Switch style', 'blockenberg'), value: a.switchStyle, options: SWITCH_STYLE_OPTIONS, onChange: function (v) { setAttributes({ switchStyle: v }); } }), |
| 214 |
el(SelectControl, { label: __('Alignment', 'blockenberg'), value: a.switchAlign, options: ALIGN_OPTIONS, onChange: function (v) { setAttributes({ switchAlign: v }); } }), |
| 215 |
el(RangeControl, { label: __('Switch radius (px)', 'blockenberg'), value: a.switchRadius, min: 0, max: 99, onChange: function (v) { setAttributes({ switchRadius: v }); } }) |
| 216 |
), |
| 217 |
el(PanelBody, { title: __('Panel Layout', 'blockenberg'), initialOpen: false }, |
| 218 |
el(SelectControl, { label: __('Image position', 'blockenberg'), value: a.panelLayout, options: LAYOUT_OPTIONS, onChange: function (v) { setAttributes({ panelLayout: v }); } }), |
| 219 |
a.panelLayout !== 'text-only' && el(SelectControl, { label: __('Image aspect ratio', 'blockenberg'), value: a.imageRatio, options: RATIO_OPTIONS, onChange: function (v) { setAttributes({ imageRatio: v }); } }), |
| 220 |
a.panelLayout !== 'text-only' && el(RangeControl, { label: __('Image radius (px)', 'blockenberg'), value: a.imageRadius, min: 0, max: 32, onChange: function (v) { setAttributes({ imageRadius: v }); } }), |
| 221 |
a.panelLayout !== 'text-only' && el(ToggleControl, { label: __('Image shadow', 'blockenberg'), checked: a.imageShadow, onChange: function (v) { setAttributes({ imageShadow: v }); }, __nextHasNoMarginBottom: true }), |
| 222 |
el(ToggleControl, { label: __('Show bullets', 'blockenberg'), checked: a.showBullets, onChange: function (v) { setAttributes({ showBullets: v }); }, __nextHasNoMarginBottom: true }), |
| 223 |
a.showBullets && el(SelectControl, { label: __('Bullet icon', 'blockenberg'), value: a.bulletIcon, options: BULLET_OPTIONS, onChange: function (v) { setAttributes({ bulletIcon: v }); } }), |
| 224 |
el(RangeControl, { label: __('CTA radius (px)', 'blockenberg'), value: a.ctaRadius, min: 0, max: 99, onChange: function (v) { setAttributes({ ctaRadius: v }); } }), |
| 225 |
el(ToggleControl, { label: __('Animate on scroll', 'blockenberg'), checked: a.animate, onChange: function (v) { setAttributes({ animate: v }); }, __nextHasNoMarginBottom: true }) |
| 226 |
), |
| 227 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 228 |
getTC() && el(getTC(), { label: __('Headline', 'blockenberg'), value: a.typoHeadline, onChange: function (v) { setAttributes({ typoHeadline: v }); } }), |
| 229 |
getTC() && el(getTC(), { label: __('Body Text', 'blockenberg'), value: a.typoBody, onChange: function (v) { setAttributes({ typoBody: v }); } }), |
| 230 |
el(RangeControl, { label: __('Switch label (px)', 'blockenberg'), value: a.switchSize, min: 12, max: 20, onChange: function (v) { setAttributes({ switchSize: v }); } }), |
| 231 |
el(RangeControl, { label: __('Bullets (px)', 'blockenberg'), value: a.bulletSize, min: 12, max: 20, onChange: function (v) { setAttributes({ bulletSize: v }); } }), |
| 232 |
el(RangeControl, { label: __('Badge (px)', 'blockenberg'), value: a.badgeSize, min: 10, max: 17, onChange: function (v) { setAttributes({ badgeSize: v }); } }) |
| 233 |
), |
| 234 |
el(PanelBody, { title: __('Colors', 'blockenberg'), initialOpen: false }, |
| 235 |
cc('accentColor', __('Accent', 'blockenberg'), 'accentColor'), |
| 236 |
cc('switchBg', __('Switch background', 'blockenberg'), 'switchBg'), |
| 237 |
cc('switchActiveText',__('Active label text', 'blockenberg'), 'switchActiveText'), |
| 238 |
cc('headlineColor', __('Headline', 'blockenberg'), 'headlineColor'), |
| 239 |
cc('bodyColor', __('Body text', 'blockenberg'), 'bodyColor'), |
| 240 |
cc('bulletColor', __('Bullet text', 'blockenberg'), 'bulletColor'), |
| 241 |
cc('bulletIconColor',__('Bullet icon', 'blockenberg'), 'bulletIconColor'), |
| 242 |
cc('ctaBg', __('CTA background', 'blockenberg'), 'ctaBg'), |
| 243 |
cc('ctaColor', __('CTA text', 'blockenberg'), 'ctaColor'), |
| 244 |
cc('bgColor', __('Section background', 'blockenberg'), 'bgColor') |
| 245 |
), |
| 246 |
el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false }, |
| 247 |
el(RangeControl, { label: __('Padding top (px)', 'blockenberg'), value: a.paddingTop, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingTop: v }); } }), |
| 248 |
el(RangeControl, { label: __('Padding bottom (px)', 'blockenberg'), value: a.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingBottom: v }); } }) |
| 249 |
), |
| 250 |
/* Per-panel settings */ |
| 251 |
el(PanelBody, { title: __('Panels', 'blockenberg'), initialOpen: false }, |
| 252 |
a.panels.map(function (panel, pi) { |
| 253 |
return el(PanelBody, { key: panel.id, title: panel.switchLabel || ('Panel ' + (pi + 1)), initialOpen: pi === active }, |
| 254 |
el(TextControl, { label: __('Switch label', 'blockenberg'), value: panel.switchLabel, onChange: function (v) { updatePanel(panel.id, 'switchLabel', v); } }), |
| 255 |
el(ToggleControl, { label: __('Show badge', 'blockenberg'), checked: panel.showBadge, onChange: function (v) { updatePanel(panel.id, 'showBadge', v); }, __nextHasNoMarginBottom: true }), |
| 256 |
panel.showBadge && el(TextControl, { label: __('Badge text', 'blockenberg'), value: panel.badge, onChange: function (v) { updatePanel(panel.id, 'badge', v); } }), |
| 257 |
a.panelLayout !== 'text-only' && el(MediaUploadCheck, null, |
| 258 |
el(MediaUpload, { |
| 259 |
onSelect: function (media) { setAttributes({ panels: a.panels.map(function (p) { return p.id !== panel.id ? p : Object.assign({}, p, { imageUrl: media.url, imageId: media.id }); }) }); }, |
| 260 |
allowedTypes: ['image'], value: panel.imageId, |
| 261 |
render: function (p) { return el('div', { style: { marginBottom: '8px' } }, |
| 262 |
panel.imageUrl && el('img', { src: panel.imageUrl, style: { width: '100%', borderRadius: '6px', marginBottom: '6px' } }), |
| 263 |
el(Button, { onClick: p.open, variant: panel.imageUrl ? 'secondary' : 'primary', size: 'compact' }, panel.imageUrl ? __('Replace image', 'blockenberg') : __('Add panel image', 'blockenberg')) |
| 264 |
); } |
| 265 |
}) |
| 266 |
), |
| 267 |
el(TextControl, { label: __('CTA label', 'blockenberg'), value: panel.ctaLabel, onChange: function (v) { updatePanel(panel.id, 'ctaLabel', v); } }), |
| 268 |
el(TextControl, { label: __('CTA URL', 'blockenberg'), value: panel.ctaUrl, onChange: function (v) { updatePanel(panel.id, 'ctaUrl', v); } }), |
| 269 |
a.showBullets && el('div', null, |
| 270 |
el('strong', { style: { display: 'block', marginBottom: '6px', fontSize: '12px' } }, __('Bullets', 'blockenberg')), |
| 271 |
(panel.bullets || []).map(function (b) { |
| 272 |
return el('div', { key: b.id, style: { display: 'flex', gap: '6px', alignItems: 'center', marginBottom: '4px' } }, |
| 273 |
el(TextControl, { value: b.text, onChange: function (v) { updateBullet(panel.id, b.id, v); }, style: { flex: 1 } }), |
| 274 |
el(Button, { onClick: function () { removeBullet(panel.id, b.id); }, isDestructive: true, variant: 'tertiary', size: 'compact' }, '✕') |
| 275 |
); |
| 276 |
}), |
| 277 |
el(Button, { onClick: function () { addBullet(panel.id); }, variant: 'secondary', size: 'compact' }, __('+ Bullet', 'blockenberg')) |
| 278 |
) |
| 279 |
); |
| 280 |
}) |
| 281 |
) |
| 282 |
), |
| 283 |
|
| 284 |
el('div', blockProps, |
| 285 |
el(SwitchBar, { panels: a.panels, active: active, a: a, onSwitch: setActive }), |
| 286 |
el(PanelPreview, { |
| 287 |
panel: currentPanel, a: a, |
| 288 |
onHeadlineChange: function (v) { updatePanel(currentPanel.id, 'headline', v); }, |
| 289 |
onBodyChange: function (v) { updatePanel(currentPanel.id, 'body', v); }, |
| 290 |
}) |
| 291 |
) |
| 292 |
); |
| 293 |
}, |
| 294 |
|
| 295 |
save: function (props) { |
| 296 |
var a = props.attributes; |
| 297 |
|
| 298 |
function renderPanel(panel, isActive) { |
| 299 |
var isLeft = a.panelLayout === 'image-left'; |
| 300 |
var isTop = a.panelLayout === 'image-top'; |
| 301 |
var isTextOnly= a.panelLayout === 'text-only'; |
| 302 |
var ratioParts= a.imageRatio.split('/'); |
| 303 |
var ratioVal = parseInt(ratioParts[1], 10) / parseInt(ratioParts[0], 10); |
| 304 |
var flexDir = isTop ? 'column' : isLeft ? 'row-reverse' : 'row'; |
| 305 |
|
| 306 |
var imgBox = !isTextOnly ? el('div', { className: 'bkbg-csw-img-col', style: { flex: isTop ? undefined : '0 0 45%', borderRadius: a.imageRadius + 'px', overflow: 'hidden', boxShadow: a.imageShadow ? '0 16px 48px rgba(0,0,0,0.12)' : 'none', position: 'relative' } }, |
| 307 |
el('div', { style: { paddingBottom: (ratioVal * 100) + '%' } }), |
| 308 |
panel.imageUrl && el('img', { src: panel.imageUrl, alt: '', loading: 'lazy', style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } }) |
| 309 |
) : null; |
| 310 |
|
| 311 |
var textBox = el('div', { className: 'bkbg-csw-text-col', style: { flex: '1 1 0', minWidth: 0 } }, |
| 312 |
panel.showBadge && panel.badge && el('span', { className: 'bkbg-csw-badge', style: { background: a.accentColor + '18', color: a.accentColor } }, panel.badge), |
| 313 |
el(RichText.Content, { tagName: 'h2', value: panel.headline, className: 'bkbg-csw-headline', style: { color: a.headlineColor } }), |
| 314 |
el(RichText.Content, { tagName: 'p', value: panel.body, className: 'bkbg-csw-body', style: { color: a.bodyColor } }), |
| 315 |
a.showBullets && panel.bullets && panel.bullets.length > 0 && el('ul', { className: 'bkbg-csw-bullets' }, |
| 316 |
panel.bullets.map(function (b) { |
| 317 |
return el('li', { key: b.id, className: 'bkbg-csw-bullet' }, |
| 318 |
el('span', { className: 'bkbg-csw-bullet-icon', style: { color: a.bulletIconColor } }, bulletChar(a.bulletIcon)), |
| 319 |
el('span', null, b.text) |
| 320 |
); |
| 321 |
}) |
| 322 |
), |
| 323 |
panel.ctaLabel && el('a', { href: panel.ctaUrl || '#', target: panel.ctaTarget ? '_blank' : undefined, rel: panel.ctaTarget ? 'noopener noreferrer' : undefined, className: 'bkbg-csw-cta', style: { background: a.ctaBg, color: a.ctaColor, borderRadius: a.ctaRadius + 'px' } }, panel.ctaLabel) |
| 324 |
); |
| 325 |
|
| 326 |
return el('div', { className: 'bkbg-csw-panel' + (isActive ? ' is-active' : '') + (a.animate ? ' bkbg-csw-anim' : ''), 'data-panel': panel.id, 'aria-hidden': isActive ? 'false' : 'true', style: { display: isActive ? undefined : 'none', flexDirection: flexDir, gap: '48px', alignItems: 'center' } }, |
| 327 |
imgBox, textBox |
| 328 |
); |
| 329 |
} |
| 330 |
|
| 331 |
return el('div', wp.blockEditor.useBlockProps.save({ className: 'bkbg-csw-wrapper', style: buildWrapStyle(a) }), |
| 332 |
el('div', { className: 'bkbg-csw-switch-bar', 'data-style': a.switchStyle, style: { textAlign: a.switchAlign } }, |
| 333 |
el('div', { className: 'bkbg-csw-switch bkbg-csw-switch--' + a.switchStyle, style: { display: 'inline-flex', borderRadius: a.switchRadius + 'px' } }, |
| 334 |
a.panels.map(function (panel, i) { |
| 335 |
return el('button', { key: i, type: 'button', className: 'bkbg-csw-switch-btn' + (i === (a.defaultActive || 0) ? ' is-active' : ''), 'data-target': panel.id, style: { borderRadius: a.switchRadius + 'px' } }, panel.switchLabel || ('Panel ' + (i + 1))); |
| 336 |
}) |
| 337 |
) |
| 338 |
), |
| 339 |
el('div', { className: 'bkbg-csw-panels' }, |
| 340 |
a.panels.map(function (panel, i) { return renderPanel(panel, i === (a.defaultActive || 0)); }) |
| 341 |
) |
| 342 |
); |
| 343 |
} |
| 344 |
}); |
| 345 |
}() ); |
| 346 |
|