import { __ } from '@wordpress/i18n'; import { PanelBody, TextControl, TextareaControl } from '@wordpress/components'; import BaseFieldEdit from './BaseFieldEdit'; // Shared preview renderer for the comma-separated options/labels field // family. 'select' / 'select-multiple' render a native ) ) :
{ __( '(no options defined)', 'profile-builder' ) }
} ); } const isMultiple = previewType === 'select-multiple'; return ( ); } /** * Shared editor for the comma-separated options/labels field family. Each * consuming block keeps its own edit.js (required by the register-blocks.js * require.context glob, which discovers blocks by their edit.js default * export) and its own __( 'X Settings', … ) panel-title call (required for * .pot extraction — the string must be a literal at the call site), passed * in as `panelTitle`. Everything else — the Options/Labels textareas, the * Default Value control, and the preview markup — lives here once. */ export default function OptionsFieldEdit( { panelTitle, previewType = 'select', defaultValueAttr = 'default-option', showDefaultHelp = false, extraControls = null, ...props } ) { const { attributes, setAttributes } = props; const extraPanels = ( setAttributes( { options: val } ) } help={ __( 'Enter options separated by comma.', 'profile-builder' ) } /> setAttributes( { labels: val } ) } help={ __( 'Enter labels separated by comma. If empty, options will be used.', 'profile-builder' ) } /> setAttributes( { [ defaultValueAttr ]: val } ) } help={ showDefaultHelp ? __( 'Enter default selected options separated by comma.', 'profile-builder' ) : undefined } /> { extraControls } ); const optionsList = attributes.options ? attributes.options.split( ',' ) : []; const labelsList = attributes.labels ? attributes.labels.split( ',' ) : []; return ( { renderPreview( previewType, optionsList, labelsList ) } ); }