From 3d987faaff38b5e1947f2b2b55cd6bb4032c04c8 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 12 May 2023 17:11:48 +0300 Subject: [PATCH 1/8] [Site Editor]: Update the add template menu --- .../add-new-template/new-template.js | 208 +++++++----------- .../components/add-new-template/style.scss | 92 ++++---- 2 files changed, 134 insertions(+), 166 deletions(-) diff --git a/packages/edit-site/src/components/add-new-template/new-template.js b/packages/edit-site/src/components/add-new-template/new-template.js index 3db38fffdee81a..1ae6dcca087d65 100644 --- a/packages/edit-site/src/components/add-new-template/new-template.js +++ b/packages/edit-site/src/components/add-new-template/new-template.js @@ -2,33 +2,16 @@ * WordPress dependencies */ import { - DropdownMenu, - MenuGroup, - MenuItem, - Tooltip, - VisuallyHidden, + Button, + Modal, + __experimentalGrid as Grid, + __experimentalText as Text, + __experimentalVStack as VStack, } from '@wordpress/components'; import { useState } from '@wordpress/element'; import { useDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; -import { - archive, - blockMeta, - category, - home, - list, - media, - notFound, - page, - plus, - post, - postAuthor, - postDate, - postList, - search, - tag, - layout as customGenericTemplateIcon, -} from '@wordpress/icons'; +import { plus } from '@wordpress/icons'; import { __, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; import { privateApis as routerPrivateApis } from '@wordpress/router'; @@ -68,28 +51,33 @@ const DEFAULT_TEMPLATE_SLUGS = [ '404', ]; -const TEMPLATE_ICONS = { - 'front-page': home, - home: postList, - single: post, - page, - archive, - search, - 404: notFound, - index: list, - category, - author: postAuthor, - taxonomy: blockMeta, - date: postDate, - tag, - attachment: media, -}; +function TemplateListItem( { title, description, onClick } ) { + return ( + + ); +} export default function NewTemplate( { postType, toggleProps, showIcon = true, } ) { + const [ showTemplatesListModal, setShowTemplatesListModal ] = + useState( false ); const [ showCustomTemplateModal, setShowCustomTemplateModal ] = useState( false ); const [ @@ -167,99 +155,63 @@ export default function NewTemplate( { if ( ! missingTemplates.length ) { return null; } - - const customTemplateDescription = __( - 'A custom template can be manually applied to any post or page.' - ); - + const { as: Toggle = Button, ...restToggleProps } = toggleProps ?? {}; + // TODO: Remove obsolete styles.. return ( <> - } + { + setShowTemplatesListModal( true ); } } - toggleProps={ toggleProps } + icon={ showIcon ? plus : null } + label={ postType.labels.add_new } > - { () => ( - <> - { isCreatingTemplate && ( - - ) } -
- - { missingTemplates.map( ( template ) => { - const { - title, - description, - slug, - onClick, - icon, - } = template; - return ( - - - onClick - ? onClick( template ) - : createTemplate( - template - ) - } - > - { title } - { /* TODO: This probably won't be needed if the component is accessible. - * @see https://github.com/WordPress/gutenberg/issues/48222 */ } - - { description } - - - - ); - } ) } - - - - - setShowCustomGenericTemplateModal( - true - ) - } - > - { __( 'Custom template' ) } - { /* TODO: This probably won't be needed if the component is accessible. - * @see https://github.com/WordPress/gutenberg/issues/48222 */ } - - { customTemplateDescription } - - - - -
- - ) } -
+ { showIcon ? null : postType.labels.add_new } + + { showTemplatesListModal && ( + setShowTemplatesListModal( false ) } + > + + { missingTemplates.map( ( template ) => { + const { title, description, slug, onClick } = + template; + return ( + + onClick + ? onClick( template ) + : createTemplate( template ) + } + /> + ); + } ) } + + setShowCustomGenericTemplateModal( true ) + } + /> + + + ) } { showCustomTemplateModal && ( setShowCustomTemplateModal( false ) } diff --git a/packages/edit-site/src/components/add-new-template/style.scss b/packages/edit-site/src/components/add-new-template/style.scss index fc33da1f35a133..880d4b3c54e6ba 100644 --- a/packages/edit-site/src/components/add-new-template/style.scss +++ b/packages/edit-site/src/components/add-new-template/style.scss @@ -25,46 +25,8 @@ &__contents { > .components-button { - padding: $grid-unit-30; - border-radius: $radius-block-ui; height: auto; - display: flex; - flex-direction: column; justify-content: center; - border: $border-width solid $gray-300; - - // Show the boundary of the button, in High Contrast Mode. - outline: 1px solid transparent; - - span:first-child { - color: $gray-900; - } - - span { - color: $gray-700; - } - - &:hover { - color: var(--wp-admin-theme-color-darker-10); - background: rgba(var(--wp-admin-theme-color--rgb), 0.04); - border-color: transparent; - - span { - color: var(--wp-admin-theme-color); - } - } - - &:focus { - box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); - border-color: transparent; - - // Windows High Contrast mode will show this outline, but not the box-shadow. - outline: 3px solid transparent; - - span:first-child { - color: var(--wp-admin-theme-color); - } - } } } @@ -178,4 +140,58 @@ justify-content: center; height: 100%; } + .components-modal__children-container { + height: 100%; + } +} + +.edit-site-custom-template-modal__contents, +.edit-site-add-new-template__modal__contents { + > .components-button { + padding: $grid-unit-30; + border-radius: $radius-block-ui; + display: flex; + flex-direction: column; + border: $border-width solid $gray-300; + + // Show the boundary of the button, in High Contrast Mode. + outline: 1px solid transparent; + + span:first-child { + color: $gray-900; + } + + span { + color: $gray-700; + } + + &:hover { + color: var(--wp-admin-theme-color-darker-10); + background: rgba(var(--wp-admin-theme-color--rgb), 0.04); + border-color: transparent; + + span { + color: var(--wp-admin-theme-color); + } + } + + &:focus { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); + border-color: transparent; + + // Windows High Contrast mode will show this outline, but not the box-shadow. + outline: 3px solid transparent; + + span:first-child { + color: var(--wp-admin-theme-color); + } + } + } +} + +.edit-site-add-new-template__modal__contents { + > .components-button { + height: 100%; + text-align: start; + } } From 54e915bd13adb793081ebeca59c16fcdfe9c8375 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Mon, 15 May 2023 13:05:51 +0300 Subject: [PATCH 2/8] use single Modal part 1 --- .../add-custom-generic-template-modal.js | 91 ++++----- .../add-custom-template-modal.js | 39 ++-- .../add-new-template/new-template.js | 175 +++++++++++------- .../components/add-new-template/style.scss | 36 +++- 4 files changed, 189 insertions(+), 152 deletions(-) diff --git a/packages/edit-site/src/components/add-new-template/add-custom-generic-template-modal.js b/packages/edit-site/src/components/add-new-template/add-custom-generic-template-modal.js index 05688d032a5917..97c6fc041a2cf0 100644 --- a/packages/edit-site/src/components/add-new-template/add-custom-generic-template-modal.js +++ b/packages/edit-site/src/components/add-new-template/add-custom-generic-template-modal.js @@ -10,22 +10,12 @@ import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Button, - Modal, TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack, } from '@wordpress/components'; -/** - * Internal dependencies - */ -import TemplateActionsLoadingScreen from './template-actions-loading-screen'; - -function AddCustomGenericTemplateModal( { - onClose, - createTemplate, - isCreatingTemplate, -} ) { +function AddCustomGenericTemplateModal( { onClose, createTemplate } ) { const [ title, setTitle ] = useState( '' ); const defaultTitle = __( 'Custom Template' ); const [ isBusy, setIsBusy ] = useState( false ); @@ -50,51 +40,42 @@ function AddCustomGenericTemplateModal( { } } return ( - { - onClose(); - } } - overlayClassName="edit-site-custom-generic-template__modal" - > - { isCreatingTemplate && } -
- - - + + + + + - - - - -
+ { __( 'Create' ) } + + + + ); } diff --git a/packages/edit-site/src/components/add-new-template/add-custom-template-modal.js b/packages/edit-site/src/components/add-new-template/add-custom-template-modal.js index ccab5d82bd0587..b6e91da3cb589f 100644 --- a/packages/edit-site/src/components/add-new-template/add-custom-template-modal.js +++ b/packages/edit-site/src/components/add-new-template/add-custom-template-modal.js @@ -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, @@ -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 = []; @@ -179,36 +177,25 @@ function SuggestionList( { entityForSuggestions, onSelect } ) { ); } -function AddCustomTemplateModal( { - onClose, - onSelect, - entityForSuggestions, - isCreatingTemplate, -} ) { +function AddCustomTemplateModal( { onSelect, entityForSuggestions } ) { const [ showSearchEntities, setShowSearchEntities ] = useState( entityForSuggestions.hasGeneralTemplate ); - const baseCssClass = 'edit-site-custom-template-modal'; return ( - - { isCreatingTemplate && } + <> { ! showSearchEntities && ( - + { __( 'Select whether to create a single template for all items or a specific one.' ) } @@ -275,7 +262,11 @@ function AddCustomTemplateModal( { ) } { showSearchEntities && ( - + { __( 'This template will be used only for the specific item chosen.' @@ -287,7 +278,7 @@ function AddCustomTemplateModal( { /> ) } - + ); } diff --git a/packages/edit-site/src/components/add-new-template/new-template.js b/packages/edit-site/src/components/add-new-template/new-template.js index 1ae6dcca087d65..e90931e5e6c307 100644 --- a/packages/edit-site/src/components/add-new-template/new-template.js +++ b/packages/edit-site/src/components/add-new-template/new-template.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ @@ -54,7 +59,12 @@ const DEFAULT_TEMPLATE_SLUGS = [ function TemplateListItem( { title, description, onClick } ) { return (