-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor: Add New - Custom/General template
- Loading branch information
1 parent
0af4bc7
commit 1a89e8e
Showing
3 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
packages/edit-site/src/components/add-new-template/add-custom-generic-template-modal.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,97 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { kebabCase } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
Button, | ||
Flex, | ||
FlexItem, | ||
Modal, | ||
TextControl, | ||
} from '@wordpress/components'; | ||
|
||
function AddCustomGenericTemplateModal( { onClose, createTemplate } ) { | ||
const [ title, setTitle ] = useState( '' ); | ||
const defaultTitle = __( 'Custom Template' ); | ||
const [ isBusy, setIsBusy ] = useState( false ); | ||
async function onCreateTemplate( event ) { | ||
event.preventDefault(); | ||
|
||
if ( isBusy ) { | ||
return; | ||
} | ||
|
||
setIsBusy( true ); | ||
|
||
createTemplate( | ||
{ | ||
slug: | ||
'wp-custom-template-' + kebabCase( title || defaultTitle ), | ||
title: title || defaultTitle, | ||
}, | ||
false | ||
); | ||
} | ||
return ( | ||
<Modal | ||
title={ __( 'Create custom template' ) } | ||
closeLabel={ __( 'Close' ) } | ||
onRequestClose={ () => { | ||
onClose(); | ||
} } | ||
overlayClassName="edit-site-custom-generic-template__modal" | ||
> | ||
<form onSubmit={ onCreateTemplate }> | ||
<Flex align="flex-start" gap={ 8 }> | ||
<FlexItem> | ||
<TextControl | ||
label={ __( 'Name' ) } | ||
value={ title } | ||
onChange={ setTitle } | ||
placeholder={ defaultTitle } | ||
disabled={ isBusy } | ||
help={ __( | ||
'Describe the purpose of the template, e.g. "Full Width".' | ||
) } | ||
/> | ||
</FlexItem> | ||
</Flex> | ||
|
||
<Flex | ||
className="edit-site-custom-generic-template__modal-actions" | ||
justify="flex-end" | ||
expanded={ false } | ||
> | ||
<FlexItem> | ||
<Button | ||
variant="tertiary" | ||
onClick={ () => { | ||
onClose(); | ||
} } | ||
> | ||
{ __( 'Cancel' ) } | ||
</Button> | ||
</FlexItem> | ||
<FlexItem> | ||
<Button | ||
variant="primary" | ||
type="submit" | ||
isBusy={ isBusy } | ||
aria-disabled={ isBusy } | ||
> | ||
{ __( 'Create' ) } | ||
</Button> | ||
</FlexItem> | ||
</Flex> | ||
</form> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default AddCustomGenericTemplateModal; |
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
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