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 / dark-hero / index.js

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

269 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* ====================================================
2 Dark Hero — editor (index.js)
3 Block: blockenberg/dark-hero
4 ==================================================== */
5 ( function () {
6 var el = wp.element.createElement;
7 var useState = wp.element.useState;
8 var Fragment = wp.element.Fragment;
9 var RichText = wp.blockEditor.RichText;
10 var registerBlockType = wp.blocks.registerBlockType;
11 var InspectorControls = wp.blockEditor.InspectorControls;
12 var useBlockProps = wp.blockEditor.useBlockProps;
13 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
14 var PanelBody = wp.components.PanelBody;
15 var RangeControl = wp.components.RangeControl;
16 var SelectControl = wp.components.SelectControl;
17 var ToggleControl = wp.components.ToggleControl;
18 var TextControl = wp.components.TextControl;
19 var ColorPicker = wp.components.ColorPicker;
20 var Popover = wp.components.Popover;
21 var Button = wp.components.Button;
22 var __ = wp.i18n.__;
23
24 var _dhTC, _dhTV;
25 function _tc() { return _dhTC || (_dhTC = window.bkbgTypographyControl); }
26 function _tv(obj, prefix) { var fn = _dhTV || (_dhTV = window.bkbgTypoCssVars); return fn ? fn(obj, prefix) : {}; }
27
28 function uid() { return Math.random().toString(36).slice(2,9); }
29
30 var BG_PRESETS = {
31 'dark-purple': '#0d0a1e',
32 'dark-blue': '#060c1f',
33 'dark-gray': '#0a0a0a',
34 'dark-green': '#060f0d',
35 'dark-rose': '#120810',
36 'custom': null,
37 };
38
39 function getBg(a) {
40 return a.bgStyle === 'custom' ? (a.customBg || '#0a0a0f') : (BG_PRESETS[a.bgStyle] || '#0d0a1e');
41 }
42
43 function headlineStyle(a) {
44 if (a.headlineStyle === 'gradient') {
45 return {
46 backgroundImage: 'linear-gradient(' + a.gradientAngle + 'deg,' + a.gradientFrom + ',' + a.gradientTo + ')',
47 WebkitBackgroundClip: 'text',
48 WebkitTextFillColor: 'transparent',
49 backgroundClip: 'text',
50 color: 'transparent',
51 display: 'inline-block',
52 };
53 }
54 if (a.headlineStyle === 'white') return { color: '#ffffff' };
55 return { color: a.gradientFrom };
56 }
57
58 function wrapStyle(a) {
59 var s = {
60 background: getBg(a),
61 '--bkbg-dh-pt': a.paddingTop + 'px',
62 '--bkbg-dh-pb': a.paddingBottom + 'px',
63 '--bkbg-dh-mh': a.minHeight + 'px',
64 '--bkbg-dh-mw': a.contentMaxWidth + 'px',
65 '--bkbg-dh-sub-c': a.subtitleColor,
66 '--bkbg-dh-primary-bg': a.primaryBg,
67 '--bkbg-dh-primary-c': a.primaryColor,
68 '--bkbg-dh-glow-c': a.glowColor,
69 '--bkbg-dh-glow-sz': a.glowSize + 'px',
70 '--bkbg-dh-r': a.btnRadius + 'px',
71 '--bkbg-dh-stats-c': a.statsColor,
72 /* legacy fallback vars */
73 '--bkbg-dh-hl-sz': a.headingSize + 'px',
74 '--bkbg-dh-sub-sz': a.subtitleSize + 'px',
75 };
76 Object.assign(s, _tv(a.typoHeading || {}, '--bkbg-dh-hdg-'));
77 Object.assign(s, _tv(a.typoSubtitle || {}, '--bkbg-dh-sub2-'));
78 return s;
79 }
80
81 /* ── colour-swatch + popover ─────────────────────────────── */
82 function BkbgColorSwatch(p) {
83 var st = useState(false);
84 var open = st[0], setOpen = st[1];
85 return el('div', { style:{ display:'flex', alignItems:'center', justifyContent:'space-between', padding:'4px 0', gap:'8px' } },
86 el('span', { style:{ fontSize:'12px', color:'#1e1e1e', flex:1, lineHeight:1.4 } }, p.label),
87 el('div', { style:{ position:'relative', flexShrink:0 } },
88 el('button', {
89 type:'button', title: p.value || 'none',
90 onClick: function(){ setOpen(!open); },
91 style:{ width:'28px', height:'28px', borderRadius:'4px',
92 border: open ? '2px solid #007cba' : '2px solid #ddd',
93 cursor:'pointer', padding:0, display:'block',
94 background: p.value || '#ffffff', flexShrink:0 }
95 }),
96 open && el(Popover, { position:'bottom left', onClose:function(){ setOpen(false); } },
97 el('div', { style:{ padding:'8px' }, onMouseDown:function(e){ e.stopPropagation(); } },
98 el('div', { style:{ display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:'6px' } },
99 el('strong', { style:{ fontSize:'12px' } }, p.label),
100 el(Button, { icon:'no-alt', isSmall:true, onClick:function(){ setOpen(false); } })
101 ),
102 el(ColorPicker, { color: p.value, enableAlpha:true, onChange: p.onChange })
103 )
104 )
105 )
106 );
107 }
108
109 registerBlockType('blockenberg/dark-hero', {
110 edit: function (props) {
111 var a = props.attributes;
112 var setAttr = props.setAttributes;
113
114 function updateStat(idx, patch) {
115 var arr = a.stats.map(function(s,i){ return i===idx ? Object.assign({},s,patch) : s; });
116 setAttr({ stats: arr });
117 }
118 function deleteStat(idx) { setAttr({ stats: a.stats.filter(function(_,i){ return i!==idx; }) }); }
119 function addStat() { setAttr({ stats: a.stats.concat([{id:uid(), value:'0', label:'Label'}]) }); }
120
121 var blockProps = useBlockProps({
122 className: 'bkbg-dh-wrap bkbg-dh-align--' + a.textAlign,
123 style: wrapStyle(a)
124 });
125
126 var inspector = el(InspectorControls, null,
127 el(PanelBody, { title:__('Content','blockenberg'), initialOpen:true },
128 el(ToggleControl, { label:__('Show badge','blockenberg'), checked:a.showBadge, onChange:function(v){ setAttr({showBadge:v}); } }),
129 el(TextControl, { label:__('Badge text','blockenberg'), value:a.badgeText, onChange:function(v){ setAttr({badgeText:v}); } }),
130 el(SelectControl, { label:__('Badge style','blockenberg'), value:a.badgeStyle, options:[{label:'Glow pill',value:'glow'},{label:'Border pill',value:'border'},{label:'Subtle',value:'subtle'}], onChange:function(v){ setAttr({badgeStyle:v}); } }),
131 el(ToggleControl, { label:__('Show subtitle','blockenberg'), checked:a.showSubtitle, onChange:function(v){ setAttr({showSubtitle:v}); } }),
132 el(TextControl, { label:__('Primary button','blockenberg'), value:a.primaryLabel, onChange:function(v){ setAttr({primaryLabel:v}); } }),
133 el(TextControl, { label:__('Primary URL','blockenberg'), value:a.primaryUrl, onChange:function(v){ setAttr({primaryUrl:v}); } }),
134 el(ToggleControl, { label:__('Show secondary button','blockenberg'), checked:a.showSecondary, onChange:function(v){ setAttr({showSecondary:v}); } }),
135 el(TextControl, { label:__('Secondary button','blockenberg'), value:a.secondaryLabel, onChange:function(v){ setAttr({secondaryLabel:v}); } }),
136 el(TextControl, { label:__('Secondary URL','blockenberg'), value:a.secondaryUrl, onChange:function(v){ setAttr({secondaryUrl:v}); } })
137 ),
138 el(PanelBody, { title:__('Stats','blockenberg'), initialOpen:false },
139 el(ToggleControl, { label:__('Show stats row','blockenberg'), checked:a.showStats, onChange:function(v){ setAttr({showStats:v}); } }),
140 a.stats.map(function(s, i) {
141 return el('div', { key:s.id, style:{ display:'flex', gap:6, marginBottom:8 } },
142 el(TextControl, { value:s.value, onChange:function(v){ updateStat(i,{value:v}); }, placeholder:'Value' }),
143 el(TextControl, { value:s.label, onChange:function(v){ updateStat(i,{label:v}); }, placeholder:'Label' }),
144 el(Button, { isSmall:true, isDestructive:true, onClick:function(){ deleteStat(i); } }, '')
145 );
146 }),
147 el(Button, { isSmall:true, variant:'tertiary', onClick:addStat, style:{marginTop:4} }, __('+ Add stat','blockenberg'))
148 ),
149 el(PanelBody, { title:__('Background & Effects','blockenberg'), initialOpen:false },
150 el(SelectControl, { label:__('Background preset','blockenberg'), value:a.bgStyle, options:[
151 {label:'Dark purple',value:'dark-purple'},
152 {label:'Dark blue', value:'dark-blue'},
153 {label:'Dark gray', value:'dark-gray'},
154 {label:'Dark green', value:'dark-green'},
155 {label:'Dark rose', value:'dark-rose'},
156 {label:'Custom', value:'custom'},
157 ], onChange:function(v){ setAttr({bgStyle:v}); } }),
158 a.bgStyle === 'custom' ? el(BkbgColorSwatch, { label:__('Custom background color','blockenberg'), value:a.customBg, onChange:function(v){ setAttr({customBg:v}); } }) : null,
159 el(ToggleControl, { label:__('Radial glow','blockenberg'), checked:a.showGlow, onChange:function(v){ setAttr({showGlow:v}); } }),
160 el(ToggleControl, { label:__('Grid lines','blockenberg'), checked:a.showGrid, onChange:function(v){ setAttr({showGrid:v}); } }),
161 el(ToggleControl, { label:__('Noise texture','blockenberg'), checked:a.showNoise, onChange:function(v){ setAttr({showNoise:v}); } }),
162 el(RangeControl, { label:__('Glow size (px)','blockenberg'), value:a.glowSize, min:100, max:1200, onChange:function(v){ setAttr({glowSize:v}); } })
163 ),
164 el(PanelBody, { title:__('Headline style','blockenberg'), initialOpen:false },
165 el(SelectControl, { label:__('Style','blockenberg'), value:a.headlineStyle, options:[{label:'Gradient text',value:'gradient'},{label:'White',value:'white'},{label:'Custom color',value:'custom'}], onChange:function(v){ setAttr({headlineStyle:v}); } }),
166 el(BkbgColorSwatch, { label:__('Gradient from','blockenberg'), value:a.gradientFrom, onChange:function(v){ setAttr({gradientFrom:v}); } }),
167 el(BkbgColorSwatch, { label:__('Gradient to','blockenberg'), value:a.gradientTo, onChange:function(v){ setAttr({gradientTo:v}); } }),
168 el(RangeControl, { label:__('Gradient angle','blockenberg'), value:a.gradientAngle, min:0, max:360, onChange:function(v){ setAttr({gradientAngle:v}); } }),
169 el(SelectControl, { label:__('Text align','blockenberg'), value:a.textAlign, options:[{label:'Center',value:'center'},{label:'Left',value:'left'}], onChange:function(v){ setAttr({textAlign:v}); } })
170 ),
171 el(PanelBody, { title:__('Typography','blockenberg'), initialOpen:false },
172 _tc() && el(_tc(), { label:__('Heading','blockenberg'), value:a.typoHeading, onChange:function(v){ setAttr({typoHeading:v}); } }),
173 _tc() && el(_tc(), { label:__('Subtitle','blockenberg'), value:a.typoSubtitle, onChange:function(v){ setAttr({typoSubtitle:v}); } })
174 ),
175 el(PanelBody, { title:__('Appearance','blockenberg'), initialOpen:false },
176 el(RangeControl, { label:__('Min height (px)','blockenberg'), value:a.minHeight, min:300, max:1000, onChange:function(v){ setAttr({minHeight:v}); } }),
177 el(RangeControl, { label:__('Content max width (px)','blockenberg'), value:a.contentMaxWidth, min:400, max:1100, onChange:function(v){ setAttr({contentMaxWidth:v}); } }),
178 el(RangeControl, { label:__('Button radius (px)','blockenberg'), value:a.btnRadius, min:0, max:50, onChange:function(v){ setAttr({btnRadius:v}); } })
179 ),
180 el(PanelBody, { title:__('Spacing','blockenberg'), initialOpen:false },
181 el(RangeControl, { label:__('Padding top (px)','blockenberg'), value:a.paddingTop, min:0, max:240, onChange:function(v){ setAttr({paddingTop:v}); } }),
182 el(RangeControl, { label:__('Padding bottom (px)','blockenberg'), value:a.paddingBottom, min:0, max:240, onChange:function(v){ setAttr({paddingBottom:v}); } })
183 ),
184 el(PanelColorSettings, { title:__('Colors','blockenberg'), initialOpen:false, colorSettings:[
185 {label:__('Glow color','blockenberg'), value:a.glowColor, onChange:function(v){ setAttr({glowColor:v||''}); }},
186 {label:__('Subtitle','blockenberg'), value:a.subtitleColor,onChange:function(v){ setAttr({subtitleColor:v||''}); }},
187 {label:__('Primary button bg','blockenberg'),value:a.primaryBg, onChange:function(v){ setAttr({primaryBg:v||''}); }},
188 {label:__('Primary button text','blockenberg'),value:a.primaryColor,onChange:function(v){ setAttr({primaryColor:v||''}); }},
189 {label:__('Stats text','blockenberg'), value:a.statsColor, onChange:function(v){ setAttr({statsColor:v||''}); }},
190 ] })
191 );
192
193 return el(Fragment, null,
194 inspector,
195 el('div', blockProps,
196 a.showGlow ? el('div', { className:'bkbg-dh-glow' }) : null,
197 a.showGrid ? el('div', { className:'bkbg-dh-grid' }) : null,
198 a.showNoise ? el('div', { className:'bkbg-dh-noise' }) : null,
199 el('div', { className:'bkbg-dh-inner' },
200 a.showBadge ? el('div', { className:'bkbg-dh-badge bkbg-dh-badge--' + a.badgeStyle },
201 el('span', { className:'bkbg-dh-badge-dot' }),
202 a.badgeText
203 ) : null,
204 el(RichText, { tagName:'h1', className:'bkbg-dh-headline', value:a.headline,
205 style: headlineStyle(a),
206 onChange:function(v){ setAttr({headline:v}); },
207 placeholder:__('Your headline…','blockenberg')
208 }),
209 a.showSubtitle ? el(RichText, { tagName:'p', className:'bkbg-dh-subtitle', value:a.subtitle, onChange:function(v){ setAttr({subtitle:v}); }, placeholder:__('Subtitle…','blockenberg') }) : null,
210 el('div', { className:'bkbg-dh-buttons' },
211 el('a', { href:'#', className:'bkbg-dh-btn bkbg-dh-btn--primary', onClick:function(e){ e.preventDefault(); } }, a.primaryLabel),
212 a.showSecondary ? el('a', { href:'#', className:'bkbg-dh-btn bkbg-dh-btn--ghost', onClick:function(e){ e.preventDefault(); } }, a.secondaryLabel, el('span', null,'')) : null
213 ),
214 a.showStats && a.stats.length ? el('div', { className:'bkbg-dh-stats' },
215 a.stats.map(function(s) {
216 return el('div', { key:s.id, className:'bkbg-dh-stat' },
217 el('span', { className:'bkbg-dh-stat-value' }, s.value),
218 el('span', { className:'bkbg-dh-stat-label' }, s.label)
219 );
220 })
221 ) : null
222 )
223 )
224 );
225 },
226
227 save: function (props) {
228 var a = props.attributes;
229 var blockProps = wp.blockEditor.useBlockProps.save({
230 className: 'bkbg-dh-wrap bkbg-dh-align--' + a.textAlign,
231 style: wrapStyle(a)
232 });
233 return el('div', blockProps,
234 a.showGlow ? el('div', { className:'bkbg-dh-glow' }) : null,
235 a.showGrid ? el('div', { className:'bkbg-dh-grid' }) : null,
236 a.showNoise ? el('div', { className:'bkbg-dh-noise' }) : null,
237 el('div', { className:'bkbg-dh-inner' },
238 a.showBadge ? el('div', { className:'bkbg-dh-badge bkbg-dh-badge--' + a.badgeStyle },
239 el('span', { className:'bkbg-dh-badge-dot' }),
240 a.badgeText
241 ) : null,
242 el(RichText.Content, { tagName:'h1', className:'bkbg-dh-headline', value:a.headline,
243 style: {
244 backgroundImage: a.headlineStyle === 'gradient' ? 'linear-gradient(' + a.gradientAngle + 'deg,' + a.gradientFrom + ',' + a.gradientTo + ')' : undefined,
245 WebkitBackgroundClip: a.headlineStyle === 'gradient' ? 'text' : undefined,
246 WebkitTextFillColor: a.headlineStyle === 'gradient' ? 'transparent' : undefined,
247 backgroundClip: a.headlineStyle === 'gradient' ? 'text' : undefined,
248 color: a.headlineStyle !== 'gradient' ? (a.headlineStyle === 'white' ? '#fff' : a.gradientFrom) : undefined,
249 }
250 }),
251 a.showSubtitle ? el(RichText.Content, { tagName:'p', className:'bkbg-dh-subtitle', value:a.subtitle }) : null,
252 el('div', { className:'bkbg-dh-buttons' },
253 el('a', { href:a.primaryUrl, className:'bkbg-dh-btn bkbg-dh-btn--primary', target:a.primaryTarget, rel:a.primaryTarget==='_blank'?'noopener noreferrer':undefined }, a.primaryLabel),
254 a.showSecondary ? el('a', { href:a.secondaryUrl, className:'bkbg-dh-btn bkbg-dh-btn--ghost', target:a.secondaryTarget, rel:a.secondaryTarget==='_blank'?'noopener noreferrer':undefined }, a.secondaryLabel, el('span', null,'')) : null
255 ),
256 a.showStats && a.stats.length ? el('div', { className:'bkbg-dh-stats' },
257 a.stats.map(function(s) {
258 return el('div', { key:s.id, className:'bkbg-dh-stat' },
259 el('span', { className:'bkbg-dh-stat-value' }, s.value),
260 el('span', { className:'bkbg-dh-stat-label' }, s.label)
261 );
262 })
263 ) : null
264 )
265 );
266 }
267 });
268 }() );
269