UNPKG

@wordpress/edit-post

Version:
70 lines (61 loc) 1.91 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; /** * WordPress dependencies */ import { Component } from '@wordpress/element'; import { withSelect } from '@wordpress/data'; var MetaBoxVisibility = /*#__PURE__*/ function (_Component) { _inherits(MetaBoxVisibility, _Component); function MetaBoxVisibility() { _classCallCheck(this, MetaBoxVisibility); return _possibleConstructorReturn(this, _getPrototypeOf(MetaBoxVisibility).apply(this, arguments)); } _createClass(MetaBoxVisibility, [{ key: "componentDidMount", value: function componentDidMount() { this.updateDOM(); } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { if (this.props.isVisible !== prevProps.isVisible) { this.updateDOM(); } } }, { key: "updateDOM", value: function updateDOM() { var _this$props = this.props, id = _this$props.id, isVisible = _this$props.isVisible; var element = document.getElementById(id); if (!element) { return; } if (isVisible) { element.classList.remove('is-hidden'); } else { element.classList.add('is-hidden'); } } }, { key: "render", value: function render() { return null; } }]); return MetaBoxVisibility; }(Component); export default withSelect(function (select, _ref) { var id = _ref.id; return { isVisible: select('core/edit-post').isEditorPanelEnabled("meta-box-".concat(id)) }; })(MetaBoxVisibility); //# sourceMappingURL=meta-box-visibility.js.map