| 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 useBlockProps = wp.blockEditor.useBlockProps; |
| 9 |
var RichText = wp.blockEditor.RichText; |
| 10 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 11 |
var PanelBody = wp.components.PanelBody; |
| 12 |
var ToggleControl = wp.components.ToggleControl; |
| 13 |
var RangeControl = wp.components.RangeControl; |
| 14 |
var SelectControl = wp.components.SelectControl; |
| 15 |
var TextControl = wp.components.TextControl; |
| 16 |
var Button = wp.components.Button; |
| 17 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 18 |
var IP = function () { return window.bkbgIconPicker; }; |
| 19 |
|
| 20 |
var CARD_STYLE_OPTIONS = [ |
| 21 |
{ label: 'Elevated (shadow)', value: 'elevated' }, |
| 22 |
{ label: 'Flat', value: 'flat' }, |
| 23 |
{ label: 'Bordered', value: 'bordered' }, |
| 24 |
{ label: 'Ghost', value: 'ghost' }, |
| 25 |
]; |
| 26 |
var CTA_STYLE_OPTIONS = [ |
| 27 |
{ label: 'Filled', value: 'filled' }, |
| 28 |
{ label: 'Outline', value: 'outline' }, |
| 29 |
{ label: 'Subtle', value: 'subtle' }, |
| 30 |
{ label: 'Link', value: 'link' }, |
| 31 |
]; |
| 32 |
var TAG_OPTIONS = [ |
| 33 |
{ label: 'H2', value: 'h2' }, |
| 34 |
{ label: 'H3', value: 'h3' }, |
| 35 |
{ label: 'H4', value: 'h4' }, |
| 36 |
{ label: 'p', value: 'p' }, |
| 37 |
]; |
| 38 |
|
| 39 |
function updatePlan(plans, idx, field, val) { |
| 40 |
return plans.map(function (p, i) { |
| 41 |
if (i !== idx) return p; |
| 42 |
var up = {}; up[field] = val; |
| 43 |
return Object.assign({}, p, up); |
| 44 |
}); |
| 45 |
} |
| 46 |
|
| 47 |
function updateFeature(plans, planIdx, featIdx, field, val) { |
| 48 |
return plans.map(function (p, pi) { |
| 49 |
if (pi !== planIdx) return p; |
| 50 |
var feats = p.features.map(function (f, fi) { |
| 51 |
if (fi !== featIdx) return f; |
| 52 |
var uf = {}; uf[field] = val; |
| 53 |
return Object.assign({}, f, uf); |
| 54 |
}); |
| 55 |
return Object.assign({}, p, { features: feats }); |
| 56 |
}); |
| 57 |
} |
| 58 |
|
| 59 |
registerBlockType('blockenberg/pricing-section', { |
| 60 |
title: __('Pricing Section', 'blockenberg'), |
| 61 |
icon: 'money-alt', |
| 62 |
category: 'bkbg-marketing', |
| 63 |
description: __('Multi-tier pricing section with monthly/yearly toggle, feature rows, popular badge, and per-plan CTAs.', 'blockenberg'), |
| 64 |
|
| 65 |
edit: function (props) { |
| 66 |
var a = props.attributes; |
| 67 |
var set = props.setAttributes; |
| 68 |
var yearlyState = useState(a.defaultYearly); |
| 69 |
var isYearly = yearlyState[0]; |
| 70 |
var setIsYearly = yearlyState[1]; |
| 71 |
var activePlanState = useState(0); |
| 72 |
var activePlan = activePlanState[0]; |
| 73 |
var setActivePlan = activePlanState[1]; |
| 74 |
|
| 75 |
var blockProps = useBlockProps({ |
| 76 |
style: { background: a.containerBg || '', padding: a.containerPadding + 'px 0' } |
| 77 |
}); |
| 78 |
|
| 79 |
function addPlan() { |
| 80 |
var newPlan = { |
| 81 |
name: 'New Plan', eyebrow: 'For everyone', |
| 82 |
price: '19', priceYearly: '14', |
| 83 |
period: '/month', yearlyPeriod: '/month, billed yearly', |
| 84 |
description: 'A great plan for everyone.', |
| 85 |
isPopular: false, popularLabel: 'Most Popular', |
| 86 |
ctaLabel: 'Get started', ctaUrl: '#', ctaStyle: 'outline', |
| 87 |
accentColor: '#6366f1', |
| 88 |
features: [ |
| 89 |
{ text: 'Feature one', included: true }, |
| 90 |
{ text: 'Feature two', included: false }, |
| 91 |
] |
| 92 |
}; |
| 93 |
set({ plans: a.plans.concat([newPlan]) }); |
| 94 |
} |
| 95 |
|
| 96 |
function removePlan(i) { |
| 97 |
if (a.plans.length <= 1) return; |
| 98 |
set({ plans: a.plans.filter(function (_, idx) { return idx !== i; }) }); |
| 99 |
setActivePlan(Math.max(0, activePlan - 1)); |
| 100 |
} |
| 101 |
|
| 102 |
function addFeature(planIdx) { |
| 103 |
var plans = a.plans.map(function (p, i) { |
| 104 |
if (i !== planIdx) return p; |
| 105 |
return Object.assign({}, p, { features: p.features.concat([{ text: 'New feature', included: true }]) }); |
| 106 |
}); |
| 107 |
set({ plans: plans }); |
| 108 |
} |
| 109 |
|
| 110 |
function removeFeature(planIdx, featIdx) { |
| 111 |
var plans = a.plans.map(function (p, i) { |
| 112 |
if (i !== planIdx) return p; |
| 113 |
return Object.assign({}, p, { features: p.features.filter(function (_, fi) { return fi !== featIdx; }) }); |
| 114 |
}); |
| 115 |
set({ plans: plans }); |
| 116 |
} |
| 117 |
|
| 118 |
// Render a plan card preview |
| 119 |
function renderPlan(plan, i) { |
| 120 |
var isPopular = plan.isPopular; |
| 121 |
var cardBg = isPopular ? a.popularBg : a.cardBg; |
| 122 |
var nameColor = isPopular ? a.popularNameColor : a.nameColor; |
| 123 |
var priceColor = isPopular ? a.popularPriceColor : a.priceColor; |
| 124 |
var descColor = isPopular ? 'rgba(255,255,255,0.75)' : a.descColor; |
| 125 |
var featureColor = isPopular ? 'rgba(255,255,255,0.9)' : a.featureColor; |
| 126 |
var missingColor = isPopular ? 'rgba(255,255,255,0.3)' : a.featureMissingColor; |
| 127 |
var borderStyle = {}; |
| 128 |
if (a.cardStyle === 'bordered') { |
| 129 |
borderStyle.border = '2px solid ' + (isPopular ? a.popularBg : '#e5e7eb'); |
| 130 |
} else if (a.cardStyle === 'elevated') { |
| 131 |
borderStyle.boxShadow = isPopular |
| 132 |
? '0 20px 60px rgba(99,102,241,0.3)' |
| 133 |
: '0 4px 24px rgba(0,0,0,0.08)'; |
| 134 |
} |
| 135 |
var ctaBg = plan.ctaStyle === 'filled' |
| 136 |
? (isPopular ? '#ffffff' : a.popularBg) |
| 137 |
: 'transparent'; |
| 138 |
var ctaColor = plan.ctaStyle === 'filled' |
| 139 |
? (isPopular ? a.popularBg : '#ffffff') |
| 140 |
: (isPopular ? '#ffffff' : a.popularBg); |
| 141 |
var ctaBorder = plan.ctaStyle === 'outline' || plan.ctaStyle === 'link' |
| 142 |
? (isPopular ? '2px solid rgba(255,255,255,0.5)' : '2px solid ' + a.popularBg) |
| 143 |
: 'none'; |
| 144 |
|
| 145 |
return el('div', { |
| 146 |
key: i, |
| 147 |
onClick: function () { setActivePlan(i); }, |
| 148 |
style: Object.assign({ |
| 149 |
background: cardBg, |
| 150 |
borderRadius: a.cardRadius + 'px', |
| 151 |
padding: a.cardPadding + 'px', |
| 152 |
cursor: 'pointer', |
| 153 |
flex: '1', |
| 154 |
display: 'flex', |
| 155 |
flexDirection: 'column', |
| 156 |
gap: 16, |
| 157 |
outline: i === activePlan ? '2px solid #fbbf24' : 'none', |
| 158 |
outlineOffset: 2, |
| 159 |
position: 'relative', |
| 160 |
}, borderStyle), |
| 161 |
}, |
| 162 |
|
| 163 |
// Popular badge |
| 164 |
isPopular && a.showEyebrow && el('div', { |
| 165 |
style: { |
| 166 |
display: 'inline-block', |
| 167 |
fontSize: 11, |
| 168 |
fontWeight: 700, |
| 169 |
letterSpacing: '0.05em', |
| 170 |
padding: '4px 12px', |
| 171 |
borderRadius: 999, |
| 172 |
background: a.popularBadgeBg, |
| 173 |
color: a.popularBadgeColor, |
| 174 |
alignSelf: 'flex-start', |
| 175 |
} |
| 176 |
}, plan.popularLabel), |
| 177 |
|
| 178 |
// Eyebrow (non-popular) |
| 179 |
!isPopular && a.showEyebrow && el('div', { |
| 180 |
style: { fontSize: 12, fontWeight: 600, color: a.periodColor, textTransform: 'uppercase', letterSpacing: '0.05em' } |
| 181 |
}, plan.eyebrow), |
| 182 |
|
| 183 |
// Name |
| 184 |
el('div', { style: { color: nameColor } }, plan.name), |
| 185 |
|
| 186 |
// Price |
| 187 |
el('div', { style: { display: 'flex', alignItems: 'baseline', gap: 2 } }, |
| 188 |
el('span', { style: { fontSize: 22, fontWeight: 500, color: priceColor, opacity: 0.7 } }, a.currencySymbol), |
| 189 |
el('span', { style: { color: priceColor, lineHeight: 1 } }, |
| 190 |
isYearly ? plan.priceYearly : plan.price |
| 191 |
), |
| 192 |
el('span', { style: { fontSize: 13, color: isPopular ? 'rgba(255,255,255,0.6)' : a.periodColor, marginLeft: 4 } }, |
| 193 |
isYearly ? plan.yearlyPeriod : plan.period |
| 194 |
) |
| 195 |
), |
| 196 |
|
| 197 |
// Description |
| 198 |
a.showDescription && el('p', { |
| 199 |
style: { margin: 0, color: descColor, lineHeight: 1.6 } |
| 200 |
}, plan.description), |
| 201 |
|
| 202 |
// CTA |
| 203 |
el('div', { |
| 204 |
style: { |
| 205 |
padding: '11px 20px', |
| 206 |
borderRadius: 8, |
| 207 |
background: ctaBg, |
| 208 |
color: ctaColor, |
| 209 |
border: ctaBorder, |
| 210 |
textAlign: 'center', |
| 211 |
fontWeight: 600, |
| 212 |
fontSize: 14, |
| 213 |
cursor: 'pointer', |
| 214 |
} |
| 215 |
}, plan.ctaLabel), |
| 216 |
|
| 217 |
// Features |
| 218 |
a.showFeatures && el('div', { style: { display: 'flex', flexDirection: 'column', gap: 10, marginTop: 4 } }, |
| 219 |
el('div', { style: { width: '100%', height: 1, background: isPopular ? 'rgba(255,255,255,0.15)' : '#f3f4f6' } }), |
| 220 |
plan.features.map(function (feat, fi) { |
| 221 |
return el('div', { |
| 222 |
key: fi, |
| 223 |
style: { display: 'flex', alignItems: 'center', gap: 10 } |
| 224 |
}, |
| 225 |
el('span', { |
| 226 |
style: { |
| 227 |
fontWeight: 700, |
| 228 |
color: feat.included ? a.includedIconColor : missingColor, |
| 229 |
flexShrink: 0, |
| 230 |
fontSize: 16, |
| 231 |
} |
| 232 |
}, (function() { |
| 233 |
var _t = feat.included ? (a.includedIconType || 'custom-char') : (a.notIncludedIconType || 'custom-char'); |
| 234 |
var _c = feat.included ? a.includedIcon : a.notIncludedIcon; |
| 235 |
var _d = feat.included ? a.includedIconDashicon : a.notIncludedIconDashicon; |
| 236 |
var _u = feat.included ? a.includedIconImageUrl : a.notIncludedIconImageUrl; |
| 237 |
var _dc = feat.included ? a.includedIconDashiconColor : a.notIncludedIconDashiconColor; |
| 238 |
return _t !== 'custom-char' ? IP().buildEditorIcon(_t, _c, _d, _u, _dc) : _c; |
| 239 |
})()), |
| 240 |
el('span', { |
| 241 |
style: { color: feat.included ? featureColor : missingColor } |
| 242 |
}, feat.text) |
| 243 |
); |
| 244 |
}) |
| 245 |
) |
| 246 |
); |
| 247 |
} |
| 248 |
|
| 249 |
var plan = a.plans[activePlan] || a.plans[0]; |
| 250 |
|
| 251 |
return el(Fragment, null, |
| 252 |
el(InspectorControls, null, |
| 253 |
// Section heading panel |
| 254 |
el(PanelBody, { title: 'Section Header', initialOpen: true }, |
| 255 |
el(ToggleControl, { |
| 256 |
label: 'Show heading', |
| 257 |
checked: a.showSectionHeading, |
| 258 |
onChange: function (v) { set({ showSectionHeading: v }); }, |
| 259 |
__nextHasNoMarginBottom: true, |
| 260 |
}), |
| 261 |
a.showSectionHeading && el(Fragment, null, |
| 262 |
el('div', { style: { height: 8 } }), |
| 263 |
el(TextControl, { |
| 264 |
label: 'Heading text', |
| 265 |
value: a.sectionHeading, |
| 266 |
onChange: function (v) { set({ sectionHeading: v }); }, |
| 267 |
__nextHasNoMarginBottom: true, |
| 268 |
}), |
| 269 |
el('div', { style: { height: 8 } }), |
| 270 |
el(SelectControl, { |
| 271 |
label: 'Heading tag', |
| 272 |
value: a.headingTag, |
| 273 |
options: TAG_OPTIONS, |
| 274 |
onChange: function (v) { set({ headingTag: v }); }, |
| 275 |
__nextHasNoMarginBottom: true, |
| 276 |
}) |
| 277 |
), |
| 278 |
el('div', { style: { height: 8 } }), |
| 279 |
el(ToggleControl, { |
| 280 |
label: 'Show sub-text', |
| 281 |
checked: a.showSectionSubtext, |
| 282 |
onChange: function (v) { set({ showSectionSubtext: v }); }, |
| 283 |
__nextHasNoMarginBottom: true, |
| 284 |
}), |
| 285 |
a.showSectionSubtext && el(Fragment, null, |
| 286 |
el('div', { style: { height: 8 } }), |
| 287 |
el(TextControl, { |
| 288 |
label: 'Sub-text', |
| 289 |
value: a.sectionSubtext, |
| 290 |
onChange: function (v) { set({ sectionSubtext: v }); }, |
| 291 |
__nextHasNoMarginBottom: true, |
| 292 |
}) |
| 293 |
) |
| 294 |
), |
| 295 |
|
| 296 |
// Toggle panel |
| 297 |
el(PanelBody, { title: 'Billing Toggle', initialOpen: false }, |
| 298 |
el(ToggleControl, { |
| 299 |
label: 'Show monthly/yearly toggle', |
| 300 |
checked: a.showToggle, |
| 301 |
onChange: function (v) { set({ showToggle: v }); }, |
| 302 |
__nextHasNoMarginBottom: true, |
| 303 |
}), |
| 304 |
el('div', { style: { height: 8 } }), |
| 305 |
el(TextControl, { label: 'Monthly label', value: a.toggleLabelMonthly, onChange: function (v) { set({ toggleLabelMonthly: v }); }, __nextHasNoMarginBottom: true }), |
| 306 |
el('div', { style: { height: 8 } }), |
| 307 |
el(TextControl, { label: 'Yearly label', value: a.toggleLabelYearly, onChange: function (v) { set({ toggleLabelYearly: v }); }, __nextHasNoMarginBottom: true }), |
| 308 |
el('div', { style: { height: 8 } }), |
| 309 |
el(ToggleControl, { |
| 310 |
label: 'Show savings badge', |
| 311 |
checked: a.showSavingsBadge, |
| 312 |
onChange: function (v) { set({ showSavingsBadge: v }); }, |
| 313 |
__nextHasNoMarginBottom: true, |
| 314 |
}), |
| 315 |
a.showSavingsBadge && el(Fragment, null, |
| 316 |
el('div', { style: { height: 8 } }), |
| 317 |
el(TextControl, { label: 'Savings badge text', value: a.savingsBadge, onChange: function (v) { set({ savingsBadge: v }); }, __nextHasNoMarginBottom: true }) |
| 318 |
), |
| 319 |
el('div', { style: { height: 8 } }), |
| 320 |
el(ToggleControl, { |
| 321 |
label: 'Default to yearly view', |
| 322 |
checked: a.defaultYearly, |
| 323 |
onChange: function (v) { set({ defaultYearly: v }); setIsYearly(v); }, |
| 324 |
__nextHasNoMarginBottom: true, |
| 325 |
}) |
| 326 |
), |
| 327 |
|
| 328 |
// Plans panel |
| 329 |
el(PanelBody, { title: 'Plans (' + a.plans.length + ')', initialOpen: false }, |
| 330 |
a.plans.map(function (plan, i) { |
| 331 |
return el('div', { |
| 332 |
key: i, |
| 333 |
style: { |
| 334 |
border: i === activePlan ? '2px solid #6366f1' : '1px solid #e5e7eb', |
| 335 |
borderRadius: 8, padding: 10, marginBottom: 8, |
| 336 |
background: i === activePlan ? '#f5f3ff' : '#fff', |
| 337 |
} |
| 338 |
}, |
| 339 |
el('div', { |
| 340 |
style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', cursor: 'pointer' }, |
| 341 |
onClick: function () { setActivePlan(i); } |
| 342 |
}, |
| 343 |
el('strong', { style: { fontSize: 13 } }, plan.name + (plan.isPopular ? ' ⭐' : '')), |
| 344 |
el('div', { style: { display: 'flex', gap: 4 } }, |
| 345 |
el(Button, { isDestructive: true, variant: 'tertiary', size: 'small', onClick: function (e) { e.stopPropagation(); removePlan(i); }, __nextHasNoMarginBottom: true }, '✕') |
| 346 |
) |
| 347 |
), |
| 348 |
i === activePlan && el(Fragment, null, |
| 349 |
el('div', { style: { height: 8 } }), |
| 350 |
el(TextControl, { label: 'Plan name', value: plan.name, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'name', v) }); }, __nextHasNoMarginBottom: true }), |
| 351 |
el('div', { style: { height: 6 } }), |
| 352 |
el(TextControl, { label: 'Eyebrow', value: plan.eyebrow, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'eyebrow', v) }); }, __nextHasNoMarginBottom: true }), |
| 353 |
el('div', { style: { height: 6 } }), |
| 354 |
el(TextControl, { label: 'Description', value: plan.description, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'description', v) }); }, __nextHasNoMarginBottom: true }), |
| 355 |
el('div', { style: { height: 6 } }), |
| 356 |
el(TextControl, { label: 'Monthly price (number only)', value: plan.price, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'price', v) }); }, __nextHasNoMarginBottom: true }), |
| 357 |
el('div', { style: { height: 6 } }), |
| 358 |
el(TextControl, { label: 'Yearly price (number only)', value: plan.priceYearly, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'priceYearly', v) }); }, __nextHasNoMarginBottom: true }), |
| 359 |
el('div', { style: { height: 6 } }), |
| 360 |
el(TextControl, { label: 'Period label (monthly)', value: plan.period, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'period', v) }); }, __nextHasNoMarginBottom: true }), |
| 361 |
el('div', { style: { height: 6 } }), |
| 362 |
el(TextControl, { label: 'Period label (yearly)', value: plan.yearlyPeriod, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'yearlyPeriod', v) }); }, __nextHasNoMarginBottom: true }), |
| 363 |
el('div', { style: { height: 6 } }), |
| 364 |
el(TextControl, { label: 'CTA label', value: plan.ctaLabel, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'ctaLabel', v) }); }, __nextHasNoMarginBottom: true }), |
| 365 |
el('div', { style: { height: 6 } }), |
| 366 |
el(TextControl, { label: 'CTA URL', value: plan.ctaUrl, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'ctaUrl', v) }); }, __nextHasNoMarginBottom: true }), |
| 367 |
el('div', { style: { height: 6 } }), |
| 368 |
el(SelectControl, { label: 'CTA style', value: plan.ctaStyle, options: CTA_STYLE_OPTIONS, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'ctaStyle', v) }); }, __nextHasNoMarginBottom: true }), |
| 369 |
el('div', { style: { height: 6 } }), |
| 370 |
el(ToggleControl, { label: 'Mark as popular', checked: plan.isPopular, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'isPopular', v) }); }, __nextHasNoMarginBottom: true }), |
| 371 |
plan.isPopular && el(Fragment, null, |
| 372 |
el('div', { style: { height: 6 } }), |
| 373 |
el(TextControl, { label: 'Popular badge text', value: plan.popularLabel, onChange: function (v) { set({ plans: updatePlan(a.plans, i, 'popularLabel', v) }); }, __nextHasNoMarginBottom: true }) |
| 374 |
), |
| 375 |
el('div', { style: { marginTop: 12, marginBottom: 6, fontWeight: 600, fontSize: 12, color: '#374151' } }, 'Features'), |
| 376 |
plan.features.map(function (feat, fi) { |
| 377 |
return el('div', { key: fi, style: { display: 'flex', gap: 6, marginBottom: 6, alignItems: 'center' } }, |
| 378 |
el(TextControl, { value: feat.text, onChange: function (v) { set({ plans: updateFeature(a.plans, i, fi, 'text', v) }); }, __nextHasNoMarginBottom: true, style: { flex: 1 } }), |
| 379 |
el(Button, { |
| 380 |
variant: feat.included ? 'primary' : 'secondary', |
| 381 |
size: 'small', |
| 382 |
onClick: function () { set({ plans: updateFeature(a.plans, i, fi, 'included', !feat.included) }); }, |
| 383 |
__nextHasNoMarginBottom: true, |
| 384 |
}, feat.included ? '✓' : '✗'), |
| 385 |
el(Button, { isDestructive: true, variant: 'tertiary', size: 'small', onClick: function () { removeFeature(i, fi); }, __nextHasNoMarginBottom: true }, '✕') |
| 386 |
); |
| 387 |
}), |
| 388 |
el(Button, { variant: 'secondary', size: 'small', onClick: function () { addFeature(i); }, style: { width: '100%', justifyContent: 'center', marginTop: 4 }, __nextHasNoMarginBottom: true }, '+ Add Feature') |
| 389 |
) |
| 390 |
); |
| 391 |
}), |
| 392 |
el(Button, { variant: 'secondary', onClick: addPlan, style: { width: '100%', justifyContent: 'center', marginTop: 8 }, __nextHasNoMarginBottom: true }, '+ Add Plan') |
| 393 |
), |
| 394 |
|
| 395 |
// Layout panel |
| 396 |
el(PanelBody, { title: 'Layout & Cards', initialOpen: false }, |
| 397 |
el(RangeControl, { label: 'Columns', value: a.columns, min: 1, max: 4, onChange: function (v) { set({ columns: v }); }, __nextHasNoMarginBottom: true }), |
| 398 |
el('div', { style: { height: 10 } }), |
| 399 |
el(RangeControl, { label: 'Gap (px)', value: a.gap, min: 0, max: 60, onChange: function (v) { set({ gap: v }); }, __nextHasNoMarginBottom: true }), |
| 400 |
el('div', { style: { height: 10 } }), |
| 401 |
el(RangeControl, { label: 'Max width (px)', value: a.maxWidth, min: 600, max: 1600, step: 50, onChange: function (v) { set({ maxWidth: v }); }, __nextHasNoMarginBottom: true }), |
| 402 |
el('div', { style: { height: 10 } }), |
| 403 |
el(RangeControl, { label: 'Container padding (px)', value: a.containerPadding, min: 0, max: 120, onChange: function (v) { set({ containerPadding: v }); }, __nextHasNoMarginBottom: true }), |
| 404 |
el('div', { style: { height: 10 } }), |
| 405 |
el(SelectControl, { label: 'Card style', value: a.cardStyle, options: CARD_STYLE_OPTIONS, onChange: function (v) { set({ cardStyle: v }); }, __nextHasNoMarginBottom: true }), |
| 406 |
el('div', { style: { height: 10 } }), |
| 407 |
el(RangeControl, { label: 'Card border radius (px)', value: a.cardRadius, min: 0, max: 32, onChange: function (v) { set({ cardRadius: v }); }, __nextHasNoMarginBottom: true }), |
| 408 |
el('div', { style: { height: 10 } }), |
| 409 |
el(RangeControl, { label: 'Card padding (px)', value: a.cardPadding, min: 16, max: 64, onChange: function (v) { set({ cardPadding: v }); }, __nextHasNoMarginBottom: true }), |
| 410 |
el('div', { style: { height: 10 } }), |
| 411 |
el(TextControl, { label: 'Currency symbol', value: a.currencySymbol, onChange: function (v) { set({ currencySymbol: v }); }, __nextHasNoMarginBottom: true }), |
| 412 |
el('div', { style: { height: 10 } }), |
| 413 |
el(ToggleControl, { label: 'Show eyebrow', checked: a.showEyebrow, onChange: function (v) { set({ showEyebrow: v }); }, __nextHasNoMarginBottom: true }), |
| 414 |
el('div', { style: { height: 6 } }), |
| 415 |
el(ToggleControl, { label: 'Show description', checked: a.showDescription, onChange: function (v) { set({ showDescription: v }); }, __nextHasNoMarginBottom: true }), |
| 416 |
el('div', { style: { height: 6 } }), |
| 417 |
el(ToggleControl, { label: 'Show feature list', checked: a.showFeatures, onChange: function (v) { set({ showFeatures: v }); }, __nextHasNoMarginBottom: true }), |
| 418 |
el('div', { style: { height: 10 } }), |
| 419 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, set, { charAttr: 'includedIcon', typeAttr: 'includedIconType', dashiconAttr: 'includedIconDashicon', imageUrlAttr: 'includedIconImageUrl', colorAttr: 'includedIconDashiconColor' })), |
| 420 |
el('div', { style: { height: 6 } }), |
| 421 |
el(IP().IconPickerControl, IP().iconPickerProps(attr, set, { charAttr: 'notIncludedIcon', typeAttr: 'notIncludedIconType', dashiconAttr: 'notIncludedIconDashicon', imageUrlAttr: 'notIncludedIconImageUrl', colorAttr: 'notIncludedIconDashiconColor' })) |
| 422 |
), |
| 423 |
|
| 424 |
// Typography panel |
| 425 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 426 |
(function () { |
| 427 |
var TC = getTypoControl(); |
| 428 |
if (!TC) return el('p', null, 'Loading…'); |
| 429 |
return el(Fragment, null, |
| 430 |
el(TC, { label: __('Section Heading', 'blockenberg'), value: a.headingTypo, onChange: function (v) { set({ headingTypo: v }); } }), |
| 431 |
el(TC, { label: __('Subtext', 'blockenberg'), value: a.subtextTypo, onChange: function (v) { set({ subtextTypo: v }); } }), |
| 432 |
el(TC, { label: __('Plan Name', 'blockenberg'), value: a.nameTypo, onChange: function (v) { set({ nameTypo: v }); } }), |
| 433 |
el(TC, { label: __('Price', 'blockenberg'), value: a.priceTypo, onChange: function (v) { set({ priceTypo: v }); } }), |
| 434 |
el(TC, { label: __('Description', 'blockenberg'), value: a.descTypo, onChange: function (v) { set({ descTypo: v }); } }), |
| 435 |
el(TC, { label: __('Feature', 'blockenberg'), value: a.featureTypo, onChange: function (v) { set({ featureTypo: v }); } }) |
| 436 |
); |
| 437 |
})() |
| 438 |
), |
| 439 |
|
| 440 |
// Colors panel |
| 441 |
el(PanelColorSettings, { |
| 442 |
title: 'Colors', |
| 443 |
initialOpen: false, |
| 444 |
colorSettings: [ |
| 445 |
{ label: 'Container Background', value: a.containerBg, onChange: function (v) { set({ containerBg: v || '' }); } }, |
| 446 |
{ label: 'Card Background', value: a.cardBg, onChange: function (v) { set({ cardBg: v || '#ffffff' }); } }, |
| 447 |
{ label: 'Popular Plan Background', value: a.popularBg, onChange: function (v) { set({ popularBg: v || '#6366f1' }); } }, |
| 448 |
{ label: 'Plan Name Color', value: a.nameColor, onChange: function (v) { set({ nameColor: v || '#111827' }); } }, |
| 449 |
{ label: 'Price Color', value: a.priceColor, onChange: function (v) { set({ priceColor: v || '#111827' }); } }, |
| 450 |
{ label: 'Period Color', value: a.periodColor, onChange: function (v) { set({ periodColor: v || '#6b7280' }); } }, |
| 451 |
{ label: 'Description Color', value: a.descColor, onChange: function (v) { set({ descColor: v || '#6b7280' }); } }, |
| 452 |
{ label: 'Feature Color', value: a.featureColor, onChange: function (v) { set({ featureColor: v || '#374151' }); } }, |
| 453 |
{ label: 'Missing Feature Color', value: a.featureMissingColor, onChange: function (v) { set({ featureMissingColor: v || '#d1d5db' }); } }, |
| 454 |
{ label: 'Included Icon Color', value: a.includedIconColor, onChange: function (v) { set({ includedIconColor: v || '#10b981' }); } }, |
| 455 |
{ label: 'Popular Name Color', value: a.popularNameColor, onChange: function (v) { set({ popularNameColor: v || '#ffffff' }); } }, |
| 456 |
{ label: 'Popular Price Color', value: a.popularPriceColor, onChange: function (v) { set({ popularPriceColor: v || '#ffffff' }); } }, |
| 457 |
{ label: 'Toggle Active Background', value: a.toggleActiveBg, onChange: function (v) { set({ toggleActiveBg: v || '#6366f1' }); } }, |
| 458 |
{ label: 'Heading Color', value: a.headingColor, onChange: function (v) { set({ headingColor: v || '#111827' }); } }, |
| 459 |
{ label: 'Subtext Color', value: a.subtextColor, onChange: function (v) { set({ subtextColor: v || '#6b7280' }); } }, |
| 460 |
] |
| 461 |
}) |
| 462 |
), |
| 463 |
|
| 464 |
// Editor preview |
| 465 |
el('div', blockProps, |
| 466 |
el('div', { style: { maxWidth: a.maxWidth + 'px', margin: '0 auto', padding: '0 24px' } }, |
| 467 |
// Section heading |
| 468 |
(a.showSectionHeading || a.showSectionSubtext || a.showToggle) && el('div', { |
| 469 |
style: { textAlign: 'center', marginBottom: 40 } |
| 470 |
}, |
| 471 |
a.showSectionHeading && el(a.headingTag || 'h2', { |
| 472 |
style: { color: a.headingColor, margin: '0 0 12px' } |
| 473 |
}, a.sectionHeading), |
| 474 |
a.showSectionSubtext && el('p', { |
| 475 |
style: { color: a.subtextColor, margin: '0 0 24px' } |
| 476 |
}, a.sectionSubtext), |
| 477 |
// Toggle |
| 478 |
a.showToggle && el('div', { |
| 479 |
style: { display: 'inline-flex', alignItems: 'center', gap: 12, background: a.toggleBg, borderRadius: 999, padding: '4px 6px' } |
| 480 |
}, |
| 481 |
el('button', { |
| 482 |
onClick: function () { setIsYearly(false); }, |
| 483 |
style: { |
| 484 |
padding: '8px 20px', borderRadius: 999, border: 'none', cursor: 'pointer', fontWeight: 600, fontSize: 14, |
| 485 |
background: !isYearly ? a.toggleActiveBg : 'transparent', |
| 486 |
color: !isYearly ? a.toggleActiveColor : a.toggleInactiveColor, |
| 487 |
transition: 'all 0.2s', |
| 488 |
} |
| 489 |
}, a.toggleLabelMonthly), |
| 490 |
el('button', { |
| 491 |
onClick: function () { setIsYearly(true); }, |
| 492 |
style: { |
| 493 |
padding: '8px 20px', borderRadius: 999, border: 'none', cursor: 'pointer', fontWeight: 600, fontSize: 14, |
| 494 |
background: isYearly ? a.toggleActiveBg : 'transparent', |
| 495 |
color: isYearly ? a.toggleActiveColor : a.toggleInactiveColor, |
| 496 |
display: 'flex', alignItems: 'center', gap: 6, transition: 'all 0.2s', |
| 497 |
} |
| 498 |
}, a.toggleLabelYearly, |
| 499 |
a.showSavingsBadge && el('span', { |
| 500 |
style: { fontSize: 11, fontWeight: 700, padding: '2px 8px', borderRadius: 999, background: a.savingsBadgeBg, color: a.savingsBadgeColor } |
| 501 |
}, a.savingsBadge) |
| 502 |
) |
| 503 |
) |
| 504 |
), |
| 505 |
|
| 506 |
// Plans grid |
| 507 |
el('div', { |
| 508 |
style: { |
| 509 |
display: 'grid', |
| 510 |
gridTemplateColumns: 'repeat(' + Math.min(a.columns, a.plans.length) + ', 1fr)', |
| 511 |
gap: a.gap + 'px', |
| 512 |
} |
| 513 |
}, |
| 514 |
a.plans.map(function (plan, i) { return renderPlan(plan, i); }) |
| 515 |
), |
| 516 |
|
| 517 |
// Info note |
| 518 |
el('p', { style: { textAlign: 'center', fontSize: 12, color: '#9ca3af', marginTop: 16 } }, |
| 519 |
'💡 Click a plan to edit it in the sidebar. Toggle above switches price preview.' |
| 520 |
) |
| 521 |
) |
| 522 |
) |
| 523 |
); |
| 524 |
}, |
| 525 |
|
| 526 |
save: function (props) { |
| 527 |
return el('div', useBlockProps.save(), |
| 528 |
el('div', { className: 'bkbg-ps-app', 'data-opts': JSON.stringify(props.attributes) }) |
| 529 |
); |
| 530 |
} |
| 531 |
}); |
| 532 |
}() ); |
| 533 |
|