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 / payment-methods / index.js

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

311 lines 16.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 useBlockProps = wp.blockEditor.useBlockProps;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var PanelBody = wp.components.PanelBody;
10 var ToggleControl = wp.components.ToggleControl;
11 var RangeControl = wp.components.RangeControl;
12 var SelectControl = wp.components.SelectControl;
13 var TextControl = wp.components.TextControl;
14
15 var _tc, _tv;
16 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
17 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
18
19 /* ── Brand definitions ── */
20 var BRANDS = {
21 visa: { label: 'Visa', bg: '#1434CB', color: '#fff', text: 'VISA', font: 'italic', weight: '900', size: 15 },
22 mastercard: { label: 'Mastercard', bg: '#252525', color: '#fff', text: 'MC', font: 'normal', weight: '800', size: 14, circles: true },
23 amex: { label: 'Amex', bg: '#007BC1', color: '#fff', text: 'AMEX', font: 'normal', weight: '700', size: 12 },
24 paypal: { label: 'PayPal', bg: '#003087', color: '#009cde', text: 'PayPal', font: 'normal', weight: '800', size: 11 },
25 applepay: { label: 'Apple Pay', bg: '#000000', color: '#fff', text: ' Pay', font: 'normal', weight: '600', size: 11, prefix: '🍎' },
26 googlepay: { label: 'Google Pay', bg: '#ffffff', color: '#1a73e8', text: 'G Pay', font: 'normal', weight: '700', size: 12, border: '#dadce0' },
27 discover: { label: 'Discover', bg: '#231F20', color: '#F76F20', text: 'DISCOVER', font: 'normal', weight: '700', size: 9 },
28 stripe: { label: 'Stripe', bg: '#635BFF', color: '#fff', text: 'stripe', font: 'normal', weight: '700', size: 12 },
29 klarna: { label: 'Klarna', bg: '#FFB3C7', color: '#17120f', text: 'klarna', font: 'normal', weight: '700', size: 11 },
30 afterpay: { label: 'Afterpay', bg: '#B2FCE4', color: '#000', text: 'afterpay', font: 'normal', weight: '700', size: 9 },
31 amazonpay: { label: 'Amazon Pay', bg: '#232F3E', color: '#FF9900', text: 'amazon\npay',font: 'normal', weight: '700', size: 9 },
32 venmo: { label: 'Venmo', bg: '#3D95CE', color: '#fff', text: 'venmo', font: 'normal', weight: '700', size: 11 },
33 maestro: { label: 'Maestro', bg: '#fff', color: '#333', text: 'maestro', font: 'normal', weight: '600', size: 10, border: '#ccc' },
34 bitcoin: { label: 'Bitcoin', bg: '#F7931A', color: '#fff', text: '', font: 'normal', weight: '700', size: 20 },
35 shoppay: { label: 'Shop Pay', bg: '#5A31F4', color: '#fff', text: 'shop\npay', font: 'normal', weight: '700', size: 10 }
36 };
37
38 var BADGE_ICONS = {
39 ssl: '🔒',
40 pci: '🛡',
41 '256bit': '🔐',
42 shield: ''
43 };
44
45 /* ── Preview icon ── */
46 function BrandIcon(props) {
47 var id = props.id;
48 var size = props.size || 44;
49 var radius = props.radius || 8;
50 var bg = props.bg;
51 var border = props.border;
52 var b = BRANDS[id];
53 if (!b) return null;
54
55 var brd = border || b.border || 'none';
56 return el('div', {
57 title: b.label,
58 style: {
59 width: size * 1.6 + 'px',
60 height: size + 'px',
61 background: bg || b.bg,
62 border: brd === 'none' ? 'none' : '1px solid ' + brd,
63 borderRadius: radius + 'px',
64 display: 'inline-flex',
65 alignItems: 'center',
66 justifyContent: 'center',
67 flexShrink: 0,
68 flexDirection: 'column',
69 boxSizing: 'border-box'
70 }
71 },
72 el('span', {
73 style: {
74 color: b.color,
75 fontSize: b.size + 'px',
76 fontWeight: b.weight,
77 fontStyle: b.font === 'italic' ? 'italic' : 'normal',
78 fontFamily: b.font === 'italic' ? 'Georgia, serif' : 'system-ui, sans-serif',
79 lineHeight: '1.1',
80 textAlign: 'center',
81 whiteSpace: 'pre'
82 }
83 }, (b.prefix || '') + b.text)
84 );
85 }
86
87 /* ── Payment methods preview ── */
88 function PaymentPreview(props) {
89 var a = props.attributes;
90 var enabledMethods = (a.methods || []).filter(function (m) { return m.enabled; });
91
92 var justifyMap = { center: 'center', left: 'flex-start', right: 'flex-end' };
93 var justify = justifyMap[a.align] || 'center';
94
95 var icons = el('div', {
96 style: {
97 display: 'flex',
98 flexWrap: 'wrap',
99 gap: a.iconGap + 'px',
100 justifyContent: justify,
101 alignItems: 'center'
102 }
103 },
104 enabledMethods.length ? enabledMethods.map(function (m, idx) {
105 return el('div', { key: idx, style: { display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '4px' } },
106 el(BrandIcon, { id: m.id, size: a.iconSize, radius: a.iconRadius, bg: a.iconBg || undefined, border: a.iconBorder || undefined }),
107 a.showLabels && el('span', {
108 style: {
109 fontSize: '10px',
110 color: a.labelColor || '#6b7280',
111 textAlign: 'center'
112 }
113 }, (BRANDS[m.id] || {}).label || m.id)
114 );
115 }) : el('span', { style: { color: '#9ca3af', fontSize: '13px' } }, 'Enable payment methods in the sidebar')
116 );
117
118 var badges = a.showSecurityBadges && el('div', {
119 style: {
120 display: 'flex',
121 flexWrap: 'wrap',
122 gap: '12px',
123 justifyContent: justify,
124 alignItems: 'center',
125 marginTop: a.badgePosition === 'below' ? '12px' : '0'
126 }
127 },
128 (a.securityBadges || []).filter(function (b) { return b.enabled; }).map(function (badge, bi) {
129 return el('div', { key: bi, style: { display: 'flex', alignItems: 'center', gap: '4px' } },
130 el('span', null, BADGE_ICONS[badge.id] || '🔒'),
131 el('span', { className: 'bkbg-pmth-badge-text', style: { color: a.badgeColor || '#6b7280' } }, badge.label)
132 );
133 })
134 );
135
136 var outerStyle = {
137 paddingTop: (a.paddingTop || 0) + 'px',
138 paddingBottom: (a.paddingBottom || 0) + 'px',
139 background: a.bgColor || '',
140 maxWidth: a.maxWidth > 0 ? a.maxWidth + 'px' : '100%',
141 margin: '0 auto'
142 };
143
144 if (a.badgePosition === 'right' && a.showSecurityBadges) {
145 return el('div', { style: outerStyle },
146 el('div', { style: { display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '16px', justifyContent: justify } },
147 icons,
148 badges
149 )
150 );
151 }
152
153 return el('div', { style: outerStyle },
154 icons,
155 badges
156 );
157 }
158
159 registerBlockType('blockenberg/payment-methods', {
160 edit: function (props) {
161 var a = props.attributes;
162 var set = props.setAttributes;
163
164 var blockProps = useBlockProps((function(){
165 var s = { background: a.bgColor || '' };
166 var tv = getTypoCssVars();
167 if (tv) {
168 Object.assign(s, tv(a.badgeTypo || {}, '--bkbg-pmth-badge'));
169 }
170 return { style: s };
171 })());
172
173 /* ── Method toggles ── */
174 var methodToggles = (a.methods || []).map(function (m, idx) {
175 var b = BRANDS[m.id] || {};
176 return el(ToggleControl, {
177 key: m.id,
178 label: b.label || m.id,
179 checked: m.enabled,
180 onChange: function (v) {
181 var updated = a.methods.map(function (item, i) {
182 if (i !== idx) return item;
183 return Object.assign({}, item, { enabled: v });
184 });
185 set({ methods: updated });
186 },
187 __nextHasNoMarginBottom: true
188 });
189 });
190
191 /* ── Badge toggles + label edit ── */
192 var badgeControls = (a.securityBadges || []).map(function (badge, bi) {
193 return el('div', { key: badge.id, style: { borderBottom: '1px solid #e5e7eb', paddingBottom: '8px', marginBottom: '8px' } },
194 el(ToggleControl, {
195 label: BADGE_ICONS[badge.id] + ' ' + (badge.label || badge.id),
196 checked: badge.enabled,
197 onChange: function (v) {
198 var updated = a.securityBadges.map(function (item, i) {
199 if (i !== bi) return item;
200 return Object.assign({}, item, { enabled: v });
201 });
202 set({ securityBadges: updated });
203 },
204 __nextHasNoMarginBottom: true
205 }),
206 badge.enabled && el(TextControl, {
207 label: __('Badge Label', 'blockenberg'),
208 value: badge.label || '',
209 onChange: function (v) {
210 var updated = a.securityBadges.map(function (item, i) {
211 if (i !== bi) return item;
212 return Object.assign({}, item, { label: v });
213 });
214 set({ securityBadges: updated });
215 },
216 __nextHasNoMarginBottom: true
217 })
218 );
219 });
220
221 var inspector = el(InspectorControls, null,
222 el(PanelBody, { title: __('Payment Methods', 'blockenberg'), initialOpen: true },
223 el('p', { style: { fontSize: '11px', color: '#6b7280', marginBottom: '8px' } }, __('Toggle which payment brands to display.', 'blockenberg')),
224 methodToggles
225 ),
226
227 el(PanelBody, { title: __('Security Badges', 'blockenberg'), initialOpen: false },
228 el(ToggleControl, { label: __('Show Security Badges', 'blockenberg'), checked: a.showSecurityBadges, onChange: function (v) { set({ showSecurityBadges: v }); }, __nextHasNoMarginBottom: true }),
229 a.showSecurityBadges && el('div', { style: { marginTop: '8px' } }, badgeControls),
230 a.showSecurityBadges && el('div', { style: { marginTop: '8px' } },
231 el(SelectControl, {
232 label: __('Badge Position', 'blockenberg'),
233 value: a.badgePosition,
234 options: [
235 { value: 'below', label: 'Below icons' },
236 { value: 'right', label: 'Beside icons' }
237 ],
238 onChange: function (v) { set({ badgePosition: v }); },
239 __nextHasNoMarginBottom: true
240 })
241 ),
242 ),
243
244 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false },
245 el(SelectControl, {
246 label: __('Alignment', 'blockenberg'),
247 value: a.align,
248 options: [
249 { value: 'center', label: 'Center' },
250 { value: 'left', label: 'Left' },
251 { value: 'right', label: 'Right' }
252 ],
253 onChange: function (v) { set({ align: v }); },
254 __nextHasNoMarginBottom: true
255 }),
256 el(ToggleControl, { label: __('Show Brand Labels', 'blockenberg'), checked: a.showLabels, onChange: function (v) { set({ showLabels: v }); }, __nextHasNoMarginBottom: true }),
257 el('div', { style: { marginTop: '8px' } },
258 el(RangeControl, { label: __('Icon Size (px)', 'blockenberg'), value: a.iconSize, min: 24, max: 80, onChange: function (v) { set({ iconSize: v }); }, __nextHasNoMarginBottom: true })
259 ),
260 el('div', { style: { marginTop: '8px' } },
261 el(RangeControl, { label: __('Icon Corner Radius', 'blockenberg'), value: a.iconRadius, min: 0, max: 20, onChange: function (v) { set({ iconRadius: v }); }, __nextHasNoMarginBottom: true })
262 ),
263 el('div', { style: { marginTop: '8px' } },
264 el(RangeControl, { label: __('Gap Between Icons', 'blockenberg'), value: a.iconGap, min: 4, max: 32, onChange: function (v) { set({ iconGap: v }); }, __nextHasNoMarginBottom: true })
265 ),
266 el('div', { style: { marginTop: '8px' } },
267 el(RangeControl, { label: __('Max Width (0 = full)', 'blockenberg'), value: a.maxWidth, min: 0, max: 1200, step: 20, onChange: function (v) { set({ maxWidth: v }); }, __nextHasNoMarginBottom: true })
268 ),
269 el('div', { style: { marginTop: '8px' } },
270 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: a.paddingTop, min: 0, max: 120, step: 4, onChange: function (v) { set({ paddingTop: v }); }, __nextHasNoMarginBottom: true })
271 ),
272 el('div', { style: { marginTop: '8px' } },
273 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: a.paddingBottom, min: 0, max: 120, step: 4, onChange: function (v) { set({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
274 )
275 ),
276
277
278 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
279 (function(){ var C = getTypoControl(); return C ? [
280 el(C, { key: 'badge', label: __('Badge Text', 'blockenberg'), value: a.badgeTypo || {}, onChange: function(v){ set({badgeTypo: v}); } })
281 ] : null; })()
282 ),
283 el(PanelColorSettings, {
284 title: __('Colors', 'blockenberg'),
285 initialOpen: false,
286 colorSettings: [
287 { value: a.bgColor, onChange: function (v) { set({ bgColor: v }); }, label: __('Section Background', 'blockenberg') },
288 { value: a.iconBg, onChange: function (v) { set({ iconBg: v }); }, label: __('Icon Background Override', 'blockenberg') },
289 { value: a.iconBorder, onChange: function (v) { set({ iconBorder: v }); }, label: __('Icon Border Color', 'blockenberg') },
290 { value: a.labelColor, onChange: function (v) { set({ labelColor: v }); }, label: __('Label Color', 'blockenberg') },
291 { value: a.badgeColor, onChange: function (v) { set({ badgeColor: v }); }, label: __('Badge Text Color', 'blockenberg') }
292 ]
293 })
294 );
295
296 return el(Fragment, null,
297 inspector,
298 el('div', blockProps,
299 el(PaymentPreview, { attributes: a })
300 )
301 );
302 },
303
304 save: function (props) {
305 return el('div', useBlockProps.save(),
306 el('div', { className: 'bkbg-pmth-app', 'data-opts': JSON.stringify(props.attributes) })
307 );
308 }
309 });
310 }() );
311