edit.js
132 lines
| 1 | import preview from './preview'; |
| 2 | |
| 3 | const { |
| 4 | BlockClassName, |
| 5 | BlockAddPrevButton, |
| 6 | BlockPrevButtonLabel, |
| 7 | } = JetFBComponents; |
| 8 | |
| 9 | const { __ } = wp.i18n; |
| 10 | |
| 11 | const { |
| 12 | InspectorControls, |
| 13 | useBlockProps, |
| 14 | RichText, |
| 15 | } = wp.blockEditor ? wp.blockEditor : wp.editor; |
| 16 | |
| 17 | const { |
| 18 | TextareaControl, |
| 19 | TextControl, |
| 20 | PanelBody, |
| 21 | Button, |
| 22 | ToggleControl, |
| 23 | } = wp.components; |
| 24 | |
| 25 | export default function FormBreakEdit( props ) { |
| 26 | |
| 27 | const blockProps = useBlockProps(); |
| 28 | |
| 29 | const { |
| 30 | attributes, |
| 31 | setAttributes, |
| 32 | editProps: { uniqKey, attrHelp }, |
| 33 | } = props; |
| 34 | |
| 35 | if ( attributes.isPreview ) { |
| 36 | return <div style={ { |
| 37 | width: '100%', |
| 38 | display: 'flex', |
| 39 | justifyContent: 'center', |
| 40 | } }> |
| 41 | { preview } |
| 42 | </div>; |
| 43 | } |
| 44 | |
| 45 | return [ |
| 46 | props.isSelected && <InspectorControls |
| 47 | key={ uniqKey( 'InspectorControls' ) } |
| 48 | > |
| 49 | <PanelBody |
| 50 | title={ __( 'Buttons Settings', 'jet-form-builder' ) } |
| 51 | > |
| 52 | <ToggleControl |
| 53 | key={ uniqKey( 'add_next_button' ) } |
| 54 | label={ __( 'Enable "Next" Button', 'jet-form-builder' ) } |
| 55 | checked={ attributes.add_next_button } |
| 56 | help={ attrHelp( 'add_next_button' ) } |
| 57 | onChange={ add_next_button => setAttributes( |
| 58 | { add_next_button } ) } |
| 59 | /> |
| 60 | { attributes.add_next_button && <TextControl |
| 61 | label={ __( 'Next Button label', 'jet-form-builder' ) } |
| 62 | value={ attributes.label } |
| 63 | onChange={ label => setAttributes( { label } ) } |
| 64 | /> } |
| 65 | <BlockAddPrevButton/> |
| 66 | <BlockPrevButtonLabel/> |
| 67 | </PanelBody> |
| 68 | <PanelBody |
| 69 | title={ __( 'Page Settings', 'jet-form-builder' ) } |
| 70 | > |
| 71 | <TextControl |
| 72 | label={ __( 'Label of progress', 'jet-form-builder' ) } |
| 73 | value={ attributes.label_progress } |
| 74 | help={ attrHelp( 'label_progress' ) } |
| 75 | onChange={ ( newValue ) => { |
| 76 | props.setAttributes( { label_progress: newValue } ); |
| 77 | } } |
| 78 | /> |
| 79 | <TextareaControl |
| 80 | key="page_break_disabled" |
| 81 | value={ attributes.page_break_disabled } |
| 82 | label={ __( 'Validation message', 'jet-form-builder' ) } |
| 83 | help={ attrHelp( 'page_break_disabled' ) } |
| 84 | onChange={ ( newValue ) => { |
| 85 | setAttributes( { page_break_disabled: newValue } ); |
| 86 | } } |
| 87 | /> |
| 88 | </PanelBody> |
| 89 | <PanelBody |
| 90 | title={ __( 'Advanced', 'jet-form-builder' ) } |
| 91 | > |
| 92 | <BlockClassName/> |
| 93 | </PanelBody> |
| 94 | </InspectorControls>, |
| 95 | <div { ...blockProps } key={ uniqKey( 'viewBlock' ) }> |
| 96 | <div |
| 97 | className={ 'jet-form-builder__next-page-wrap jet-form-builder__bottom-line' }> |
| 98 | { attributes.add_next_button && <Button |
| 99 | isSecondary |
| 100 | key="next_page_button" |
| 101 | className="jet-form-builder__next-page" |
| 102 | > |
| 103 | <RichText |
| 104 | placeholder="Next..." |
| 105 | allowedFormats={ [] } |
| 106 | value={ attributes.label } |
| 107 | onChange={ label => setAttributes( { label } ) } |
| 108 | /> |
| 109 | </Button> } |
| 110 | { attributes.add_prev && <Button |
| 111 | isSecondary |
| 112 | key="prev_page_button" |
| 113 | className="jet-form-builder__prev-page" |
| 114 | > |
| 115 | <RichText |
| 116 | placeholder="Prev..." |
| 117 | allowedFormats={ [] } |
| 118 | value={ attributes.prev_label } |
| 119 | onChange={ prev_label => setAttributes( |
| 120 | { prev_label } ) } |
| 121 | /> |
| 122 | </Button> } |
| 123 | { ( |
| 124 | !attributes.add_next_button && !attributes.add_prev |
| 125 | ) && <span> |
| 126 | { __( 'Form Break', 'jet-form-builder' ) } |
| 127 | </span> } |
| 128 | </div> |
| 129 | </div>, |
| 130 | ]; |
| 131 | |
| 132 | } |