PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / blocks / src / loop / review / edit.js
shop-press / blocks / src / loop / review Last commit date
block.json 1 year ago edit.js 2 years ago index.js 2 years ago render.php 2 years ago
edit.js
129 lines
1 import { __ } from '@wordpress/i18n';
2 import {
3 useBlockProps,
4 InspectorControls,
5 MediaUpload,
6 MediaUploadCheck,
7 } from '@wordpress/block-editor';
8 import {
9 PanelBody,
10 Button,
11 __experimentalHeading as Heading,
12 } from '@wordpress/components';
13 import ServerSideRender from '@wordpress/server-side-render';
14 import Styler from '../../styler';
15 import Wrapper from '../../wrapper';
16
17 const Inspector = ( { attributes, setAttributes, clientId } ) => {
18 const { icon } = attributes;
19
20 const onMediaSelect = ( media ) => {
21 const { id, url, type } = media;
22
23 const icon = { value: id, url, type };
24
25 setAttributes( { icon: icon } );
26 };
27
28 const onRemoveImage = () => {
29 setAttributes( { icon: { value: '', url: '', type: '' } } );
30 };
31
32 return (
33 <InspectorControls>
34 <PanelBody title={ __( 'General', 'shop-press' ) }>
35 <MediaUploadCheck>
36 <MediaUpload
37 onSelect={ ( media ) => onMediaSelect( media ) }
38 allowedTypes={ [ 'image' ] }
39 value={ icon?.value }
40 render={ ( { open } ) => (
41 <>
42 <Heading>
43 { __( 'Icon', 'shop-press' ) }
44 </Heading>
45 <div style={ { display: 'flex', gap: '10px' } }>
46 <Button variant="primary" onClick={ open }>
47 { __( 'Upload', 'shop-press' ) }
48 </Button>
49
50 { icon?.value && (
51 <Button
52 variant="secondary"
53 onClick={ onRemoveImage }
54 >
55 { __( 'Remove', 'shop-press' ) }
56 </Button>
57 ) }
58 </div>
59 </>
60 ) }
61 />
62
63 { icon && (
64 <div style={ { marginTop: '15px' } }>
65 <img width={ 70 } src={ icon?.url } />
66 </div>
67 ) }
68 </MediaUploadCheck>
69 </PanelBody>
70
71 <PanelBody
72 title={ __( 'Styles', 'shop-press' ) }
73 initialOpen={ false }
74 >
75 <Styler
76 clientId={ clientId }
77 label={ __( 'Wrapper', 'shop-press' ) }
78 selector=".sp-product-review"
79 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
80 attributes={ attributes }
81 setAttributes={ setAttributes }
82 />
83
84 <Styler
85 clientId={ clientId }
86 label={ __( 'Review Count', 'shop-press' ) }
87 selector=".sp-product-review span.review-count"
88 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
89 attributes={ attributes }
90 setAttributes={ setAttributes }
91 />
92
93 <Styler
94 clientId={ clientId }
95 label={ __( 'Review Icon', 'shop-press' ) }
96 selector=".sp-product-review i"
97 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
98 attributes={ attributes }
99 setAttributes={ setAttributes }
100 />
101 </PanelBody>
102 </InspectorControls>
103 );
104 };
105
106 const Edit = ( props ) => {
107 const { attributes, setAttributes, clientId } = props;
108 const blockProps = useBlockProps();
109
110 return (
111 <div { ...blockProps }>
112 <Inspector
113 attributes={ attributes }
114 setAttributes={ setAttributes }
115 clientId={ clientId }
116 />
117
118 <Wrapper { ...props }>
119 <ServerSideRender
120 block="shop-press/loop-review"
121 attributes={ attributes }
122 />
123 </Wrapper>
124 </div>
125 );
126 };
127
128 export default Edit;
129