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

Display a document icon when using the site editor #48052

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ function useSecondaryText() {

if ( activeEntityBlockId ) {
return {
label: getBlockDisplayText( getBlock( activeEntityBlockId ) ),
secondaryLabel: getBlockDisplayText(
getBlock( activeEntityBlockId )
),
isActive: true,
icon: blockInformation?.icon,
secondaryIcon: blockInformation?.icon,
};
}

Expand All @@ -75,8 +77,8 @@ export default function DocumentActions() {
),
[]
);
const { isLoaded, record, getTitle } = useEditedEntityRecord();
const { label, icon } = useSecondaryText();
const { isLoaded, record, getTitle, icon } = useEditedEntityRecord();
const { secondaryLabel, secondaryIcon } = useSecondaryText();

// Use internal state instead of a ref to make sure that the component
// re-renders when the popover's anchor updates.
Expand Down Expand Up @@ -119,7 +121,7 @@ export default function DocumentActions() {
return (
<div
className={ classnames( 'edit-site-document-actions', {
'has-secondary-label': !! label,
'has-secondary-label': !! secondaryLabel,
} ) }
>
<div
Expand All @@ -131,6 +133,7 @@ export default function DocumentActions() {
className="edit-site-document-actions__title"
as="h1"
>
<BlockIcon icon={ icon } />
<VisuallyHidden as="span">
{ sprintf(
/* translators: %s: the entity being edited, like "template"*/
Expand All @@ -141,8 +144,8 @@ export default function DocumentActions() {
{ getTitle() }
</Text>
<div className="edit-site-document-actions__secondary-item">
<BlockIcon icon={ icon } showColors />
<Text size="body">{ label ?? '' }</Text>
<BlockIcon icon={ secondaryIcon } showColors />
<Text size="body">{ secondaryLabel ?? '' }</Text>
</div>

<Dropdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
overflow: hidden;
text-overflow: ellipsis;
color: currentColor;
align-items: center;
display: inline-flex;
gap: $grid-unit-05;
}

.edit-site-document-actions__secondary-item {
Expand All @@ -68,7 +71,8 @@
opacity: 1;
padding: 0 4px;
max-width: 180px;
margin-left: 6px;
margin-left: $grid-unit-15;
gap: $grid-unit-05;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { decodeEntities } from '@wordpress/html-entities';
import { store as editSiteStore } from '../../store';

export default function useEditedEntityRecord( postType, postId ) {
const { record, title, description, isLoaded } = useSelect(
const { record, title, description, isLoaded, icon } = useSelect(
( select ) => {
const { getEditedPostType, getEditedPostId } =
select( editSiteStore );
Expand All @@ -34,13 +34,15 @@ export default function useEditedEntityRecord( postType, postId ) {
title: templateInfo.title,
description: templateInfo.description,
isLoaded: _isLoaded,
icon: templateInfo.icon,
};
},
[ postType, postId ]
);

return {
isLoaded,
icon,
record,
getTitle: () => ( title ? decodeEntities( title ) : null ),
getDescription: () =>
Expand Down