PluginProbe
Canvas / 2.4.9
Canvas v2.4.9
2.5.5 2.5.4 trunk 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 All 54 releases
canvas / components / basic-elements / block-alert / edit.jsx

edit.jsx in Canvas 2.4.9, at components/basic-elements/block-alert/edit.jsx

101 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * External dependencies
3 */
4 import classnames from 'classnames';
5
6 /**
7 * WordPress dependencies
8 */
9 const {
10 __,
11 } = wp.i18n;
12
13 const {
14 Component,
15 Fragment,
16 } = wp.element;
17
18 const {
19 InnerBlocks,
20 } = wp.blockEditor;
21
22 const {
23 withSelect,
24 } = wp.data;
25
26 /**
27 * Component
28 */
29 class AlertBlockEdit extends Component {
30 constructor() {
31 super(...arguments);
32
33 this.state = {
34 // fix for WP 5.2
35 // styles control generates error
36 showInnerBlocks: !!this.props.clientId,
37 };
38 }
39
40 render() {
41 const {
42 setAttributes,
43 hasChildBlocks,
44 } = this.props;
45
46 let {
47 className,
48 attributes,
49 } = this.props;
50
51 const {
52 dismissible,
53 canvasClassName,
54 } = attributes;
55
56 className = classnames(
57 'cnvs-block-alert',
58 {
59 'cnvs-block-alert-dismissible': dismissible,
60 },
61 canvasClassName,
62 className
63 );
64
65 return (
66 <Fragment>
67 <div className={className}>
68 <div className="cnvs-block-alert-inner">
69 {this.state.showInnerBlocks ? (
70 <InnerBlocks
71 templateLock={false}
72 renderAppender={(
73 hasChildBlocks ?
74 undefined :
75 () => <InnerBlocks.ButtonBlockAppender />
76 )}
77 />
78 ) : __('Alert content')}
79 </div>
80 {dismissible ? (
81 <button className="cnvs-close" type="button" data-dismiss="alert" aria-label={__('Close')}>
82 <i className="cnvs-icon-x" />
83 </button>
84 ) : ''}
85 </div>
86 </Fragment>
87 );
88 }
89 }
90
91 const AlertBlockEditWithSelect = withSelect((select, ownProps) => {
92 const { clientId } = ownProps;
93 const blockEditor = select('core/block-editor');
94
95 return {
96 hasChildBlocks: blockEditor ? blockEditor.getBlockOrder(clientId).length > 0 : false,
97 };
98 })(AlertBlockEdit);
99
100 export default AlertBlockEditWithSelect;
101