PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / blocks / src / loop / quick-view / edit.js
shop-press / blocks / src / loop / quick-view 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
186 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 TextControl,
11 ToggleControl,
12 SelectControl,
13 Button,
14 __experimentalHeading as Heading,
15 } from '@wordpress/components';
16 import ServerSideRender from '@wordpress/server-side-render';
17 import Styler from '../../styler';
18 import Wrapper from '../../wrapper';
19
20 const Inspector = ( { attributes, setAttributes, clientId } ) => {
21 const { icon, icon_pos, overlay, label } = attributes;
22
23 const onMediaSelect = ( media ) => {
24 const { id, url, type } = media;
25
26 const icon = { value: id, url, type };
27
28 setAttributes( { icon: icon } );
29 };
30
31 const onRemoveImage = () => {
32 setAttributes( { icon: { value: '', url: '', type: '' } } );
33 };
34
35 return (
36 <InspectorControls>
37 <PanelBody
38 title={ __( 'General', 'shop-press' ) }
39 initialOpen={ true }
40 >
41 <TextControl
42 label={ __( 'Label', 'shop-press' ) }
43 value={ label }
44 onChange={ ( value ) => setAttributes( { label: value } ) }
45 />
46
47 <ToggleControl
48 label={ __( 'Overlay', 'shop-press' ) }
49 checked={ overlay }
50 onChange={ () => setAttributes( { overlay: ! overlay } ) }
51 />
52
53 <SelectControl
54 label={ __( 'Icon Position', 'shop-press' ) }
55 value={ icon_pos }
56 options={ [
57 { label: 'Left', value: 'left' },
58 { label: 'Right', value: 'right' },
59 ] }
60 onChange={ ( value ) =>
61 setAttributes( { icon_pos: value } )
62 }
63 __nextHasNoMarginBottom
64 />
65
66 <MediaUploadCheck>
67 <MediaUpload
68 onSelect={ ( media ) => onMediaSelect( media ) }
69 allowedTypes={ [ 'image' ] }
70 value={ icon?.value }
71 render={ ( { open } ) => (
72 <>
73 <Heading>
74 { __( 'Icon', 'shop-press' ) }
75 </Heading>
76 <div style={ { display: 'flex', gap: '10px' } }>
77 <Button variant="primary" onClick={ open }>
78 { __( 'Upload', 'shop-press' ) }
79 </Button>
80
81 { icon?.value && (
82 <Button
83 variant="secondary"
84 onClick={ onRemoveImage }
85 >
86 { __( 'Remove', 'shop-press' ) }
87 </Button>
88 ) }
89 </div>
90 </>
91 ) }
92 />
93
94 { icon && (
95 <div style={ { marginTop: '15px' } }>
96 <img width={ 70 } src={ icon?.url } />
97 </div>
98 ) }
99 </MediaUploadCheck>
100 </PanelBody>
101 <PanelBody
102 title={ __( 'Styles', 'shop-press' ) }
103 initialOpen={ false }
104 >
105 <Styler
106 clientId={ clientId }
107 label={ __( 'Button', 'shop-press' ) }
108 selector=".sp-quick-view"
109 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
110 attributes={ attributes }
111 setAttributes={ setAttributes }
112 />
113
114 <Styler
115 clientId={ clientId }
116 label={ __( 'Icon Wrapper', 'shop-press' ) }
117 selector=".sp-quick-view .sp-quick-view-icon"
118 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
119 attributes={ attributes }
120 setAttributes={ setAttributes }
121 />
122
123 <Styler
124 clientId={ clientId }
125 label={ __( 'Icon', 'shop-press' ) }
126 selector=".sp-quick-view .sp-quick-view-icon i.sp-icon"
127 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
128 attributes={ attributes }
129 setAttributes={ setAttributes }
130 />
131
132 <Styler
133 clientId={ clientId }
134 label={ __( 'Label', 'shop-press' ) }
135 selector=".sp-quick-view .sp-quickview-label"
136 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
137 attributes={ attributes }
138 setAttributes={ setAttributes }
139 />
140
141 <Styler
142 clientId={ clientId }
143 label={ __( 'Tooltip', 'shop-press' ) }
144 selector=" .sp-quick-view.overlay .sp-quickview-label"
145 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
146 attributes={ attributes }
147 setAttributes={ setAttributes }
148 />
149
150 <Styler
151 clientId={ clientId }
152 label={ __( 'Tooltip Arrow', 'shop-press' ) }
153 selector=".sp-quick-view.overlay span:before"
154 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
155 attributes={ attributes }
156 setAttributes={ setAttributes }
157 />
158 </PanelBody>
159 </InspectorControls>
160 );
161 };
162
163 const Edit = ( props ) => {
164 const { attributes, setAttributes, clientId } = props;
165 const blockProps = useBlockProps();
166
167 return (
168 <div { ...blockProps }>
169 <Inspector
170 attributes={ attributes }
171 setAttributes={ setAttributes }
172 clientId={ clientId }
173 />
174
175 <Wrapper { ...props }>
176 <ServerSideRender
177 block="shop-press/loop-quick-view"
178 attributes={ attributes }
179 />
180 </Wrapper>
181 </div>
182 );
183 };
184
185 export default Edit;
186