Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Editor: Move "Add Template"'s descriptions to tooltips #48710

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/components/src/tooltip/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// @ts-nocheck

/**
* External dependencies
*/
import classNames from 'classnames';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -66,19 +71,22 @@ const addPopoverToGrandchildren = ( {
position,
shortcut,
text,
className,
...props
} ) =>
concatChildren(
grandchildren,
isOver && (
<Popover
focusOnMount={ false }
position={ position }
className="components-tooltip"
className={ classNames( 'components-tooltip', className ) }
aria-hidden="true"
animate={ false }
offset={ offset }
anchor={ anchor }
shift
{ ...props }
>
{ text }
<Shortcut
Expand Down Expand Up @@ -113,6 +121,7 @@ function Tooltip( props ) {
text,
shortcut,
delay = TOOLTIP_DELAY,
...popoverProps
} = props;
/**
* Whether a mouse is currently pressed, used in determining whether
Expand Down Expand Up @@ -270,6 +279,7 @@ function Tooltip( props ) {
const childrenWithPopover = addPopoverToGrandchildren( {
grandchildren,
...popoverData,
...popoverProps,
} );

return getElementWithPopover( {
Expand Down
89 changes: 57 additions & 32 deletions packages/edit-site/src/components/add-new-template/new-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
DropdownMenu,
MenuGroup,
MenuItem,
NavigableMenu,
Tooltip,
VisuallyHidden,
} from '@wordpress/components';
import { useState } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -164,6 +165,11 @@ export default function NewTemplate( {
if ( ! missingTemplates.length ) {
return null;
}

const customTemplateDescription = __(
'Custom templates can be applied to any post or page.'
);

return (
<>
<DropdownMenu
Expand All @@ -181,7 +187,7 @@ export default function NewTemplate( {
{ isCreatingTemplate && (
<TemplateActionsLoadingScreen />
) }
<NavigableMenu className="edit-site-new-template-dropdown__popover">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<NavigableMenu> doesn't seem to be needed since <DropdownMenu> already renders it under the hood.

<div className="edit-site-new-template-dropdown__menu-groups">
<MenuGroup label={ postType.labels.add_new_item }>
{ missingTemplates.map( ( template ) => {
const {
Expand All @@ -192,44 +198,63 @@ export default function NewTemplate( {
icon,
} = template;
return (
<MenuItem
icon={
icon ||
TEMPLATE_ICONS[ slug ] ||
post
}
iconPosition="left"
info={ description }
<Tooltip
key={ slug }
onClick={ () =>
onClick
? onClick( template )
: createTemplate( template )
}
position="top right"
text={ description }
className="edit-site-new-template-dropdown__menu-item-tooltip"
>
{ title }
</MenuItem>
<MenuItem
icon={
icon ||
TEMPLATE_ICONS[ slug ] ||
post
}
iconPosition="left"
onClick={ () =>
onClick
? onClick( template )
: createTemplate(
template
)
}
>
{ title }
{ /* TODO: This probably won't be needed if the <Tooltip> component is accessible.
* @see https://github.com/WordPress/gutenberg/issues/48222 */ }
<VisuallyHidden>
{ description }
</VisuallyHidden>
</MenuItem>
</Tooltip>
);
} ) }
</MenuGroup>
<MenuGroup>
<MenuItem
icon={ customGenericTemplateIcon }
iconPosition="left"
info={ __(
'Custom templates can be applied to any post or page.'
) }
key="custom-template"
onClick={ () =>
setShowCustomGenericTemplateModal(
true
)
}
<Tooltip
position="top right"
text={ customTemplateDescription }
className="edit-site-new-template-dropdown__menu-item-tooltip"
>
{ __( 'Custom template' ) }
</MenuItem>
<MenuItem
icon={ customGenericTemplateIcon }
iconPosition="left"
onClick={ () =>
setShowCustomGenericTemplateModal(
true
)
}
>
{ __( 'Custom template' ) }
{ /* TODO: This probably won't be needed if the <Tooltip> component is accessible.
* @see https://github.com/WordPress/gutenberg/issues/48222 */ }
<VisuallyHidden>
{ customTemplateDescription }
</VisuallyHidden>
</MenuItem>
</Tooltip>
</MenuGroup>
</NavigableMenu>
</div>
</>
) }
</DropdownMenu>
Expand Down
13 changes: 12 additions & 1 deletion packages/edit-site/src/components/add-new-template/style.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
.edit-site-new-template-dropdown {
.edit-site-new-template-dropdown__popover {
.edit-site-new-template-dropdown__menu-groups {
@include break-small() {
min-width: 300px;
}
}

// The specificity is needed to override the default tooltip styles.
&__menu-item-tooltip.components-tooltip .components-popover__content {
max-width: 320px;
padding: $grid-unit-10 $grid-unit-15;
border-radius: 2px;
white-space: pre-wrap;
min-width: 0;
width: auto;
text-align: left;
}
}

.edit-site-custom-template-modal {
Expand Down