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 / phone-button / index.js

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

331 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 useBlockProps = wp.blockEditor.useBlockProps;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
8 var PanelBody = wp.components.PanelBody;
9 var TextControl = wp.components.TextControl;
10 var TextareaControl = wp.components.TextareaControl;
11 var SelectControl = wp.components.SelectControl;
12 var RangeControl = wp.components.RangeControl;
13 var ToggleControl = wp.components.ToggleControl;
14
15 var _tcCache, _tvCache;
16 function getTypoControl() { return _tcCache || (_tcCache = window.bkbgTypographyControl); }
17 function getTypoCssVars() { return _tvCache || (_tvCache = window.bkbgTypoCssVars); }
18
19 var MODE_ICON = { phone: '📞', whatsapp: '💬', both: '📞💬' };
20
21 registerBlockType('blockenberg/phone-button', {
22 title: __('Phone Button'),
23 icon: 'phone',
24 category: 'bkbg-marketing',
25
26 edit: function (props) {
27 var attr = props.attributes;
28 var setAttr = props.setAttributes;
29 var blockProps = useBlockProps((function () {
30 var _tv = getTypoCssVars();
31 var s = {};
32 Object.assign(s, _tv(attr.labelTypo, '--bkbg-phb-lb-'));
33 return { className: 'bkbg-phb-editor-wrap', style: s };
34 })());
35
36 var showPhone = attr.mode !== 'whatsapp';
37 var showWhatsapp = attr.mode !== 'phone';
38 var isFloating = attr.layout === 'floating';
39
40 /* ── Editor preview ──────────────────────────────────────── */
41 var preview = el('div', {
42 className: 'bkbg-phb-preview',
43 style: {
44 display: 'flex',
45 flexDirection: 'column',
46 alignItems: 'center',
47 gap: '12px',
48 padding: '24px',
49 background: '#f1f5f9',
50 borderRadius: '12px'
51 }
52 },
53 el('div', {
54 style: {
55 fontSize: '13px',
56 color: '#64748b',
57 marginBottom: '6px',
58 fontWeight: 600
59 }
60 }, isFloating
61 ? __('Floating button — fixed position on frontend')
62 : __('Inline button — displayed in page flow')
63 ),
64 el('div', {
65 style: {
66 display: 'flex',
67 gap: attr.gap + 'px',
68 alignItems: 'center'
69 }
70 },
71 showPhone && el('a', {
72 href: 'tel:' + attr.phoneNumber,
73 className: 'bkbg-phb-btn bkbg-phb-phone',
74 style: {
75 display: 'flex',
76 alignItems: 'center',
77 justifyContent: 'center',
78 width: attr.buttonSize + 'px',
79 height: attr.buttonSize + 'px',
80 borderRadius: attr.borderRadius + 'px',
81 background: attr.phoneBg,
82 color: attr.phoneColor,
83 fontSize: attr.iconSize + 'px',
84 textDecoration: 'none',
85 boxShadow: '0 4px 18px rgba(0,0,0,0.18)'
86 }
87 }, '📞'),
88 showWhatsapp && el('a', {
89 href: '#',
90 className: 'bkbg-phb-btn bkbg-phb-whatsapp',
91 style: {
92 display: 'flex',
93 alignItems: 'center',
94 justifyContent: 'center',
95 width: attr.buttonSize + 'px',
96 height: attr.buttonSize + 'px',
97 borderRadius: attr.borderRadius + 'px',
98 background: attr.whatsappBg,
99 color: attr.whatsappColor,
100 fontSize: attr.iconSize + 'px',
101 textDecoration: 'none',
102 boxShadow: '0 4px 18px rgba(0,0,0,0.18)'
103 }
104 }, '💬')
105 ),
106 attr.showPulse && el('div', {
107 style: { fontSize: '12px', color: '#6366f1' }
108 }, __('✦ Pulse animation enabled'))
109 );
110
111 /* ── Inspector ───────────────────────────────────────────── */
112 var inspector = el(InspectorControls, {},
113 /* Contact Details */
114 el(PanelBody, { title: __('Contact Details'), initialOpen: true },
115 el(SelectControl, {
116 label: __('Mode'),
117 value: attr.mode,
118 options: [
119 { label: __('Phone only'), value: 'phone' },
120 { label: __('WhatsApp only'), value: 'whatsapp' },
121 { label: __('Both'), value: 'both' }
122 ],
123 onChange: function (v) { setAttr({ mode: v }); },
124 __nextHasNoMarginBottom: true
125 }),
126 (attr.mode !== 'whatsapp') && el(TextControl, {
127 label: __('Phone Number'),
128 value: attr.phoneNumber,
129 onChange: function (v) { setAttr({ phoneNumber: v }); },
130 __nextHasNoMarginBottom: true
131 }),
132 (attr.mode !== 'phone') && el(TextControl, {
133 label: __('WhatsApp Number (intl format)'),
134 value: attr.whatsappNumber,
135 onChange: function (v) { setAttr({ whatsappNumber: v }); },
136 __nextHasNoMarginBottom: true
137 }),
138 (attr.mode !== 'phone') && el(TextareaControl, {
139 label: __('WhatsApp Pre-filled Message'),
140 value: attr.whatsappMessage,
141 rows: 3,
142 onChange: function (v) { setAttr({ whatsappMessage: v }); },
143 __nextHasNoMarginBottom: true
144 })
145 ),
146
147 /* Layout */
148 el(PanelBody, { title: __('Layout'), initialOpen: false },
149 el(SelectControl, {
150 label: __('Layout'),
151 value: attr.layout,
152 options: [
153 { label: __('Floating (fixed)'), value: 'floating' },
154 { label: __('Inline'), value: 'inline' }
155 ],
156 onChange: function (v) { setAttr({ layout: v }); },
157 __nextHasNoMarginBottom: true
158 }),
159 attr.layout === 'floating' && el(SelectControl, {
160 label: __('Screen Position'),
161 value: attr.position,
162 options: [
163 { label: __('Bottom Right'), value: 'bottom-right' },
164 { label: __('Bottom Left'), value: 'bottom-left' },
165 { label: __('Bottom Center'), value: 'bottom-center' },
166 { label: __('Top Right'), value: 'top-right' },
167 { label: __('Top Left'), value: 'top-left' }
168 ],
169 onChange: function (v) { setAttr({ position: v }); },
170 __nextHasNoMarginBottom: true
171 }),
172 el(ToggleControl, {
173 label: __('Show Pulse Animation'),
174 checked: attr.showPulse,
175 onChange: function (v) { setAttr({ showPulse: v }); },
176 __nextHasNoMarginBottom: true
177 }),
178 el(ToggleControl, {
179 label: __('Show Button Label'),
180 checked: attr.showText,
181 onChange: function (v) { setAttr({ showText: v }); },
182 __nextHasNoMarginBottom: true
183 }),
184 attr.showText && el(TextControl, {
185 label: __('Label Text'),
186 value: attr.buttonText,
187 onChange: function (v) { setAttr({ buttonText: v }); },
188 __nextHasNoMarginBottom: true
189 }),
190 el(RangeControl, {
191 label: __('Button Size (px)'),
192 value: attr.buttonSize,
193 min: 36, max: 100,
194 onChange: function (v) { setAttr({ buttonSize: v }); },
195 __nextHasNoMarginBottom: true
196 }),
197 el(RangeControl, {
198 label: __('Icon Size (px)'),
199 value: attr.iconSize,
200 min: 14, max: 56,
201 onChange: function (v) { setAttr({ iconSize: v }); },
202 __nextHasNoMarginBottom: true
203 }),
204 el(RangeControl, {
205 label: __('Border Radius (px)'),
206 value: attr.borderRadius,
207 min: 0, max: 999,
208 onChange: function (v) { setAttr({ borderRadius: v }); },
209 __nextHasNoMarginBottom: true
210 }),
211 attr.mode === 'both' && el(RangeControl, {
212 label: __('Gap Between Buttons (px)'),
213 value: attr.gap,
214 min: 4, max: 40,
215 onChange: function (v) { setAttr({ gap: v }); },
216 __nextHasNoMarginBottom: true
217 }),
218 el(RangeControl, {
219 label: __('Shadow Strength (%)'),
220 value: attr.shadowStrength,
221 min: 0, max: 80,
222 onChange: function (v) { setAttr({ shadowStrength: v }); },
223 __nextHasNoMarginBottom: true
224 }),
225 attr.layout === 'floating' && el(RangeControl, {
226 label: __('Show After Scroll (px, 0 = always)'),
227 value: attr.scrollOffset,
228 min: 0, max: 1000, step: 10,
229 onChange: function (v) { setAttr({ scrollOffset: v }); },
230 __nextHasNoMarginBottom: true
231 })
232 ),
233
234 /* Typography */
235 el(PanelBody, { title: __('Typography'), initialOpen: false },
236 el(getTypoControl(), { label: __('Label'), value: attr.labelTypo, onChange: function(v) { setAttr({ labelTypo: v }); } })
237 ),
238
239 /* Colors */
240 el(PanelColorSettings, {
241 title: __('Colors'),
242 initialOpen: false,
243 colorSettings: [
244 {
245 label: __('Phone Button BG'),
246 value: attr.phoneBg,
247 onChange: function (v) { setAttr({ phoneBg: v || '#6366f1' }); }
248 },
249 {
250 label: __('Phone Button Icon'),
251 value: attr.phoneColor,
252 onChange: function (v) { setAttr({ phoneColor: v || '#ffffff' }); }
253 },
254 {
255 label: __('Phone Pulse Color'),
256 value: attr.phonePulseBg,
257 onChange: function (v) { setAttr({ phonePulseBg: v || '#6366f1' }); }
258 },
259 {
260 label: __('WhatsApp Button BG'),
261 value: attr.whatsappBg,
262 onChange: function (v) { setAttr({ whatsappBg: v || '#25d366' }); }
263 },
264 {
265 label: __('WhatsApp Button Icon'),
266 value: attr.whatsappColor,
267 onChange: function (v) { setAttr({ whatsappColor: v || '#ffffff' }); }
268 },
269 {
270 label: __('WhatsApp Pulse Color'),
271 value: attr.whatsappPulseBg,
272 onChange: function (v) { setAttr({ whatsappPulseBg: v || '#25d366' }); }
273 },
274 {
275 label: __('Label Background'),
276 value: attr.labelBg,
277 onChange: function (v) { setAttr({ labelBg: v || '#1e1b4b' }); }
278 },
279 {
280 label: __('Label Text Color'),
281 value: attr.labelColor,
282 onChange: function (v) { setAttr({ labelColor: v || '#ffffff' }); }
283 }
284 ]
285 })
286 );
287
288 return el(wp.element.Fragment, {}, inspector,
289 el('div', blockProps, preview)
290 );
291 },
292
293 save: function (props) {
294 var attr = props.attributes;
295 var blockProps = useBlockProps.save();
296 var opts = {
297 phoneNumber: attr.phoneNumber,
298 whatsappNumber: attr.whatsappNumber,
299 whatsappMessage: attr.whatsappMessage,
300 mode: attr.mode,
301 layout: attr.layout,
302 position: attr.position,
303 showPulse: attr.showPulse,
304 buttonText: attr.buttonText,
305 showText: attr.showText,
306 buttonSize: attr.buttonSize,
307 iconSize: attr.iconSize,
308 borderRadius: attr.borderRadius,
309 gap: attr.gap,
310 shadowStrength: attr.shadowStrength,
311 scrollOffset: attr.scrollOffset,
312 phoneBg: attr.phoneBg,
313 phoneColor: attr.phoneColor,
314 phonePulseBg: attr.phonePulseBg,
315 whatsappBg: attr.whatsappBg,
316 whatsappColor: attr.whatsappColor,
317 whatsappPulseBg: attr.whatsappPulseBg,
318 labelBg: attr.labelBg,
319 labelColor: attr.labelColor,
320 labelTypo: attr.labelTypo
321 };
322 return el('div', blockProps,
323 el('div', {
324 className: 'bkbg-phb-app',
325 'data-opts': JSON.stringify(opts)
326 })
327 );
328 }
329 });
330 }() );
331