PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.12
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.12
2.0.14 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 / comparison-swipe-wall / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.12, at blocks/comparison-swipe-wall/index.js

278 lines 22.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* ====================================================
2 Comparison Wall — editor (index.js)
3 Block: blockenberg/comparison-swipe-wall
4 ==================================================== */
5 ( function () {
6 var el = wp.element.createElement;
7 var Fragment = wp.element.Fragment;
8 var useState = wp.element.useState;
9 var RichText = wp.blockEditor.RichText;
10 var registerBlockType = wp.blocks.registerBlockType;
11 var InspectorControls = wp.blockEditor.InspectorControls;
12 var useBlockProps = wp.blockEditor.useBlockProps;
13 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
14 var PanelBody = wp.components.PanelBody;
15 var RangeControl = wp.components.RangeControl;
16 var SelectControl = wp.components.SelectControl;
17 var ToggleControl = wp.components.ToggleControl;
18 var TextControl = wp.components.TextControl;
19 var Button = wp.components.Button;
20 var __ = wp.i18n.__;
21
22 function getTypographyControl() { return (window.bkbgTypographyControl || function () { return null; }); }
23 function getTypoCssVars() { return (window.bkbgTypoCssVars || function () { return {}; }); }
24 function _tv(typo, prefix) { var fn = getTypoCssVars(); return fn(typo || {}, prefix); }
25 var IP = function () { return window.bkbgIconPicker; };
26
27 function uid() { return 'cmp' + Math.random().toString(36).slice(2,7); }
28 function move(arr, from, to) { var a=arr.slice(); a.splice(to,0,a.splice(from,1)[0]); return a; }
29
30 function wrapStyle(a) {
31 return Object.assign({
32 '--bkbg-cmp-pt': a.paddingTop+'px',
33 '--bkbg-cmp-pb': a.paddingBottom+'px',
34 '--bkbg-cmp-gap': a.gap+'px',
35 '--bkbg-cmp-r': a.cardRadius+'px',
36 '--bkbg-cmp-item-sz': a.itemSize+'px',
37 '--bkbg-cmp-sec-title-sz': a.sectionTitleSize+'px',
38 '--bkbg-cmp-sec-sub-sz': a.sectionSubSize+'px',
39 '--bkbg-cmp-left-bg': a.leftCardBg,
40 '--bkbg-cmp-right-bg': a.rightCardBg,
41 '--bkbg-cmp-left-title': a.leftTitleColor,
42 '--bkbg-cmp-right-title':a.rightTitleColor,
43 '--bkbg-cmp-left-icon': a.leftIconColor,
44 '--bkbg-cmp-right-icon': a.rightIconColor,
45 '--bkbg-cmp-left-item': a.leftItemColor,
46 '--bkbg-cmp-right-item': a.rightItemColor,
47 '--bkbg-cmp-ey-bg': a.eyebrowBg,
48 '--bkbg-cmp-ey-c': a.eyebrowColor,
49 '--bkbg-cmp-sec-title-c':a.sectionTitleColor || undefined,
50 '--bkbg-cmp-sec-sub-c': a.sectionSubColor || undefined,
51 background: a.sectionBg || undefined,
52 }, _tv(a.typoTitle, '--bkcw-title-'), _tv(a.typoSubtitle, '--bkcw-sub-'), _tv(a.typoItem, '--bkcw-item-'));
53 }
54
55 function itemsPanel(title, items, side, setItems, iconProp, iconColor) {
56 return el(PanelBody, { title:title, initialOpen:false },
57 items.map(function(item, idx) {
58 return el('div', { key:item.id, style:{display:'flex',alignItems:'center',gap:'6px',marginBottom:'4px'} },
59 el(TextControl, { value:item.text, onChange:function(v){ setItems(items.map(function(it){ return it.id===item.id ? Object.assign({},it,{text:v}) : it; })); }, style:{flex:1,margin:0} }),
60 el(Button, { icon:'arrow-up', isSmall:true, disabled:idx===0, onClick:function(){ setItems(move(items,idx,idx-1)); } }),
61 el(Button, { icon:'arrow-down', isSmall:true, disabled:idx===items.length-1, onClick:function(){ setItems(move(items,idx,idx+1)); } }),
62 el(Button, { icon:'no-alt', isSmall:true, isDestructive:true, onClick:function(){ setItems(items.filter(function(it){ return it.id!==item.id; })); } })
63 );
64 }),
65 el(Button, { variant:'secondary', isSmall:true, style:{marginTop:'4px',width:'100%'},
66 onClick:function(){ setItems(items.concat([{id:uid(),text:'New item'}])); }
67 }, __('+ Add Item','blockenberg'))
68 );
69 }
70
71 registerBlockType('blockenberg/comparison-swipe-wall', {
72 edit: function (props) {
73 var a = props.attributes;
74 var setAttr = props.setAttributes;
75
76 var blockProps = useBlockProps({
77 className: 'bkbg-cmp-wrap bkbg-cmp-style--' + a.cardStyle,
78 style: wrapStyle(a)
79 });
80
81 var headerEl = a.showHeader ? el('div', { className:'bkbg-cmp-header', style:{textAlign:a.headerAlign,marginBottom:'48px'} },
82 a.showEyebrow ? el('span', { className:'bkbg-cmp-eyebrow' }, a.eyebrow) : null,
83 el(RichText, { tagName:'h2', className:'bkbg-cmp-section-title', value:a.sectionTitle, onChange:function(v){ setAttr({sectionTitle:v}); }, placeholder:__('Section title…','blockenberg') }),
84 el(RichText, { tagName:'p', className:'bkbg-cmp-section-sub', value:a.sectionSubtitle, onChange:function(v){ setAttr({sectionSubtitle:v}); }, placeholder:__('Subtitle…','blockenberg') })
85 ) : null;
86
87 function renderCol(side) {
88 var isLeft = side === 'left';
89 var items = isLeft ? a.leftItems : a.rightItems;
90 var title = isLeft ? a.leftTitle : a.rightTitle;
91 var emoji = isLeft ? a.leftEmoji : a.rightEmoji;
92 var icon = isLeft ? a.leftIcon : a.rightIcon;
93 var emojiType = isLeft ? (a.leftEmojiType || 'custom-char') : (a.rightEmojiType || 'custom-char');
94 var emojiDash = isLeft ? a.leftEmojiDashicon : a.rightEmojiDashicon;
95 var emojiImg = isLeft ? a.leftEmojiImageUrl : a.rightEmojiImageUrl;
96 var iconType = isLeft ? (a.leftIconType || 'custom-char') : (a.rightIconType || 'custom-char');
97 var iconDash = isLeft ? a.leftIconDashicon : a.rightIconDashicon;
98 var iconImg = isLeft ? a.leftIconImageUrl : a.rightIconImageUrl;
99 var emojiDashColor = isLeft ? a.leftEmojiDashiconColor : a.rightEmojiDashiconColor;
100 var iconDashColor = isLeft ? a.leftIconDashiconColor : a.rightIconDashiconColor;
101 return el('div', { className:'bkbg-cmp-col bkbg-cmp-col--'+side },
102 el('div', { className:'bkbg-cmp-col-header' },
103 el('span', { className:'bkbg-cmp-col-emoji' },
104 emojiType !== 'custom-char' ? IP().buildEditorIcon(emojiType, emoji, emojiDash, emojiImg, emojiDashColor) : emoji
105 ),
106 el('h3', { className:'bkbg-cmp-col-title' }, title)
107 ),
108 el('ul', { className:'bkbg-cmp-list' },
109 items.map(function(item) {
110 return el('li', { key:item.id, className:'bkbg-cmp-item' },
111 a.showIcons ? el('span', { className:'bkbg-cmp-item-icon' },
112 iconType !== 'custom-char' ? IP().buildEditorIcon(iconType, icon, iconDash, iconImg, iconDashColor) : icon
113 ) : null,
114 el('span', { className:'bkbg-cmp-item-text' }, item.text)
115 );
116 })
117 )
118 );
119 }
120
121 var inspector = el(InspectorControls, null,
122 el(PanelBody, { title:__('Left Column','blockenberg'), initialOpen:true },
123 el(TextControl, { label:__('Title','blockenberg'), value:a.leftTitle, onChange:function(v){ setAttr({leftTitle:v}); } }),
124 el('p', { style:{fontSize:'11px',fontWeight:600,marginTop:'12px'} }, __('Column Emoji','blockenberg')),
125 el(IP().IconPickerControl, IP().iconPickerProps(a, setAttr, { charAttr:'leftEmoji', typeAttr:'leftEmojiType', dashiconAttr:'leftEmojiDashicon', imageUrlAttr:'leftEmojiImageUrl', colorAttr: 'leftEmojiDashiconColor' })),
126 el('p', { style:{fontSize:'11px',fontWeight:600,marginTop:'12px'} }, __('Row Icon','blockenberg')),
127 el(IP().IconPickerControl, IP().iconPickerProps(a, setAttr, { charAttr:'leftIcon', typeAttr:'leftIconType', dashiconAttr:'leftIconDashicon', imageUrlAttr:'leftIconImageUrl', colorAttr: 'leftIconDashiconColor' })),
128 el('p', { style:{fontSize:'12px',color:'#64748b',margin:'4px 0 8px'} }, __('Items:','blockenberg')),
129 a.leftItems.map(function(item, idx) {
130 return el('div', { key:item.id, style:{display:'flex',alignItems:'center',gap:'4px',marginBottom:'4px'} },
131 el(TextControl, { value:item.text, onChange:function(v){ setAttr({leftItems:a.leftItems.map(function(it){ return it.id===item.id ? Object.assign({},it,{text:v}) : it; })}); }, style:{flex:1,margin:0} }),
132 el(Button, { icon:'arrow-up', isSmall:true, disabled:idx===0, onClick:function(){ setAttr({leftItems:move(a.leftItems,idx,idx-1)}); } }),
133 el(Button, { icon:'arrow-down', isSmall:true, disabled:idx===a.leftItems.length-1, onClick:function(){ setAttr({leftItems:move(a.leftItems,idx,idx+1)}); } }),
134 el(Button, { icon:'no-alt', isSmall:true, isDestructive:true, onClick:function(){ setAttr({leftItems:a.leftItems.filter(function(it){ return it.id!==item.id; })}); } })
135 );
136 }),
137 el(Button, { variant:'secondary', isSmall:true, style:{marginTop:'4px',width:'100%'}, onClick:function(){ setAttr({leftItems:a.leftItems.concat([{id:uid(),text:'New item'}])}); } }, __('+ Add left item','blockenberg'))
138 ),
139 el(PanelBody, { title:__('Right Column','blockenberg'), initialOpen:false },
140 el(TextControl, { label:__('Title','blockenberg'), value:a.rightTitle, onChange:function(v){ setAttr({rightTitle:v}); } }),
141 el('p', { style:{fontSize:'11px',fontWeight:600,marginTop:'12px'} }, __('Column Emoji','blockenberg')),
142 el(IP().IconPickerControl, IP().iconPickerProps(a, setAttr, { charAttr:'rightEmoji', typeAttr:'rightEmojiType', dashiconAttr:'rightEmojiDashicon', imageUrlAttr:'rightEmojiImageUrl', colorAttr: 'rightEmojiDashiconColor' })),
143 el('p', { style:{fontSize:'11px',fontWeight:600,marginTop:'12px'} }, __('Row Icon','blockenberg')),
144 el(IP().IconPickerControl, IP().iconPickerProps(a, setAttr, { charAttr:'rightIcon', typeAttr:'rightIconType', dashiconAttr:'rightIconDashicon', imageUrlAttr:'rightIconImageUrl', colorAttr: 'rightIconDashiconColor' })),
145 el('p', { style:{fontSize:'12px',color:'#64748b',margin:'4px 0 8px'} }, __('Items:','blockenberg')),
146 a.rightItems.map(function(item, idx) {
147 return el('div', { key:item.id, style:{display:'flex',alignItems:'center',gap:'4px',marginBottom:'4px'} },
148 el(TextControl, { value:item.text, onChange:function(v){ setAttr({rightItems:a.rightItems.map(function(it){ return it.id===item.id ? Object.assign({},it,{text:v}) : it; })}); }, style:{flex:1,margin:0} }),
149 el(Button, { icon:'arrow-up', isSmall:true, disabled:idx===0, onClick:function(){ setAttr({rightItems:move(a.rightItems,idx,idx-1)}); } }),
150 el(Button, { icon:'arrow-down', isSmall:true, disabled:idx===a.rightItems.length-1, onClick:function(){ setAttr({rightItems:move(a.rightItems,idx,idx+1)}); } }),
151 el(Button, { icon:'no-alt', isSmall:true, isDestructive:true, onClick:function(){ setAttr({rightItems:a.rightItems.filter(function(it){ return it.id!==item.id; })}); } })
152 );
153 }),
154 el(Button, { variant:'secondary', isSmall:true, style:{marginTop:'4px',width:'100%'}, onClick:function(){ setAttr({rightItems:a.rightItems.concat([{id:uid(),text:'New item'}])}); } }, __('+ Add right item','blockenberg'))
155 ),
156 el(PanelBody, { title:__('Style & Layout','blockenberg'), initialOpen:false },
157 el(SelectControl, { label:__('Card style','blockenberg'), value:a.cardStyle, options:[
158 {label:'Split cards', value:'split-card'},
159 {label:'Flat (no card bg)', value:'flat'},
160 {label:'Dark right column', value:'dark-right'},
161 {label:'Table comparison', value:'table'},
162 ], onChange:function(v){ setAttr({cardStyle:v}); } }),
163 el(ToggleControl, { label:__('Show row icons','blockenberg'), checked:a.showIcons, onChange:function(v){ setAttr({showIcons:v}); } }),
164 el(RangeControl, { label:__('Card radius (px)','blockenberg'), value:a.cardRadius, min:0, max:32, onChange:function(v){ setAttr({cardRadius:v}); } }),
165 el(RangeControl, { label:__('Gap (px)','blockenberg'), value:a.gap, min:0, max:80, onChange:function(v){ setAttr({gap:v}); } })
166 ),
167 el(PanelBody, { title:__('Typography','blockenberg'), initialOpen:false },
168 el(getTypographyControl(), { label: __('Title Typography', 'blockenberg'), value: a.typoTitle, onChange: function (v) { setAttr({ typoTitle: v }); } }),
169 el(getTypographyControl(), { label: __('Subtitle Typography', 'blockenberg'), value: a.typoSubtitle, onChange: function (v) { setAttr({ typoSubtitle: v }); } }),
170 el(getTypographyControl(), { label: __('Item Typography', 'blockenberg'), value: a.typoItem, onChange: function (v) { setAttr({ typoItem: v }); } })
171 ),
172 el(PanelBody, { title:__('Header','blockenberg'), initialOpen:false },
173 el(ToggleControl, { label:__('Show header','blockenberg'), checked:a.showHeader, onChange:function(v){ setAttr({showHeader:v}); } }),
174 el(ToggleControl, { label:__('Show eyebrow','blockenberg'), checked:a.showEyebrow, onChange:function(v){ setAttr({showEyebrow:v}); } }),
175 el(TextControl, { label:__('Eyebrow text','blockenberg'), value:a.eyebrow, onChange:function(v){ setAttr({eyebrow:v}); } }),
176 el(SelectControl, { label:__('Header align','blockenberg'), value:a.headerAlign, options:[{label:'Left',value:'left'},{label:'Center',value:'center'}], onChange:function(v){ setAttr({headerAlign:v}); } }),
177 el(ToggleControl, { label:__('Show CTA button','blockenberg'), checked:a.showCta, onChange:function(v){ setAttr({showCta:v}); } }),
178 el(TextControl, { label:__('CTA label','blockenberg'), value:a.ctaLabel, onChange:function(v){ setAttr({ctaLabel:v}); } }),
179 el(TextControl, { label:__('CTA URL','blockenberg'), value:a.ctaUrl, onChange:function(v){ setAttr({ctaUrl:v}); } })
180 ),
181 el(PanelBody, { title:__('Spacing','blockenberg'), initialOpen:false },
182 el(RangeControl, { label:__('Padding top (px)','blockenberg'), value:a.paddingTop, min:0, max:160, onChange:function(v){ setAttr({paddingTop:v}); } }),
183 el(RangeControl, { label:__('Padding bottom (px)','blockenberg'), value:a.paddingBottom, min:0, max:160, onChange:function(v){ setAttr({paddingBottom:v}); } })
184 ),
185 el(PanelColorSettings, { title:__('Colors','blockenberg'), initialOpen:false, colorSettings:[
186 {label:__('Section bg','blockenberg'), value:a.sectionBg, onChange:function(v){ setAttr({sectionBg:v||''}); }},
187 {label:__('Left card bg','blockenberg'), value:a.leftCardBg, onChange:function(v){ setAttr({leftCardBg:v||''}); }},
188 {label:__('Right card bg','blockenberg'), value:a.rightCardBg, onChange:function(v){ setAttr({rightCardBg:v||''}); }},
189 {label:__('Left title','blockenberg'), value:a.leftTitleColor, onChange:function(v){ setAttr({leftTitleColor:v||''}); }},
190 {label:__('Right title','blockenberg'), value:a.rightTitleColor, onChange:function(v){ setAttr({rightTitleColor:v||''}); }},
191 {label:__('Left icon color','blockenberg'), value:a.leftIconColor, onChange:function(v){ setAttr({leftIconColor:v||''}); }},
192 {label:__('Right icon color','blockenberg'), value:a.rightIconColor, onChange:function(v){ setAttr({rightIconColor:v||''}); }},
193 {label:__('Left item text','blockenberg'), value:a.leftItemColor, onChange:function(v){ setAttr({leftItemColor:v||''}); }},
194 {label:__('Right item text','blockenberg'), value:a.rightItemColor, onChange:function(v){ setAttr({rightItemColor:v||''}); }},
195 {label:__('Eyebrow bg','blockenberg'), value:a.eyebrowBg, onChange:function(v){ setAttr({eyebrowBg:v||''}); }},
196 {label:__('Eyebrow text','blockenberg'), value:a.eyebrowColor, onChange:function(v){ setAttr({eyebrowColor:v||''}); }},
197 {label:__('Section title','blockenberg'), value:a.sectionTitleColor, onChange:function(v){ setAttr({sectionTitleColor:v||''}); }},
198 {label:__('Section subtitle','blockenberg'), value:a.sectionSubColor, onChange:function(v){ setAttr({sectionSubColor:v||''}); }},
199 ] })
200 );
201
202 return el(Fragment, null,
203 inspector,
204 el('div', blockProps,
205 headerEl,
206 el('div', { className:'bkbg-cmp-grid' },
207 renderCol('left'),
208 renderCol('right')
209 ),
210 a.showCta ? el('div', { className:'bkbg-cmp-cta-wrap' },
211 el('a', { href:a.ctaUrl, className:'bkbg-cmp-cta', onClick:function(e){ e.preventDefault(); } }, a.ctaLabel)
212 ) : null
213 )
214 );
215 },
216
217 save: function (props) {
218 var a = props.attributes;
219 var blockProps = wp.blockEditor.useBlockProps.save({
220 className:'bkbg-cmp-wrap bkbg-cmp-style--'+a.cardStyle,
221 style: Object.assign({
222 '--bkbg-cmp-pt':a.paddingTop+'px','--bkbg-cmp-pb':a.paddingBottom+'px','--bkbg-cmp-gap':a.gap+'px','--bkbg-cmp-r':a.cardRadius+'px','--bkbg-cmp-item-sz':a.itemSize+'px','--bkbg-cmp-left-bg':a.leftCardBg,'--bkbg-cmp-right-bg':a.rightCardBg,'--bkbg-cmp-left-title':a.leftTitleColor,'--bkbg-cmp-right-title':a.rightTitleColor,'--bkbg-cmp-left-icon':a.leftIconColor,'--bkbg-cmp-right-icon':a.rightIconColor,'--bkbg-cmp-left-item':a.leftItemColor,'--bkbg-cmp-right-item':a.rightItemColor,'--bkbg-cmp-ey-bg':a.eyebrowBg,'--bkbg-cmp-ey-c':a.eyebrowColor,'--bkbg-cmp-sec-title-c':a.sectionTitleColor||undefined,'--bkbg-cmp-sec-sub-c':a.sectionSubColor||undefined,background:a.sectionBg||undefined,
223 }, _tv(a.typoTitle, '--bkcw-title-'), _tv(a.typoSubtitle, '--bkcw-sub-'), _tv(a.typoItem, '--bkcw-item-'))
224 });
225
226 function colEl(side) {
227 var isLeft = side==='left';
228 var items = isLeft ? a.leftItems : a.rightItems;
229 var title = isLeft ? a.leftTitle : a.rightTitle;
230 var emoji = isLeft ? a.leftEmoji : a.rightEmoji;
231 var icon = isLeft ? a.leftIcon : a.rightIcon;
232 var emojiType = isLeft ? (a.leftEmojiType || 'custom-char') : (a.rightEmojiType || 'custom-char');
233 var emojiDash = isLeft ? a.leftEmojiDashicon : a.rightEmojiDashicon;
234 var emojiImg = isLeft ? a.leftEmojiImageUrl : a.rightEmojiImageUrl;
235 var iconType = isLeft ? (a.leftIconType || 'custom-char') : (a.rightIconType || 'custom-char');
236 var iconDash = isLeft ? a.leftIconDashicon : a.rightIconDashicon;
237 var iconImg = isLeft ? a.leftIconImageUrl : a.rightIconImageUrl;
238 var emojiDashColor = isLeft ? a.leftEmojiDashiconColor : a.rightEmojiDashiconColor;
239 var iconDashColor = isLeft ? a.leftIconDashiconColor : a.rightIconDashiconColor;
240 return el('div', { className:'bkbg-cmp-col bkbg-cmp-col--'+side },
241 el('div', { className:'bkbg-cmp-col-header' },
242 el('span', { className:'bkbg-cmp-col-emoji' },
243 emojiType !== 'custom-char'
244 ? IP().buildSaveIcon(emojiType, emoji, emojiDash, emojiImg, emojiDashColor)
245 : emoji
246 ),
247 el('h3', { className:'bkbg-cmp-col-title' }, title)
248 ),
249 el('ul', { className:'bkbg-cmp-list' },
250 items.map(function(item) {
251 return el('li', { key:item.id, className:'bkbg-cmp-item' },
252 a.showIcons ? el('span', { className:'bkbg-cmp-item-icon' },
253 iconType !== 'custom-char'
254 ? IP().buildSaveIcon(iconType, icon, iconDash, iconImg, iconDashColor)
255 : icon
256 ) : null,
257 el('span', { className:'bkbg-cmp-item-text' }, item.text)
258 );
259 })
260 )
261 );
262 }
263
264 return el('div', blockProps,
265 a.showHeader ? el('div', { className:'bkbg-cmp-header', style:{textAlign:a.headerAlign,marginBottom:'48px'} },
266 a.showEyebrow ? el('span', { className:'bkbg-cmp-eyebrow' }, a.eyebrow) : null,
267 el(RichText.Content, { tagName:'h2', className:'bkbg-cmp-section-title', value:a.sectionTitle }),
268 el(RichText.Content, { tagName:'p', className:'bkbg-cmp-section-sub', value:a.sectionSubtitle })
269 ) : null,
270 el('div', { className:'bkbg-cmp-grid' }, colEl('left'), colEl('right')),
271 a.showCta ? el('div', { className:'bkbg-cmp-cta-wrap' },
272 el('a', { href:a.ctaUrl, className:'bkbg-cmp-cta' }, a.ctaLabel)
273 ) : null
274 );
275 }
276 });
277 }() );
278