Skip to content

Commit

Permalink
Update the add template modal design (#51806)
Browse files Browse the repository at this point in the history
* Add icons

* alignment

* Custom descriptions

* justify content

* Style custom template button

* Remove min-height

* Don't display description when there isn't one

* Reduce space between template + description

* Style icon

* Style custom template

* increase button size

* Add prompt

* Update template icons

* Make year dynamic

* Remove short descriptions

* Revert "Remove short descriptions"

This reverts commit 7eb06e8ab845b9cda3975989456614df5b221c29.

* re-instate descriptions but only show as a tooltip

* simplify a bit

---------

Co-authored-by: ntsekouras <ntsekouras@outlook.com>
  • Loading branch information
jameskoster and ntsekouras authored Jun 23, 2023
1 parent d4b1931 commit 1464f18
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 26 deletions.
144 changes: 120 additions & 24 deletions packages/edit-site/src/components/add-new-template/new-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,32 @@ import {
__experimentalGrid as Grid,
__experimentalText as Text,
__experimentalVStack as VStack,
Flex,
Icon,
} from '@wordpress/components';
import { decodeEntities } from '@wordpress/html-entities';
import { useState } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { plus } from '@wordpress/icons';
import {
archive,
blockMeta,
calendar,
category,
commentAuthorAvatar,
edit,
home,
layout,
list,
media,
notFound,
page,
plus,
pin,
postList,
search,
tag,
} from '@wordpress/icons';
import { __, sprintf } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import { privateApis as routerPrivateApis } from '@wordpress/router';
Expand Down Expand Up @@ -56,27 +76,64 @@ const DEFAULT_TEMPLATE_SLUGS = [
'404',
];

function TemplateListItem( { title, description, onClick } ) {
const TEMPLATE_ICONS = {
'front-page': home,
home: postList,
single: pin,
page,
archive,
search,
404: notFound,
index: list,
category,
author: commentAuthorAvatar,
taxonomy: blockMeta,
date: calendar,
tag,
attachment: media,
};

function TemplateListItem( {
title,
direction,
className,
description,
icon,
onClick,
children,
} ) {
return (
<Button onClick={ onClick }>
<VStack
<Button
className={ className }
onClick={ onClick }
label={ description }
showTooltip={ !! description }
>
<Flex
as="span"
spacing={ 2 }
justify="flex-start"
align="center"
justify="center"
style={ { width: '100%' } }
direction={ direction }
>
<Text
weight={ 500 }
lineHeight={ 1.53846153846 } // 20px
<div className="edit-site-add-new-template__template-icon">
<Icon icon={ icon } />
</div>
<VStack
className="edit-site-add-new-template__template-name"
alignment="center"
spacing={ 0 }
>
{ title }
</Text>
<Text
lineHeight={ 1.53846153846 } // 20px
>
{ description }
</Text>
</VStack>
<Text
weight={ 500 }
lineHeight={ 1.53846153846 } // 20px
>
{ title }
</Text>
{ children }
</VStack>
</Flex>
</Button>
);
}
Expand Down Expand Up @@ -104,6 +161,26 @@ export default function NewTemplate( {
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );
const { setTemplate } = unlock( useDispatch( editSiteStore ) );

const { homeUrl } = useSelect( ( select ) => {
const {
getUnstableBase, // Site index.
} = select( coreStore );

return {
homeUrl: getUnstableBase()?.home,
};
}, [] );

const TEMPLATE_SHORT_DESCRIPTIONS = {
'front-page': homeUrl,
date: sprintf(
// translators: %s: The homepage url.
__( 'E.g. %s' ),
homeUrl + '/' + new Date().getFullYear()
),
};

async function createTemplate( template, isWPSuggestion = true ) {
if ( isCreatingTemplate ) {
return;
Expand Down Expand Up @@ -220,14 +297,25 @@ export default function NewTemplate( {
justify="center"
className="edit-site-add-new-template__template-list__contents"
>
<Flex className="edit-site-add-new-template__template-list__prompt">
{ __(
'Select what the new template should apply to:'
) }
</Flex>
{ missingTemplates.map( ( template ) => {
const { title, description, slug, onClick } =
template;
const { title, slug, onClick } = template;
return (
<TemplateListItem
key={ slug }
title={ title }
description={ description }
direction="column"
className="edit-site-add-new-template__template-button"
description={
TEMPLATE_SHORT_DESCRIPTIONS[ slug ]
}
icon={
TEMPLATE_ICONS[ slug ] || layout
}
onClick={ () =>
onClick
? onClick( template )
Expand All @@ -238,15 +326,23 @@ export default function NewTemplate( {
} ) }
<TemplateListItem
title={ __( 'Custom template' ) }
description={ __(
'A custom template can be manually applied to any post or page.'
) }
direction="row"
className="edit-site-add-new-template__custom-template-button"
icon={ edit }
onClick={ () =>
setModalContent(
modalContentMap.customGenericTemplate
)
}
/>
>
<Text
lineHeight={ 1.53846153846 } // 20px
>
{ __(
'A custom template can be manually applied to any post or page.'
) }
</Text>
</TemplateListItem>
</Grid>
) }
{ modalContent === modalContentMap.customTemplate && (
Expand Down
32 changes: 30 additions & 2 deletions packages/edit-site/src/components/add-new-template/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,39 @@
@include break-large() {
width: calc(100% - #{$grid-unit-80 * 2});
}

.edit-site-add-new-template__template-button,
.edit-site-add-new-template__custom-template-button {
svg {
fill: var(--wp-admin-theme-color);
}
}

.edit-site-add-new-template__custom-template-button {
.edit-site-add-new-template__template-name {
flex-grow: 1;
align-items: flex-start;
}
}

.edit-site-add-new-template__template-icon {
padding: $grid-unit-10;
background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
border-radius: 100%;
max-height: $grid-unit-50;
max-width: $grid-unit-50;
}
}

.edit-site-custom-template-modal__contents,
.edit-site-add-new-template__template-list__contents {
> .components-button {
padding: $grid-unit-30;
padding: $grid-unit-40;
border-radius: $radius-block-ui;
display: flex;
flex-direction: column;
border: $border-width solid $gray-300;
min-height: $grid-unit-80 * 3;
justify-content: center;

// Show the boundary of the button, in High Contrast Mode.
outline: 1px solid transparent;
Expand Down Expand Up @@ -183,6 +205,12 @@
}
}
}

.edit-site-add-new-template__custom-template-button,
.edit-site-add-new-template__template-list__prompt {
grid-column-start: 1;
grid-column-end: 4;
}
}

.edit-site-add-new-template__template-list__contents {
Expand Down

0 comments on commit 1464f18

Please sign in to comment.