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 / founder-quote / index.js

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

311 lines 16.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 useBlockProps = wp.blockEditor.useBlockProps;
8 var MediaUpload = wp.blockEditor.MediaUpload;
9 var RichText = wp.blockEditor.RichText;
10 var PanelBody = wp.components.PanelBody;
11 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
12 var ToggleControl = wp.components.ToggleControl;
13 var RangeControl = wp.components.RangeControl;
14 var SelectControl = wp.components.SelectControl;
15 var TextControl = wp.components.TextControl;
16 var Button = wp.components.Button;
17
18 var styleOptions = [
19 { label: __('Minimal', 'blockenberg'), value: 'minimal' },
20 { label: __('Card', 'blockenberg'), value: 'card' },
21 { label: __('Split (Photo left)', 'blockenberg'), value: 'split' },
22 { label: __('Dark', 'blockenberg'), value: 'dark' },
23 { label: __('Centered', 'blockenberg'), value: 'centered' },
24 { label: __('Border Left', 'blockenberg'), value: 'border-left' }
25 ];
26
27 var _fqTC, _fqTV;
28 function _tc() { return _fqTC || (_fqTC = window.bkbgTypographyControl); }
29 function _tv() { return _fqTV || (_fqTV = window.bkbgTypoCssVars); }
30
31 function wrapStyle(a) {
32 return Object.assign(
33 {
34 '--bkbg-fq-accent': a.accentColor,
35 '--bkbg-fq-bg': a.bgColor,
36 '--bkbg-fq-border': a.borderColor,
37 '--bkbg-fq-quote-c': a.quoteColor,
38 '--bkbg-fq-name-c': a.nameColor,
39 '--bkbg-fq-title-c': a.titleColor,
40 '--bkbg-fq-eyebrow-c': a.eyebrowColor,
41 '--bkbg-fq-photo-sz': a.photoSize + 'px',
42 '--bkbg-fq-pt': a.paddingTop + 'px',
43 '--bkbg-fq-pb': a.paddingBottom + 'px',
44 '--bkbg-fq-mw': a.maxWidth + 'px'
45 },
46 _tv()(a.typoEyebrow, '--bkbg-fq-eb-'),
47 _tv()(a.typoQuote, '--bkbg-fq-qt-'),
48 _tv()(a.typoName, '--bkbg-fq-nm-'),
49 _tv()(a.typoTitle, '--bkbg-fq-tt-'),
50 _tv()(a.typoSignature, '--bkbg-fq-sg-')
51 );
52 }
53
54 registerBlockType('blockenberg/founder-quote', {
55 title: __('Founder Quote', 'blockenberg'),
56 icon: 'format-quote',
57 category: 'bkbg-business',
58 description: __('CEO or founder personal message with photo and signature.', 'blockenberg'),
59
60 edit: function (props) {
61 var a = props.attributes;
62 var setAttributes = props.setAttributes;
63
64 var inspector = el(InspectorControls, {},
65 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
66 el(ToggleControl, {
67 label: __('Show Eyebrow', 'blockenberg'),
68 checked: a.showEyebrow,
69 __nextHasNoMarginBottom: true,
70 onChange: function (v) { setAttributes({ showEyebrow: v }); }
71 }),
72 a.showEyebrow && el(TextControl, {
73 label: __('Eyebrow Text', 'blockenberg'),
74 value: a.eyebrow,
75 onChange: function (v) { setAttributes({ eyebrow: v }); }
76 }),
77 el(TextControl, {
78 label: __('Name', 'blockenberg'),
79 value: a.name,
80 onChange: function (v) { setAttributes({ name: v }); }
81 }),
82 el(TextControl, {
83 label: __('Title / Role', 'blockenberg'),
84 value: a.title,
85 onChange: function (v) { setAttributes({ title: v }); }
86 }),
87 el(TextControl, {
88 label: __('Company', 'blockenberg'),
89 value: a.company,
90 onChange: function (v) { setAttributes({ company: v }); }
91 }),
92 el(ToggleControl, {
93 label: __('Show Signature', 'blockenberg'),
94 checked: a.showSignature,
95 __nextHasNoMarginBottom: true,
96 onChange: function (v) { setAttributes({ showSignature: v }); }
97 }),
98 a.showSignature && el(TextControl, {
99 label: __('Signature Text', 'blockenberg'),
100 value: a.signature,
101 onChange: function (v) { setAttributes({ signature: v }); }
102 })
103 ),
104
105 el(PanelBody, { title: __('Photo', 'blockenberg'), initialOpen: false },
106 el(ToggleControl, {
107 label: __('Show Photo', 'blockenberg'),
108 checked: a.showPhoto,
109 __nextHasNoMarginBottom: true,
110 onChange: function (v) { setAttributes({ showPhoto: v }); }
111 }),
112 a.showPhoto && el(MediaUpload, {
113 onSelect: function (media) {
114 setAttributes({ photoUrl: media.url, photoId: media.id });
115 },
116 allowedTypes: ['image'],
117 value: a.photoId,
118 render: function (obj) {
119 return el(Button, {
120 variant: a.photoUrl ? 'secondary' : 'primary',
121 onClick: obj.open
122 }, a.photoUrl ? __('Change Photo', 'blockenberg') : __('Upload Photo', 'blockenberg'));
123 }
124 }),
125 a.showPhoto && a.photoUrl && el(Button, {
126 variant: 'link',
127 isDestructive: true,
128 onClick: function () { setAttributes({ photoUrl: '', photoId: 0 }); }
129 }, __('Remove Photo', 'blockenberg')),
130 a.showPhoto && el(RangeControl, {
131 label: __('Photo Size (px)', 'blockenberg'),
132 value: a.photoSize,
133 onChange: function (v) { setAttributes({ photoSize: v }); },
134 min: 40, max: 160
135 })
136 ),
137
138 el(PanelBody, { title: __('Company Logo', 'blockenberg'), initialOpen: false },
139 el(ToggleControl, {
140 label: __('Show Company Logo', 'blockenberg'),
141 checked: a.showCompanyLogo,
142 __nextHasNoMarginBottom: true,
143 onChange: function (v) { setAttributes({ showCompanyLogo: v }); }
144 }),
145 a.showCompanyLogo && el(MediaUpload, {
146 onSelect: function (media) {
147 setAttributes({ companyLogoUrl: media.url, companyLogoId: media.id });
148 },
149 allowedTypes: ['image'],
150 value: a.companyLogoId,
151 render: function (obj) {
152 return el(Button, {
153 variant: a.companyLogoUrl ? 'secondary' : 'primary',
154 onClick: obj.open
155 }, a.companyLogoUrl ? __('Change Logo', 'blockenberg') : __('Upload Logo', 'blockenberg'));
156 }
157 }),
158 a.showCompanyLogo && a.companyLogoUrl && el(Button, {
159 variant: 'link',
160 isDestructive: true,
161 onClick: function () { setAttributes({ companyLogoUrl: '', companyLogoId: 0 }); }
162 }, __('Remove Logo', 'blockenberg')),
163 a.showCompanyLogo && el(RangeControl, {
164 label: __('Logo Width (px)', 'blockenberg'),
165 value: a.companyLogoWidth,
166 onChange: function (v) { setAttributes({ companyLogoWidth: v }); },
167 min: 40, max: 240
168 })
169 ),
170
171 el(PanelBody, { title: __('Style & Layout', 'blockenberg'), initialOpen: false },
172 el(SelectControl, {
173 label: __('Visual Style', 'blockenberg'),
174 value: a.style,
175 options: styleOptions,
176 onChange: function (v) { setAttributes({ style: v }); }
177 }),
178 el(RangeControl, {
179 label: __('Max Width (px)', 'blockenberg'),
180 value: a.maxWidth,
181 onChange: function (v) { setAttributes({ maxWidth: v }); },
182 min: 400, max: 1200
183 }),
184 el(RangeControl, {
185 label: __('Padding Top (px)', 'blockenberg'),
186 value: a.paddingTop,
187 onChange: function (v) { setAttributes({ paddingTop: v }); },
188 min: 0, max: 120
189 }),
190 el(RangeControl, {
191 label: __('Padding Bottom (px)', 'blockenberg'),
192 value: a.paddingBottom,
193 onChange: function (v) { setAttributes({ paddingBottom: v }); },
194 min: 0, max: 120
195 })
196 ),
197
198 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
199 _tc()({ label: __('Eyebrow', 'blockenberg'), value: a.typoEyebrow, onChange: function (v) { setAttributes({ typoEyebrow: v }); } }),
200 _tc()({ label: __('Quote', 'blockenberg'), value: a.typoQuote, onChange: function (v) { setAttributes({ typoQuote: v }); } }),
201 _tc()({ label: __('Name', 'blockenberg'), value: a.typoName, onChange: function (v) { setAttributes({ typoName: v }); } }),
202 _tc()({ label: __('Title', 'blockenberg'), value: a.typoTitle, onChange: function (v) { setAttributes({ typoTitle: v }); } }),
203 _tc()({ label: __('Signature', 'blockenberg'), value: a.typoSignature, onChange: function (v) { setAttributes({ typoSignature: v }); } })
204 ),
205
206 el(PanelColorSettings, {
207 title: __('Colors', 'blockenberg'),
208 initialOpen: false,
209 colorSettings: [
210 { value: a.quoteColor, onChange: function (v) { setAttributes({ quoteColor: v || '#1e293b' }); }, label: __('Quote Text', 'blockenberg') },
211 { value: a.nameColor, onChange: function (v) { setAttributes({ nameColor: v || '#0f172a' }); }, label: __('Name', 'blockenberg') },
212 { value: a.titleColor, onChange: function (v) { setAttributes({ titleColor: v || '#64748b' }); }, label: __('Title', 'blockenberg') },
213 { value: a.eyebrowColor, onChange: function (v) { setAttributes({ eyebrowColor: v || '#6c3fb5' }); }, label: __('Eyebrow', 'blockenberg') },
214 { value: a.accentColor, onChange: function (v) { setAttributes({ accentColor: v || '#6c3fb5' }); }, label: __('Accent / Quotation Marks', 'blockenberg') },
215 { value: a.bgColor, onChange: function (v) { setAttributes({ bgColor: v || '#ffffff' }); }, label: __('Background', 'blockenberg') },
216 { value: a.borderColor, onChange: function (v) { setAttributes({ borderColor: v || '#e2e8f0' }); }, label: __('Border / Divider', 'blockenberg') }
217 ]
218 })
219 );
220
221 var wrapClass = 'bkbg-fq-wrap bkbg-fq-style--' + a.style;
222 var blockProps = useBlockProps({ className: wrapClass, style: wrapStyle(a) });
223
224 // Photo element
225 var photoEl = null;
226 if (a.showPhoto) {
227 if (a.photoUrl) {
228 photoEl = el('img', { className: 'bkbg-fq-photo', src: a.photoUrl, alt: a.name || '' });
229 } else {
230 photoEl = el('div', { className: 'bkbg-fq-photo bkbg-fq-photo-placeholder' },
231 el('span', { className: 'dashicons dashicons-admin-users' })
232 );
233 }
234 }
235
236 // The attribution row (photo + name + title)
237 var attrEl = el('div', { className: 'bkbg-fq-attr' },
238 photoEl,
239 el('div', { className: 'bkbg-fq-attr-text' },
240 el('div', { className: 'bkbg-fq-name' }, a.name),
241 el('div', { className: 'bkbg-fq-title' },
242 a.title, a.company ? el('span', { className: 'bkbg-fq-company' }, ' · ' + a.company) : null
243 )
244 ),
245 a.showCompanyLogo && a.companyLogoUrl && el('img', {
246 className: 'bkbg-fq-company-logo',
247 src: a.companyLogoUrl,
248 alt: a.company || '',
249 style: { width: a.companyLogoWidth + 'px' }
250 })
251 );
252
253 return el(Fragment, {},
254 inspector,
255 el('div', blockProps,
256 el('div', { className: 'bkbg-fq-inner' },
257 a.showEyebrow && el('div', { className: 'bkbg-fq-eyebrow' }, a.eyebrow),
258 el('blockquote', { className: 'bkbg-fq-quote' },
259 el('span', { className: 'bkbg-fq-qq bkbg-fq-qq--open' }, '\u201C'),
260 el(RichText, {
261 tagName: 'p',
262 className: 'bkbg-fq-quote-text',
263 value: a.quote,
264 onChange: function (v) { setAttributes({ quote: v }); },
265 placeholder: __('Type your quote here…', 'blockenberg')
266 }),
267 el('span', { className: 'bkbg-fq-qq bkbg-fq-qq--close' }, '\u201D')
268 ),
269 a.showSignature && el('div', { className: 'bkbg-fq-signature' }, a.signature),
270 attrEl
271 )
272 )
273 );
274 },
275
276 save: function (props) {
277 var a = props.attributes;
278
279 var wrapClass = 'bkbg-fq-wrap bkbg-fq-style--' + a.style;
280 var blockProps = wp.blockEditor.useBlockProps.save({ className: wrapClass, style: wrapStyle(a) });
281
282 return el('div', blockProps,
283 el('div', { className: 'bkbg-fq-inner' },
284 a.showEyebrow && el('div', { className: 'bkbg-fq-eyebrow' }, a.eyebrow),
285 el('blockquote', { className: 'bkbg-fq-quote' },
286 el('span', { className: 'bkbg-fq-qq bkbg-fq-qq--open' }, '\u201C'),
287 el(RichText.Content, { tagName: 'p', className: 'bkbg-fq-quote-text', value: a.quote }),
288 el('span', { className: 'bkbg-fq-qq bkbg-fq-qq--close' }, '\u201D')
289 ),
290 a.showSignature && el('div', { className: 'bkbg-fq-signature' }, a.signature),
291 el('div', { className: 'bkbg-fq-attr' },
292 a.showPhoto && a.photoUrl && el('img', { className: 'bkbg-fq-photo', src: a.photoUrl, alt: a.name || '' }),
293 el('div', { className: 'bkbg-fq-attr-text' },
294 el('div', { className: 'bkbg-fq-name' }, a.name),
295 el('div', { className: 'bkbg-fq-title' },
296 a.title, a.company ? el('span', { className: 'bkbg-fq-company' }, ' · ' + a.company) : null
297 )
298 ),
299 a.showCompanyLogo && a.companyLogoUrl && el('img', {
300 className: 'bkbg-fq-company-logo',
301 src: a.companyLogoUrl,
302 alt: a.company || '',
303 style: { width: a.companyLogoWidth + 'px' }
304 })
305 )
306 )
307 );
308 }
309 });
310 }() );
311