Skip to content

Commit

Permalink
Site Editor: Allow editing custom template title (#36933)
Browse files Browse the repository at this point in the history
* Site Editor: Allow editing custom template title

* Fallback to slug
  • Loading branch information
Mamaduka authored and noisysocks committed Nov 30, 2021
1 parent 223023d commit ea2bd81
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { TextControl } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';

export default function EditTemplateTitle( { template } ) {
const [ title, setTitle ] = useEntityProp(
'postType',
template.type,
'title',
template.id
);

return (
<TextControl
label={ __( 'Title' ) }
value={ title }
help={ __(
'Give the template a title that indicates its purpose, e.g. "Full Width".'
) }
onChange={ ( newTitle ) => {
setTitle( newTitle || template.slug );
} }
/>
);
}
19 changes: 12 additions & 7 deletions packages/edit-site/src/components/template-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from '../navigation-sidebar/navigation-panel/constants';
import { store as editSiteStore } from '../../store';
import TemplateAreas from './template-areas';
import EditTemplateTitle from './edit-template-title';

export default function TemplateDetails( { template, onClose } ) {
const { title, description } = useSelect(
Expand Down Expand Up @@ -55,13 +56,17 @@ export default function TemplateDetails( { template, onClose } ) {
return (
<div className="edit-site-template-details">
<div className="edit-site-template-details__group">
<Heading
level={ 4 }
weight={ 600 }
className="edit-site-template-details__title"
>
{ title }
</Heading>
{ template.is_custom ? (
<EditTemplateTitle template={ template } />
) : (
<Heading
level={ 4 }
weight={ 600 }
className="edit-site-template-details__title"
>
{ title }
</Heading>
) }

{ description && (
<Text
Expand Down

0 comments on commit ea2bd81

Please sign in to comment.