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 / affiliate-disclosure / index.js

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

160 lines 9.8 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 __ = wp.i18n.__;
4 var registerBlockType = wp.blocks.registerBlockType;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var useBlockProps = wp.blockEditor.useBlockProps;
7 var RichText = wp.blockEditor.RichText;
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 var Fragment = wp.element.Fragment;
15
16 // Lazy lookup so the typography control is resolved at render time
17 function getTypographyControl() {
18 return (typeof window.bkbgTypographyControl !== 'undefined') ? window.bkbgTypographyControl : null;
19 }
20 function getTypoCssVars() {
21 return (typeof window.bkbgTypoCssVars !== 'undefined') ? window.bkbgTypoCssVars : function() { return {}; };
22 }
23
24 registerBlockType('blockenberg/affiliate-disclosure', {
25 edit: function (props) {
26 var attr = props.attributes;
27 var set = props.setAttributes;
28
29 var blockProps = useBlockProps();
30
31 /* Compute wrapper style from style attribute */
32 var wrapStyle = {
33 display: 'flex', alignItems: 'flex-start', gap: '12px',
34 borderRadius: attr.borderRadius + 'px',
35 background: attr.bgColor, borderColor: attr.borderColor
36 };
37 if (attr.style === 'banner') {
38 wrapStyle.borderTop = '3px solid ' + attr.accentColor;
39 wrapStyle.borderLeft = 'none';
40 wrapStyle.padding = '14px 18px';
41 wrapStyle.border = '1px solid ' + attr.borderColor;
42 wrapStyle.borderTop = '3px solid ' + attr.accentColor;
43 } else if (attr.style === 'left-bar') {
44 wrapStyle.borderLeft = '4px solid ' + attr.accentColor;
45 wrapStyle.padding = '12px 16px';
46 wrapStyle.borderRadius = '0 ' + attr.borderRadius + 'px ' + attr.borderRadius + 'px 0';
47 } else if (attr.style === 'box') {
48 wrapStyle.border = '2px solid ' + attr.borderColor;
49 wrapStyle.padding = '16px 20px';
50 } else { /* minimal */
51 wrapStyle.background = 'transparent';
52 wrapStyle.border = 'none';
53 wrapStyle.padding = '8px 0';
54 wrapStyle.borderRadius = '0';
55 }
56
57 var controls = el(InspectorControls, {},
58 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
59 el(TextControl, {
60 label: __('Icon (emoji)', 'blockenberg'), value: attr.icon, __nextHasNoMarginBottom: true,
61 onChange: function (v) { set({ icon: v }); }
62 }),
63 el('div', { style: { marginTop: '12px' } },
64 el(ToggleControl, { label: __('Show Icon', 'blockenberg'), checked: attr.showIcon, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showIcon: v }); } })
65 ),
66 el('div', { style: { marginTop: '12px' } },
67 el(TextControl, {
68 label: __('Label (bold prefix)', 'blockenberg'), value: attr.label, __nextHasNoMarginBottom: true,
69 onChange: function (v) { set({ label: v }); }
70 })
71 ),
72 el('div', { style: { marginTop: '8px' } },
73 el(ToggleControl, { label: __('Show Label', 'blockenberg'), checked: attr.showLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showLabel: v }); } })
74 ),
75 el('div', { style: { marginTop: '12px' } },
76 el(ToggleControl, { label: __('Collapsible', 'blockenberg'), checked: attr.collapsible, __nextHasNoMarginBottom: true, onChange: function (v) { set({ collapsible: v }); } })
77 ),
78 el('div', { style: { marginTop: '12px' } },
79 el(ToggleControl, { label: __('Show Policy Link', 'blockenberg'), checked: attr.showLink, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showLink: v }); } })
80 ),
81 attr.showLink && el('div', { style: { marginTop: '8px' } },
82 el(TextControl, { label: __('Link Text', 'blockenberg'), value: attr.linkText, __nextHasNoMarginBottom: true, onChange: function (v) { set({ linkText: v }); } }),
83 el('div', { style: { marginTop: '8px' } },
84 el(TextControl, { label: __('Link URL', 'blockenberg'), value: attr.linkUrl, __nextHasNoMarginBottom: true, onChange: function (v) { set({ linkUrl: v }); } })
85 )
86 )
87 ),
88 el(PanelBody, { title: __('Style', 'blockenberg'), initialOpen: false },
89 el(SelectControl, {
90 label: __('Visual Style', 'blockenberg'), value: attr.style, __nextHasNoMarginBottom: true,
91 options: [
92 { label: 'Banner (top accent border)', value: 'banner' },
93 { label: 'Left Bar (left accent)', value: 'left-bar' },
94 { label: 'Box (solid border)', value: 'box' },
95 { label: 'Minimal (no background)', value: 'minimal' }
96 ],
97 onChange: function (v) { set({ style: v }); }
98 }),
99 el('div', { style: { marginTop: '12px' } },
100 el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 20, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } })
101 )
102 ),
103 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
104 (function () {
105 var TC = getTypographyControl();
106 if (!TC) return el('p', { style: { color: '#999', fontSize: '12px', padding: '8px 0' } }, __('Typography control loading…', 'blockenberg'));
107 return el(Fragment, {},
108 el(TC, { label: __('Text', 'blockenberg'), value: attr.textTypo || {}, onChange: function (v) { set({ textTypo: v }); } }),
109 el(RangeControl, { label: __('Icon Size (px)', 'blockenberg'), value: attr.iconFontSize, min: 12, max: 32, __nextHasNoMarginBottom: true, onChange: function (v) { set({ iconFontSize: v }); } })
110 );
111 })()
112 ),
113 el(PanelColorSettings, {
114 title: __('Colors', 'blockenberg'), initialOpen: false,
115 colorSettings: [
116 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#fffbeb' }); } },
117 { label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#fcd34d' }); } },
118 { label: __('Accent (top/left bar)', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#d97706' }); } },
119 { label: __('Text', 'blockenberg'), value: attr.textColor, onChange: function (v) { set({ textColor: v || '#78350f' }); } },
120 { label: __('Label', 'blockenberg'), value: attr.labelColor, onChange: function (v) { set({ labelColor: v || '#92400e' }); } },
121 { label: __('Link', 'blockenberg'), value: attr.linkColor, onChange: function (v) { set({ linkColor: v || '#d97706' }); } }
122 ]
123 })
124 );
125
126 return el('div', blockProps,
127 controls,
128 el('div', { className: 'bkbg-afd-wrap bkbg-afd-' + attr.style, style: (function () {
129 var s = Object.assign({}, wrapStyle, {
130 '--bkbg-afd-text-sz': (attr.textFontSize || 13) + 'px'
131 });
132 var _tv = getTypoCssVars();
133 Object.assign(s, _tv(attr.textTypo || {}, '--bkbg-afd-text-'));
134 return s;
135 })() },
136 attr.showIcon && el('span', { className: 'bkbg-afd-icon', style: { fontSize: (attr.iconFontSize || 18) + 'px', flexShrink: 0, marginTop: '1px' } }, attr.icon),
137 el('div', { className: 'bkbg-afd-body', style: { flex: 1 } },
138 el('div', { style: { color: attr.textColor } },
139 attr.showLabel && el('strong', { style: { color: attr.labelColor, marginRight: '4px' } }, attr.label + ':'),
140 el(RichText, {
141 tagName: 'span', value: attr.text, placeholder: __('Disclosure text…', 'blockenberg'),
142 style: { color: attr.textColor },
143 onChange: function (v) { set({ text: v }); }
144 })
145 ),
146 attr.showLink && el('a', { href: '#', style: { display: 'block', marginTop: '6px', fontSize: '12px', color: attr.linkColor, textDecoration: 'underline' } }, attr.linkText)
147 )
148 )
149 );
150 },
151 save: function (props) {
152 var attr = props.attributes;
153 var useBlockProps = wp.blockEditor.useBlockProps;
154 return el('div', useBlockProps.save(),
155 el('div', { className: 'bkbg-afd-app', 'data-opts': JSON.stringify(attr) })
156 );
157 }
158 });
159 }() );
160