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

Template Part: Allow changing properties in focus mode #43151

Merged
merged 5 commits into from
Aug 16, 2022
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 @@ -19,9 +19,13 @@ export default function EditTemplateTitle( { template } ) {
<TextControl
label={ __( 'Title' ) }
value={ forceEmpty ? '' : title }
help={ __(
'Give the template a title that indicates its purpose, e.g. "Full Width".'
) }
help={
template.type !== 'wp_template_part'
? __(
'Give the template a title that indicates its purpose, e.g. "Full Width".'
)
: null
}
onChange={ ( newTitle ) => {
if ( ! newTitle && ! forceEmpty ) {
setForceEmpty( true );
Expand Down
27 changes: 20 additions & 7 deletions packages/edit-site/src/components/template-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Button,
MenuGroup,
MenuItem,
__experimentalHeading as Heading,
__experimentalVStack as VStack,
__experimentalText as Text,
} from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
Expand All @@ -20,6 +20,7 @@ import { store as editSiteStore } from '../../store';
import TemplateAreas from './template-areas';
import EditTemplateTitle from './edit-template-title';
import { useLink } from '../routes/link';
import TemplatePartAreaSelector from './template-part-area-selector';

export default function TemplateDetails( { template, onClose } ) {
const { title, description } = useSelect(
Expand All @@ -35,8 +36,13 @@ export default function TemplateDetails( { template, onClose } ) {
postId: undefined,
} );

const isTemplatePart = template.type === 'wp_template_part';

// Only user-created and non-default templates can change the name.
const canEditTitle = template.is_custom && ! template.has_theme_file;
// But any user-created template part can be renamed.
const canEditTitle = isTemplatePart
? ! template.has_theme_file
: template.is_custom && ! template.has_theme_file;

if ( ! template ) {
return null;
Expand All @@ -49,17 +55,18 @@ export default function TemplateDetails( { template, onClose } ) {

return (
<div className="edit-site-template-details">
<div className="edit-site-template-details__group">
<VStack className="edit-site-template-details__group" spacing={ 3 }>
Copy link
Member Author

Choose a reason for hiding this comment

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

I switched to VStrack. It makes it much easier to control spacing.

{ canEditTitle ? (
<EditTemplateTitle template={ template } />
) : (
<Heading
level={ 4 }
<Text
size={ 16 }
Comment on lines +62 to +63
Copy link
Member Author

Choose a reason for hiding this comment

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

I ported this from #42495. Props to @afercia.

weight={ 600 }
className="edit-site-template-details__title"
as="p"
>
{ title }
</Heading>
</Text>
) }

{ description && (
Expand All @@ -71,7 +78,13 @@ export default function TemplateDetails( { template, onClose } ) {
{ description }
</Text>
) }
</div>
</VStack>

{ isTemplatePart && (
<div className="edit-site-template-details__group">
<TemplatePartAreaSelector id={ template.id } />
</div>
) }

<TemplateAreas closeTemplateDetailsDropdown={ onClose } />

Expand Down
5 changes: 0 additions & 5 deletions packages/edit-site/src/components/template-details/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
border-top: $border-width solid $gray-400;
}

.edit-site-template-details__title {
margin: 0;
}

.edit-site-template-details__description {
margin: $grid-unit-15 0 0;
color: $gray-700;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { SelectControl } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';

export default function TemplatePartAreaSelector( { id } ) {
const [ area, setArea ] = useEntityProp(
'postType',
'wp_template_part',
'area',
id
);

const definedAreas = useSelect(
( select ) =>
select( editorStore ).__experimentalGetDefaultTemplatePartAreas(),
[]
);

const areaOptions = definedAreas.map( ( { label, area: _area } ) => ( {
label,
value: _area,
} ) );

return (
<SelectControl
label={ __( 'Area' ) }
labelPosition="top"
options={ areaOptions }
value={ area }
onChange={ setArea }
/>
);
}