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 / icon-stats / index.js

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

189 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 const el = window.wp.element.createElement;
3 const { registerBlockType } = window.wp.blocks;
4 const { InspectorControls, useBlockProps, PanelColorSettings } = window.wp.blockEditor;
5 const { PanelBody, RangeControl, ToggleControl, TextControl, Button } = window.wp.components;
6 const { __ } = window.wp.i18n;
7
8 var _TypographyControl, _typoCssVars;
9 function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); }
10 function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); }
11
12 var IP = function () { return window.bkbgIconPicker; };
13
14 // ── Single stat card ──────────────────────────────────────────────────────
15 function StatCard( { stat, a } ) {
16 return el( 'div', { className: 'bkbg-is-card', style: {
17 background: a.cardBg,
18 border: '1px solid ' + a.borderColor,
19 borderRadius: a.cardRadius + 'px',
20 padding: a.cardPadding + 'px',
21 display: 'flex',
22 flexDirection: 'column',
23 alignItems: 'flex-start',
24 gap: 10,
25 boxSizing: 'border-box',
26 } },
27 // Icon circle
28 a.showIcon && el( 'div', { className: 'bkbg-is-icon', style: {
29 width: a.iconBgSize + 'px', height: a.iconBgSize + 'px',
30 borderRadius: a.iconBgRadius + 'px',
31 background: ( stat.accentColor || '#6366f1' ) + '18',
32 display: 'flex', alignItems: 'center', justifyContent: 'center',
33 fontSize: a.iconSize + 'px', flexShrink: 0,
34 } }, (stat.iconType || 'custom-char') !== 'custom-char' ? IP().buildSaveIcon(stat.iconType, stat.icon, stat.iconDashicon, stat.iconImageUrl, stat.iconDashiconColor) : stat.icon ),
35
36 // Value
37 el( 'div', { className: 'bkbg-is-value', style: {
38 color: stat.accentColor || a.valueColor,
39 } }, stat.value ),
40
41 // Label
42 el( 'div', { className: 'bkbg-is-label', style: {
43 color: a.labelColor,
44 } }, stat.label ),
45
46 // Description
47 stat.desc && el( 'div', { className: 'bkbg-is-desc', style: {
48 color: a.descColor,
49 } }, stat.desc ),
50 );
51 }
52
53 // ── Full render ───────────────────────────────────────────────────────────
54 function renderIconStats( a ) {
55 return el( 'div', { className: 'bkbg-is-grid', style: {
56 display: 'grid',
57 gridTemplateColumns: 'repeat(' + a.columns + ', 1fr)',
58 gap: a.gap + 'px',
59 } },
60 ( a.stats || [] ).map( ( stat, i ) => el( StatCard, { key: i, stat, a } ) )
61 );
62 }
63
64 function updStat( setAttributes, stats, si, field, val ) {
65 setAttributes( { stats: stats.map( ( s, i ) => i === si ? { ...s, [field]: val } : s ) } );
66 }
67
68 // ── Block ─────────────────────────────────────────────────────────────────
69 registerBlockType( 'blockenberg/icon-stats', {
70 edit: function ( props ) {
71 const { attributes: a, setAttributes } = props;
72 var wrapStyle = {
73 background: a.bgColor,
74 '--bkbg-is-heading-sz': (a.valueFontSize * 0.6 + 8) + 'px',
75 '--bkbg-is-subtitle-sz': a.labelFontSize + 'px',
76 '--bkbg-is-value-sz': a.valueFontSize + 'px',
77 '--bkbg-is-label-sz': a.labelFontSize + 'px',
78 '--bkbg-is-desc-sz': a.descFontSize + 'px',
79 };
80 var _tv = getTypoCssVars();
81 if (_tv) {
82 Object.assign(wrapStyle, _tv(a.headingTypo, '--bkbg-is-hd-'));
83 Object.assign(wrapStyle, _tv(a.subtitleTypo, '--bkbg-is-st-'));
84 Object.assign(wrapStyle, _tv(a.valueTypo, '--bkbg-is-vl-'));
85 Object.assign(wrapStyle, _tv(a.labelTypo, '--bkbg-is-lb-'));
86 Object.assign(wrapStyle, _tv(a.descTypo, '--bkbg-is-ds-'));
87 }
88 const blockProps = useBlockProps( { className: 'bkbg-is-wrap', style: wrapStyle } );
89
90 return el( 'div', blockProps,
91 el( InspectorControls, {},
92
93 el( PanelBody, { title: __( 'Settings', 'blockenberg' ), initialOpen: true },
94 el( ToggleControl, { label: __( 'Show Title', 'blockenberg' ), checked: a.showTitle, onChange: v => setAttributes( { showTitle: v } ) } ),
95 a.showTitle && el( TextControl, { label: __( 'Title', 'blockenberg' ), value: a.title, onChange: v => setAttributes( { title: v } ) } ),
96 el( ToggleControl, { label: __( 'Show Subtitle', 'blockenberg' ), checked: a.showSubtitle, onChange: v => setAttributes( { showSubtitle: v } ) } ),
97 a.showSubtitle && el( TextControl, { label: __( 'Subtitle', 'blockenberg' ), value: a.subtitle, onChange: v => setAttributes( { subtitle: v } ) } ),
98 el( ToggleControl, { label: __( 'Show Icons', 'blockenberg' ), checked: a.showIcon, onChange: v => setAttributes( { showIcon: v } ) } ),
99 el( RangeControl, { label: __( 'Columns', 'blockenberg' ), value: a.columns, onChange: v => setAttributes( { columns: v } ), min: 1, max: 6 } ),
100 ),
101
102 el( PanelBody, { title: __( 'Style', 'blockenberg' ), initialOpen: false },
103 el( RangeControl, { label: __( 'Icon Size', 'blockenberg' ), value: a.iconSize, onChange: v => setAttributes( { iconSize: v } ), min: 16, max: 64 } ),
104 el( RangeControl, { label: __( 'Icon Circle Size', 'blockenberg' ),value: a.iconBgSize, onChange: v => setAttributes( { iconBgSize: v } ), min: 32, max: 120 } ),
105 el( RangeControl, { label: __( 'Icon Circle Radius', 'blockenberg' ),value: a.iconBgRadius,onChange: v => setAttributes( { iconBgRadius: v } ), min: 0, max: 99 } ),
106 el( RangeControl, { label: __( 'Card Padding', 'blockenberg' ), value: a.cardPadding, onChange: v => setAttributes( { cardPadding: v } ), min: 12, max: 56 } ),
107 el( RangeControl, { label: __( 'Card Radius', 'blockenberg' ), value: a.cardRadius, onChange: v => setAttributes( { cardRadius: v } ), min: 0, max: 32 } ),
108 el( RangeControl, { label: __( 'Gap', 'blockenberg' ), value: a.gap, onChange: v => setAttributes( { gap: v } ), min: 8, max: 40 } ),
109 ),
110
111
112 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
113 getTypographyControl() && el(getTypographyControl(), { label: __('Heading', 'blockenberg'), typo: a.headingTypo || {}, onChange: v => setAttributes({ headingTypo: v }) }),
114 getTypographyControl() && el(getTypographyControl(), { label: __('Subtitle', 'blockenberg'), typo: a.subtitleTypo || {}, onChange: v => setAttributes({ subtitleTypo: v }) }),
115 getTypographyControl() && el(getTypographyControl(), { label: __('Value', 'blockenberg'), typo: a.valueTypo || {}, onChange: v => setAttributes({ valueTypo: v }) }),
116 getTypographyControl() && el(getTypographyControl(), { label: __('Label', 'blockenberg'), typo: a.labelTypo || {}, onChange: v => setAttributes({ labelTypo: v }) }),
117 getTypographyControl() && el(getTypographyControl(), { label: __('Description', 'blockenberg'), typo: a.descTypo || {}, onChange: v => setAttributes({ descTypo: v }) })
118 ),
119 el( PanelColorSettings, {
120 title: __( 'Colors', 'blockenberg' ), initialOpen: false,
121 colorSettings: [
122 { label: __( 'Background', 'blockenberg' ), value: a.bgColor, onChange: v => setAttributes( { bgColor: v || '#ffffff' } ) },
123 { label: __( 'Card Background', 'blockenberg' ),value: a.cardBg, onChange: v => setAttributes( { cardBg: v || '#f9fafb' } ) },
124 { label: __( 'Border', 'blockenberg' ), value: a.borderColor, onChange: v => setAttributes( { borderColor: v || '#e5e7eb' } ) },
125 { label: __( 'Heading', 'blockenberg' ), value: a.headingColor,onChange: v => setAttributes( { headingColor: v || '#111827' } ) },
126 { label: __( 'Subtitle', 'blockenberg' ), value: a.subtitleColor,onChange: v => setAttributes( { subtitleColor:v || '#6b7280' } ) },
127 { label: __( 'Value (default)', 'blockenberg' ),value: a.valueColor, onChange: v => setAttributes( { valueColor: v || '#111827' } ) },
128 { label: __( 'Label', 'blockenberg' ), value: a.labelColor, onChange: v => setAttributes( { labelColor: v || '#374151' } ) },
129 { label: __( 'Description', 'blockenberg' ), value: a.descColor, onChange: v => setAttributes( { descColor: v || '#6b7280' } ) },
130 ]
131 } ),
132
133 el( PanelBody, { title: __( 'Stats', 'blockenberg' ), initialOpen: false },
134 el( Button, {
135 variant: 'secondary', style: { marginBottom: 10 },
136 onClick: () => setAttributes( { stats: [ ...( a.stats || [] ), { icon: '📊', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', value: '99%', label: 'New Stat', desc: 'Description', accentColor: '#6366f1' } ] } ),
137 }, __( '+ Add Stat', 'blockenberg' ) ),
138 a.stats.map( ( stat, si ) =>
139 el( PanelBody, { key: si, title: ( stat.icon ? stat.icon + ' ' : '' ) + stat.label, initialOpen: false },
140 el( IP().IconPickerControl, { iconType: stat.iconType || 'custom-char', customChar: stat.icon, dashicon: stat.iconDashicon || '', imageUrl: stat.iconImageUrl || '',
141 onChangeType: function (v) { updStat( setAttributes, a.stats, si, 'iconType', v ); }, onChangeChar: function (v) { updStat( setAttributes, a.stats, si, 'icon', v ); },
142 onChangeDashicon: function (v) { updStat( setAttributes, a.stats, si, 'iconDashicon', v ); }, onChangeImageUrl: function (v) { updStat( setAttributes, a.stats, si, 'iconImageUrl', v ); } }),
143 el( TextControl, { label: __( 'Value', 'blockenberg' ), value: stat.value, onChange: v => updStat( setAttributes, a.stats, si, 'value', v ) } ),
144 el( TextControl, { label: __( 'Label', 'blockenberg' ), value: stat.label, onChange: v => updStat( setAttributes, a.stats, si, 'label', v ) } ),
145 el( TextControl, { label: __( 'Description', 'blockenberg' ), value: stat.desc, onChange: v => updStat( setAttributes, a.stats, si, 'desc', v ) } ),
146 el( 'div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 } },
147 el( 'label', { style: { fontSize: 11 } }, __( 'Accent Color', 'blockenberg' ) ),
148 el( 'input', { type: 'color', value: stat.accentColor || '#6366f1', style: { width: 40, height: 28, border: 'none', borderRadius: 4, cursor: 'pointer' }, onChange: e => updStat( setAttributes, a.stats, si, 'accentColor', e.target.value ) } ),
149 ),
150 el( Button, { isDestructive: true, isSmall: true, onClick: () => setAttributes( { stats: a.stats.filter( ( _, x ) => x !== si ) } ) }, __( 'Remove', 'blockenberg' ) ),
151 )
152 ),
153 ),
154 ),
155
156 // Header
157 ( a.showTitle && a.title ) && el( 'h3', { className: 'bkbg-is-title', style: { color: a.headingColor, margin: '0 0 6px' } }, a.title ),
158 ( a.showSubtitle && a.subtitle ) && el( 'p', { className: 'bkbg-is-subtitle', style: { color: a.subtitleColor, margin: '0 0 20px' } }, a.subtitle ),
159 renderIconStats( a ),
160 );
161 },
162
163 save: function ( { attributes: a } ) {
164 var saveStyle = {
165 background: a.bgColor,
166 '--bkbg-is-heading-sz': (a.valueFontSize * 0.6 + 8) + 'px',
167 '--bkbg-is-subtitle-sz': a.labelFontSize + 'px',
168 '--bkbg-is-value-sz': a.valueFontSize + 'px',
169 '--bkbg-is-label-sz': a.labelFontSize + 'px',
170 '--bkbg-is-desc-sz': a.descFontSize + 'px',
171 };
172 var _tv2 = getTypoCssVars();
173 if (_tv2) {
174 Object.assign(saveStyle, _tv2(a.headingTypo, '--bkbg-is-hd-'));
175 Object.assign(saveStyle, _tv2(a.subtitleTypo, '--bkbg-is-st-'));
176 Object.assign(saveStyle, _tv2(a.valueTypo, '--bkbg-is-vl-'));
177 Object.assign(saveStyle, _tv2(a.labelTypo, '--bkbg-is-lb-'));
178 Object.assign(saveStyle, _tv2(a.descTypo, '--bkbg-is-ds-'));
179 }
180 const blockProps = useBlockProps.save( { className: 'bkbg-is-wrap', style: saveStyle } );
181 return el( 'div', blockProps,
182 ( a.showTitle && a.title ) ? el( 'h3', { className: 'bkbg-is-title', style: { color: a.headingColor, margin: '0 0 6px' } }, a.title ) : null,
183 ( a.showSubtitle && a.subtitle ) ? el( 'p', { className: 'bkbg-is-subtitle', style: { color: a.subtitleColor, margin: '0 0 20px' } }, a.subtitle ) : null,
184 renderIconStats( a ),
185 );
186 },
187 } );
188 }() );
189