Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Implement new author panel design. #61362

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/editor/src/components/post-author/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function PostAuthorCombobox() {
onFilterValueChange={ debounce( handleKeydown, 300 ) }
onChange={ handleSelect }
allowReset={ false }
hideLabelFromVision
/>
);
}
2 changes: 1 addition & 1 deletion packages/editor/src/components/post-author/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ export function useAuthorsQuery( search ) {
return fetchedAuthors;
}, [ authors, postAuthor ] );

return { authorId, authorOptions };
return { authorId, authorOptions, postAuthor };
}
66 changes: 64 additions & 2 deletions packages/editor/src/components/post-author/panel.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,82 @@
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { Button, Dropdown } from '@wordpress/components';
import { useState, useMemo } from '@wordpress/element';
import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import PostAuthorCheck from './check';
import PostAuthorForm from './index';
import PostPanelRow from '../post-panel-row';
import { useAuthorsQuery } from './hook';

function PostAuthorToggle( { isOpen, onClick } ) {
const { postAuthor } = useAuthorsQuery();
const authorName = postAuthor?.name || '';
return (
<Button
size="compact"
className="editor-post-author__panel-toggle"
variant="tertiary"
aria-expanded={ isOpen }
// translators: %s: Current post link.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong translators comment 😄

aria-label={ sprintf( __( 'Change author: %s' ), authorName ) }
onClick={ onClick }
>
{ authorName }
</Button>
);
}

/**
* Renders the Post Author Panel component.
*
* @return {Component} The component to be rendered.
*/
export function PostAuthor() {
// 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 (
<PostAuthorCheck>
<PostPanelRow className="editor-post-author__panel">
<PostAuthorForm />
<PostPanelRow label={ __( 'Author' ) } ref={ setPopoverAnchor }>
<Dropdown
popoverProps={ popoverProps }
className="editor-post-author__panel-dropdown"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not using this className.

contentClassName="editor-post-author__panel-dialog"
focusOnMount
renderToggle={ ( { isOpen, onToggle } ) => (
<PostAuthorToggle
isOpen={ isOpen }
onClick={ onToggle }
/>
) }
renderContent={ ( { onClose } ) => (
<div className="editor-post-author">
<InspectorPopoverHeader
title={ __( 'Author' ) }
onClose={ onClose }
/>
<PostAuthorForm onClose={ onClose } />
</div>
) }
/>
</PostPanelRow>
</PostAuthorCheck>
);
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/post-author/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function PostAuthorSelect() {
options={ authorOptions }
onChange={ setAuthorId }
value={ authorId }
hideLabelFromVision
/>
);
}
6 changes: 6 additions & 0 deletions packages/editor/src/components/post-author/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
.editor-post-author__panel .editor-post-panel__row-control > div {
width: 100%;
}

.editor-post-author__panel-dialog .editor-post-author {
// sidebar width - popover padding - form margin
min-width: $sidebar-width - $grid-unit-20 - $grid-unit-20;
margin: $grid-unit-10;
}
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 @@ -81,12 +81,12 @@ export default function PostSummary( { onActionPerformed } ) {
<PostSchedulePanel />
<PostTemplatePanel />
<PostURLPanel />
<PostAuthorPanel />
<PostDiscussionPanel />
<PostSyncStatus />
</VStack>
<PostStickyPanel />
<PostFormatPanel />
<PostAuthorPanel />
{ isTemplate && <TemplateAreas /> }
{ fills }
{ ! isPattern &&
Expand Down
Loading