UNPKG

@wordpress/editor

Version:
98 lines (95 loc) 3.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = PostVisibility; var _i18n = require("@wordpress/i18n"); var _element = require("@wordpress/element"); var _components = require("@wordpress/components"); var _compose = require("@wordpress/compose"); var _data = require("@wordpress/data"); var _blockEditor = require("@wordpress/block-editor"); var _utils = require("./utils"); var _store = require("../../store"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * Allows users to set the visibility of a post. * * @param {Object} props The component props. * @param {Function} props.onClose Function to call when the popover is closed. * @return {React.ReactNode} The rendered component. */function PostVisibility({ onClose }) { const instanceId = (0, _compose.useInstanceId)(PostVisibility); const { status, visibility, password } = (0, _data.useSelect)(select => ({ status: select(_store.store).getEditedPostAttribute('status'), visibility: select(_store.store).getEditedPostVisibility(), password: select(_store.store).getEditedPostAttribute('password') })); const { editPost } = (0, _data.useDispatch)(_store.store); const [hasPassword, setHasPassword] = (0, _element.useState)(!!password); function updateVisibility(value) { const nextValues = { public: { status: visibility === 'private' ? 'draft' : status, password: '' }, private: { status: 'private', password: '' }, password: { status: visibility === 'private' ? 'draft' : status, password: password || '' } }; editPost(nextValues[value]); setHasPassword(value === 'password'); } const updatePassword = value => { editPost({ password: value }); }; return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { className: "editor-post-visibility", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.__experimentalInspectorPopoverHeader, { title: (0, _i18n.__)('Visibility'), help: (0, _i18n.__)('Control how this post is viewed.'), onClose: onClose }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, { spacing: 4, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.RadioControl, { label: (0, _i18n.__)('Visibility'), hideLabelFromVision: true, options: _utils.VISIBILITY_OPTIONS, selected: hasPassword ? 'password' : visibility, onChange: updateVisibility }), hasPassword && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, { label: (0, _i18n.__)('Password'), onChange: updatePassword, value: password, placeholder: (0, _i18n.__)('Use a secure password'), type: "text", id: `editor-post-visibility__password-input-${instanceId}`, __next40pxDefaultSize: true, __nextHasNoMarginBottom: true, maxLength: 255 })] })] }); } //# sourceMappingURL=index.js.map