deprecated
2 weeks ago
block.json
1 month ago
edit.js
2 months ago
icon-info.svg
2 months ago
icon-success.svg
2 months ago
icon-warning.svg
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
variations.js
2 months ago
edit.js
127 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { PanelBody, SelectControl, BaseControl } from '@wordpress/components'; |
| 3 | import { |
| 4 | InspectorControls, |
| 5 | InnerBlocks, |
| 6 | RichText, |
| 7 | useBlockProps, |
| 8 | } from '@wordpress/block-editor'; |
| 9 | import { FontAwesome } from '@vkblocks/utils/font-awesome-new'; |
| 10 | import { iconLabel } from '@vkblocks/utils/icon-label'; |
| 11 | import parse from 'html-react-parser'; |
| 12 | import { useEffect } from '@wordpress/element'; |
| 13 | import { fixBrokenUnicode } from '@vkblocks/utils/fixBrokenUnicode'; |
| 14 | |
| 15 | export default function AlertEdit(props) { |
| 16 | const { attributes, setAttributes } = props; |
| 17 | const { style, icon, iconText, mobileIconPosition } = attributes; |
| 18 | |
| 19 | useEffect(() => { |
| 20 | if (icon) { |
| 21 | const fixed = fixBrokenUnicode(icon); |
| 22 | if (fixed !== icon) { |
| 23 | setAttributes({ icon: fixed }); |
| 24 | } |
| 25 | } |
| 26 | }, [icon]); |
| 27 | |
| 28 | const blockProps = useBlockProps({ |
| 29 | className: `vk_alert alert alert-${style} ${icon ? 'has-alert-icon' : ''} ${ |
| 30 | mobileIconPosition === 'top' ? 'mobile-icon-top' : '' |
| 31 | }`, |
| 32 | }); |
| 33 | |
| 34 | let alertIcon = ''; |
| 35 | if (icon !== '' && icon !== undefined) { |
| 36 | alertIcon = ( |
| 37 | <div className="vk_alert_icon"> |
| 38 | <div className="vk_alert_icon_icon">{parse(icon)}</div> |
| 39 | <div className="vk_alert_icon_text"> |
| 40 | <RichText |
| 41 | tagName="span" |
| 42 | placeholder={__('Icon Text', 'vk-blocks')} |
| 43 | value={iconText} |
| 44 | onChange={(value) => setAttributes({ iconText: value })} |
| 45 | /> |
| 46 | </div> |
| 47 | </div> |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | return ( |
| 52 | <> |
| 53 | <InspectorControls> |
| 54 | <PanelBody title={__('Style Settings', 'vk-blocks')}> |
| 55 | <BaseControl |
| 56 | label={__('Alert Style', 'vk-blocks')} |
| 57 | id={`vk_alert-style`} |
| 58 | > |
| 59 | <SelectControl |
| 60 | value={style} |
| 61 | onChange={(value) => |
| 62 | setAttributes({ style: value }) |
| 63 | } |
| 64 | options={[ |
| 65 | { |
| 66 | label: __('Success', 'vk-blocks'), |
| 67 | value: 'success', |
| 68 | }, |
| 69 | { |
| 70 | label: __('Info', 'vk-blocks'), |
| 71 | value: 'info', |
| 72 | }, |
| 73 | { |
| 74 | label: __('Warning', 'vk-blocks'), |
| 75 | value: 'warning', |
| 76 | }, |
| 77 | { |
| 78 | label: __('Danger', 'vk-blocks'), |
| 79 | value: 'danger', |
| 80 | }, |
| 81 | ]} |
| 82 | /> |
| 83 | </BaseControl> |
| 84 | <BaseControl |
| 85 | label={iconLabel(__('Icon', 'vk-blocks'))} |
| 86 | id={`vk_alert-icon`} |
| 87 | > |
| 88 | <FontAwesome attributeName={'icon'} {...props} /> |
| 89 | </BaseControl> |
| 90 | {icon && ( |
| 91 | <BaseControl |
| 92 | label={__('Mobile Icon Position', 'vk-blocks')} |
| 93 | id={`vk_alert-mobile-icon-position`} |
| 94 | > |
| 95 | <SelectControl |
| 96 | value={mobileIconPosition} |
| 97 | onChange={(value) => |
| 98 | setAttributes({ mobileIconPosition: value }) |
| 99 | } |
| 100 | options={[ |
| 101 | { |
| 102 | label: __( |
| 103 | 'Left (Default)', |
| 104 | 'vk-blocks' |
| 105 | ), |
| 106 | value: 'left', |
| 107 | }, |
| 108 | { |
| 109 | label: __('Top', 'vk-blocks'), |
| 110 | value: 'top', |
| 111 | }, |
| 112 | ]} |
| 113 | /> |
| 114 | </BaseControl> |
| 115 | )} |
| 116 | </PanelBody> |
| 117 | </InspectorControls> |
| 118 | <div {...blockProps}> |
| 119 | {alertIcon} |
| 120 | <div className="vk_alert_content"> |
| 121 | <InnerBlocks /> |
| 122 | </div> |
| 123 | </div> |
| 124 | </> |
| 125 | ); |
| 126 | } |
| 127 |