-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bb8eaf0
Allow renaming any user-created template part
Mamaduka 8f689de
Use text instead of heading
Mamaduka 680caeb
Add template parts area selector
Mamaduka b751aaf
Hide text control help for template parts
Mamaduka 355eace
Move template part area selector into a separate group
Mamaduka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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( | ||
|
@@ -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; | ||
|
@@ -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 }> | ||
{ canEditTitle ? ( | ||
<EditTemplateTitle template={ template } /> | ||
) : ( | ||
<Heading | ||
level={ 4 } | ||
<Text | ||
size={ 16 } | ||
Comment on lines
+62
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
weight={ 600 } | ||
className="edit-site-template-details__title" | ||
as="p" | ||
> | ||
{ title } | ||
</Heading> | ||
</Text> | ||
) } | ||
|
||
{ description && ( | ||
|
@@ -71,7 +78,11 @@ export default function TemplateDetails( { template, onClose } ) { | |
{ description } | ||
</Text> | ||
) } | ||
</div> | ||
|
||
{ isTemplatePart && ( | ||
<TemplatePartAreaSelector id={ template.id } /> | ||
) } | ||
</VStack> | ||
|
||
<TemplateAreas closeTemplateDetailsDropdown={ onClose } /> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/edit-site/src/components/template-details/template-part-area-selector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
/> | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.