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

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

143 lines 12.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 Fragment = wp.element.Fragment;
4 var __ = wp.i18n.__;
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 PanelBody = wp.components.PanelBody;
12 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
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
19 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
20 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
21
22 function buildWrapStyle(attr) {
23 var s = {
24 '--bkst-qt-sz': attr.quoteSize + 'px',
25 '--bkst-qt-w': attr.quoteFontWeight,
26 '--bkst-nm-sz': (attr.authorSize + 2) + 'px',
27 '--bkst-mt-sz': attr.authorSize + 'px',
28 };
29 var fn = getTypoCssVars();
30 if (fn) {
31 Object.assign(s, fn(attr.quoteTypo, '--bkst-qt'));
32 Object.assign(s, fn(attr.nameTypo, '--bkst-nm'));
33 Object.assign(s, fn(attr.metaTypo, '--bkst-mt'));
34 }
35 return s;
36 }
37
38 registerBlockType('blockenberg/split-testimonial', {
39 edit: function (props) {
40 var attr = props.attributes;
41 var setAttr = props.setAttributes;
42 var blockProps = useBlockProps({ className: 'bkbg-st-editor', style: buildWrapStyle(attr) });
43
44 var previewStyle = { background: attr.bgColor, padding: attr.paddingTop + 'px 40px ' + attr.paddingBottom + 'px', position: 'relative', overflow: 'hidden' };
45 var innerStyle = { maxWidth: attr.maxWidth + 'px', margin: '0 auto', display: 'grid', gridTemplateColumns: attr.layout === 'left-photo' ? '1fr 2fr' : '2fr 1fr', gap: 64, alignItems: 'center' };
46 var photoOrder = attr.layout === 'left-photo' ? 0 : 1;
47 var textOrder = attr.layout === 'left-photo' ? 1 : 0;
48
49 var avatarRadius = attr.avatarShape === 'circle' ? '50%' : attr.avatarShape === 'rounded' ? '20%' : '0';
50
51 return el(Fragment, null,
52 el(InspectorControls, null,
53 el(PanelBody, { title: __('Author', 'blockenberg'), initialOpen: true },
54 el(TextControl, { label: __('Name', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.authorName, onChange: function (v) { setAttr({ authorName: v }); } }),
55 el(TextControl, { label: __('Title', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.authorTitle, onChange: function (v) { setAttr({ authorTitle: v }); } }),
56 el(ToggleControl, { label: __('Show Company', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showCompany, onChange: function (v) { setAttr({ showCompany: v }); } }),
57 attr.showCompany && el(TextControl, { label: __('Company', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.authorCompany, onChange: function (v) { setAttr({ authorCompany: v }); } }),
58 el(ToggleControl, { label: __('Show Stars', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showStars, onChange: function (v) { setAttr({ showStars: v }); } }),
59 attr.showStars && el(RangeControl, { label: __('Star Rating', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.stars, min: 1, max: 5, onChange: function (v) { setAttr({ stars: v }); } })
60 ),
61 el(PanelBody, { title: __('Photo', 'blockenberg'), initialOpen: false },
62 el(MediaUploadCheck, null,
63 el(MediaUpload, {
64 onSelect: function (m) { setAttr({ authorImageUrl: m.url, authorImageId: m.id, authorAlt: m.alt || '' }); },
65 allowedTypes: ['image'], value: attr.authorImageId,
66 render: function (r) {
67 return el(Fragment, null,
68 attr.authorImageUrl && el('img', { src: attr.authorImageUrl, style: { width: 100, height: 100, borderRadius: avatarRadius, objectFit: 'cover', display: 'block', marginBottom: 8 } }),
69 el(Button, { onClick: r.open, variant: 'secondary', __nextHasNoMarginBottom: true }, attr.authorImageUrl ? __('Change Photo', 'blockenberg') : __('Select Photo', 'blockenberg')),
70 attr.authorImageUrl && el(Button, { onClick: function () { setAttr({ authorImageUrl: '', authorImageId: 0 }); }, variant: 'link', isDestructive: true, __nextHasNoMarginBottom: true, style: { marginLeft: 8 } }, __('Remove', 'blockenberg'))
71 );
72 }
73 })
74 ),
75 el(SelectControl, { label: __('Photo Shape', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.avatarShape,
76 options: [{ label: 'Circle', value: 'circle' }, { label: 'Rounded', value: 'rounded' }, { label: 'Square', value: 'square' }],
77 onChange: function (v) { setAttr({ avatarShape: v }); } }),
78 el(RangeControl, { label: __('Photo Size (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.avatarSize, min: 60, max: 300, onChange: function (v) { setAttr({ avatarSize: v }); } }),
79 el(SelectControl, { label: __('Layout', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.layout,
80 options: [{ label: 'Photo Left', value: 'left-photo' }, { label: 'Photo Right', value: 'right-photo' }],
81 onChange: function (v) { setAttr({ layout: v }); } })
82 ),
83 el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false },
84 el(ToggleControl, { label: __('Show Quote Mark', 'blockenberg'), __nextHasNoMarginBottom: true, checked: attr.showQuoteMark, onChange: function (v) { setAttr({ showQuoteMark: v }); } }),
85 el(RangeControl, { label: __('Author Size (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.authorSize, min: 12, max: 24, onChange: function (v) { setAttr({ authorSize: v }); } }),
86 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.maxWidth, min: 500, max: 1400, step: 10, onChange: function (v) { setAttr({ maxWidth: v }); } }),
87 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingTop, min: 0, max: 200, onChange: function (v) { setAttr({ paddingTop: v }); } }),
88 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), __nextHasNoMarginBottom: true, value: attr.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttr({ paddingBottom: v }); } })
89 ),
90
91 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
92 getTypoControl() ? el(getTypoControl(), { label:__('Quote','blockenberg'), value:attr.quoteTypo, onChange:function(v){ setAttr({quoteTypo:v}); } }) : null,
93 getTypoControl() ? el(getTypoControl(), { label:__('Author name','blockenberg'), value:attr.nameTypo, onChange:function(v){ setAttr({nameTypo:v}); } }) : null,
94 getTypoControl() ? el(getTypoControl(), { label:__('Author meta','blockenberg'), value:attr.metaTypo, onChange:function(v){ setAttr({metaTypo:v}); } }) : null
95 ),
96 el(PanelColorSettings, {
97 title: __('Colors', 'blockenberg'), initialOpen: false,
98 colorSettings: [
99 { value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#1e1b4b' }); }, label: __('Background', 'blockenberg') },
100 { value: attr.accentBg, onChange: function (v) { setAttr({ accentBg: v || '#7c3aed' }); }, label: __('Photo Accent BG', 'blockenberg') },
101 { value: attr.quoteColor, onChange: function (v) { setAttr({ quoteColor: v || '#ffffff' }); }, label: __('Quote Text', 'blockenberg') },
102 { value: attr.authorColor, onChange: function (v) { setAttr({ authorColor: v || '#c4b5fd' }); }, label: __('Author Text', 'blockenberg') },
103 { value: attr.starColor, onChange: function (v) { setAttr({ starColor: v || '#fbbf24' }); }, label: __('Stars', 'blockenberg') },
104 { value: attr.quoteMarkColor, onChange: function (v) { setAttr({ quoteMarkColor: v || 'rgba(124,58,237,.45)' }); }, label: __('Quote Mark', 'blockenberg') }
105 ]
106 })
107 ),
108 el('div', blockProps,
109 el('div', { style: previewStyle },
110 attr.showQuoteMark && el('div', { style: { position: 'absolute', top: 20, left: 40, fontSize: 200, lineHeight: 1, color: attr.quoteMarkColor, fontFamily: 'Georgia,serif', pointerEvents: 'none', userSelect: 'none' } }, '"'),
111 el('div', { style: innerStyle },
112 // Photo column
113 el('div', { style: { order: photoOrder, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 20 } },
114 el('div', { style: { width: attr.avatarSize + 'px', height: attr.avatarSize + 'px', borderRadius: avatarRadius, background: attr.accentBg, overflow: 'hidden', flexShrink: 0, boxShadow: '0 0 0 6px ' + attr.accentBg + '44' } },
115 attr.authorImageUrl
116 ? el('img', { src: attr.authorImageUrl, alt: attr.authorAlt, style: { width: '100%', height: '100%', objectFit: 'cover', display: 'block' } })
117 : el('div', { style: { width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'rgba(255,255,255,.6)', fontSize: 13 } }, __('Photo', 'blockenberg'))
118 ),
119 el('div', { style: { textAlign: 'center' } },
120 el('div', { className: 'bkbg-st-author-name', style: { color: '#ffffff' } }, attr.authorName),
121 el('div', { className: 'bkbg-st-author-meta', style: { color: attr.authorColor } }, attr.authorTitle + (attr.showCompany && attr.authorCompany ? ', ' + attr.authorCompany : ''))
122 )
123 ),
124 // Quote column
125 el('div', { style: { order: textOrder, display: 'flex', flexDirection: 'column', gap: 24 } },
126 attr.showStars && el('div', { style: { fontSize: 24, color: attr.starColor, letterSpacing: 2 } }, '�
127 '.repeat(attr.stars) + ''.repeat(5 - attr.stars)),
128 el(RichText, { tagName: 'blockquote', className: 'bkbg-st-quote', value: attr.quote, onChange: function (v) { setAttr({ quote: v }); }, style: { color: attr.quoteColor, margin: 0 }, placeholder: __('Enter the testimonial quote…', 'blockenberg') })
129 )
130 )
131 )
132 )
133 );
134 },
135 save: function (props) {
136 var attr = props.attributes;
137 return el('div', useBlockProps.save(),
138 el('div', { className: 'bkbg-split-testimonial-app', 'data-opts': JSON.stringify(attr) })
139 );
140 }
141 });
142 }() );
143