UNPKG

4.04 kBJavaScriptView Raw
1import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3import _createClass from "@babel/runtime/helpers/esm/createClass";
4import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
5import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6import _inherits from "@babel/runtime/helpers/esm/inherits";
7import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
8import { createElement } from "@wordpress/element";
9
10/**
11 * WordPress dependencies
12 */
13import { InspectorControls } from '@wordpress/block-editor';
14import { Disabled, PanelBody, RangeControl, ToggleControl } from '@wordpress/components';
15import { ServerSideRender } from '@wordpress/editor';
16import { Component, Fragment } from '@wordpress/element';
17import { __ } from '@wordpress/i18n';
18/**
19 * Minimum number of comments a user can show using this block.
20 *
21 * @type {number}
22 */
23
24var MIN_COMMENTS = 1;
25/**
26 * Maximum number of comments a user can show using this block.
27 *
28 * @type {number}
29 */
30
31var MAX_COMMENTS = 100;
32
33var LatestComments =
34/*#__PURE__*/
35function (_Component) {
36 _inherits(LatestComments, _Component);
37
38 function LatestComments() {
39 var _this;
40
41 _classCallCheck(this, LatestComments);
42
43 _this = _possibleConstructorReturn(this, _getPrototypeOf(LatestComments).apply(this, arguments));
44 _this.setCommentsToShow = _this.setCommentsToShow.bind(_assertThisInitialized(_assertThisInitialized(_this))); // Create toggles for each attribute; we create them here rather than
45 // passing `this.createToggleAttribute( 'displayAvatar' )` directly to
46 // `onChange` to avoid re-renders.
47
48 _this.toggleDisplayAvatar = _this.createToggleAttribute('displayAvatar');
49 _this.toggleDisplayDate = _this.createToggleAttribute('displayDate');
50 _this.toggleDisplayExcerpt = _this.createToggleAttribute('displayExcerpt');
51 return _this;
52 }
53
54 _createClass(LatestComments, [{
55 key: "createToggleAttribute",
56 value: function createToggleAttribute(propName) {
57 var _this2 = this;
58
59 return function () {
60 var value = _this2.props.attributes[propName];
61 var setAttributes = _this2.props.setAttributes;
62 setAttributes(_defineProperty({}, propName, !value));
63 };
64 }
65 }, {
66 key: "setCommentsToShow",
67 value: function setCommentsToShow(commentsToShow) {
68 this.props.setAttributes({
69 commentsToShow: commentsToShow
70 });
71 }
72 }, {
73 key: "render",
74 value: function render() {
75 var _this$props$attribute = this.props.attributes,
76 commentsToShow = _this$props$attribute.commentsToShow,
77 displayAvatar = _this$props$attribute.displayAvatar,
78 displayDate = _this$props$attribute.displayDate,
79 displayExcerpt = _this$props$attribute.displayExcerpt;
80 return createElement(Fragment, null, createElement(InspectorControls, null, createElement(PanelBody, {
81 title: __('Latest Comments Settings')
82 }, createElement(ToggleControl, {
83 label: __('Display Avatar'),
84 checked: displayAvatar,
85 onChange: this.toggleDisplayAvatar
86 }), createElement(ToggleControl, {
87 label: __('Display Date'),
88 checked: displayDate,
89 onChange: this.toggleDisplayDate
90 }), createElement(ToggleControl, {
91 label: __('Display Excerpt'),
92 checked: displayExcerpt,
93 onChange: this.toggleDisplayExcerpt
94 }), createElement(RangeControl, {
95 label: __('Number of Comments'),
96 value: commentsToShow,
97 onChange: this.setCommentsToShow,
98 min: MIN_COMMENTS,
99 max: MAX_COMMENTS,
100 required: true
101 }))), createElement(Disabled, null, createElement(ServerSideRender, {
102 block: "core/latest-comments",
103 attributes: this.props.attributes
104 })));
105 }
106 }]);
107
108 return LatestComments;
109}(Component);
110
111export default LatestComments;
112//# sourceMappingURL=edit.js.map
\No newline at end of file