| 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 |
function getTypographyControl() { return (window.bkbgTypographyControl || function () { return null; }); } |
| 18 |
function getTypoCssVars() { return (window.bkbgTypoCssVars || function () { return {}; }); } |
| 19 |
function _tv(typo, prefix) { var fn = getTypoCssVars(); return fn(typo || {}, prefix); } |
| 20 |
var IP = function () { return window.bkbgIconPicker; }; |
| 21 |
|
| 22 |
var statusOptions = [ |
| 23 |
{ label: '✓ Yes', value: 'yes' }, |
| 24 |
{ label: '✗ No', value: 'no' }, |
| 25 |
{ label: '~ Partial', value: 'partial' } |
| 26 |
]; |
| 27 |
|
| 28 |
function statusIcon(v, colors) { |
| 29 |
if (v === 'yes') return el('span', { style: { color: colors.yes, fontSize: 22, fontWeight: 700 } }, '✓'); |
| 30 |
if (v === 'no') return el('span', { style: { color: colors.no, fontSize: 22, fontWeight: 700 } }, '✗'); |
| 31 |
if (v === 'partial') return el('span', { style: { color: colors.partial, fontSize: 20 } }, '∼'); |
| 32 |
return el('span', null, v); |
| 33 |
} |
| 34 |
|
| 35 |
registerBlockType('blockenberg/comparison-section', { |
| 36 |
edit: function (props) { |
| 37 |
var attr = props.attributes; |
| 38 |
var setAttr = props.setAttributes; |
| 39 |
var blockProps = useBlockProps({ className: 'bkbg-cmp-editor', style: Object.assign({}, _tv(attr.typoHeading, '--bkcs-heading-'), _tv(attr.typoBody, '--bkcs-body-')) }); |
| 40 |
|
| 41 |
var colors = { yes: attr.yesColor, no: attr.noColor, partial: attr.partialColor }; |
| 42 |
|
| 43 |
function updateRow(idx, key, val) { |
| 44 |
var next = attr.rows.map(function (r, i) { |
| 45 |
return i === idx ? Object.assign({}, r, { [key]: val }) : r; |
| 46 |
}); |
| 47 |
setAttr({ rows: next }); |
| 48 |
} |
| 49 |
|
| 50 |
function addRow() { |
| 51 |
setAttr({ rows: attr.rows.concat([{ feature: 'New feature', col1: 'yes', col2: 'no' }]) }); |
| 52 |
} |
| 53 |
|
| 54 |
function removeRow(idx) { |
| 55 |
setAttr({ rows: attr.rows.filter(function (_, i) { return i !== idx; }) }); |
| 56 |
} |
| 57 |
|
| 58 |
var col1IsHl = attr.highlightCol === 'col1'; |
| 59 |
var col2IsHl = attr.highlightCol === 'col2'; |
| 60 |
var hlStyle = { background: attr.highlightBg, color: attr.highlightColor }; |
| 61 |
|
| 62 |
return el(Fragment, null, |
| 63 |
el(InspectorControls, null, |
| 64 |
el(PanelBody, { title: __('Heading', 'blockenberg'), initialOpen: true }, |
| 65 |
el(ToggleControl, { label: __('Show Heading', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showHeading, onChange: function (v) { setAttr({ showHeading: v }); } }) |
| 66 |
), |
| 67 |
el(PanelBody, { title: __('Columns', 'blockenberg'), initialOpen: true }, |
| 68 |
el(TextControl, { label: __('Col 1 Label (You)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.col1Label, onChange: function (v) { setAttr({ col1Label: v }); } }), |
| 69 |
el('p', { style: { fontSize: 11, fontWeight: 600, marginTop: 12 } }, __('Col 1 Icon', 'blockenberg')), |
| 70 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, setAttr, { charAttr: 'col1Icon', typeAttr: 'col1IconType', dashiconAttr: 'col1IconDashicon', imageUrlAttr: 'col1IconImageUrl', colorAttr: 'col1IconDashiconColor' })), |
| 71 |
el(TextControl, { label: __('Col 2 Label (Others)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.col2Label, onChange: function (v) { setAttr({ col2Label: v }); } }), |
| 72 |
el('p', { style: { fontSize: 11, fontWeight: 600, marginTop: 12 } }, __('Col 2 Icon', 'blockenberg')), |
| 73 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, setAttr, { charAttr: 'col2Icon', typeAttr: 'col2IconType', dashiconAttr: 'col2IconDashicon', imageUrlAttr: 'col2IconImageUrl', colorAttr: 'col2IconDashiconColor' })), |
| 74 |
el(ToggleControl, { label: __('Show Icons', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showColIcons, onChange: function (v) { setAttr({ showColIcons: v }); } }), |
| 75 |
el(SelectControl, { label: __('Highlight Column', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.highlightCol, |
| 76 |
options: [{ label: 'Col 1 (You)', value: 'col1' }, { label: 'Col 2 (Others)', value: 'col2' }, { label: 'None', value: 'none' }], |
| 77 |
onChange: function (v) { setAttr({ highlightCol: v }); } }) |
| 78 |
), |
| 79 |
el(PanelBody, { title: __('Feature Rows', 'blockenberg'), initialOpen: false }, |
| 80 |
attr.rows.map(function (r, i) { |
| 81 |
return el('div', { key: i, style: { borderLeft: '3px solid #7c3aed', paddingLeft: 8, marginBottom: 12 } }, |
| 82 |
el(TextControl, { label: __('Feature', 'blockenberg') + ' ' + (i + 1), __nextHasNoMarginBottom: true, value: r.feature, onChange: function (v) { updateRow(i, 'feature', v); } }), |
| 83 |
el(SelectControl, { label: attr.col1Label, __nextHasNoMarginBottom: true, value: r.col1, options: statusOptions, onChange: function (v) { updateRow(i, 'col1', v); } }), |
| 84 |
el(SelectControl, { label: attr.col2Label, __nextHasNoMarginBottom: true, value: r.col2, options: statusOptions, onChange: function (v) { updateRow(i, 'col2', v); } }), |
| 85 |
attr.rows.length > 1 && el(Button, { onClick: function () { removeRow(i); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true }, __('Remove', 'blockenberg')) |
| 86 |
); |
| 87 |
}), |
| 88 |
el(Button, { onClick: addRow, variant: 'secondary', __nextHasNoMarginBottom: true }, __('+ Add Row', 'blockenberg')) |
| 89 |
), |
| 90 |
el(PanelBody, { title: __('CTA', 'blockenberg'), initialOpen: false }, |
| 91 |
el(ToggleControl, { label: __('Show CTA', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showCta, onChange: function (v) { setAttr({ showCta: v }); } }), |
| 92 |
attr.showCta && el(TextControl, { label: __('CTA Label', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ctaLabel, onChange: function (v) { setAttr({ ctaLabel: v }); } }), |
| 93 |
attr.showCta && el(TextControl, { label: __('CTA URL', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.ctaUrl, onChange: function (v) { setAttr({ ctaUrl: v }); } }) |
| 94 |
), |
| 95 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false }, |
| 96 |
el(TextControl, { label: __('Table Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.tableWidth, onChange: function (v) { setAttr({ tableWidth: v }); } }), |
| 97 |
el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }), |
| 98 |
el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } }), |
| 99 |
el(RangeControl, { label: __('Outer Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 600, max: 1600, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }) |
| 100 |
), |
| 101 |
|
| 102 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 103 |
el(getTypographyControl(), { label: __('Heading Typography', 'blockenberg'), value: attr.typoHeading, onChange: function (v) { setAttr({ typoHeading: v }); } }), |
| 104 |
el(getTypographyControl(), { label: __('Body Typography', 'blockenberg'), value: attr.typoBody, onChange: function (v) { setAttr({ typoBody: v }); } }) |
| 105 |
), |
| 106 |
el(PanelColorSettings, { |
| 107 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 108 |
colorSettings: [ |
| 109 |
{ value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); }, label: __('Background', 'blockenberg') }, |
| 110 |
{ value: attr.highlightBg, onChange: function (v) { setAttr({ highlightBg: v || '#7c3aed' }); }, label: __('Highlight Column BG', 'blockenberg') }, |
| 111 |
{ value: attr.highlightColor, onChange: function (v) { setAttr({ highlightColor: v || '#ffffff' }); }, label: __('Highlight Column Text', 'blockenberg') }, |
| 112 |
{ value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); }, label: __('Heading', 'blockenberg') }, |
| 113 |
{ value: attr.textColor, onChange: function (v) { setAttr({ textColor: v || '#6b7280' }); }, label: __('Subtext', 'blockenberg') }, |
| 114 |
{ value: attr.featureColor, onChange: function (v) { setAttr({ featureColor: v || '#374151' }); }, label: __('Feature Text', 'blockenberg') }, |
| 115 |
{ value: attr.yesColor, onChange: function (v) { setAttr({ yesColor: v || '#16a34a' }); }, label: __('Yes / checkmark', 'blockenberg') }, |
| 116 |
{ value: attr.noColor, onChange: function (v) { setAttr({ noColor: v || '#dc2626' }); }, label: __('No / cross', 'blockenberg') }, |
| 117 |
{ value: attr.partialColor, onChange: function (v) { setAttr({ partialColor: v || '#d97706' }); }, label: __('Partial', 'blockenberg') }, |
| 118 |
{ value: attr.borderColor, onChange: function (v) { setAttr({ borderColor: v || '#e5e7eb' }); }, label: __('Table Border', 'blockenberg') }, |
| 119 |
{ value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#7c3aed' }); }, label: __('CTA Background', 'blockenberg') }, |
| 120 |
{ value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#ffffff' }); }, label: __('CTA Text', 'blockenberg') } |
| 121 |
] |
| 122 |
}) |
| 123 |
), |
| 124 |
el('div', blockProps, |
| 125 |
el('div', { style: { background: attr.bgColor, padding: attr.paddingTop + 'px 40px ' + attr.paddingBottom + 'px' } }, |
| 126 |
el('div', { style: { maxWidth: attr.maxWidth + 'px', margin: '0 auto', textAlign: 'center' } }, |
| 127 |
attr.showHeading && el(Fragment, null, |
| 128 |
el(RichText, { tagName: 'h2', className: 'bkbg-cmp-heading', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, style: { color: attr.headingColor, margin: '0 0 16px', fontWeight: 700 }, placeholder: __('Heading…', 'blockenberg') }), |
| 129 |
el(RichText, { tagName: 'p', className: 'bkbg-cmp-subtext', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, style: { color: attr.textColor, margin: '0 0 48px' }, placeholder: __('Subtext…', 'blockenberg') }) |
| 130 |
), |
| 131 |
el('table', { style: { width: '100%', maxWidth: attr.tableWidth + 'px', margin: '0 auto', borderCollapse: 'collapse', borderRadius: 12, overflow: 'hidden', boxShadow: '0 0 0 1px ' + attr.borderColor } }, |
| 132 |
el('thead', null, |
| 133 |
el('tr', null, |
| 134 |
el('th', { style: { background: attr.tableHeaderBg, padding: '20px 24px', textAlign: 'left', width: '50%', fontSize: attr.textSize + 'px', color: attr.featureColor, borderBottom: '1px solid ' + attr.borderColor } }, ''), |
| 135 |
el('th', { style: Object.assign({ padding: '20px 24px', fontSize: attr.textSize + 2 + 'px', fontWeight: 700, borderBottom: '1px solid ' + attr.borderColor, width: '25%' }, col1IsHl ? hlStyle : { background: attr.tableHeaderBg, color: attr.featureColor }) }, |
| 136 |
attr.showColIcons && el('span', { className: 'bkbg-cmp-col-icon', style: { marginRight: 6 } }, |
| 137 |
(!attr.col1IconType || attr.col1IconType === 'custom-char') |
| 138 |
? attr.col1Icon |
| 139 |
: IP().buildEditorIcon(attr.col1IconType, attr.col1Icon, attr.col1IconDashicon, attr.col1IconImageUrl, attr.col1IconDashiconColor) |
| 140 |
), |
| 141 |
attr.col1Label |
| 142 |
), |
| 143 |
el('th', { style: Object.assign({ padding: '20px 24px', fontSize: attr.textSize + 2 + 'px', fontWeight: 700, borderBottom: '1px solid ' + attr.borderColor, width: '25%' }, col2IsHl ? hlStyle : { background: attr.tableHeaderBg, color: attr.featureColor }) }, |
| 144 |
attr.showColIcons && el('span', { className: 'bkbg-cmp-col-icon', style: { marginRight: 6 } }, |
| 145 |
(!attr.col2IconType || attr.col2IconType === 'custom-char') |
| 146 |
? attr.col2Icon |
| 147 |
: IP().buildEditorIcon(attr.col2IconType, attr.col2Icon, attr.col2IconDashicon, attr.col2IconImageUrl, attr.col2IconDashiconColor) |
| 148 |
), |
| 149 |
attr.col2Label |
| 150 |
) |
| 151 |
) |
| 152 |
), |
| 153 |
el('tbody', null, |
| 154 |
attr.rows.map(function (r, i) { |
| 155 |
var rowBg = i % 2 === 0 ? '#ffffff' : '#fafafa'; |
| 156 |
return el('tr', { key: i }, |
| 157 |
el('td', { style: { padding: '16px 24px', borderBottom: '1px solid ' + attr.borderColor, textAlign: 'left', fontSize: attr.textSize + 'px', color: attr.featureColor, background: rowBg } }, r.feature), |
| 158 |
el('td', { style: Object.assign({ padding: '16px 24px', textAlign: 'center', borderBottom: '1px solid ' + attr.borderColor }, col1IsHl ? { background: attr.highlightBg + '22' } : { background: rowBg }) }, statusIcon(r.col1, colors)), |
| 159 |
el('td', { style: Object.assign({ padding: '16px 24px', textAlign: 'center', borderBottom: '1px solid ' + attr.borderColor }, col2IsHl ? { background: attr.highlightBg + '22' } : { background: rowBg }) }, statusIcon(r.col2, colors)) |
| 160 |
); |
| 161 |
}) |
| 162 |
) |
| 163 |
), |
| 164 |
attr.showCta && el('div', { style: { marginTop: 48 } }, |
| 165 |
el('a', { href: '#', style: { display: 'inline-flex', alignItems: 'center', gap: 8, padding: '14px 36px', borderRadius: 8, fontWeight: 700, fontSize: attr.textSize + 'px', background: attr.ctaBg, color: attr.ctaColor, textDecoration: 'none' } }, attr.ctaLabel, el('span', null, '→')) |
| 166 |
) |
| 167 |
) |
| 168 |
) |
| 169 |
) |
| 170 |
); |
| 171 |
}, |
| 172 |
save: function (props) { |
| 173 |
var attr = props.attributes; |
| 174 |
var sv = Object.assign({}, _tv(attr.typoHeading, '--bkcs-heading-'), _tv(attr.typoBody, '--bkcs-body-')); |
| 175 |
return el('div', useBlockProps.save({ style: sv }), |
| 176 |
el('div', { className: 'bkbg-comparison-section-app', 'data-opts': JSON.stringify(attr) }) |
| 177 |
); |
| 178 |
} |
| 179 |
}); |
| 180 |
}() ); |
| 181 |
|