PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / onboarding-steps / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/onboarding-steps/index.js

206 lines 15.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 TextareaControl = wp.components.TextareaControl;
15 var Button = wp.components.Button;
16
17 var _tc, _tv;
18 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
19 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
20 var IP = function () { return window.bkbgIconPicker; };
21
22 registerBlockType('blockenberg/onboarding-steps', {
23 edit: function (props) {
24 var attr = props.attributes;
25 var setAttr = props.setAttributes;
26
27 function updateStep(idx, key, val) {
28 var steps = (attr.steps || []).map(function (s, i) {
29 return i === idx ? Object.assign({}, s, {[key]: val}) : s;
30 });
31 setAttr({ steps: steps });
32 }
33
34 var inspector = el(InspectorControls, null,
35 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true },
36 el(SelectControl, {
37 __nextHasNoMarginBottom: true,
38 label: __('Layout', 'blockenberg'),
39 value: attr.layout,
40 options: [
41 { label: 'Horizontal (side by side)', value: 'horizontal' },
42 { label: 'Vertical (stacked)', value: 'vertical' },
43 { label: 'Cards Grid', value: 'cards' },
44 { label: 'Numbered List', value: 'numbered' }
45 ],
46 onChange: function (v) { setAttr({ layout: v }); }
47 }),
48 el(SelectControl, {
49 __nextHasNoMarginBottom: true,
50 label: __('Connector Style', 'blockenberg'),
51 value: attr.connectorStyle,
52 options: [
53 { label: 'Line', value: 'line' },
54 { label: 'Dots', value: 'dots' },
55 { label: 'None', value: 'none' }
56 ],
57 onChange: function (v) { setAttr({ connectorStyle: v }); }
58 }),
59 el(ToggleControl, {
60 __nextHasNoMarginBottom: true,
61 label: __('Show Step Numbers', 'blockenberg'),
62 checked: attr.showNumbers,
63 onChange: function (v) { setAttr({ showNumbers: v }); }
64 }),
65 el(ToggleControl, {
66 __nextHasNoMarginBottom: true,
67 label: __('Show Step Icons', 'blockenberg'),
68 checked: attr.showIcons,
69 onChange: function (v) { setAttr({ showIcons: v }); }
70 }),
71 el(ToggleControl, {
72 __nextHasNoMarginBottom: true,
73 label: __('Show Per-Step CTAs', 'blockenberg'),
74 checked: attr.showStepCtas,
75 onChange: function (v) { setAttr({ showStepCtas: v }); }
76 }),
77 el(RangeControl, {
78 __nextHasNoMarginBottom: true,
79 label: __('Max Width (px)', 'blockenberg'),
80 value: attr.maxWidth, min: 600, max: 1400,
81 onChange: function (v) { setAttr({ maxWidth: v }); }
82 }),
83 el(RangeControl, {
84 __nextHasNoMarginBottom: true,
85 label: __('Padding Top (px)', 'blockenberg'),
86 value: attr.paddingTop, min: 0, max: 200,
87 onChange: function (v) { setAttr({ paddingTop: v }); }
88 }),
89 el(RangeControl, {
90 __nextHasNoMarginBottom: true,
91 label: __('Padding Bottom (px)', 'blockenberg'),
92 value: attr.paddingBottom, min: 0, max: 200,
93 onChange: function (v) { setAttr({ paddingBottom: v }); }
94 })
95 ),
96 el(PanelBody, { title: __('Main CTA', 'blockenberg'), initialOpen: false },
97 el(ToggleControl, {
98 __nextHasNoMarginBottom: true,
99 label: __('Show Main CTA Button', 'blockenberg'),
100 checked: attr.showMainCta,
101 onChange: function (v) { setAttr({ showMainCta: v }); }
102 }),
103 attr.showMainCta && el(TextControl, { __nextHasNoMarginBottom: true, label: __('CTA Label', 'blockenberg'), value: attr.mainCtaLabel, onChange: function (v) { setAttr({ mainCtaLabel: v }); } }),
104 attr.showMainCta && el(TextControl, { __nextHasNoMarginBottom: true, label: __('CTA URL', 'blockenberg'), value: attr.mainCtaUrl, onChange: function (v) { setAttr({ mainCtaUrl: v }); } })
105 ),
106 el(PanelBody, { title: __('Steps', 'blockenberg'), initialOpen: false },
107 (attr.steps || []).map(function (step, idx) {
108 return el(PanelBody, { key: idx, title: (step.number + '. ' + step.title), initialOpen: false },
109 el(TextControl, { __nextHasNoMarginBottom: true, label: __('Number', 'blockenberg'), value: step.number, onChange: function (v) { updateStep(idx, 'number', v); } }),
110 el(IP().IconPickerControl, { iconType: step.iconType || 'custom-char', customChar: step.icon || '', dashicon: step.iconDashicon || '', imageUrl: step.iconImageUrl || '', onChangeType: function (v) { updateStep(idx, 'iconType', v); }, onChangeChar: function (v) { updateStep(idx, 'icon', v); }, onChangeDashicon: function (v) { updateStep(idx, 'iconDashicon', v); }, onChangeImageUrl: function (v) { updateStep(idx, 'iconImageUrl', v); } }),
111 el(TextControl, { __nextHasNoMarginBottom: true, label: __('Title', 'blockenberg'), value: step.title, onChange: function (v) { updateStep(idx, 'title', v); } }),
112 el(TextareaControl, { __nextHasNoMarginBottom: true, label: __('Description', 'blockenberg'), value: step.description, onChange: function (v) { updateStep(idx, 'description', v); } }),
113 el(TextControl, { __nextHasNoMarginBottom: true, label: __('CTA Label (optional)', 'blockenberg'), value: step.ctaLabel, onChange: function (v) { updateStep(idx, 'ctaLabel', v); } }),
114 el(TextControl, { __nextHasNoMarginBottom: true, label: __('CTA URL', 'blockenberg'), value: step.ctaUrl, onChange: function (v) { updateStep(idx, 'ctaUrl', v); } }),
115 el(Button, { isDestructive: true, variant: 'secondary', onClick: function () { setAttr({ steps: (attr.steps || []).filter(function (_, i) { return i !== idx; }) }); } }, __('Remove Step', 'blockenberg'))
116 );
117 }),
118 el(Button, { isPrimary: true, variant: 'primary', onClick: function () {
119 var n = (attr.steps || []).length + 1;
120 setAttr({ steps: (attr.steps || []).concat([{ number: String(n).padStart(2, '0'), icon: '', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', title: 'Step ' + n, description: 'Step description goes here.', ctaLabel: '', ctaUrl: '' }]) });
121 }}, __('+ Add Step', 'blockenberg'))
122 ),
123 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
124 TypoCtrl && el(TypoCtrl, { label: __('Heading', 'blockenberg'), value: attr.headingTypo, onChange: function (v) { setAttr({ headingTypo: v }); } }),
125 TypoCtrl && el(TypoCtrl, { label: __('Subtext', 'blockenberg'), value: attr.subtextTypo, onChange: function (v) { setAttr({ subtextTypo: v }); } }),
126 TypoCtrl && el(TypoCtrl, { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowTypo, onChange: function (v) { setAttr({ eyebrowTypo: v }); } }),
127 TypoCtrl && el(TypoCtrl, { label: __('Step Title', 'blockenberg'), value: attr.stepTitleTypo, onChange: function (v) { setAttr({ stepTitleTypo: v }); } }),
128 TypoCtrl && el(TypoCtrl, { label: __('Step Description', 'blockenberg'), value: attr.stepDescTypo, onChange: function (v) { setAttr({ stepDescTypo: v }); } })
129 ),
130 el(PanelColorSettings, {
131 title: __('Colors', 'blockenberg'),
132 initialOpen: false,
133 colorSettings: [
134 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); } },
135 { label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); } },
136 { label: __('Subtext', 'blockenberg'), value: attr.subColor, onChange: function (v) { setAttr({ subColor: v || '#6b7280' }); } },
137 { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowColor, onChange: function (v) { setAttr({ eyebrowColor: v || '#6366f1' }); } },
138 { label: __('Step Number BG', 'blockenberg'), value: attr.stepNumBg, onChange: function (v) { setAttr({ stepNumBg: v || '#6366f1' }); } },
139 { label: __('Step Number Text', 'blockenberg'), value: attr.stepNumColor, onChange: function (v) { setAttr({ stepNumColor: v || '#ffffff' }); } },
140 { label: __('Step Title', 'blockenberg'), value: attr.stepTitleColor, onChange: function (v) { setAttr({ stepTitleColor: v || '#111827' }); } },
141 { label: __('Step Description', 'blockenberg'), value: attr.stepDescColor, onChange: function (v) { setAttr({ stepDescColor: v || '#6b7280' }); } },
142 { label: __('Connector', 'blockenberg'), value: attr.connectorColor, onChange: function (v) { setAttr({ connectorColor: v || '#e5e7eb' }); } },
143 { label: __('Card Background', 'blockenberg'), value: attr.cardBg, onChange: function (v) { setAttr({ cardBg: v || '#f9fafb' }); } },
144 { label: __('CTA BG', 'blockenberg'), value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#6366f1' }); } },
145 { label: __('CTA Text', 'blockenberg'), value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#ffffff' }); } }
146 ]
147 })
148 );
149
150 var TypoCtrl = getTypoControl();
151 var blockProps = (function () {
152 var bp = useBlockProps({ className: 'bkbg-obs-wrap bkbg-obs-editor' });
153 var _tvf = getTypoCssVars();
154 var s = {};
155 if (_tvf) {
156 Object.assign(s, _tvf(attr.headingTypo, '--bkbg-obs-hd-'));
157 Object.assign(s, _tvf(attr.subtextTypo, '--bkbg-obs-st-'));
158 Object.assign(s, _tvf(attr.eyebrowTypo, '--bkbg-obs-ey-'));
159 Object.assign(s, _tvf(attr.stepTitleTypo, '--bkbg-obs-stt-'));
160 Object.assign(s, _tvf(attr.stepDescTypo, '--bkbg-obs-sd-'));
161 }
162 if (Object.keys(s).length) bp.style = Object.assign(s, bp.style || {});
163 return bp;
164 }());
165 var colCount = (attr.steps || []).length || 3;
166 var isHoriz = attr.layout === 'horizontal';
167
168 return el('div', blockProps,
169 inspector,
170 el('div', { style: { background: attr.bgColor, padding: '40px', borderRadius: '8px', fontFamily: 'sans-serif' } },
171 el('div', { style: { textAlign: 'center', marginBottom: '48px' } },
172 el(RichText, { tagName: 'p', className: 'bkbg-obs-eyebrow', value: attr.eyebrow, onChange: function (v) { setAttr({ eyebrow: v }); }, placeholder: __('Eyebrow…', 'blockenberg'), style: { color: attr.eyebrowColor, margin: '0 0 8px' } }),
173 el(RichText, { tagName: 'h2', className: 'bkbg-obs-heading', value: attr.heading, onChange: function (v) { setAttr({ heading: v }); }, placeholder: __('Heading…', 'blockenberg'), style: { color: attr.headingColor, margin: '0 0 12px' } }),
174 el(RichText, { tagName: 'p', className: 'bkbg-obs-sub', value: attr.subtext, onChange: function (v) { setAttr({ subtext: v }); }, placeholder: __('Subtext…', 'blockenberg'), style: { color: attr.subColor, maxWidth: '600px', margin: '0 auto' } })
175 ),
176 el('div', { style: { display: isHoriz ? 'grid' : 'block', gridTemplateColumns: isHoriz ? ('repeat(' + colCount + ',1fr)') : undefined, gap: '24px', position: 'relative' } },
177 (attr.steps || []).map(function (step, i) {
178 return el('div', { key: i, style: { background: attr.cardBg, borderRadius: '12px', padding: '28px 24px', textAlign: isHoriz ? 'center' : 'left', marginBottom: isHoriz ? 0 : '24px', display: !isHoriz ? 'flex' : 'block', alignItems: 'flex-start', gap: '16px' } },
179 el('div', { style: { display: 'flex', alignItems: 'center', justifyContent: isHoriz ? 'center' : 'flex-start', gap: '12px', marginBottom: '12px' } },
180 attr.showNumbers && el('span', { style: { background: attr.stepNumBg, color: attr.stepNumColor, borderRadius: '50%', width: '40px', height: '40px', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontWeight: 800, fontSize: '14px', flexShrink: 0 } }, step.number),
181 attr.showIcons && el('span', { style: { fontSize: '28px' } }, (step.iconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(step.iconType, step.icon, step.iconDashicon, step.iconImageUrl, step.iconDashiconColor) : step.icon)
182 ),
183 el('div', null,
184 el('div', { className: 'bkbg-obs-step-title', style: { color: attr.stepTitleColor, marginBottom: '8px' } }, step.title),
185 el('div', { className: 'bkbg-obs-step-desc', style: { color: attr.stepDescColor } }, step.description)
186 )
187 );
188 })
189 ),
190 attr.showMainCta && el('div', { style: { textAlign: 'center', marginTop: '40px' } },
191 el('a', { href: attr.mainCtaUrl, style: { display: 'inline-block', background: attr.ctaBg, color: attr.ctaColor, padding: '14px 36px', borderRadius: '8px', fontWeight: 700, textDecoration: 'none', fontSize: '16px' } }, attr.mainCtaLabel)
192 )
193 )
194 );
195 },
196
197 save: function (props) {
198 var attr = props.attributes;
199 var useBlockProps = wp.blockEditor.useBlockProps;
200 return el('div', useBlockProps.save(),
201 el('div', { className: 'bkbg-obs-app', 'data-opts': JSON.stringify(attr) })
202 );
203 }
204 });
205 }() );
206