Skip to content

Commit

Permalink
Editor: Align the Post Format control design with the rest of the pos…
Browse files Browse the repository at this point in the history
…t sidebar controls (WordPress#62066)

Co-authored-by: youknowriad <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
4 people authored and carstingaxion committed Jun 4, 2024
1 parent 2a74bc8 commit 9e5c5f4
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 17 deletions.
1 change: 0 additions & 1 deletion packages/editor/src/components/post-author/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export function PostAuthor() {
<PostPanelRow label={ __( 'Author' ) } ref={ setPopoverAnchor }>
<Dropdown
popoverProps={ popoverProps }
className="editor-post-author__panel-dropdown"
contentClassName="editor-post-author__panel-dialog"
focusOnMount
renderToggle={ ( { isOpen, onToggle } ) => (
Expand Down
9 changes: 5 additions & 4 deletions packages/editor/src/components/post-format/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { Button, SelectControl } from '@wordpress/components';
import { Button, RadioControl } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { useInstanceId } from '@wordpress/compose';
import { store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -85,16 +85,17 @@ export default function PostFormat() {
return (
<PostFormatCheck>
<div className="editor-post-format">
<SelectControl
__nextHasNoMarginBottom
<RadioControl
className="editor-post-format__options"
label={ __( 'Post Format' ) }
value={ postFormat }
selected={ postFormat }
onChange={ ( format ) => onUpdatePostFormat( format ) }
id={ postFormatSelectorId }
options={ formats.map( ( format ) => ( {
label: format.caption,
value: format.id,
} ) ) }
hideLabelFromVision
/>
{ suggestion && suggestion.id !== postFormat && (
<p className="editor-post-format__suggestion">
Expand Down
77 changes: 71 additions & 6 deletions packages/editor/src/components/post-format/panel.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,85 @@
/**
* WordPress dependencies
*/
import { PanelRow } from '@wordpress/components';
import { Button, Dropdown } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useState, useMemo } from '@wordpress/element';
import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import PostFormatForm from './';
import { default as PostFormatForm, POST_FORMATS } from './';
import PostFormatCheck from './check';
import PostPanelRow from '../post-panel-row';
import { store as editorStore } from '../../store';

export function PostFormat() {
/**
* Renders the Post Author Panel component.
*
* @return {Component} The component to be rendered.
*/
function PostFormat() {
const { postFormat } = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( editorStore );
const _postFormat = getEditedPostAttribute( 'format' );
return {
postFormat: _postFormat ?? 'standard',
};
}, [] );
const activeFormat = POST_FORMATS.find(
( format ) => format.id === postFormat
);

// Use internal state instead of a ref to make sure that the component
// re-renders when the popover's anchor updates.
const [ popoverAnchor, setPopoverAnchor ] = useState( null );
// Memoize popoverProps to avoid returning a new object every time.
const popoverProps = useMemo(
() => ( {
// Anchor the popover to the middle of the entire row so that it doesn't
// move around when the label changes.
anchor: popoverAnchor,
placement: 'left-start',
offset: 36,
shift: true,
} ),
[ popoverAnchor ]
);
return (
<PostFormatCheck>
<PanelRow className="editor-post-format__panel">
<PostFormatForm />
</PanelRow>
<PostPanelRow label={ __( 'Format' ) } ref={ setPopoverAnchor }>
<Dropdown
popoverProps={ popoverProps }
contentClassName="editor-post-format__dialog"
focusOnMount
renderToggle={ ( { isOpen, onToggle } ) => (
<Button
size="compact"
variant="tertiary"
aria-expanded={ isOpen }
aria-label={ sprintf(
// translators: %s: Current post format.
__( 'Change format: %s' ),
activeFormat?.caption
) }
onClick={ onToggle }
>
{ activeFormat?.caption }
</Button>
) }
renderContent={ ( { onClose } ) => (
<div className="editor-post-format__dialog-content">
<InspectorPopoverHeader
title={ __( 'Format' ) }
onClose={ onClose }
/>
<PostFormatForm />
</div>
) }
/>
</PostPanelRow>
</PostFormatCheck>
);
}
Expand Down
14 changes: 10 additions & 4 deletions packages/editor/src/components/post-format/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
margin: $grid-unit-05 0 0 0;
}

.editor-post-format__panel {
display: flex;
flex-direction: column;
align-items: stretch;
.editor-post-format__dialog .editor-post-format__dialog-content {
// sidebar width - popover padding - form margin
min-width: $sidebar-width - $grid-unit-20 - $grid-unit-20;
margin: $grid-unit-10;
}

.editor-post-format__options {
.components-base-control__field > .components-v-stack {
gap: $grid-unit-15;
}
}
2 changes: 1 addition & 1 deletion packages/editor/src/components/sidebar/post-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export default function PostSummary( { onActionPerformed } ) {
<BlogTitle />
<PostsPerPage />
<SiteDiscussion />
<PostFormatPanel />
<PostStickyPanel />
</VStack>
<PostFormatPanel />
<TemplateAreas />
{ fills }
</VStack>
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/new-post.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test.describe( 'new editor state', () => {
// Should display the Post Formats UI.
await editor.openDocumentSettingsSidebar();
await expect(
page.locator( 'role=combobox[name="Post Format"i]' )
page.locator( 'role=button[name="Change Format: Standard"i]' )
).toBeVisible();
} );

Expand Down

0 comments on commit 9e5c5f4

Please sign in to comment.