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 / number-box / index.js

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

208 lines 9.6 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 RichText = wp.blockEditor.RichText;
7 var PanelBody = wp.components.PanelBody;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var SelectControl = wp.components.SelectControl;
10 var ToggleControl = wp.components.ToggleControl;
11 var RangeControl = wp.components.RangeControl;
12 var TextControl = wp.components.TextControl;
13 var useBlockProps = wp.blockEditor.useBlockProps;
14
15 var _tc, _tv;
16 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
17 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
18
19 registerBlockType( 'blockenberg/number-box', {
20 edit: function ( props ) {
21 var attrs = props.attributes;
22 var setAttr = props.setAttributes;
23 var radius = attrs.shape === 'circle' ? '50%' : attrs.borderRadius + 'px';
24
25 var blockProps = useBlockProps((function () {
26 var _tvf = getTypoCssVars();
27 var s = {};
28 if (_tvf) { Object.assign(s, _tvf(attrs.numberTypo, '--bknb-num-')); Object.assign(s, _tvf(attrs.labelTypo, '--bknb-lbl-')); }
29 return { style: s };
30 })());
31
32 var wrapStyle = {
33 '--bknb-bg': attrs.bgColor,
34 '--bknb-text': attrs.textColor,
35 '--bknb-label': attrs.labelColor || attrs.textColor,
36 '--bknb-numSz': attrs.numberSz + 'px',
37 '--bknb-numFw': attrs.numberFontWeight || 700,
38 '--bknb-labelSz': attrs.labelSz + 'px',
39 '--bknb-labelFw': attrs.labelFontWeight || 500,
40 '--bknb-lh': attrs.lineHeight || 1.2,
41 '--bknb-size': attrs.boxSize + 'px',
42 '--bknb-radius': radius,
43 '--bknb-brd': attrs.border ? attrs.borderWidth + 'px solid ' + attrs.borderColor : 'none',
44 '--bknb-shadow': attrs.shadow ? '0 8px 32px rgba(0,0,0,.18)' : 'none'
45 };
46
47 return el( 'div', blockProps,
48 el( InspectorControls, null,
49 el( PanelBody, { title: __( 'Content', 'blockenberg' ), initialOpen: true },
50 el( TextControl, {
51 label: __( 'Prefix', 'blockenberg' ),
52 value: attrs.prefix,
53 onChange: function (v) { setAttr({ prefix: v }); }
54 } ),
55 el( TextControl, {
56 label: __( 'Suffix', 'blockenberg' ),
57 value: attrs.suffix,
58 onChange: function (v) { setAttr({ suffix: v }); }
59 } )
60 ),
61 el( PanelBody, { title: __( 'Style', 'blockenberg' ), initialOpen: false },
62 el( SelectControl, {
63 label: __( 'Shape', 'blockenberg' ),
64 value: attrs.shape,
65 options: [
66 { label: 'Square', value: 'square' },
67 { label: 'Circle', value: 'circle' }
68 ],
69 onChange: function (v) { setAttr({ shape: v }); }
70 } ),
71 el( RangeControl, {
72 label: __( 'Box Size (px)', 'blockenberg' ),
73 value: attrs.boxSize, min: 80, max: 320,
74 onChange: function (v) { setAttr({ boxSize: v }); }
75 } ),
76 attrs.shape !== 'circle' && el( RangeControl, {
77 label: __( 'Border Radius (px)', 'blockenberg' ),
78 value: attrs.borderRadius, min: 0, max: 60,
79 onChange: function (v) { setAttr({ borderRadius: v }); }
80 } ),
81 el( ToggleControl, {
82 label: __( 'Box Shadow', 'blockenberg' ),
83 checked: attrs.shadow,
84 onChange: function (v) { setAttr({ shadow: v }); },
85 __nextHasNoMarginBottom: true
86 } ),
87 el( ToggleControl, {
88 label: __( 'Border', 'blockenberg' ),
89 checked: attrs.border,
90 onChange: function (v) { setAttr({ border: v }); },
91 __nextHasNoMarginBottom: true
92 } ),
93 attrs.border && el( RangeControl, {
94 label: __( 'Border Width (px)', 'blockenberg' ),
95 value: attrs.borderWidth, min: 1, max: 8,
96 onChange: function (v) { setAttr({ borderWidth: v }); }
97 } )
98 ),
99
100 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
101 el( getTypoControl(), { label: __( 'Number Typography', 'blockenberg' ), value: attrs.numberTypo, onChange: function (v) { setAttr({ numberTypo: v }); } } ),
102 el( getTypoControl(), { label: __( 'Label Typography', 'blockenberg' ), value: attrs.labelTypo, onChange: function (v) { setAttr({ labelTypo: v }); } } )
103 ),
104 el( PanelBody, { title: __( 'Colors', 'blockenberg' ), initialOpen: false },
105 el( PanelColorSettings, {
106 title: __( 'Colors', 'blockenberg' ),
107 colorSettings: [
108 { value: attrs.bgColor, onChange: function(v){setAttr({bgColor:v||'#6c3fb5'});}, label: __('Background') },
109 { value: attrs.textColor, onChange: function(v){setAttr({textColor:v||'#ffffff'});}, label: __('Number & Text') },
110 { value: attrs.labelColor, onChange: function(v){setAttr({labelColor:v||''});}, label: __('Label (override)') },
111 { value: attrs.borderColor, onChange: function(v){setAttr({borderColor:v||'#e0d7f8'});}, label: __('Border') }
112 ]
113 } )
114 )
115 ),
116 el( 'div', { className: 'bknb-outer' },
117 el( 'div', { className: 'bknb-box bknb-shape-' + attrs.shape, style: wrapStyle },
118 el( 'div', { className: 'bknb-number' },
119 attrs.prefix && el( 'span', { className: 'bknb-prefix' }, attrs.prefix ),
120 el( RichText, {
121 tagName: 'span',
122 className: 'bknb-value',
123 value: attrs.number,
124 onChange: function (v) { setAttr({ number: v }); },
125 placeholder: '42'
126 } ),
127 attrs.suffix && el( 'span', { className: 'bknb-suffix' }, attrs.suffix )
128 ),
129 el( RichText, {
130 tagName: 'p',
131 className: 'bknb-label',
132 value: attrs.label,
133 onChange: function (v) { setAttr({ label: v }); },
134 placeholder: __( 'Label…', 'blockenberg' )
135 } )
136 )
137 )
138 );
139 },
140 save: function ( props ) {
141 var attrs = props.attributes;
142 var _tvf = window.bkbgTypoCssVars;
143 var radius = attrs.shape === 'circle' ? '50%' : attrs.borderRadius + 'px';
144 var boxStyle = {
145 '--bknb-bg': attrs.bgColor,
146 '--bknb-text': attrs.textColor,
147 '--bknb-label': attrs.labelColor || attrs.textColor,
148 '--bknb-numSz': attrs.numberSz + 'px',
149 '--bknb-numFw': attrs.numberFontWeight || 700,
150 '--bknb-labelSz': attrs.labelSz + 'px',
151 '--bknb-labelFw': attrs.labelFontWeight || 500,
152 '--bknb-lh': attrs.lineHeight || 1.2,
153 '--bknb-size': attrs.boxSize + 'px',
154 '--bknb-radius': radius,
155 '--bknb-brd': attrs.border ? attrs.borderWidth + 'px solid ' + attrs.borderColor : 'none',
156 '--bknb-shadow': attrs.shadow ? '0 8px 32px rgba(0,0,0,.18)' : 'none'
157 };
158 if (_tvf) { Object.assign(boxStyle, _tvf(attrs.numberTypo, '--bknb-num-')); Object.assign(boxStyle, _tvf(attrs.labelTypo, '--bknb-lbl-')); }
159 return el( 'div', { className: 'bknb-outer' },
160 el( 'div', {
161 className: 'bknb-box bknb-shape-' + attrs.shape,
162 style: boxStyle
163 },
164 el( 'div', { className: 'bknb-number' },
165 attrs.prefix && el( 'span', { className: 'bknb-prefix' }, attrs.prefix ),
166 el( RichText.Content, { tagName: 'span', className: 'bknb-value', value: attrs.number } ),
167 attrs.suffix && el( 'span', { className: 'bknb-suffix' }, attrs.suffix )
168 ),
169 el( RichText.Content, { tagName: 'p', className: 'bknb-label', value: attrs.label } )
170 )
171 );
172 },
173 deprecated: [{
174 attributes: wp.blocks.getBlockType ? undefined : undefined,
175 save: function ( props ) {
176 var attrs = props.attributes;
177 var radius = attrs.shape === 'circle' ? '50%' : attrs.borderRadius + 'px';
178 return el( 'div', { className: 'bknb-outer' },
179 el( 'div', {
180 className: 'bknb-box bknb-shape-' + attrs.shape,
181 style: {
182 '--bknb-bg': attrs.bgColor,
183 '--bknb-text': attrs.textColor,
184 '--bknb-label': attrs.labelColor || attrs.textColor,
185 '--bknb-numSz': attrs.numberSz + 'px',
186 '--bknb-numFw': attrs.numberFontWeight || 700,
187 '--bknb-labelSz': attrs.labelSz + 'px',
188 '--bknb-labelFw': attrs.labelFontWeight || 500,
189 '--bknb-lh': attrs.lineHeight || 1.2,
190 '--bknb-size': attrs.boxSize + 'px',
191 '--bknb-radius': radius,
192 '--bknb-brd': attrs.border ? attrs.borderWidth + 'px solid ' + attrs.borderColor : 'none',
193 '--bknb-shadow': attrs.shadow ? '0 8px 32px rgba(0,0,0,.18)' : 'none'
194 }
195 },
196 el( 'div', { className: 'bknb-number' },
197 attrs.prefix && el( 'span', { className: 'bknb-prefix' }, attrs.prefix ),
198 el( RichText.Content, { tagName: 'span', className: 'bknb-value', value: attrs.number } ),
199 attrs.suffix && el( 'span', { className: 'bknb-suffix' }, attrs.suffix )
200 ),
201 el( RichText.Content, { tagName: 'p', className: 'bknb-label', value: attrs.label } )
202 )
203 );
204 }
205 }]
206 } );
207 } )();
208