Skip to content

Commit

Permalink
implement logic to reset to default template
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Oct 30, 2024
1 parent ca3b59b commit 61f9655
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/fields/src/fields/template/template-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,29 @@ export const TemplateEdit = ( {
: '' }
</Button>
) }
renderContent={ () => (
renderContent={ ( { onToggle } ) => (
<MenuGroup>
<MenuItem onClick={ () => setShowModal( true ) }>
<MenuItem
onClick={ () => {
setShowModal( true );
onToggle();
} }
>
{ __( 'Swap template' ) }
</MenuItem>
{
// The default template in a post is indicated by an empty string
value !== '' && (
<MenuItem
onClick={ () => {
onChangeControl( '' );
onToggle();
} }
>
{ __( 'Use default template' ) }
</MenuItem>
)
}
</MenuGroup>
) }
/>
Expand All @@ -212,8 +230,11 @@ export const TemplateEdit = ( {
label={ __( 'Templates' ) }
blockPatterns={ templatesAsPatterns }
shownPatterns={ shownTemplates }
onClickPattern={ ( template: WpTemplate ) => {
onChangeControl( template.id );
onClickPattern={ (
template: ( typeof templatesAsPatterns )[ 0 ]
) => {
onChangeControl( template.name );
setShowModal( false );
} }
/>
</div>
Expand Down

0 comments on commit 61f9655

Please sign in to comment.