PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.1
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.1
2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 68 releases
better-payment / src / campaign-builder / components / FieldItem.js

FieldItem.js in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.2.1, at src/campaign-builder/components/FieldItem.js

57 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n';
2 import { getField } from '../fields/FieldRegistry';
3
4 /**
5 * A single field card in the canvas.
6 * Shows field label + drag handle + delete button.
7 * Clicking selects the field (shows its settings in the right panel).
8 */
9 export default function FieldItem( { field, index, isSelected, dispatch, onDropAbove } ) {
10 const def = getField( field.type );
11
12 const handleDragStart = ( e ) => {
13 e.dataTransfer.setData( 'bp_field_id', field.id );
14 e.dataTransfer.effectAllowed = 'move';
15 };
16
17 const handleDragOver = ( e ) => {
18 e.preventDefault();
19 e.stopPropagation();
20 };
21
22 return (
23 <div
24 className={ `bp-cb-field-item-canvas${ isSelected ? ' is-selected' : '' }` }
25 onClick={ () => dispatch( { type: isSelected ? 'DESELECT_FIELD' : 'SELECT_FIELD', fieldId: field.id } ) }
26 >
27 {/* Drop zone above this item */ }
28 <div
29 className="bp-cb-drop-zone"
30 onDragOver={ handleDragOver }
31 onDrop={ onDropAbove }
32 />
33
34 <div
35 className="bp-cb-field-inner"
36 draggable
37 onDragStart={ handleDragStart }
38 >
39 <span className="bp-cb-drag-handle dashicons dashicons-move" title={ __( 'Drag to reorder', 'better-payment' ) } />
40 <span className={ `dashicons dashicons-${ def?.icon || 'block-default' }` } />
41 <span className="bp-cb-field-label">{ def?.label || field.type }</span>
42
43 <button
44 className="bp-cb-field-delete"
45 title={ __( 'Remove field', 'better-payment' ) }
46 onClick={ ( e ) => {
47 e.stopPropagation();
48 dispatch( { type: 'REMOVE_FIELD', fieldId: field.id } );
49 } }
50 >
51 ✕
52 </button>
53 </div>
54 </div>
55 );
56 }
57