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 / skill-bar / index.js

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

161 lines 11.1 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 _tc; function getTC() { return _tc || (_tc = window.bkbgTypographyControl); }
9 var _tv; function getTV() { return _tv || (_tv = window.bkbgTypoCssVars); }
10
11 function buildTypoVars( a ) {
12 var fn = getTV();
13 if ( !fn ) return {};
14 var v = {};
15 Object.assign( v, fn( a.titleTypo || {}, '--bksb-tt-' ) );
16 Object.assign( v, fn( a.labelTypo || {}, '--bksb-lt-' ) );
17 Object.assign( v, fn( a.valueTypo || {}, '--bksb-vt-' ) );
18 return v;
19 }
20
21 // ── Renderer (legacy — for deprecated) ─────────────────────────────────────────────
22 function renderSkillBars( a ) {
23 const skills = a.skills || [];
24 return el( 'div', { className: 'bkbg-sb-bars', style: { display: 'flex', flexDirection: 'column', gap: a.gap + 'px' } },
25 skills.map( ( skill, i ) => {
26 const pct = Math.min( 100, Math.max( 0, skill.value || 0 ) );
27 const clr = skill.color || '#6366f1';
28 return el( 'div', { key: i, className: 'bkbg-sb-item' },
29 // Label row
30 el( 'div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 6 } },
31 el( 'span', { style: { fontSize: a.labelFontSize + 'px', fontWeight: a.labelFontWeight, color: a.labelColor } }, skill.label ),
32 ( a.showValue || a.showPercent ) && el( 'span', { style: { fontSize: a.valueFontSize + 'px', color: a.valueColor, fontWeight: a.valueFontWeight } },
33 a.showPercent ? pct + '%' : pct
34 ),
35 ),
36 // Track
37 el( 'div', { style: { height: a.barHeight + 'px', background: a.trackColor, borderRadius: a.barRadius + 'px', overflow: 'hidden' } },
38 el( 'div', { style: {
39 height: '100%',
40 width: pct + '%',
41 background: clr,
42 borderRadius: a.barRadius + 'px',
43 } } )
44 ),
45 );
46 } )
47 );
48 }
49
50 // ── Renderer (new — no inline font styles) ───────────────────────────────
51 function renderSkillBarsNew( a ) {
52 const skills = a.skills || [];
53 return el( 'div', { className: 'bkbg-sb-bars', style: { display: 'flex', flexDirection: 'column', gap: a.gap + 'px' } },
54 skills.map( ( skill, i ) => {
55 const pct = Math.min( 100, Math.max( 0, skill.value || 0 ) );
56 const clr = skill.color || '#6366f1';
57 return el( 'div', { key: i, className: 'bkbg-sb-item' },
58 el( 'div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 6 } },
59 el( 'span', { className: 'bkbg-sb-label', style: { color: a.labelColor } }, skill.label ),
60 ( a.showValue || a.showPercent ) && el( 'span', { className: 'bkbg-sb-value', style: { color: a.valueColor } },
61 a.showPercent ? pct + '%' : pct
62 ),
63 ),
64 el( 'div', { style: { height: a.barHeight + 'px', background: a.trackColor, borderRadius: a.barRadius + 'px', overflow: 'hidden' } },
65 el( 'div', { style: { height: '100%', width: pct + '%', background: clr, borderRadius: a.barRadius + 'px' } } )
66 ),
67 );
68 } )
69 );
70 }
71
72 function updSkill( setAttributes, skills, si, field, val ) {
73 setAttributes( { skills: skills.map( ( s, i ) => i === si ? { ...s, [field]: val } : s ) } );
74 }
75
76 // ── Block ─────────────────────────────────────────────────────────────────
77 registerBlockType( 'blockenberg/skill-bar', {
78 edit: function ( props ) {
79 const { attributes: a, setAttributes } = props;
80 const blockProps = useBlockProps( { className: 'bkbg-sb-wrap', style: Object.assign( { background: a.bgColor, boxSizing: 'border-box' }, buildTypoVars( a ) ) } );
81
82 return el( 'div', blockProps,
83 el( InspectorControls, {},
84
85 el( PanelBody, { title: __( 'Settings', 'blockenberg' ), initialOpen: true },
86 el( TextControl, { label: __( 'Title', 'blockenberg' ), value: a.title, onChange: v => setAttributes( { title: v } ) } ),
87 el( ToggleControl, { label: __( 'Show Title', 'blockenberg' ), checked: a.showTitle, onChange: v => setAttributes( { showTitle: v } ) } ),
88 el( ToggleControl, { label: __( 'Show Percentage', 'blockenberg' ),checked: a.showPercent, onChange: v => setAttributes( { showPercent: v } ) } ),
89 ),
90
91 el( PanelBody, { title: __( 'Style', 'blockenberg' ), initialOpen: false },
92 el( RangeControl, { label: __( 'Bar Height', 'blockenberg' ), value: a.barHeight, onChange: v => setAttributes( { barHeight: v } ), min: 4, max: 40 } ),
93 el( RangeControl, { label: __( 'Bar Radius', 'blockenberg' ), value: a.barRadius, onChange: v => setAttributes( { barRadius: v } ), min: 0, max: 99 } ),
94 el( RangeControl, { label: __( 'Gap Between Bars', 'blockenberg' ),value: a.gap, onChange: v => setAttributes( { gap: v } ), min: 6, max: 48 } ),
95 ),
96
97
98 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
99 el( getTC(), { label: __( 'Title', 'blockenberg' ), value: a.titleTypo || {}, onChange: function( v ) { setAttributes( { titleTypo: v } ); } } ),
100 el( getTC(), { label: __( 'Label', 'blockenberg' ), value: a.labelTypo || {}, onChange: function( v ) { setAttributes( { labelTypo: v } ); } } ),
101 el( getTC(), { label: __( 'Value', 'blockenberg' ), value: a.valueTypo || {}, onChange: function( v ) { setAttributes( { valueTypo: v } ); } } ),
102 ),
103 el( PanelColorSettings, {
104 title: __( 'Colors', 'blockenberg' ), initialOpen: false,
105 colorSettings: [
106 { label: __( 'Background', 'blockenberg' ), value: a.bgColor, onChange: v => setAttributes( { bgColor: v || '#ffffff' } ) },
107 { label: __( 'Track', 'blockenberg' ), value: a.trackColor, onChange: v => setAttributes( { trackColor: v || '#f1f5f9' } ) },
108 { label: __( 'Label', 'blockenberg' ), value: a.labelColor, onChange: v => setAttributes( { labelColor: v || '#111827' } ) },
109 { label: __( 'Value', 'blockenberg' ), value: a.valueColor, onChange: v => setAttributes( { valueColor: v || '#6b7280' } ) },
110 { label: __( 'Title', 'blockenberg' ), value: a.titleColor, onChange: v => setAttributes( { titleColor: v || '#111827' } ) },
111 ]
112 } ),
113
114 el( PanelBody, { title: __( 'Skills', 'blockenberg' ), initialOpen: false },
115 el( Button, { variant: 'secondary', style: { marginBottom: 10 }, onClick: () => setAttributes( { skills: [ ...( a.skills || [] ), { label: 'New Skill', value: 75, color: '#6366f1' } ] } ) }, __( '+ Add Skill', 'blockenberg' ) ),
116 a.skills.map( ( skill, si ) =>
117 el( PanelBody, { key: si, title: `${ skill.label }${ skill.value }%`, initialOpen: false },
118 el( TextControl, { label: __( 'Skill Label', 'blockenberg' ), value: skill.label, onChange: v => updSkill( setAttributes, a.skills, si, 'label', v ) } ),
119 el( RangeControl, { label: __( 'Level (%)', 'blockenberg' ), value: skill.value, onChange: v => updSkill( setAttributes, a.skills, si, 'value', v ), min: 0, max: 100 } ),
120 el( 'div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 } },
121 el( 'label', { style: { fontSize: 12 } }, __( 'Bar Color', 'blockenberg' ) ),
122 el( 'input', { type: 'color', value: skill.color || '#6366f1', style: { width: 40, height: 28, border: 'none', borderRadius: 4, cursor: 'pointer' }, onChange: e => updSkill( setAttributes, a.skills, si, 'color', e.target.value ) } ),
123 ),
124 el( Button, { isDestructive: true, isSmall: true, onClick: () => setAttributes( { skills: a.skills.filter( ( _, x ) => x !== si ) } ) }, __( 'Remove', 'blockenberg' ) ),
125 )
126 ),
127 ),
128 ),
129
130 a.showTitle && a.title && el( 'h3', { className: 'bkbg-sb-title', style: { color: a.titleColor, margin: '0 0 20px' } }, a.title ),
131 renderSkillBarsNew( a ),
132 );
133 },
134
135 save: function ( { attributes: a } ) {
136 const blockProps = useBlockProps.save( { className: 'bkbg-sb-wrap', style: Object.assign( { background: a.bgColor, boxSizing: 'border-box' }, buildTypoVars( a ) ) } );
137 return el( 'div', blockProps,
138 a.showTitle && a.title ? el( 'h3', { className: 'bkbg-sb-title', style: { color: a.titleColor, margin: '0 0 20px' } }, a.title ) : null,
139 renderSkillBarsNew( a ),
140 );
141 },
142
143 deprecated: [ {
144 save: function ( { attributes: a } ) {
145 var bp = useBlockProps.save( { className: 'bkbg-sb-wrap', style: { background: a.bgColor, boxSizing: 'border-box' } } );
146 return el( 'div', bp,
147 a.showTitle && a.title ? el( 'h3', { className: 'bkbg-sb-title', style: { color: a.titleColor, margin: '0 0 20px', fontSize: ( a.labelFontSize + 4 ) + 'px' } }, a.title ) : null,
148 renderSkillBars( a ),
149 );
150 },
151 migrate: function ( attrs ) {
152 var n = Object.assign( {}, attrs );
153 n.titleTypo = { sizeDesktop: ( attrs.labelFontSize || 14 ) + 4, weight: String( attrs.labelFontWeight || 600 ) };
154 n.labelTypo = { sizeDesktop: attrs.labelFontSize || 14, weight: String( attrs.labelFontWeight || 600 ) };
155 n.valueTypo = { sizeDesktop: attrs.valueFontSize || 13, weight: String( attrs.valueFontWeight || 500 ) };
156 return n;
157 },
158 } ],
159 } );
160 }() );
161