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

Updated code to set active pattern and its styling #66185

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 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 @@ -42,8 +42,7 @@ function BlockPattern( {
showTitle = true,
showTooltip,
category,
isSelected, // new prop to manage active state
setActivePattern, // function to set the active pattern
isSelected,
} ) {
const [ isDragging, setIsDragging ] = useState( false );
const { blocks, viewportWidth } = pattern;
Expand Down Expand Up @@ -79,10 +78,7 @@ function BlockPattern( {
>
{ ( { draggable, onDragStart, onDragEnd } ) => (
<div
className={ clsx(
'block-editor-block-patterns-list__list-item',
{ 'is-selected': isSelected } // Apply 'is-selected' class if this pattern is active
) }
className="block-editor-block-patterns-list__list-item"
draggable={ draggable }
onDragStart={ ( event ) => {
setIsDragging( true );
Expand All @@ -97,10 +93,6 @@ function BlockPattern( {
onDragEnd( event );
}
} }
onClick={ () => {
onClick( pattern, blocks );
onHover?.( null );
} }
>
<WithToolTip
showTooltip={
Expand All @@ -113,7 +105,6 @@ function BlockPattern( {
render={
<div
role="option"
tabIndex={ 0 }
aria-label={ pattern.title }
aria-describedby={
pattern.description
Expand All @@ -127,13 +118,13 @@ function BlockPattern( {
pattern.type ===
INSERTER_PATTERN_TYPES.user &&
! pattern.syncStatus,
'is-selected': isSelected,
}
) }
/>
}
id={ id }
onClick={ () => {
setActivePattern( id ); // Set active pattern when clicked
onClick( pattern, blocks );
onHover?.( null );
} }
Expand Down Expand Up @@ -224,17 +215,15 @@ function BlockPatternsList(

setActiveCompositeId( firstCompositeItemId );
}, [ shownPatterns, blockPatterns ] );
const handleClickPattern = ( pattern ) => {
setActivePattern( pattern.name ); // Set the clicked pattern as active
onClickPattern( pattern ); // Original onClick logic
const handleClickPattern = ( pattern, blocks ) => {
setActivePattern( pattern.name );
onClickPattern( pattern, blocks );
};
return (
<Composite
orientation={ orientation }
activeId={ activeCompositeId }
setActiveId={ setActiveCompositeId }
selectedId={ activePattern }
setSelectedId={ setActivePattern }
role="listbox"
className="block-editor-block-patterns-list"
aria-label={ label }
Expand All @@ -253,8 +242,9 @@ function BlockPatternsList(
showTitle={ showTitle }
showTooltip={ showTitlesAsTooltip }
category={ category }
isSelected={ activePattern === pattern.name } // Highlight the active pattern
setActivePattern={ setActivePattern } // Function to set the active pattern
isSelected={
!! activePattern && activePattern === pattern.name
}
/>
) : (
<BlockPatternPlaceholder key={ pattern.name } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
&[draggable="true"] {
cursor: grab;
}

// Solution for "Add "selected" styling to selected pattern in the design selector."
// https: //github.com/WordPress/gutenberg/issues/65127

&.is-selected {
border: $border-width solid var(--wp-admin-theme-color);
}
}

.block-editor-block-patterns-list__item {
Expand Down Expand Up @@ -52,16 +45,21 @@
}
}

&:hover:not(:focus) .block-editor-block-preview__container::after {
outline-color: rgba($black, 0.3);
&:hover:not( [data-focus-visible] )
.block-editor-block-preview__container::after {
outline-color: rgba( $black, 0.3 );
}

&:focus .block-editor-block-preview__container::after {
outline-color: var(--wp-admin-theme-color);
outline-width: var(--wp-admin-border-width-focus);
outline-offset: calc((-1 * var(--wp-admin-border-width-focus)));
&[data-focus-visible] .block-editor-block-preview__container::after {
outline-color: var( --wp-admin-theme-color );
outline-width: var( --wp-admin-border-width-focus );
outline-offset: calc( ( -1 * var( --wp-admin-border-width-focus ) ) );
transition: outline 0.1s linear;
@include reduce-motion("transition");
@include reduce-motion( 'transition' );
}

&.is-selected .block-editor-block-preview__container::after {
background-color: rgba( var( --wp-admin-theme-color--rgb ), 0.04 );
}

.block-editor-patterns__pattern-details:not(:empty) {
Expand Down
Loading