Skip to content

Commit

Permalink
Fix styling and allow long description
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Mar 3, 2023
1 parent afe8d43 commit f9cf7a6
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 63 deletions.
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
126 changes: 66 additions & 60 deletions packages/edit-site/src/components/add-new-template/new-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,68 +187,74 @@ export default function NewTemplate( {
{ isCreatingTemplate && (
<TemplateActionsLoadingScreen />
) }
<MenuGroup label={ postType.labels.add_new_item }>
{ missingTemplates.map( ( template ) => {
const {
title,
description,
slug,
onClick,
icon,
} = template;
return (
<Tooltip
key={ slug }
position="top right"
text={ description }
>
<MenuItem
icon={
icon ||
TEMPLATE_ICONS[ slug ] ||
post
}
iconPosition="left"
onClick={ () =>
onClick
? onClick( template )
: createTemplate( template )
}
<div className="edit-site-new-template-dropdown__menu-groups">
<MenuGroup label={ postType.labels.add_new_item }>
{ missingTemplates.map( ( template ) => {
const {
title,
description,
slug,
onClick,
icon,
} = template;
return (
<Tooltip
key={ slug }
position="top right"
text={ description }
className="edit-site-new-template-dropdown__menu-item-tooltip"
>
{ 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>
<Tooltip
position="top right"
text={ customTemplateDescription }
>
<MenuItem
icon={ customGenericTemplateIcon }
iconPosition="left"
onClick={ () =>
setShowCustomGenericTemplateModal(
true
)
}
<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>
<Tooltip
position="top right"
text={ customTemplateDescription }
className="edit-site-new-template-dropdown__menu-item-tooltip"
>
{ __( '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>
<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>
</div>
</>
) }
</DropdownMenu>
Expand Down
17 changes: 15 additions & 2 deletions packages/edit-site/src/components/add-new-template/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
.edit-site-new-template-dropdown {
@include break-small() {
min-width: 300px;
.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: 400px;
padding: $grid-unit-10 $grid-unit-15;
border-radius: 2px;
white-space: pre-wrap;
min-width: 0;
width: auto;
text-align: left;
}
}

Expand Down

0 comments on commit f9cf7a6

Please sign in to comment.