edit.js
102 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import ServerSideRender from '@wordpress/server-side-render'; |
| 3 | import { PanelBody, ToggleControl } from '@wordpress/components'; |
| 4 | import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; |
| 5 | import Styler from '../../styler'; |
| 6 | import Wrapper from '../../wrapper'; |
| 7 | |
| 8 | const Inspector = ( { attributes, setAttributes, clientId } ) => { |
| 9 | const { hide_additional_fields_title } = attributes; |
| 10 | |
| 11 | return ( |
| 12 | <InspectorControls> |
| 13 | <PanelBody |
| 14 | title={ __( 'General', 'shop-press' ) } |
| 15 | initialOpen={ true } |
| 16 | > |
| 17 | <ToggleControl |
| 18 | label={ __( 'Hide Title', 'shop-press' ) } |
| 19 | checked={ hide_additional_fields_title } |
| 20 | onChange={ ( value ) => { |
| 21 | setAttributes( { |
| 22 | hide_additional_fields_title: value, |
| 23 | } ); |
| 24 | } } |
| 25 | /> |
| 26 | </PanelBody> |
| 27 | <PanelBody |
| 28 | title={ __( 'Styles', 'shop-press' ) } |
| 29 | initialOpen={ false } |
| 30 | > |
| 31 | <Styler |
| 32 | clientId={ clientId } |
| 33 | label={ __( 'Wrapper', 'shop-press' ) } |
| 34 | selector=".sp-checkout-additional-fields" |
| 35 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 36 | attributes={ attributes } |
| 37 | setAttributes={ setAttributes } |
| 38 | /> |
| 39 | |
| 40 | <Styler |
| 41 | clientId={ clientId } |
| 42 | label={ __( 'Title', 'shop-press' ) } |
| 43 | selector=".woocommerce-additional-fields > .checkout-step-title" |
| 44 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 45 | attributes={ attributes } |
| 46 | setAttributes={ setAttributes } |
| 47 | /> |
| 48 | |
| 49 | <Styler |
| 50 | clientId={ clientId } |
| 51 | label={ __( 'Textarea', 'shop-press' ) } |
| 52 | selector="textarea#order_comments " |
| 53 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 54 | attributes={ attributes } |
| 55 | setAttributes={ setAttributes } |
| 56 | /> |
| 57 | |
| 58 | <Styler |
| 59 | clientId={ clientId } |
| 60 | label={ __( 'Label', 'shop-press' ) } |
| 61 | selector="#order_comments_field label" |
| 62 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 63 | attributes={ attributes } |
| 64 | setAttributes={ setAttributes } |
| 65 | /> |
| 66 | |
| 67 | <Styler |
| 68 | clientId={ clientId } |
| 69 | label={ __( 'Require', 'shop-press' ) } |
| 70 | selector="#order_comments_field label .optional" |
| 71 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 72 | attributes={ attributes } |
| 73 | setAttributes={ setAttributes } |
| 74 | /> |
| 75 | </PanelBody> |
| 76 | </InspectorControls> |
| 77 | ); |
| 78 | }; |
| 79 | |
| 80 | const Edit = ( props ) => { |
| 81 | const { attributes, setAttributes, clientId } = props; |
| 82 | const blockProps = useBlockProps(); |
| 83 | |
| 84 | return ( |
| 85 | <div { ...blockProps }> |
| 86 | <Inspector |
| 87 | attributes={ attributes } |
| 88 | setAttributes={ setAttributes } |
| 89 | clientId={ clientId } |
| 90 | /> |
| 91 | <Wrapper { ...props }> |
| 92 | <ServerSideRender |
| 93 | block="shop-press/checkout-additional-fields" |
| 94 | attributes={ attributes } |
| 95 | /> |
| 96 | </Wrapper> |
| 97 | </div> |
| 98 | ); |
| 99 | }; |
| 100 | |
| 101 | export default Edit; |
| 102 |