PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.0
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.0
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 / AddFieldButton.js

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

53 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Dashed "Add field" appender for container blocks (Columns, Repeater).
3 * Opens the full mini inserter scoped to that container.
4 */
5 import { Inserter } from '@wordpress/block-editor';
6 import { Button } from '@wordpress/components';
7 import { useState } from '@wordpress/element';
8
9 import { resolveMiniInserterPositionFor } from '../lib/miniInserterPlacement';
10 import { setMiniInserterTarget, clearMiniInserterTarget } from '../lib/miniInserterTarget';
11
12 const PlusIcon = () => (
13 <svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true" focusable="false">
14 <path d="M12 5v14M5 12h14" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
15 </svg>
16 );
17
18 /**
19 * @param {Object} props
20 * @param {string} [props.rootClientId] Container to insert into (undefined = root list).
21 * @param {string} props.label Translatable button label.
22 */
23 export default function AddFieldButton( { rootClientId, label } ) {
24 const [ position, setPosition ] = useState( 'bottom center' );
25
26 return (
27 <Inserter
28 rootClientId={ rootClientId }
29 isAppender
30 // Full menu (not quick) so Existing Fields tab is available.
31 position={ position }
32 onToggle={ ( isOpen ) =>
33 isOpen ? setMiniInserterTarget( { rootClientId } ) : clearMiniInserterTarget()
34 }
35 renderToggle={ ( { onToggle, disabled } ) => (
36 <Button
37 className="wppb-fb-add-button"
38 onClick={ ( event ) => {
39 setPosition( resolveMiniInserterPositionFor( event.currentTarget ) );
40 onToggle();
41 } }
42 disabled={ disabled }
43 aria-haspopup="true"
44 aria-label={ label }
45 >
46 <PlusIcon />
47 <span>{ label }</span>
48 </Button>
49 ) }
50 />
51 );
52 }
53