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

[Block Library - Query Loop]: Show pattern titles in setup #46688

Merged
merged 2 commits into from
Dec 21, 2022
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
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