PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / form-builder / blocks / src / components / ExtraFieldPropertiesPanel.js

ExtraFieldPropertiesPanel.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at form-builder/blocks/src/components/ExtraFieldPropertiesPanel.js

56 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Inspector panel for add-on field controls from `window.wppbFb.extraControls`.
3 * Renders only descriptors whose attribute is on this block's schema.
4 * `hideInsideRepeater` suppresses controls that classic strips from sub-fields.
5 */
6 import { PanelBody, TextControl, ToggleControl } from '@wordpress/components';
7 import { __ } from '@wordpress/i18n';
8
9 export default function ExtraFieldPropertiesPanel( { attributes, setAttributes, insideRepeater = false } ) {
10 const fb = ( typeof window !== 'undefined' && window.wppbFb ) || {};
11 const controls = Array.isArray( fb.extraControls ) ? fb.extraControls : [];
12
13 // De-dupe by attribute (last wins); skip attrs not on this block.
14 const seen = new Set();
15 const applicable = [];
16 for ( let i = controls.length - 1; i >= 0; i-- ) {
17 const c = controls[ i ];
18 if ( ! c || ! c.attribute || seen.has( c.attribute ) ) continue;
19 if ( ! Object.prototype.hasOwnProperty.call( attributes, c.attribute ) ) continue;
20 if ( insideRepeater && c.hideInsideRepeater ) continue;
21 seen.add( c.attribute );
22 applicable.unshift( c );
23 }
24 if ( applicable.length === 0 ) return null;
25
26 return (
27 <PanelBody title={ __( 'Additional Settings', 'profile-builder' ) } initialOpen={ false }>
28 { applicable.map( ( c ) => {
29 if ( c.control === 'toggle' ) {
30 const onValue = c.onValue != null ? c.onValue : 'Yes';
31 const offValue = c.offValue != null ? c.offValue : 'No';
32 return (
33 <ToggleControl
34 key={ c.attribute }
35 label={ c.label || c.attribute }
36 help={ c.help || undefined }
37 checked={ attributes[ c.attribute ] === onValue }
38 onChange={ ( on ) => setAttributes( { [ c.attribute ]: on ? onValue : offValue } ) }
39 />
40 );
41 }
42 return (
43 <TextControl
44 key={ c.attribute }
45 label={ c.label || c.attribute }
46 help={ c.help || undefined }
47 type={ c.control === 'number' ? 'number' : 'text' }
48 value={ attributes[ c.attribute ] != null ? attributes[ c.attribute ] : '' }
49 onChange={ ( val ) => setAttributes( { [ c.attribute ]: val } ) }
50 />
51 );
52 } ) }
53 </PanelBody>
54 );
55 }
56