edit.js
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import ServerSideRender from '@wordpress/server-side-render'; |
| 3 | import { |
| 4 | PanelBody, |
| 5 | ToggleControl, |
| 6 | SelectControl, |
| 7 | TextControl, |
| 8 | } from '@wordpress/components'; |
| 9 | import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; |
| 10 | import Styler from '../../styler'; |
| 11 | import Wrapper from '../../wrapper'; |
| 12 | |
| 13 | const Inspector = ( { attributes, setAttributes, clientId } ) => { |
| 14 | const { button_style, button_text, field_icon } = attributes; |
| 15 | |
| 16 | return ( |
| 17 | <InspectorControls> |
| 18 | <PanelBody |
| 19 | title={ __( 'General', 'shop-press' ) } |
| 20 | initialOpen={ true } |
| 21 | > |
| 22 | { /* <ToggleControl |
| 23 | label={__('Show Field Icon', 'shop-press')} |
| 24 | checked={field_icon} |
| 25 | onChange={(value) => { |
| 26 | setAttributes({ field_icon: value }); |
| 27 | }} |
| 28 | /> |
| 29 | |
| 30 | <SelectControl |
| 31 | label={__('Show Field Icon', 'shop-press')} |
| 32 | value={button_style} |
| 33 | options={[ |
| 34 | { label: __('Text', 'shop-press'), value: 'text' }, |
| 35 | { label: __('Icon', 'shop-press'), value: 'icon' }, |
| 36 | { |
| 37 | label: __('Text Icon', 'shop-press'), |
| 38 | value: 'button_icon', |
| 39 | }, |
| 40 | { |
| 41 | label: __('Icon Text', 'shop-press'), |
| 42 | value: 'icon_button', |
| 43 | }, |
| 44 | ]} |
| 45 | onChange={(value) => setAttributes({ button_style: value })} |
| 46 | __nextHasNoMarginBottom |
| 47 | /> */ } |
| 48 | |
| 49 | <TextControl |
| 50 | label={ __( 'Button Text', 'shop-press' ) } |
| 51 | value={ button_text } |
| 52 | onChange={ ( value ) => |
| 53 | setAttributes( { button_text: value } ) |
| 54 | } |
| 55 | /> |
| 56 | </PanelBody> |
| 57 | <PanelBody |
| 58 | title={ __( 'Styles', 'shop-press' ) } |
| 59 | initialOpen={ false } |
| 60 | > |
| 61 | <Styler |
| 62 | clientId={ clientId } |
| 63 | label={ __( 'Wrapper', 'shop-press' ) } |
| 64 | selector="#payment" |
| 65 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 66 | attributes={ attributes } |
| 67 | setAttributes={ setAttributes } |
| 68 | /> |
| 69 | |
| 70 | <Styler |
| 71 | clientId={ clientId } |
| 72 | label={ __( 'Payment Methods Wrapper', 'shop-press' ) } |
| 73 | selector=".wc_payment_methods" |
| 74 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 75 | attributes={ attributes } |
| 76 | setAttributes={ setAttributes } |
| 77 | /> |
| 78 | |
| 79 | <Styler |
| 80 | clientId={ clientId } |
| 81 | label={ __( 'Payment Methods Items', 'shop-press' ) } |
| 82 | selector=".wc_payment_method" |
| 83 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 84 | attributes={ attributes } |
| 85 | setAttributes={ setAttributes } |
| 86 | /> |
| 87 | |
| 88 | <Styler |
| 89 | clientId={ clientId } |
| 90 | label={ __( 'Payment Method Input', 'shop-press' ) } |
| 91 | selector=".wc_payment_method input" |
| 92 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 93 | attributes={ attributes } |
| 94 | setAttributes={ setAttributes } |
| 95 | /> |
| 96 | |
| 97 | <Styler |
| 98 | clientId={ clientId } |
| 99 | label={ __( 'Payment Method Label', 'shop-press' ) } |
| 100 | selector=".wc_payment_method label" |
| 101 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 102 | attributes={ attributes } |
| 103 | setAttributes={ setAttributes } |
| 104 | /> |
| 105 | |
| 106 | <Styler |
| 107 | clientId={ clientId } |
| 108 | label={ __( 'Payment Method Box', 'shop-press' ) } |
| 109 | selector="#payment div.payment_box" |
| 110 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 111 | attributes={ attributes } |
| 112 | setAttributes={ setAttributes } |
| 113 | /> |
| 114 | |
| 115 | <Styler |
| 116 | clientId={ clientId } |
| 117 | label={ __( 'Place Order Wrapper', 'shop-press' ) } |
| 118 | selector=".form-row.place-order" |
| 119 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 120 | attributes={ attributes } |
| 121 | setAttributes={ setAttributes } |
| 122 | /> |
| 123 | |
| 124 | <Styler |
| 125 | clientId={ clientId } |
| 126 | label={ __( 'Privacy Policy Wrapper', 'shop-press' ) } |
| 127 | selector=".woocommerce-privacy-policy-text" |
| 128 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 129 | attributes={ attributes } |
| 130 | setAttributes={ setAttributes } |
| 131 | /> |
| 132 | |
| 133 | <Styler |
| 134 | clientId={ clientId } |
| 135 | label={ __( 'Privacy Policy Text', 'shop-press' ) } |
| 136 | selector=".woocommerce-privacy-policy-text p" |
| 137 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 138 | attributes={ attributes } |
| 139 | setAttributes={ setAttributes } |
| 140 | /> |
| 141 | |
| 142 | <Styler |
| 143 | clientId={ clientId } |
| 144 | label={ __( 'Privacy Policy Link', 'shop-press' ) } |
| 145 | selector=".woocommerce-privacy-policy-text a" |
| 146 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 147 | attributes={ attributes } |
| 148 | setAttributes={ setAttributes } |
| 149 | /> |
| 150 | |
| 151 | <Styler |
| 152 | clientId={ clientId } |
| 153 | label={ __( 'Place Order Button', 'shop-press' ) } |
| 154 | selector=".place-order button#place_order" |
| 155 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 156 | attributes={ attributes } |
| 157 | setAttributes={ setAttributes } |
| 158 | /> |
| 159 | </PanelBody> |
| 160 | </InspectorControls> |
| 161 | ); |
| 162 | }; |
| 163 | |
| 164 | const Edit = ( props ) => { |
| 165 | const { attributes, setAttributes, clientId } = props; |
| 166 | const blockProps = useBlockProps(); |
| 167 | |
| 168 | return ( |
| 169 | <div { ...blockProps }> |
| 170 | <Inspector |
| 171 | attributes={ attributes } |
| 172 | setAttributes={ setAttributes } |
| 173 | clientId={ clientId } |
| 174 | /> |
| 175 | <Wrapper { ...props }> |
| 176 | <ServerSideRender |
| 177 | block="shop-press/checkout-payment" |
| 178 | attributes={ attributes } |
| 179 | /> |
| 180 | </Wrapper> |
| 181 | </div> |
| 182 | ); |
| 183 | }; |
| 184 | |
| 185 | export default Edit; |
| 186 |