PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / blocks / src / loop / title / edit.js
shop-press / blocks / src / loop / title Last commit date
block.json 1 year ago edit.js 1 year ago index.js 2 years ago render.php 2 years ago
edit.js
92 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 { link_to_product, link_target, tag } = attributes;
10
11 return (
12 <InspectorControls>
13 <PanelBody
14 title={ __( 'General', 'shop-press' ) }
15 initialOpen={ true }
16 >
17 <SelectControl
18 label={ __( 'Title HTML Tag', 'shop-press' ) }
19 value={ tag }
20 options={ [
21 { label: 'h1', value: 'h1' },
22 { label: 'h2', value: 'h2' },
23 { label: 'h3', value: 'h3' },
24 { label: 'h4', value: 'h4' },
25 { label: 'h5', value: 'h5' },
26 { label: 'h6', value: 'h6' },
27 { label: 'p', value: 'p' },
28 { label: 'span', value: 'span' },
29 ] }
30 onChange={ ( value ) => setAttributes( { tag: value } ) }
31 __nextHasNoMarginBottom
32 />
33
34 <ToggleControl
35 label={ __( 'Link to Product', 'shop-press' ) }
36 checked={ link_to_product }
37 onChange={ () =>
38 setAttributes( { link_to_product: ! link_to_product } )
39 }
40 />
41
42 <SelectControl
43 label={ __( 'Open link in', 'shop-press' ) }
44 value={ link_target }
45 options={ [
46 { label: 'Current Window', value: '_self' },
47 { label: 'New Window', value: '_blank' },
48 ] }
49 onChange={ ( value ) =>
50 setAttributes( { link_target: value } )
51 }
52 __nextHasNoMarginBottom
53 />
54 </PanelBody>
55 <PanelBody title={ __( 'Styles', 'shop-press' ) }>
56 <Styler
57 clientId={ clientId }
58 label={ __( 'Title', 'shop-press' ) }
59 selector=" .sp-product-title"
60 wrapper={ `.${ attributes[ 'wrapperID' ] }` }
61 attributes={ attributes }
62 setAttributes={ setAttributes }
63 />
64 </PanelBody>
65 </InspectorControls>
66 );
67 };
68
69 const Edit = ( props ) => {
70 const { attributes, setAttributes, clientId } = props;
71 const blockProps = useBlockProps();
72
73 return (
74 <div { ...blockProps }>
75 <Inspector
76 attributes={ attributes }
77 setAttributes={ setAttributes }
78 clientId={ clientId }
79 />
80
81 <Wrapper { ...props }>
82 <ServerSideRender
83 block="shop-press/loop-title"
84 attributes={ attributes }
85 />
86 </Wrapper>
87 </div>
88 );
89 };
90
91 export default Edit;
92