PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.11
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.11
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 / split-form / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.11, at blocks/split-form/index.js

250 lines 21.0 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 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 Fragment = wp.element.Fragment;
19
20 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
21 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
22 var IP = function () { return window.bkbgIconPicker; };
23
24 var RATIO_MAP = { '50-50': [50, 50], '55-45': [55, 45], '45-55': [45, 55], '60-40': [60, 40], '40-60': [40, 60] };
25
26 registerBlockType('blockenberg/split-form', {
27 edit: function (props) {
28 var attr = props.attributes;
29 var set = props.setAttributes;
30 var bullets = attr.bullets || [];
31 var submitted = useState(false);
32 var isSubmitted = submitted[0];
33 var setSubmitted = submitted[1];
34
35 function updateBullet(idx, val) {
36 var updated = bullets.map(function (b, i) { return i === idx ? { text: val } : b; });
37 set({ bullets: updated });
38 }
39 function addBullet() { set({ bullets: bullets.concat([{ text: 'New benefit' }]) }); }
40 function removeBullet(idx) { set({ bullets: bullets.filter(function (_, i) { return i !== idx; }) }); }
41
42 var inspector = el(InspectorControls, {},
43 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true },
44 el(SelectControl, {
45 label: __('Content Side', 'blockenberg'), value: attr.contentSide,
46 options: [{ label: 'Left', value: 'left' }, { label: 'Right', value: 'right' }],
47 onChange: function (v) { set({ contentSide: v }); }, __nextHasNoMarginBottom: true
48 }),
49 el(SelectControl, {
50 label: __('Split Ratio', 'blockenberg'), value: attr.splitRatio,
51 options: [
52 { label: '50 / 50', value: '50-50' },
53 { label: '55 / 45', value: '55-45' },
54 { label: '45 / 55', value: '45-55' },
55 { label: '60 / 40', value: '60-40' },
56 { label: '40 / 60', value: '40-60' }
57 ],
58 onChange: function (v) { set({ splitRatio: v }); }, __nextHasNoMarginBottom: true
59 }),
60 el(RangeControl, { label: __('Border Radius (px)', 'blockenberg'), value: attr.borderRadius, min: 0, max: 32, onChange: function (v) { set({ borderRadius: v }); }, __nextHasNoMarginBottom: true }),
61 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: attr.paddingTop, min: 0, max: 240, onChange: function (v) { set({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
62 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 240, onChange: function (v) { set({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
63 ),
64 el(PanelBody, { title: __('Content Panel', 'blockenberg'), initialOpen: true },
65 el(ToggleControl, { label: __('Use Image instead of colour', 'blockenberg'), checked: attr.useImage, onChange: function (v) { set({ useImage: v }); }, __nextHasNoMarginBottom: true }),
66 attr.useImage && el(MediaUploadCheck, {},
67 el(MediaUpload, {
68 onSelect: function (m) { set({ imageUrl: m.url, imageId: m.id, imageAlt: m.alt || '' }); },
69 allowedTypes: ['image'], value: attr.imageId,
70 render: function (ref) {
71 return el(Fragment, {},
72 attr.imageUrl && el('img', { src: attr.imageUrl, style: { width: '100%', borderRadius: '6px', marginBottom: '8px' } }),
73 el(Button, { onClick: ref.open, variant: 'secondary', isSmall: true }, attr.imageUrl ? __('Replace Image', 'blockenberg') : __('Upload Image', 'blockenberg'))
74 );
75 }
76 })
77 ),
78 attr.useImage && el(ToggleControl, { label: __('Dark overlay on image', 'blockenberg'), checked: attr.imageOverlay, onChange: function (v) { set({ imageOverlay: v }); }, __nextHasNoMarginBottom: true }),
79 el(ToggleControl, { label: __('Show Icon', 'blockenberg'), checked: attr.showIcon, onChange: function (v) { set({ showIcon: v }); }, __nextHasNoMarginBottom: true }),
80 attr.showIcon && el(IP().IconPickerControl, IP().iconPickerProps(attr, set, { charAttr: 'icon', typeAttr: 'iconType', dashiconAttr: 'iconDashicon', imageUrlAttr: 'iconImageUrl' })),
81 el(ToggleControl, { label: __('Show Eyebrow', 'blockenberg'), checked: attr.showEyebrow, onChange: function (v) { set({ showEyebrow: v }); }, __nextHasNoMarginBottom: true }),
82 el(ToggleControl, { label: __('Show Bullet List', 'blockenberg'), checked: attr.showBullets, onChange: function (v) { set({ showBullets: v }); }, __nextHasNoMarginBottom: true }),
83 attr.showBullets && el(IP().IconPickerControl, IP().iconPickerProps(attr, set, { charAttr: 'bulletIcon', typeAttr: 'bulletIconType', dashiconAttr: 'bulletIconDashicon', imageUrlAttr: 'bulletIconImageUrl', colorAttr: 'bulletIconDashiconColor' })),
84 attr.showBullets && el('div', {},
85 bullets.map(function (b, idx) {
86 return el('div', { key: idx, style: { display: 'flex', gap: '6px', marginBottom: '6px', alignItems: 'center' } },
87 el(TextControl, { value: b.text, onChange: function (v) { updateBullet(idx, v); }, style: { flex: 1 }, __nextHasNoMarginBottom: true }),
88 el(Button, { onClick: function () { removeBullet(idx); }, variant: 'link', isDestructive: true, isSmall: true }, '')
89 );
90 }),
91 el(Button, { onClick: addBullet, variant: 'secondary', isSmall: true }, __('+ Add Bullet', 'blockenberg'))
92 )
93 ),
94 el(PanelBody, { title: __('Form Panel', 'blockenberg'), initialOpen: true },
95 el(ToggleControl, { label: __('Show Form Title', 'blockenberg'), checked: attr.showFormTitle, onChange: function (v) { set({ showFormTitle: v }); }, __nextHasNoMarginBottom: true }),
96 el(TextControl, { label: __('Form Title', 'blockenberg'), value: attr.formTitle, onChange: function (v) { set({ formTitle: v }); }, __nextHasNoMarginBottom: true }),
97 el(TextControl, { label: __('Form Sub-text', 'blockenberg'), value: attr.formSubtext, onChange: function (v) { set({ formSubtext: v }); }, __nextHasNoMarginBottom: true }),
98 el(ToggleControl, { label: __('Name Field', 'blockenberg'), checked: attr.showName, onChange: function (v) { set({ showName: v }); }, __nextHasNoMarginBottom: true }),
99 attr.showName && el(TextControl, { label: __('Name Placeholder', 'blockenberg'), value: attr.namePlaceholder, onChange: function (v) { set({ namePlaceholder: v }); }, __nextHasNoMarginBottom: true }),
100 el(TextControl, { label: __('Email Placeholder', 'blockenberg'), value: attr.emailPlaceholder, onChange: function (v) { set({ emailPlaceholder: v }); }, __nextHasNoMarginBottom: true }),
101 el(ToggleControl, { label: __('Phone Field', 'blockenberg'), checked: attr.showPhone, onChange: function (v) { set({ showPhone: v }); }, __nextHasNoMarginBottom: true }),
102 attr.showPhone && el(TextControl, { label: __('Phone Placeholder', 'blockenberg'), value: attr.phonePlaceholder, onChange: function (v) { set({ phonePlaceholder: v }); }, __nextHasNoMarginBottom: true }),
103 el(TextControl, { label: __('Submit Label', 'blockenberg'), value: attr.submitLabel, onChange: function (v) { set({ submitLabel: v }); }, __nextHasNoMarginBottom: true }),
104 el(TextControl, { label: __('Form Action URL', 'blockenberg'), value: attr.formAction, onChange: function (v) { set({ formAction: v }); }, placeholder: 'https://', __nextHasNoMarginBottom: true }),
105 el(SelectControl, {
106 label: __('Method', 'blockenberg'), value: attr.formMethod,
107 options: [{ label: 'POST', value: 'post' }, { label: 'GET', value: 'get' }],
108 onChange: function (v) { set({ formMethod: v }); }, __nextHasNoMarginBottom: true
109 }),
110 el(ToggleControl, { label: __('Show Privacy Note', 'blockenberg'), checked: attr.showPrivacy, onChange: function (v) { set({ showPrivacy: v }); }, __nextHasNoMarginBottom: true }),
111 attr.showPrivacy && el(TextControl, { label: __('Privacy Note', 'blockenberg'), value: attr.privacyNote, onChange: function (v) { set({ privacyNote: v }); }, __nextHasNoMarginBottom: true }),
112 el(TextControl, { label: __('Success Message', 'blockenberg'), value: attr.successMsg, onChange: function (v) { set({ successMsg: v }); }, __nextHasNoMarginBottom: true }),
113 el(RangeControl, { label: __('Input Border Radius (px)', 'blockenberg'), value: attr.inputRadius, min: 0, max: 24, onChange: function (v) { set({ inputRadius: v }); }, __nextHasNoMarginBottom: true }),
114 el(RangeControl, { label: __('Button Border Radius (px)', 'blockenberg'), value: attr.btnRadius, min: 0, max: 24, onChange: function (v) { set({ btnRadius: v }); }, __nextHasNoMarginBottom: true })
115 ),
116 el(PanelColorSettings, {
117 title: __('Colors', 'blockenberg'), initialOpen: false,
118 colorSettings: [
119 { value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#1e1b4b' }); }, label: __('Outer Background', 'blockenberg') },
120 { value: attr.contentBg, onChange: function (v) { set({ contentBg: v || '' }); }, label: __('Content Panel BG', 'blockenberg') },
121 { value: attr.formBg, onChange: function (v) { set({ formBg: v || '#ffffff' }); }, label: __('Form Panel BG', 'blockenberg') },
122 { value: attr.eyebrowColor, onChange: function (v) { set({ eyebrowColor: v || '#a5b4fc' }); }, label: __('Eyebrow', 'blockenberg') },
123 { value: attr.headingColor, onChange: function (v) { set({ headingColor: v || '#ffffff' }); }, label: __('Content Heading', 'blockenberg') },
124 { value: attr.subtextColor, onChange: function (v) { set({ subtextColor: v || '#c7d2fe' }); }, label: __('Content Text', 'blockenberg') },
125 { value: attr.bulletColor, onChange: function (v) { set({ bulletColor: v || '#c7d2fe' }); }, label: __('Bullet Text', 'blockenberg') },
126 { value: attr.bulletIconColor,onChange: function (v) { set({ bulletIconColor: v || '#818cf8' }); }, label: __('Bullet Icon', 'blockenberg') },
127 { value: attr.formHeadingColor,onChange: function (v) { set({ formHeadingColor: v || '#111827' }); }, label: __('Form Heading', 'blockenberg') },
128 { value: attr.inputBg, onChange: function (v) { set({ inputBg: v || '#f9fafb' }); }, label: __('Input BG', 'blockenberg') },
129 { value: attr.inputBorder, onChange: function (v) { set({ inputBorder: v || '#d1d5db' }); }, label: __('Input Border', 'blockenberg') },
130 { value: attr.inputColor, onChange: function (v) { set({ inputColor: v || '#111827' }); }, label: __('Input Text', 'blockenberg') },
131 { value: attr.btnBg, onChange: function (v) { set({ btnBg: v || '#6366f1' }); }, label: __('Submit Button BG', 'blockenberg') },
132 { value: attr.btnColor, onChange: function (v) { set({ btnColor: v || '#ffffff' }); }, label: __('Submit Button Text', 'blockenberg') },
133 { value: attr.privacyColor, onChange: function (v) { set({ privacyColor: v || '#9ca3af' }); }, label: __('Privacy Note', 'blockenberg') }
134 ]
135 }),
136 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
137 getTypoControl() ? el(getTypoControl(), { label: __('Heading Typography', 'blockenberg'), value: attr.headingTypo || {}, onChange: function (v) { set({ headingTypo: v }); } }) : null,
138 getTypoControl() ? el(getTypoControl(), { label: __('Eyebrow Typography', 'blockenberg'), value: attr.eyebrowTypo || {}, onChange: function (v) { set({ eyebrowTypo: v }); } }) : null,
139 getTypoControl() ? el(getTypoControl(), { label: __('Subtext Typography', 'blockenberg'), value: attr.subtextTypo || {}, onChange: function (v) { set({ subtextTypo: v }); } }) : null,
140 getTypoControl() ? el(getTypoControl(), { label: __('Form Title Typography', 'blockenberg'), value: attr.formTitleTypo || {}, onChange: function (v) { set({ formTitleTypo: v }); } }) : null,
141 getTypoControl() ? el(getTypoControl(), { label: __('Bullet Typography', 'blockenberg'), value: attr.bulletTypo || {}, onChange: function (v) { set({ bulletTypo: v }); } }) : null
142 )
143 );
144
145 var ratio = RATIO_MAP[attr.splitRatio] || [50, 50];
146 var contentFlex = attr.contentSide === 'left' ? ratio[0] : ratio[1];
147 var formFlex = attr.contentSide === 'left' ? ratio[1] : ratio[0];
148
149 /* Input style */
150 var inputStyle = { display: 'block', width: '100%', padding: '12px 14px', border: '1px solid ' + attr.inputBorder, borderRadius: attr.inputRadius + 'px', background: attr.inputBg, color: attr.inputColor, fontSize: '15px', boxSizing: 'border-box', marginBottom: '12px' };
151
152 /* Content panel */
153 var contentPanelStyle = {
154 flex: contentFlex,
155 background: attr.contentBg || 'transparent',
156 padding: '40px',
157 display: 'flex', flexDirection: 'column', justifyContent: 'center',
158 position: 'relative', overflow: 'hidden'
159 };
160 if (attr.useImage && attr.imageUrl) {
161 contentPanelStyle.backgroundImage = 'url(' + attr.imageUrl + ')';
162 contentPanelStyle.backgroundSize = 'cover';
163 contentPanelStyle.backgroundPosition = 'center';
164 }
165
166 var contentPanel = el('div', { className: 'bkbg-sf-content', style: contentPanelStyle },
167 attr.useImage && attr.imageUrl && attr.imageOverlay && el('div', { style: { position: 'absolute', inset: 0, background: 'rgba(0,0,0,.45)' } }),
168 el('div', { style: { position: 'relative', zIndex: 1 } },
169 attr.showIcon && el('div', { style: { fontSize: '40px', marginBottom: '16px' } }, (attr.iconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(attr.iconType, attr.icon, attr.iconDashicon, attr.iconImageUrl, attr.iconDashiconColor) : attr.icon),
170 attr.showEyebrow && el(RichText, {
171 tagName: 'p', className: 'bkbg-sf-eyebrow', value: attr.eyebrow, onChange: function (v) { set({ eyebrow: v }); },
172 placeholder: __('Eyebrow…', 'blockenberg'),
173 style: { color: attr.eyebrowColor, margin: '0 0 8px' }
174 }),
175 el(RichText, {
176 tagName: 'h2', className: 'bkbg-sf-heading', value: attr.heading, onChange: function (v) { set({ heading: v }); },
177 placeholder: __('Heading…', 'blockenberg'),
178 style: { color: attr.headingColor, margin: '0 0 14px' }
179 }),
180 el(RichText, {
181 tagName: 'p', className: 'bkbg-sf-text', value: attr.subtext, onChange: function (v) { set({ subtext: v }); },
182 placeholder: __('Subtext…', 'blockenberg'),
183 style: { color: attr.subtextColor, margin: attr.showBullets ? '0 0 20px' : '0' }
184 }),
185 attr.showBullets && el('ul', { style: { listStyle: 'none', margin: 0, padding: 0 } },
186 bullets.map(function (b, idx) {
187 return el('li', { key: idx, className: 'bkbg-sf-bullet', style: { color: attr.bulletColor } },
188 el('span', { style: { color: attr.bulletIconColor, fontWeight: '700', flexShrink: 0 } }, (attr.bulletIconType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(attr.bulletIconType, attr.bulletIcon, attr.bulletIconDashicon, attr.bulletIconImageUrl, attr.bulletIconDashiconColor) : attr.bulletIcon),
189 b.text
190 );
191 })
192 )
193 )
194 );
195
196 /* Form panel */
197 var formPanel = el('div', { className: 'bkbg-sf-form-panel', style: { flex: formFlex, background: attr.formBg, padding: '40px', display: 'flex', flexDirection: 'column', justifyContent: 'center' } },
198 attr.showFormTitle && el('h3', { className: 'bkbg-sf-form-title', style: { color: attr.formHeadingColor, margin: '0 0 8px' } }, attr.formTitle),
199 attr.formSubtext && el('p', { style: { color: attr.formHeadingColor, fontSize: '14px', margin: '0 0 20px', opacity: 0.7 } }, attr.formSubtext),
200 attr.showName && el('input', { type: 'text', placeholder: attr.namePlaceholder, style: inputStyle, readOnly: true }),
201 el('input', { type: 'email', placeholder: attr.emailPlaceholder, style: inputStyle, readOnly: true }),
202 attr.showPhone && el('input', { type: 'tel', placeholder: attr.phonePlaceholder, style: inputStyle, readOnly: true }),
203 el('button', { type: 'button', className: 'bkbg-sf-submit', style: { width: '100%', padding: '14px', background: attr.btnBg, color: attr.btnColor, border: 'none', borderRadius: attr.btnRadius + 'px', cursor: 'pointer', marginBottom: '12px' } }, attr.submitLabel),
204 attr.showPrivacy && el('p', { style: { color: attr.privacyColor, fontSize: '12px', margin: 0, textAlign: 'center' } }, attr.privacyNote)
205 );
206
207 var panels = attr.contentSide === 'left' ? [contentPanel, formPanel] : [formPanel, contentPanel];
208
209 return el(Fragment, {},
210 inspector,
211 el('div', useBlockProps({ className: 'bkbg-sf-section', style: (function () {
212 var s = {
213 background: attr.bgColor,
214 paddingTop: attr.paddingTop + 'px',
215 paddingBottom: attr.paddingBottom + 'px',
216 borderRadius: attr.borderRadius + 'px',
217 overflow: 'hidden',
218 '--bksf-eb-sz': attr.eyebrowFontSize + 'px',
219 '--bksf-eb-w': attr.eyebrowFontWeight,
220 '--bksf-hd-sz': attr.headingFontSize + 'px',
221 '--bksf-hd-w': attr.headingFontWeight,
222 '--bksf-st-sz': attr.subtextFontSize + 'px',
223 '--bksf-ft-sz': attr.formTitleFontSize + 'px',
224 '--bksf-ft-w': attr.formTitleFontWeight,
225 };
226 var tv = getTypoCssVars();
227 if (tv) {
228 Object.assign(s, tv(attr.headingTypo, '--bksf-hd-'));
229 Object.assign(s, tv(attr.eyebrowTypo, '--bksf-eb-'));
230 Object.assign(s, tv(attr.subtextTypo, '--bksf-st-'));
231 Object.assign(s, tv(attr.formTitleTypo, '--bksf-ft-'));
232 Object.assign(s, tv(attr.bulletTypo, '--bksf-bl-'));
233 }
234 return s;
235 })() }),
236 el('div', { style: { display: 'flex', alignItems: 'stretch' } }, panels)
237 )
238 );
239 },
240
241 save: function (props) {
242 var el2 = wp.element.createElement;
243 var ubp = wp.blockEditor.useBlockProps;
244 return el2('div', ubp.save(),
245 el2('div', { className: 'bkbg-sf-app', 'data-opts': JSON.stringify(props.attributes) })
246 );
247 }
248 });
249 }() );
250