Skip to content

Commit

Permalink
[Site Editor]: Update the add template menu (#50595)
Browse files Browse the repository at this point in the history
* [Site Editor]: Update the add template menu

* use single Modal part 1

* rename components

* remove obsolete styles

* update e2e test

* tweak styles

* Modal dimensions

* Update packages/edit-site/src/components/add-new-template/style.scss

Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>

---------

Co-authored-by: James Koster <james@jameskoster.co.uk>
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
  • Loading branch information
3 people authored May 17, 2023
1 parent 6f2d112 commit 9018b15
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 337 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* External dependencies
*/
import { kebabCase } from 'lodash';

/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import {
Button,
TextControl,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
} from '@wordpress/components';

function AddCustomGenericTemplateModalContent( { 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 );
try {
await createTemplate(
{
slug:
'wp-custom-template-' +
kebabCase( title || defaultTitle ),
title: title || defaultTitle,
},
false
);
} finally {
setIsBusy( false );
}
}
return (
<form onSubmit={ onCreateTemplate }>
<VStack spacing={ 6 }>
<TextControl
__nextHasNoMarginBottom
label={ __( 'Name' ) }
value={ title }
onChange={ setTitle }
placeholder={ defaultTitle }
disabled={ isBusy }
help={ __(
'Describe the template, e.g. "Post with sidebar".'
) }
/>
<HStack
className="edit-site-custom-generic-template__modal-actions"
justify="right"
>
<Button
variant="tertiary"
onClick={ () => {
onClose();
} }
>
{ __( 'Cancel' ) }
</Button>
<Button
variant="primary"
type="submit"
isBusy={ isBusy }
aria-disabled={ isBusy }
>
{ __( 'Create' ) }
</Button>
</HStack>
</VStack>
</form>
);
}

export default AddCustomGenericTemplateModalContent;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
* WordPress dependencies
*/
import { useState, useMemo, useEffect } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import {
Button,
Flex,
FlexItem,
Modal,
SearchControl,
TextHighlight,
__experimentalText as Text,
Expand All @@ -23,7 +22,6 @@ import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import TemplateActionsLoadingScreen from './template-actions-loading-screen';
import { mapToIHasNameAndId } from './utils';

const EMPTY_ARRAY = [];
Expand Down Expand Up @@ -179,36 +177,25 @@ function SuggestionList( { entityForSuggestions, onSelect } ) {
);
}

function AddCustomTemplateModal( {
onClose,
onSelect,
entityForSuggestions,
isCreatingTemplate,
} ) {
function AddCustomTemplateModalContent( { onSelect, entityForSuggestions } ) {
const [ showSearchEntities, setShowSearchEntities ] = useState(
entityForSuggestions.hasGeneralTemplate
);
const baseCssClass = 'edit-site-custom-template-modal';
return (
<Modal
title={ sprintf(
// translators: %s: Name of the post type e.g: "Post".
__( 'Add template: %s' ),
entityForSuggestions.labels.singular_name
) }
className={ baseCssClass }
onRequestClose={ onClose }
<VStack
spacing={ 4 }
className="edit-site-custom-template-modal__contents-wrapper"
alignment="left"
>
{ isCreatingTemplate && <TemplateActionsLoadingScreen /> }
{ ! showSearchEntities && (
<VStack spacing={ 4 }>
<>
<Text as="p">
{ __(
'Select whether to create a single template for all items or a specific one.'
) }
</Text>
<Flex
className={ `${ baseCssClass }__contents` }
className="edit-site-custom-template-modal__contents"
gap="4"
align="initial"
>
Expand Down Expand Up @@ -272,10 +259,10 @@ function AddCustomTemplateModal( {
</Text>
</FlexItem>
</Flex>
</VStack>
</>
) }
{ showSearchEntities && (
<VStack spacing={ 4 }>
<>
<Text as="p">
{ __(
'This template will be used only for the specific item chosen.'
Expand All @@ -285,10 +272,10 @@ function AddCustomTemplateModal( {
entityForSuggestions={ entityForSuggestions }
onSelect={ onSelect }
/>
</VStack>
</>
) }
</Modal>
</VStack>
);
}

export default AddCustomTemplateModal;
export default AddCustomTemplateModalContent;
Loading

0 comments on commit 9018b15

Please sign in to comment.