AvailableMapFieldPreset.js
2 years ago
DynamicPreset.js
2 years ago
FieldWithPreset.js
2 years ago
GlobalFieldPreset.js
2 years ago
MapFieldPreset.js
2 years ago
PresetButton.js
2 years ago
withPreset.js
2 years ago
MapFieldPreset.js
101 lines
| 1 | import GroupedSelectControl from '../../components/GroupedSelectControl'; |
| 2 | |
| 3 | const { |
| 4 | TextControl, |
| 5 | SelectControl, |
| 6 | CustomSelectControl, |
| 7 | } = wp.components; |
| 8 | |
| 9 | function MapFieldPreset( { |
| 10 | data, |
| 11 | value, |
| 12 | index, |
| 13 | currentState, |
| 14 | onChangeValue, |
| 15 | isCurrentFieldVisible, |
| 16 | position = 'general', |
| 17 | } ) { |
| 18 | |
| 19 | switch ( data.type ) { |
| 20 | case 'text': |
| 21 | return ( |
| 22 | isCurrentFieldVisible( currentState, data ) && |
| 23 | <div |
| 24 | key={ data.name + index } |
| 25 | className={ 'jet-form-preset__row' } |
| 26 | > |
| 27 | <TextControl |
| 28 | key={ 'control_' + data.name + index } |
| 29 | placeholder={ data.label } |
| 30 | value={ value } |
| 31 | onChange={ newVal => { |
| 32 | onChangeValue( newVal, |
| 33 | 'current_field_' + data.name ); |
| 34 | } } |
| 35 | /> |
| 36 | </div> |
| 37 | ); |
| 38 | case 'select': |
| 39 | return ( |
| 40 | isCurrentFieldVisible( currentState, data ) && |
| 41 | <div |
| 42 | key={ data.name + index } |
| 43 | className={ 'jet-form-preset__row' } |
| 44 | > |
| 45 | <SelectControl |
| 46 | key={ 'control_' + data.name + index } |
| 47 | labelPosition="side" |
| 48 | options={ data.options } |
| 49 | label={ data.label } |
| 50 | value={ value } |
| 51 | onChange={ newVal => { |
| 52 | onChangeValue( newVal, |
| 53 | 'current_field_' + data.name ); |
| 54 | } } |
| 55 | /> |
| 56 | </div> |
| 57 | ); |
| 58 | case 'custom_select': |
| 59 | return ( |
| 60 | isCurrentFieldVisible( currentState, data ) && |
| 61 | <div |
| 62 | key={ data.name + index } |
| 63 | className={ 'jet-form-preset__row' } |
| 64 | > |
| 65 | <CustomSelectControl |
| 66 | className="jet-custom-select-control" |
| 67 | label={ data.label } |
| 68 | options={ data.options } |
| 69 | onChange={ ( { selectedItem } ) => { |
| 70 | value = selectedItem.key; |
| 71 | onChangeValue( value, 'current_field_' + data.name ); |
| 72 | } } |
| 73 | value={ data.options.find( |
| 74 | option => option.key === value ) } |
| 75 | /> |
| 76 | </div> |
| 77 | ); |
| 78 | case 'grouped_select': |
| 79 | return ( |
| 80 | isCurrentFieldVisible( currentState, data ) && |
| 81 | <div |
| 82 | key={ data.name + index } |
| 83 | className={ 'jet-form-preset__row' } |
| 84 | > |
| 85 | <GroupedSelectControl |
| 86 | options={ data.options } |
| 87 | label={ data.label } |
| 88 | labelPosition="side" |
| 89 | value={ value } |
| 90 | onChange={ newVal => { |
| 91 | onChangeValue( newVal, |
| 92 | 'current_field_' + data.name ); |
| 93 | } } |
| 94 | /> |
| 95 | </div> |
| 96 | ); |
| 97 | } |
| 98 | return null; |
| 99 | } |
| 100 | |
| 101 | export default MapFieldPreset; |