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

Inserter: Pattern title tooltip #46419

Merged
merged 2 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
71 changes: 47 additions & 24 deletions packages/block-editor/src/components/block-patterns-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
__unstableComposite as Composite,
__unstableUseCompositeState as useCompositeState,
__unstableCompositeItem as CompositeItem,
Tooltip,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
Expand All @@ -16,7 +17,20 @@ import { __ } from '@wordpress/i18n';
import BlockPreview from '../block-preview';
import InserterDraggableBlocks from '../inserter-draggable-blocks';

function BlockPattern( { isDraggable, pattern, onClick, composite } ) {
const WithToolTip = ( { showTooltip, title, children } ) => {
if ( showTooltip ) {
return <Tooltip text={ title }>{ children }</Tooltip>;
}
return <>{ children }</>;
};

function BlockPattern( {
isDraggable,
pattern,
onClick,
composite,
showTooltip,
} ) {
const { blocks, viewportWidth } = pattern;
const instanceId = useInstanceId( BlockPattern );
const descriptionId = `block-editor-block-patterns-list__item-description-${ instanceId }`;
Expand All @@ -34,30 +48,37 @@ function BlockPattern( { isDraggable, pattern, onClick, composite } ) {
onDragStart={ onDragStart }
onDragEnd={ onDragEnd }
>
<CompositeItem
role="option"
as="div"
{ ...composite }
className="block-editor-block-patterns-list__item"
onClick={ () => onClick( pattern, blocks ) }
aria-label={ pattern.title }
aria-describedby={
pattern.description ? descriptionId : undefined
}
<WithToolTip
showTooltip={ showTooltip }
title={ pattern.title }
>
<BlockPreview
blocks={ blocks }
viewportWidth={ viewportWidth }
/>
<div className="block-editor-block-patterns-list__item-title">
{ pattern.title }
</div>
{ !! pattern.description && (
<VisuallyHidden id={ descriptionId }>
{ pattern.description }
</VisuallyHidden>
) }
</CompositeItem>
<CompositeItem
role="option"
as="div"
{ ...composite }
className="block-editor-block-patterns-list__item"
onClick={ () => onClick( pattern, blocks ) }
aria-label={ pattern.title }
aria-describedby={
pattern.description ? descriptionId : undefined
}
>
<BlockPreview
blocks={ blocks }
viewportWidth={ viewportWidth }
/>
{ ! showTooltip && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Besides this check, the CompositeItem changes are whitespace ones.

<div className="block-editor-block-patterns-list__item-title">
{ pattern.title }
</div>
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
) }
{ !! pattern.description && (
<VisuallyHidden id={ descriptionId }>
{ pattern.description }
</VisuallyHidden>
) }
</CompositeItem>
</WithToolTip>
</div>
) }
</InserterDraggableBlocks>
Expand All @@ -77,6 +98,7 @@ function BlockPatternList( {
onClickPattern,
orientation,
label = __( 'Block Patterns' ),
isPatternTitleTooltip,
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
} ) {
const composite = useCompositeState( { orientation } );
return (
Expand All @@ -95,6 +117,7 @@ function BlockPatternList( {
onClick={ onClickPattern }
isDraggable={ isDraggable }
composite={ composite }
showTooltip={ isPatternTitleTooltip }
/>
) : (
<BlockPatternPlaceholder key={ pattern.name } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function BlockPatternsCategoryDialog( {
rootClientId,
onInsert,
category,
isPatternTitleTooltip,
} ) {
const container = useRef();

Expand All @@ -103,6 +104,7 @@ export function BlockPatternsCategoryDialog( {
rootClientId={ rootClientId }
onInsert={ onInsert }
category={ category }
isPatternTitleTooltip={ isPatternTitleTooltip }
/>
</div>
);
Expand All @@ -112,6 +114,7 @@ export function BlockPatternsCategoryPanel( {
rootClientId,
onInsert,
category,
isPatternTitleTooltip,
} ) {
const [ allPatterns, , onClick ] = usePatternsState(
onInsert,
Expand Down Expand Up @@ -161,6 +164,7 @@ export function BlockPatternsCategoryPanel( {
orientation="vertical"
category={ category.label }
isDraggable
isPatternTitleTooltip={ isPatternTitleTooltip }
/>
</div>
);
Expand Down Expand Up @@ -233,6 +237,7 @@ function BlockPatternsTabs( {
onInsert={ onInsert }
rootClientId={ rootClientId }
category={ category }
isPatternTitleTooltip={ false }
/>
) }
</MobileTabNavigation>
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ function InserterMenu(
rootClientId={ destinationRootClientId }
onInsert={ onInsertPattern }
category={ selectedPatternCategory }
isPatternTitleTooltip
/>
) }
</div>
Expand Down
4 changes: 0 additions & 4 deletions packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,6 @@ $block-inserter-tabs-height: 44px;
box-shadow: 0 0 0 2px $gray-900, 0 15px 25px rgb(0 0 0 / 7%);
}
}

.block-editor-block-patterns-list__item-title {
display: none;
}
}

.block-editor-inserter__patterns-category-panel {
Expand Down