edit.js
109 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; |
| 3 | import { PanelBody, ToggleControl, SelectControl } from '@wordpress/components'; |
| 4 | import ServerSideRender from '@wordpress/server-side-render'; |
| 5 | import Styler from '../../styler'; |
| 6 | import Wrapper from '../../wrapper'; |
| 7 | |
| 8 | const Inspector = ( { attributes, setAttributes, clientId } ) => { |
| 9 | const { thumbnail_type, show_arrows, show_nav } = attributes; |
| 10 | |
| 11 | return ( |
| 12 | <InspectorControls> |
| 13 | <PanelBody |
| 14 | title={ __( 'General', 'shop-press' ) } |
| 15 | initialOpen={ true } |
| 16 | > |
| 17 | <SelectControl |
| 18 | label={ __( 'Thumbnail Type', 'shop-press' ) } |
| 19 | value={ thumbnail_type } |
| 20 | options={ [ |
| 21 | { label: 'Single', value: 'single' }, |
| 22 | { |
| 23 | label: 'Change image on hover', |
| 24 | value: 'change_image_on_hover', |
| 25 | }, |
| 26 | { label: 'Slider', value: 'slider' }, |
| 27 | ] } |
| 28 | onChange={ ( value ) => |
| 29 | setAttributes( { thumbnail_type: value } ) |
| 30 | } |
| 31 | __nextHasNoMarginBottom |
| 32 | /> |
| 33 | |
| 34 | { thumbnail_type === 'slider' && ( |
| 35 | <> |
| 36 | <ToggleControl |
| 37 | label={ __( 'Arrows', 'shop-press' ) } |
| 38 | checked={ show_arrows } |
| 39 | onChange={ () => |
| 40 | setAttributes( { show_arrows: ! show_arrows } ) |
| 41 | } |
| 42 | /> |
| 43 | |
| 44 | <ToggleControl |
| 45 | label={ __( 'Navigation', 'shop-press' ) } |
| 46 | checked={ show_nav } |
| 47 | onChange={ () => |
| 48 | setAttributes( { show_nav: ! show_nav } ) |
| 49 | } |
| 50 | /> |
| 51 | </> |
| 52 | ) } |
| 53 | </PanelBody> |
| 54 | <PanelBody title={ __( 'Styles', 'shop-press' ) }> |
| 55 | <Styler |
| 56 | clientId={ clientId } |
| 57 | label={ __( 'Wrapper', 'shop-press' ) } |
| 58 | selector=".sp-product-thumbnail" |
| 59 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 60 | attributes={ attributes } |
| 61 | setAttributes={ setAttributes } |
| 62 | /> |
| 63 | |
| 64 | <Styler |
| 65 | clientId={ clientId } |
| 66 | label={ __( 'Image Wrapper', 'shop-press' ) } |
| 67 | selector=".sp-product-thumbnail a" |
| 68 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 69 | attributes={ attributes } |
| 70 | setAttributes={ setAttributes } |
| 71 | /> |
| 72 | |
| 73 | <Styler |
| 74 | clientId={ clientId } |
| 75 | label={ __( 'Image', 'shop-press' ) } |
| 76 | selector=".sp-product-thumbnail a img" |
| 77 | wrapper={ `.${ attributes[ 'wrapperID' ] }` } |
| 78 | attributes={ attributes } |
| 79 | setAttributes={ setAttributes } |
| 80 | /> |
| 81 | </PanelBody> |
| 82 | </InspectorControls> |
| 83 | ); |
| 84 | }; |
| 85 | |
| 86 | const Edit = ( props ) => { |
| 87 | const { attributes, setAttributes, clientId } = props; |
| 88 | const blockProps = useBlockProps(); |
| 89 | |
| 90 | return ( |
| 91 | <div { ...blockProps }> |
| 92 | <Inspector |
| 93 | attributes={ attributes } |
| 94 | setAttributes={ setAttributes } |
| 95 | clientId={ clientId } |
| 96 | /> |
| 97 | |
| 98 | <Wrapper { ...props }> |
| 99 | <ServerSideRender |
| 100 | block="shop-press/loop-thumbnail" |
| 101 | attributes={ attributes } |
| 102 | /> |
| 103 | </Wrapper> |
| 104 | </div> |
| 105 | ); |
| 106 | }; |
| 107 | |
| 108 | export default Edit; |
| 109 |