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 / testimonial-wall / index.js

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

264 lines 22.1 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 Fragment = wp.element.Fragment;
4 var __ = wp.i18n.__;
5 var registerBlockType = wp.blocks.registerBlockType;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
8 var MediaUpload = wp.blockEditor.MediaUpload;
9 var MediaUploadCheck = wp.blockEditor.MediaUploadCheck;
10 var useBlockProps = wp.blockEditor.useBlockProps;
11 var PanelBody = wp.components.PanelBody;
12 var RangeControl = wp.components.RangeControl;
13 var ToggleControl = wp.components.ToggleControl;
14 var TextControl = wp.components.TextControl;
15 var TextareaControl = wp.components.TextareaControl;
16 var SelectControl = wp.components.SelectControl;
17 var Button = wp.components.Button;
18
19 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
20 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
21
22 var LAYOUT_OPTIONS = [
23 { label: __('Masonry', 'blockenberg'), value: 'masonry' },
24 { label: __('Grid', 'blockenberg'), value: 'grid' },
25 { label: __('Scatter', 'blockenberg'), value: 'scatter' },
26 ];
27 var CARD_STYLE_OPTIONS = [
28 { label: __('Shadow', 'blockenberg'), value: 'shadow' },
29 { label: __('Plain', 'blockenberg'), value: 'plain' },
30 { label: __('Bordered', 'blockenberg'), value: 'bordered' },
31 ];
32 var PLATFORM_OPTIONS = [
33 { label: __('Google', 'blockenberg'), value: 'google' },
34 { label: __('G2', 'blockenberg'), value: 'g2' },
35 { label: __('Capterra', 'blockenberg'), value: 'capterra' },
36 { label: __('Twitter', 'blockenberg'), value: 'twitter' },
37 { label: __('X / Twitter', 'blockenberg'), value: 'x' },
38 { label: __('Trustpilot', 'blockenberg'), value: 'trustpilot' },
39 { label: __('None', 'blockenberg'), value: 'none' },
40 ];
41 var PLATFORM_COLORS = { google: '#4285f4', g2: '#FF492C', capterra: '#FF3D2E', twitter: '#000', x: '#000', trustpilot: '#00b67a', none: '#6b7280' };
42 var PLATFORM_LABELS = { google: 'Google', g2: 'G2', capterra: 'Capterra', twitter: 'Twitter', x: 'X', trustpilot: 'Trustpilot', none: '' };
43
44 function makeId() { return 'tw' + Math.random().toString(36).substr(2, 6); }
45
46 function renderStarsSvg(rating, size, color) {
47 var stars = [];
48 for (var i = 1; i <= 5; i++) {
49 var filled = i <= rating;
50 stars.push(
51 el('svg', { key: i, width: size, height: size, viewBox: '0 0 24 24', style: { display: 'inline-block', marginRight: '2px' } },
52 el('polygon', { points: '12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2', fill: filled ? color : 'none', stroke: color, strokeWidth: '1.5' })
53 )
54 );
55 }
56 return el('div', { style: { display: 'flex', alignItems: 'center' } }, stars);
57 }
58
59 function PlatformBadge(props) {
60 var platform = props.platform;
61 var size = props.size || 13;
62 if (platform === 'none' || !platform) return null;
63 return el('span', { style: { display: 'inline-flex', alignItems: 'center', gap: '4px', fontSize: size + 'px', fontWeight: 700, color: PLATFORM_COLORS[platform] || '#6b7280' } },
64 PLATFORM_LABELS[platform] || platform
65 );
66 }
67
68 function TestimonialCard(props) {
69 var item = props.item;
70 var a = props.a;
71 var cardStyle = {
72 background: item.cardBg || a.globalCardBg || '#fff',
73 borderRadius: a.cardRadius + 'px',
74 padding: a.cardPadding + 'px',
75 borderTop: item.featured ? '4px solid ' + a.featuredAccent : undefined,
76 boxShadow: a.cardStyle === 'shadow' ? '0 4px 24px rgba(0,0,0,0.08)' : undefined,
77 border: a.cardStyle === 'bordered' ? '1px solid #e5e7eb' : undefined,
78 marginBottom: a.layout === 'masonry' ? a.gap + 'px' : undefined,
79 breakInside: 'avoid',
80 };
81 return el('div', { className: 'bkbg-tw-card' + (item.featured ? ' bkbg-tw-card--featured' : ''), style: cardStyle },
82 a.showQuoteMark && el('div', { style: { fontSize: a.quoteMarkSize + 'px', lineHeight: 1, color: a.featuredAccent, marginBottom: '8px', opacity: 0.25, fontFamily: 'Georgia, serif' } }, '\u201C'),
83 a.showRating && el('div', { style: { marginBottom: '10px' } }, renderStarsSvg(item.rating, a.starSize, a.starColor)),
84 el('p', { className: 'bkbg-tw-quote', style: { color: a.quoteColor, margin: '0 0 16px' } }, item.quote),
85 el('div', { style: { display: 'flex', alignItems: 'center', gap: '12px' } },
86 a.showAvatar && item.avatarUrl && el('img', { src: item.avatarUrl, alt: item.author, style: { width: a.avatarSize + 'px', height: a.avatarSize + 'px', borderRadius: '50%', objectFit: 'cover', flexShrink: 0 } }),
87 a.showAvatar && !item.avatarUrl && el('div', { style: { width: a.avatarSize + 'px', height: a.avatarSize + 'px', borderRadius: '50%', background: a.featuredAccent + '22', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: (a.avatarSize * 0.4) + 'px', color: a.featuredAccent, fontWeight: 700, flexShrink: 0 } }, (item.author || '?').charAt(0).toUpperCase()),
88 el('div', null,
89 el('p', { className: 'bkbg-tw-author-name', style: { margin: '0 0 2px', color: a.authorColor } }, item.author),
90 (item.role || item.company) && el('p', { className: 'bkbg-tw-role', style: { margin: '0', color: a.roleColor } }, [item.role, a.showCompany && item.company].filter(Boolean).join(' · ')),
91 el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', marginTop: '4px' } },
92 a.showPlatform && el(PlatformBadge, { platform: item.platform, size: a.authorSize - 1 }),
93 a.showDate && item.date && el('span', { style: { fontSize: (a.roleSize - 1) + 'px', color: '#9ca3af' } }, item.date)
94 )
95 )
96 )
97 );
98 }
99
100 registerBlockType('blockenberg/testimonial-wall', {
101 edit: function (props) {
102 var a = props.attributes;
103 var setAttributes = props.setAttributes;
104 var blockProps = useBlockProps((function () {
105 var _tvf = getTypoCssVars();
106 var s = { paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px', backgroundColor: a.bgColor || undefined };
107 if (_tvf) { Object.assign(s, _tvf(a.quoteTypo, '--bktw-qt-'), _tvf(a.nameTypo, '--bktw-nm-'), _tvf(a.roleTypo, '--bktw-rl-')); }
108 return { style: s };
109 })());
110
111 function setItem(id, patch) {
112 setAttributes({ items: a.items.map(function (it) { return it.id === id ? Object.assign({}, it, patch) : it; }) });
113 }
114 function addItem() {
115 setAttributes({ items: a.items.concat([{ id: makeId(), quote: 'Great product! Highly recommend.', author: 'New Customer', role: 'Customer', company: '', avatarUrl: '', avatarId: 0, rating: 5, platform: 'google', date: '', featured: false, cardBg: '' }]) });
116 }
117 function removeItem(id) {
118 if (a.items.length <= 1) return;
119 setAttributes({ items: a.items.filter(function (it) { return it.id !== id; }) });
120 }
121
122 var wrapStyle = a.layout === 'masonry'
123 ? { columnCount: a.columns, columnGap: a.gap + 'px' }
124 : { display: 'grid', gridTemplateColumns: 'repeat(' + a.columns + ', 1fr)', gap: a.gap + 'px' };
125
126 return el(Fragment, null,
127 el(InspectorControls, null,
128 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true },
129 el(SelectControl, { label: __('Layout style', 'blockenberg'), value: a.layout, options: LAYOUT_OPTIONS, onChange: function (v) { setAttributes({ layout: v }); } }),
130 el(RangeControl, { label: __('Columns', 'blockenberg'), value: a.columns, min: 1, max: 5, onChange: function (v) { setAttributes({ columns: v }); } }),
131 el(RangeControl, { label: __('Gap (px)', 'blockenberg'), value: a.gap, min: 8, max: 80, onChange: function (v) { setAttributes({ gap: v }); } }),
132 el(SelectControl, { label: __('Card style', 'blockenberg'), value: a.cardStyle, options: CARD_STYLE_OPTIONS, onChange: function (v) { setAttributes({ cardStyle: v }); } }),
133 el(RangeControl, { label: __('Card border radius (px)', 'blockenberg'), value: a.cardRadius, min: 0, max: 40, onChange: function (v) { setAttributes({ cardRadius: v }); } }),
134 el(RangeControl, { label: __('Card padding (px)', 'blockenberg'), value: a.cardPadding, min: 8, max: 64, onChange: function (v) { setAttributes({ cardPadding: v }); } })
135 ),
136 el(PanelBody, { title: __('Display', 'blockenberg'), initialOpen: false },
137 el(ToggleControl, { label: __('Show star rating', 'blockenberg'), checked: a.showRating, onChange: function (v) { setAttributes({ showRating: v }); }, __nextHasNoMarginBottom: true }),
138 el(ToggleControl, { label: __('Show platform badge', 'blockenberg'), checked: a.showPlatform, onChange: function (v) { setAttributes({ showPlatform: v }); }, __nextHasNoMarginBottom: true }),
139 el(ToggleControl, { label: __('Show date', 'blockenberg'), checked: a.showDate, onChange: function (v) { setAttributes({ showDate: v }); }, __nextHasNoMarginBottom: true }),
140 el(ToggleControl, { label: __('Show avatar', 'blockenberg'), checked: a.showAvatar, onChange: function (v) { setAttributes({ showAvatar: v }); }, __nextHasNoMarginBottom: true }),
141 el(ToggleControl, { label: __('Show company', 'blockenberg'), checked: a.showCompany, onChange: function (v) { setAttributes({ showCompany: v }); }, __nextHasNoMarginBottom: true }),
142 el(ToggleControl, { label: __('Show opening quote mark', 'blockenberg'), checked: a.showQuoteMark, onChange: function (v) { setAttributes({ showQuoteMark: v }); }, __nextHasNoMarginBottom: true })
143 ),
144 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
145 el(RangeControl, { label: __('Star size (px)', 'blockenberg'), value: a.starSize, min: 10, max: 24, onChange: function (v) { setAttributes({ starSize: v }); } }),
146 el(RangeControl, { label: __('Quote mark size (px)', 'blockenberg'), value: a.quoteMarkSize, min: 32, max: 120, onChange: function (v) { setAttributes({ quoteMarkSize: v }); } }),
147 el(RangeControl, { label: __('Avatar size (px)', 'blockenberg'), value: a.avatarSize, min: 28, max: 80, onChange: function (v) { setAttributes({ avatarSize: v }); } }),
148 getTypoControl() && getTypoControl()({ label: __('Quote', 'blockenberg'), value: a.quoteTypo, onChange: function (v) { setAttributes({ quoteTypo: v }); } }),
149 getTypoControl() && getTypoControl()({ label: __('Author Name', 'blockenberg'), value: a.nameTypo, onChange: function (v) { setAttributes({ nameTypo: v }); } }),
150 getTypoControl() && getTypoControl()({ label: __('Role / Company', 'blockenberg'), value: a.roleTypo, onChange: function (v) { setAttributes({ roleTypo: v }); } })
151 ),
152 el(PanelColorSettings, {
153 title: __('Colors', 'blockenberg'), initialOpen: false,
154 colorSettings: [
155 { value: a.featuredAccent, onChange: function (v) { setAttributes({ featuredAccent: v || '' }); }, label: __('Featured accent', 'blockenberg') },
156 { value: a.starColor, onChange: function (v) { setAttributes({ starColor: v || '' }); }, label: __('Stars', 'blockenberg') },
157 { value: a.globalCardBg, onChange: function (v) { setAttributes({ globalCardBg: v || '' }); }, label: __('Card background (global)', 'blockenberg') },
158 { value: a.quoteColor, onChange: function (v) { setAttributes({ quoteColor: v || '' }); }, label: __('Quote text', 'blockenberg') },
159 { value: a.authorColor, onChange: function (v) { setAttributes({ authorColor: v || '' }); }, label: __('Author name', 'blockenberg') },
160 { value: a.roleColor, onChange: function (v) { setAttributes({ roleColor: v || '' }); }, label: __('Role / company', 'blockenberg') },
161 { value: a.bgColor, onChange: function (v) { setAttributes({ bgColor: v || '' }); }, label: __('Section background', 'blockenberg') },
162 ]
163 }),
164 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
165 el(RangeControl, { label: __('Padding top (px)', 'blockenberg'), value: a.paddingTop, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingTop: v }); } }),
166 el(RangeControl, { label: __('Padding bottom (px)', 'blockenberg'), value: a.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingBottom: v }); } })
167 ),
168 el(PanelBody, { title: __('Testimonials', 'blockenberg'), initialOpen: false },
169 a.items.map(function (item, idx) {
170 return el(PanelBody, { key: item.id, title: (item.author || __('Testimonial', 'blockenberg') + ' ' + (idx + 1)), initialOpen: false },
171 el(TextareaControl, { label: __('Quote', 'blockenberg'), value: item.quote, onChange: function (v) { setItem(item.id, { quote: v }); } }),
172 el(TextControl, { label: __('Author name', 'blockenberg'), value: item.author, onChange: function (v) { setItem(item.id, { author: v }); } }),
173 el(TextControl, { label: __('Role', 'blockenberg'), value: item.role, onChange: function (v) { setItem(item.id, { role: v }); } }),
174 el(TextControl, { label: __('Company', 'blockenberg'), value: item.company, onChange: function (v) { setItem(item.id, { company: v }); } }),
175 el(RangeControl, { label: __('Star rating', 'blockenberg'), value: item.rating, min: 1, max: 5, onChange: function (v) { setItem(item.id, { rating: v }); } }),
176 el(SelectControl, { label: __('Platform', 'blockenberg'), value: item.platform, options: PLATFORM_OPTIONS, onChange: function (v) { setItem(item.id, { platform: v }); } }),
177 el(TextControl, { label: __('Date', 'blockenberg'), value: item.date, onChange: function (v) { setItem(item.id, { date: v }); } }),
178 el(ToggleControl, { label: __('Featured (accent top border)', 'blockenberg'), checked: item.featured, onChange: function (v) { setItem(item.id, { featured: v }); }, __nextHasNoMarginBottom: true }),
179 el(MediaUploadCheck, null,
180 el(MediaUpload, {
181 onSelect: function (media) { setItem(item.id, { avatarUrl: media.url, avatarId: media.id }); },
182 allowedTypes: ['image'],
183 value: item.avatarId,
184 render: function (p) {
185 return el('div', { style: { marginBottom: '8px' } },
186 item.avatarUrl && el('img', { src: item.avatarUrl, alt: '', style: { width: '48px', height: '48px', borderRadius: '50%', objectFit: 'cover', marginBottom: '4px', display: 'block' } }),
187 el(Button, { onClick: p.open, variant: item.avatarUrl ? 'secondary' : 'primary', size: 'compact' }, item.avatarUrl ? __('Replace avatar', 'blockenberg') : __('Upload avatar', 'blockenberg'))
188 );
189 }
190 })
191 ),
192 a.items.length > 1 && el(Button, { onClick: function () { removeItem(item.id); }, variant: 'tertiary', isDestructive: true, size: 'compact' }, __('Remove', 'blockenberg'))
193 );
194 }),
195 el(Button, { onClick: addItem, variant: 'primary', style: { marginTop: '8px' } }, __('+ Add Testimonial', 'blockenberg'))
196 )
197 ),
198
199 el('div', blockProps,
200 el('div', { className: 'bkbg-tw bkbg-tw--' + a.layout, style: wrapStyle },
201 a.items.map(function (item) {
202 return el(TestimonialCard, { key: item.id, item: item, a: a });
203 })
204 )
205 )
206 );
207 },
208
209 save: function (props) {
210 var a = props.attributes;
211 var _tvf = getTypoCssVars();
212 var PLATFORM_COLORS = { google: '#4285f4', g2: '#FF492C', capterra: '#FF3D2E', twitter: '#000', x: '#000', trustpilot: '#00b67a', none: '#6b7280' };
213 var PLATFORM_LABELS = { google: 'Google', g2: 'G2', capterra: 'Capterra', twitter: 'Twitter', x: 'X', trustpilot: 'Trustpilot', none: '' };
214 var wrapStyle = a.layout === 'masonry'
215 ? { columnCount: a.columns, columnGap: a.gap + 'px' }
216 : { display: 'grid', gridTemplateColumns: 'repeat(' + a.columns + ', 1fr)', gap: a.gap + 'px' };
217
218 return el('div', (function () {
219 var s = { paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px', backgroundColor: a.bgColor || undefined };
220 if (_tvf) { Object.assign(s, _tvf(a.quoteTypo, '--bktw-qt-'), _tvf(a.nameTypo, '--bktw-nm-'), _tvf(a.roleTypo, '--bktw-rl-')); }
221 return wp.blockEditor.useBlockProps.save({ className: 'bkbg-testimonial-wall-wrap', style: s });
222 })(),
223 el('div', { className: 'bkbg-tw bkbg-tw--' + a.layout, style: wrapStyle },
224 a.items.map(function (item) {
225 var cardStyle = {
226 background: item.cardBg || a.globalCardBg || '#fff',
227 borderRadius: a.cardRadius + 'px',
228 padding: a.cardPadding + 'px',
229 borderTop: item.featured ? '4px solid ' + a.featuredAccent : undefined,
230 boxShadow: a.cardStyle === 'shadow' ? '0 4px 24px rgba(0,0,0,0.08)' : undefined,
231 border: a.cardStyle === 'bordered' ? '1px solid #e5e7eb' : undefined,
232 marginBottom: a.layout === 'masonry' ? a.gap + 'px' : undefined,
233 breakInside: 'avoid',
234 };
235 return el('div', { key: item.id, className: 'bkbg-tw-card' + (item.featured ? ' bkbg-tw-card--featured' : ''), style: cardStyle },
236 a.showQuoteMark && el('div', { style: { fontSize: a.quoteMarkSize + 'px', lineHeight: 1, color: a.featuredAccent, marginBottom: '8px', opacity: 0.25, fontFamily: 'Georgia, serif' } }, '\u201C'),
237 a.showRating && el('div', { style: { marginBottom: '10px', display: 'flex', alignItems: 'center' } },
238 Array.from({ length: 5 }).map(function (_, i) {
239 return el('svg', { key: i, width: a.starSize, height: a.starSize, viewBox: '0 0 24 24', style: { display: 'inline-block', marginRight: '2px' } },
240 el('polygon', { points: '12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2', fill: i < item.rating ? a.starColor : 'none', stroke: a.starColor, strokeWidth: '1.5' })
241 );
242 })
243 ),
244 el('p', { className: 'bkbg-tw-quote', style: { color: a.quoteColor, margin: '0 0 16px' } }, item.quote),
245 el('div', { style: { display: 'flex', alignItems: 'center', gap: '12px' } },
246 a.showAvatar && item.avatarUrl && el('img', { src: item.avatarUrl, alt: item.author, style: { width: a.avatarSize + 'px', height: a.avatarSize + 'px', borderRadius: '50%', objectFit: 'cover', flexShrink: 0 } }),
247 a.showAvatar && !item.avatarUrl && el('div', { style: { width: a.avatarSize + 'px', height: a.avatarSize + 'px', borderRadius: '50%', background: a.featuredAccent + '22', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: (a.avatarSize * 0.4) + 'px', color: a.featuredAccent, fontWeight: 700, flexShrink: 0 } }, (item.author || '?').charAt(0).toUpperCase()),
248 el('div', null,
249 el('p', { className: 'bkbg-tw-author-name', style: { margin: '0 0 2px', color: a.authorColor } }, item.author),
250 (item.role || item.company) && el('p', { className: 'bkbg-tw-role', style: { margin: 0, color: a.roleColor } }, [item.role, a.showCompany && item.company].filter(Boolean).join(' \u00B7 ')),
251 el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', marginTop: '4px' } },
252 a.showPlatform && item.platform && item.platform !== 'none' && el('span', { style: { fontWeight: 700, color: PLATFORM_COLORS[item.platform] || '#6b7280' } }, PLATFORM_LABELS[item.platform] || item.platform),
253 a.showDate && item.date && el('span', { style: { color: '#9ca3af' } }, item.date)
254 )
255 )
256 )
257 );
258 })
259 )
260 );
261 }
262 });
263 }() );
264