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 the title area in the template editor #32037

Merged
merged 2 commits into from
May 28, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const switchToTemplateMode = async () => {
'.edit-post-template-top-area',
( el ) => el.innerText
);
expect( title ).toContain( 'About\n' );
expect( title ).toContain( 'Just an FSE Post\n' );
};

const createNewTemplate = async ( templateName ) => {
Expand Down
42 changes: 35 additions & 7 deletions packages/edit-post/src/components/header/template-title/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { Dropdown, ToolbarItem, Button } from '@wordpress/components';
import { chevronDown } from '@wordpress/icons';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as editorStore } from '@wordpress/editor';
import DeleteTemplate from './delete-template';
import EditTemplateTitle from './edit-template-title';

function TemplateTitle() {
const { template, isEditing } = useSelect( ( select ) => {
const { template, isEditing, title } = useSelect( ( select ) => {
const { isEditingTemplate, getEditedPostTemplate } = select(
editPostStore
);
const { getEditedPostAttribute } = select( editorStore );

const _isEditing = isEditingTemplate();

return {
template: _isEditing ? getEditedPostTemplate() : null,
isEditing: _isEditing,
title: getEditedPostAttribute( 'title' ),
};
}, [] );

const { clearSelectedBlock } = useDispatch( blockEditorStore );
const { setIsEditingTemplate } = useDispatch( editPostStore );

if ( ! isEditing || ! template ) {
return null;
}
Expand All @@ -45,13 +55,31 @@ function TemplateTitle() {
contentClassName="edit-post-template-top-area__popover"
renderToggle={ ( { onToggle } ) => (
<>
<div>{ __( 'About' ) }</div>
<Button
{ ...toolbarItemHTMLProps }
isSmall
variant="tertiary"
className="edit-post-template-post-title"
isLink
showTooltip
label={ sprintf(
/* translators: %s: Title of the referring post, e.g: "Hello World!" */
__( 'Edit %s' ),
title
) }
onClick={ () => {
clearSelectedBlock();
setIsEditingTemplate( false );
} }
>
{ title }
</Button>
<Button
{ ...toolbarItemHTMLProps }
className="edit-post-template-title"
isLink
icon={ chevronDown }
showTooltip
onClick={ onToggle }
aria-label={ __( 'Template Options' ) }
label={ __( 'Template Options' ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that aria-label defaults to the label prop for <Button>s, so you can can remove aria-label here and in the above button since they are the same.

>
{ templateTitle }
</Button>
Expand Down
41 changes: 39 additions & 2 deletions packages/edit-post/src/components/header/template-title/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,45 @@
align-content: space-between;
width: 100%;
align-items: center;
.components-button.is-small {
height: $button-size-small;

.edit-post-template-title,
.edit-post-template-post-title {
padding: 0;
text-decoration: none;
height: auto;

&::before {
height: 100%;
}

&.has-icon {
svg {
order: 1;
margin-right: 0;
}
}
}

.edit-post-template-title {
color: $gray-900;
}

.edit-post-template-post-title {
margin-top: $grid-unit-05;
max-width: 160px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;

&::before {
left: 0;
right: 0;
}

@include break-xlarge() {
max-width: none;
}
}
}

Expand Down