edit.js
136 lines
| 1 | import { SelectRadioCheckPlaceholder } from '../../components/base-select-check-radio/select-radio-check-placeholder'; |
| 2 | import SelectRadioCheck |
| 3 | from '../../components/base-select-check-radio/select-radio-check'; |
| 4 | import preview from './preview'; |
| 5 | |
| 6 | const { |
| 7 | __, |
| 8 | } = wp.i18n; |
| 9 | const { |
| 10 | ToolBarFields, |
| 11 | BlockLabel, |
| 12 | BlockDescription, |
| 13 | BlockAdvancedValue, |
| 14 | BlockName, |
| 15 | BlockPlaceholder, |
| 16 | BlockAddPrevButton, |
| 17 | BlockPrevButtonLabel, |
| 18 | BlockVisibility, |
| 19 | BlockClassName, |
| 20 | FieldControl, |
| 21 | SwitchPageOnChangeControls, |
| 22 | } = JetFBComponents; |
| 23 | |
| 24 | const { |
| 25 | useUniqueNameOnDuplicate, |
| 26 | } = JetFBHooks; |
| 27 | |
| 28 | const { |
| 29 | InspectorControls, |
| 30 | useBlockProps, |
| 31 | } = wp.blockEditor; |
| 32 | |
| 33 | const { |
| 34 | ToggleControl, |
| 35 | SelectControl, |
| 36 | PanelBody, |
| 37 | TextControl, |
| 38 | RangeControl, |
| 39 | } = wp.components; |
| 40 | |
| 41 | /** |
| 42 | * @param props |
| 43 | * @returns {JSX.Element[]} |
| 44 | * @constructor |
| 45 | */ |
| 46 | export default function SelectEdit( props ) { |
| 47 | |
| 48 | const { |
| 49 | attributes, |
| 50 | setAttributes, |
| 51 | isSelected, |
| 52 | editProps: { uniqKey, attrHelp }, |
| 53 | } = props; |
| 54 | |
| 55 | const blockProps = useBlockProps(); |
| 56 | |
| 57 | useUniqueNameOnDuplicate(); |
| 58 | |
| 59 | if ( attributes.isPreview ) { |
| 60 | return <div style={ { |
| 61 | width: '100%', |
| 62 | display: 'flex', |
| 63 | justifyContent: 'center', |
| 64 | } }> |
| 65 | { preview } |
| 66 | </div>; |
| 67 | } |
| 68 | |
| 69 | return <> |
| 70 | <ToolBarFields |
| 71 | key={ uniqKey( 'ToolBarFields' ) } |
| 72 | { ...props } |
| 73 | /> |
| 74 | { !attributes.multiple && <SwitchPageOnChangeControls/> } |
| 75 | { isSelected && <InspectorControls |
| 76 | key={ uniqKey( 'InspectorControls' ) } |
| 77 | > |
| 78 | <PanelBody title={ __( 'General', 'jet-form-builder' ) }> |
| 79 | <BlockLabel/> |
| 80 | <BlockName/> |
| 81 | <BlockDescription/> |
| 82 | </PanelBody> |
| 83 | <PanelBody title={ __( 'Value', 'jet-form-builder' ) }> |
| 84 | <BlockAdvancedValue/> |
| 85 | </PanelBody> |
| 86 | <PanelBody |
| 87 | title={ __( 'Advanced', 'jet-form-builder' ) } |
| 88 | > |
| 89 | <BlockPlaceholder/> |
| 90 | { ( |
| 91 | !!attributes.placeholder.length |
| 92 | ) && <ToggleControl |
| 93 | key={ uniqKey( 'is_disabled_placeholder' ) } |
| 94 | label={ __( 'Disable placeholder', 'jet-form-builder' ) } |
| 95 | checked={ attributes.is_disabled_placeholder } |
| 96 | onChange={ is_disabled_placeholder => setAttributes( |
| 97 | { is_disabled_placeholder } ) } |
| 98 | /> } |
| 99 | <BlockAddPrevButton/> |
| 100 | <BlockPrevButtonLabel/> |
| 101 | <BlockVisibility/> |
| 102 | <BlockClassName/> |
| 103 | </PanelBody> |
| 104 | </InspectorControls> } |
| 105 | <div key={ uniqKey( 'viewBlock' ) } { ...blockProps }> |
| 106 | <SelectRadioCheckPlaceholder |
| 107 | scriptData={ window.JetFormSelectFieldData } |
| 108 | { ...props } |
| 109 | /> |
| 110 | <SelectRadioCheck { ...props }> |
| 111 | <ToggleControl |
| 112 | key="multiple" |
| 113 | label={ __( 'Is multiple', 'jet-form-builder' ) } |
| 114 | checked={ attributes.multiple } |
| 115 | help={ attrHelp( 'multiple' ) } |
| 116 | onChange={ multiple => setAttributes( { multiple } ) } |
| 117 | /> |
| 118 | { attributes.multiple && <RangeControl |
| 119 | label={ __( 'Rows count', 'jet-form-builder' ) } |
| 120 | value={ attributes.multiple_size ?? 4 } |
| 121 | onChange={ multiple_size => setAttributes( |
| 122 | { multiple_size } ) } |
| 123 | allowReset |
| 124 | resetFallbackValue={ 4 } |
| 125 | min={ 1 } |
| 126 | max={ 25 } |
| 127 | /> } |
| 128 | <FieldControl |
| 129 | type="custom_settings" |
| 130 | key={ uniqKey( 'customSettingsFields' ) } |
| 131 | { ...props } |
| 132 | /> |
| 133 | </SelectRadioCheck> |
| 134 | </div> |
| 135 | </>; |
| 136 | } |