deprecated
1 week ago
block.json
1 month ago
edit.js
2 months ago
icon.svg
2 months ago
index.js
2 months ago
index.php
2 months ago
save.js
2 months ago
style.scss
2 months ago
edit.js
104 lines
| 1 | import { |
| 2 | RichText, |
| 3 | InspectorControls, |
| 4 | MediaUpload, |
| 5 | useBlockProps, |
| 6 | } from '@wordpress/block-editor'; |
| 7 | import { __ } from '@wordpress/i18n'; |
| 8 | |
| 9 | import { RadioControl, PanelBody, Button } from '@wordpress/components'; |
| 10 | |
| 11 | export default function FlowEdit({ attributes, setAttributes, clientId }) { |
| 12 | const { heading, content, insertImage, arrowFlag, insertImageAlt } = |
| 13 | attributes; |
| 14 | const blockProps = useBlockProps({ |
| 15 | className: `${arrowFlag} vk_flow`, |
| 16 | }); |
| 17 | |
| 18 | return ( |
| 19 | <> |
| 20 | <InspectorControls> |
| 21 | <PanelBody title={__('Display of arrow', 'vk-blocks')}> |
| 22 | <RadioControl |
| 23 | selected={arrowFlag} |
| 24 | options={[ |
| 25 | { |
| 26 | label: __('Arrow display', 'vk-blocks'), |
| 27 | value: 'vk_flow-arrow-on', |
| 28 | }, |
| 29 | { |
| 30 | label: __('Arrow hidden', 'vk-blocks'), |
| 31 | value: 'vk_flow-arrow-off', |
| 32 | }, |
| 33 | ]} |
| 34 | onChange={(value) => |
| 35 | setAttributes({ arrowFlag: value }) |
| 36 | } |
| 37 | /> |
| 38 | </PanelBody> |
| 39 | </InspectorControls> |
| 40 | |
| 41 | <div {...blockProps}> |
| 42 | <div className={'vk_flow_frame'}> |
| 43 | <dl className={'vk_flow_frame_text'}> |
| 44 | <RichText |
| 45 | key={`${clientId}2`} |
| 46 | tagName="dt" |
| 47 | className={'vk_flow_frame_text_title'} |
| 48 | onChange={(value) => |
| 49 | setAttributes({ heading: value }) |
| 50 | } |
| 51 | value={heading} |
| 52 | placeholder={__('Input title', 'vk-blocks')} |
| 53 | /> |
| 54 | <RichText |
| 55 | key={`${clientId}3`} |
| 56 | tagName="dd" |
| 57 | className={'vk_flow_frame_text_content'} |
| 58 | onChange={(value) => |
| 59 | setAttributes({ content: value }) |
| 60 | } |
| 61 | value={content} |
| 62 | placeholder={__('Input content', 'vk-blocks')} |
| 63 | /> |
| 64 | </dl> |
| 65 | <div className={'vk_flow_frame_image'}> |
| 66 | <MediaUpload |
| 67 | onSelect={(value) => { |
| 68 | setAttributes({ insertImage: value.url }); |
| 69 | setAttributes({ insertImageAlt: value.alt }); |
| 70 | }} |
| 71 | type="image" |
| 72 | className={'vk_flow_frame_image'} |
| 73 | value={insertImage} |
| 74 | render={({ open }) => ( |
| 75 | <Button |
| 76 | onClick={open} |
| 77 | className={ |
| 78 | insertImage |
| 79 | ? 'image-button' |
| 80 | : 'button button-large' |
| 81 | } |
| 82 | > |
| 83 | {!insertImage ? ( |
| 84 | __('Select image', 'vk-blocks') |
| 85 | ) : ( |
| 86 | <img |
| 87 | className={'icon-image'} |
| 88 | src={insertImage} |
| 89 | alt={insertImageAlt} |
| 90 | /> |
| 91 | )} |
| 92 | </Button> |
| 93 | )} |
| 94 | /> |
| 95 | </div> |
| 96 | </div> |
| 97 | {arrowFlag === 'vk_flow-arrow-on' && ( |
| 98 | <div className={'vk_flow_frame_arrow'}></div> |
| 99 | )} |
| 100 | </div> |
| 101 | </> |
| 102 | ); |
| 103 | } |
| 104 |