diff --git a/packages/editor/src/components/post-visibility/index.js b/packages/editor/src/components/post-visibility/index.js
index fc24ce034b2883..cc8efb636e3407 100644
--- a/packages/editor/src/components/post-visibility/index.js
+++ b/packages/editor/src/components/post-visibility/index.js
@@ -4,9 +4,9 @@
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import {
- VisuallyHidden,
- __experimentalConfirmDialog as ConfirmDialog,
TextControl,
+ RadioControl,
+ __experimentalVStack as VStack,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';
@@ -15,7 +15,7 @@ import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '
/**
* Internal dependencies
*/
-import { visibilityOptions } from './utils';
+import { VISIBILITY_OPTIONS } from './utils';
import { store as editorStore } from '../../store';
/**
@@ -34,42 +34,26 @@ export default function PostVisibility( { onClose } ) {
password: select( editorStore ).getEditedPostAttribute( 'password' ),
} ) );
- const { editPost, savePost } = useDispatch( editorStore );
+ const { editPost } = useDispatch( editorStore );
const [ hasPassword, setHasPassword ] = useState( !! password );
- const [ showPrivateConfirmDialog, setShowPrivateConfirmDialog ] =
- useState( false );
- const setPublic = () => {
- editPost( {
- status: visibility === 'private' ? 'draft' : status,
- password: '',
- } );
- setHasPassword( false );
- };
-
- const setPrivate = () => {
- setShowPrivateConfirmDialog( true );
- };
-
- const confirmPrivate = () => {
- editPost( { status: 'private', password: '' } );
- setHasPassword( false );
- setShowPrivateConfirmDialog( false );
- savePost();
- };
-
- const handleDialogCancel = () => {
- setShowPrivateConfirmDialog( false );
- };
+ function updateVisibility( value ) {
+ const nextValues = {
+ public: {
+ status: visibility === 'private' ? 'draft' : status,
+ password: '',
+ },
+ private: { status: 'private', password: '' },
+ password: {
+ status: visibility === 'private' ? 'draft' : status,
+ password: password || '',
+ },
+ };
- const setPasswordProtected = () => {
- editPost( {
- status: visibility === 'private' ? 'draft' : status,
- password: password || '',
- } );
- setHasPassword( true );
- };
+ editPost( nextValues[ value ] );
+ setHasPassword( value === 'password' );
+ }
const updatePassword = ( value ) => {
editPost( { password: value } );
@@ -82,33 +66,13 @@ export default function PostVisibility( { onClose } ) {
help={ __( 'Control how this post is viewed.' ) }
onClose={ onClose }
/>
-
-
- { __( 'Would you like to privately publish this post now?' ) }
-
-
- );
-}
-
-function PostVisibilityChoice( { instanceId, value, label, info, ...props } ) {
- return (
-
-
-
-
- { info }
-
+
);
}
diff --git a/packages/editor/src/components/post-visibility/label.js b/packages/editor/src/components/post-visibility/label.js
index 50a6e14aa1a14e..ace33ed40435ab 100644
--- a/packages/editor/src/components/post-visibility/label.js
+++ b/packages/editor/src/components/post-visibility/label.js
@@ -6,7 +6,7 @@ import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
-import { visibilityOptions } from './utils';
+import { VISIBILITY_OPTIONS } from './utils';
import { store as editorStore } from '../../store';
/**
@@ -24,8 +24,11 @@ export default function PostVisibilityLabel() {
* @return {string} Post visibility label.
*/
export function usePostVisibilityLabel() {
- const visibility = useSelect( ( select ) =>
- select( editorStore ).getEditedPostVisibility()
+ const visibility = useSelect(
+ ( select ) => select( editorStore ).getEditedPostVisibility(),
+ []
);
- return visibilityOptions[ visibility ]?.label;
+
+ return VISIBILITY_OPTIONS.find( ( option ) => option.value === visibility )
+ ?.label;
}
diff --git a/packages/editor/src/components/post-visibility/style.scss b/packages/editor/src/components/post-visibility/style.scss
deleted file mode 100644
index 589f5260181c2a..00000000000000
--- a/packages/editor/src/components/post-visibility/style.scss
+++ /dev/null
@@ -1,21 +0,0 @@
-.editor-post-visibility__fieldset {
- .editor-post-visibility__radio[type="radio"] {
- @include radio-control;
- margin-top: 2px;
- }
-
- .editor-post-visibility__info {
- color: $gray-700;
- margin-left: $grid-unit-15 + $radio-input-size-sm;
- margin-top: 0.5em;
-
- @include break-small {
- margin-left: $grid-unit-15 + $radio-input-size;
- }
- }
-
- // Remove bottom margin on the last label only.
- .editor-post-visibility__choice:last-child .editor-post-visibility__info {
- margin-bottom: 0;
- }
-}
diff --git a/packages/editor/src/components/post-visibility/utils.js b/packages/editor/src/components/post-visibility/utils.js
index 8c7b1f4b63a634..f4493b220e2e34 100644
--- a/packages/editor/src/components/post-visibility/utils.js
+++ b/packages/editor/src/components/post-visibility/utils.js
@@ -3,17 +3,20 @@
*/
import { __ } from '@wordpress/i18n';
-export const visibilityOptions = {
- public: {
+export const VISIBILITY_OPTIONS = [
+ {
label: __( 'Public' ),
- info: __( 'Visible to everyone.' ),
+ value: 'public',
+ description: __( 'Visible to everyone.' ),
},
- private: {
+ {
label: __( 'Private' ),
- info: __( 'Only visible to site admins and editors.' ),
+ value: 'private',
+ description: __( 'Only visible to site admins and editors.' ),
},
- password: {
+ {
label: __( 'Password protected' ),
- info: __( 'Only visible to those who know the password.' ),
+ value: 'password',
+ description: __( 'Only visible to those who know the password.' ),
},
-};
+];
diff --git a/packages/editor/src/style.scss b/packages/editor/src/style.scss
index c3366d6aa2266f..fe7a8dfbae5981 100644
--- a/packages/editor/src/style.scss
+++ b/packages/editor/src/style.scss
@@ -41,7 +41,6 @@
@import "./components/post-text-editor/style.scss";
@import "./components/post-title/style.scss";
@import "./components/post-url/style.scss";
-@import "./components/post-visibility/style.scss";
@import "./components/posts-per-page/style.scss";
@import "./components/post-trash/style.scss";
@import "./components/preview-dropdown/style.scss";