Skip to content

Commit

Permalink
[Block Library - Query Loop]: Show pattern titles in setup (#46688)
Browse files Browse the repository at this point in the history
* [Block Library - Query Loop]: Show pattern titles in setup

* change cursors of pattern title
  • Loading branch information
ntsekouras authored Dec 21, 2022
1 parent 16a2fea commit db0ff52
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/block-editor/src/components/block-pattern-setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const SetupContent = ( {
activeSlide,
patterns,
onBlockPatternSelect,
showTitles,
} ) => {
const composite = useCompositeState();
const containerClass = 'block-editor-block-pattern-setup__container';
Expand Down Expand Up @@ -67,14 +68,15 @@ const SetupContent = ( {
pattern={ pattern }
onSelect={ onBlockPatternSelect }
composite={ composite }
showTitles={ showTitles }
/>
) ) }
</Composite>
</div>
);
};

function BlockPattern( { pattern, onSelect, composite } ) {
function BlockPattern( { pattern, onSelect, composite, showTitles } ) {
const baseClassName = 'block-editor-block-pattern-setup-list';
const { blocks, description, viewportWidth = 700 } = pattern;
const descriptionId = useInstanceId(
Expand All @@ -98,12 +100,17 @@ function BlockPattern( { pattern, onSelect, composite } ) {
blocks={ blocks }
viewportWidth={ viewportWidth }
/>
{ showTitles && (
<div className={ `${ baseClassName }__item-title` }>
{ pattern.title }
</div>
) }
{ !! description && (
<VisuallyHidden id={ descriptionId }>
{ description }
</VisuallyHidden>
) }
</CompositeItem>
{ !! description && (
<VisuallyHidden id={ descriptionId }>
{ description }
</VisuallyHidden>
) }
</div>
);
}
Expand Down Expand Up @@ -139,6 +146,7 @@ const BlockPatternSetup = ( {
filterPatternsFn,
onBlockPatternSelect,
initialViewMode = VIEWMODES.carousel,
showTitles = false,
} ) => {
const [ viewMode, setViewMode ] = useState( initialViewMode );
const [ activeSlide, setActiveSlide ] = useState( 0 );
Expand All @@ -165,6 +173,7 @@ const BlockPatternSetup = ( {
activeSlide={ activeSlide }
patterns={ patterns }
onBlockPatternSelect={ onPatternSelectCallback }
showTitles={ showTitles }
/>
<SetupToolbar
viewMode={ viewMode }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
border-radius: $radius-block-ui;

&.view-mode-grid {
padding-top: $grid-unit-05;

.block-editor-block-pattern-setup__toolbar {
justify-content: center;
}
Expand All @@ -29,10 +31,33 @@
cursor: pointer;
}

.block-editor-block-pattern-setup-list__item {
&:hover .block-editor-block-preview__container {
box-shadow: 0 0 0 2px var(--wp-admin-theme-color);
}

&:focus .block-editor-block-preview__container {
box-shadow: inset 0 0 0 1px $white, 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);

// Windows High Contrast mode will show this outline, but not the box-shadow.
outline: 2px solid transparent;
}
&:hover .block-editor-block-pattern-setup-list__item-title,
&:focus .block-editor-block-pattern-setup-list__item-title {
color: var(--wp-admin-theme-color);
}
}
.block-editor-block-pattern-setup-list__list-item {
break-inside: avoid-column;
margin-bottom: $grid-unit-30;

.block-editor-block-pattern-setup-list__item-title {
padding-top: $grid-unit-10;
font-size: 12px;
text-align: center;
cursor: pointer;
}

.block-editor-block-preview__container {
min-height: 100px;
border-radius: $radius-block-ui;
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/query/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function PatternSelectionModal( {
blockName={ blockNameForPatterns }
clientId={ clientId }
onBlockPatternSelect={ onBlockPatternSelect }
showTitles={ true }
/>
</BlockContextProvider>
</Modal>
Expand Down

1 comment on commit db0ff52

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3748000230
📝 Reported issues:

Please sign in to comment.