Skip to content

Commit

Permalink
Site editor: style the selected template pattern (#65917)
Browse files Browse the repository at this point in the history
* Updated code to set active pattern and its styling

* Fixes for linting issues on updated files

* Updated code based on the first round feedback points

* Modification to highlight active iitem on focus

* Removed local/session storage

* Changes applied from drafted PR

* Changes applied from drafted PR

* Updated with new style changes

* Linting Fix

* Updated code to set active pattern and its styling

* Fixes for linting issues on updated files

* Updated code based on the first round feedback points

* Modification to highlight active iitem on focus

* Removed local/session storage

* Changes applied from drafted PR

* Changes applied from drafted PR

* Updated with new style changes

* Linting Fix

* Fix spacing

---------

Co-authored-by: benazeer-ben <[email protected]>
Co-authored-by: ciampo <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: jasmussen <[email protected]>
Co-authored-by: patil-vipul <[email protected]>
Co-authored-by: juanfra <[email protected]>
  • Loading branch information
8 people authored Nov 27, 2024
1 parent 758b750 commit 443ce89
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function BlockPattern( {
onHover,
showTitlesAsTooltip,
category,
isSelected,
} ) {
const [ isDragging, setIsDragging ] = useState( false );
const { blocks, viewportWidth } = pattern;
Expand Down Expand Up @@ -114,6 +115,7 @@ function BlockPattern( {
pattern.type ===
INSERTER_PATTERN_TYPES.user &&
! pattern.syncStatus,
'is-selected': isSelected,
}
) }
/>
Expand Down Expand Up @@ -192,6 +194,7 @@ function BlockPatternsList(
ref
) {
const [ activeCompositeId, setActiveCompositeId ] = useState( undefined );
const [ activePattern, setActivePattern ] = useState( null ); // State to track active pattern

useEffect( () => {
// Reset the active composite item whenever the available patterns change,
Expand All @@ -201,6 +204,11 @@ function BlockPatternsList(
setActiveCompositeId( firstCompositeItemId );
}, [ blockPatterns ] );

const handleClickPattern = ( pattern, blocks ) => {
setActivePattern( pattern.name );
onClickPattern( pattern, blocks );
};

return (
<Composite
orientation={ orientation }
Expand All @@ -216,11 +224,14 @@ function BlockPatternsList(
key={ pattern.name }
id={ pattern.name }
pattern={ pattern }
onClick={ onClickPattern }
onClick={ handleClickPattern }
onHover={ onHover }
isDraggable={ isDraggable }
showTitlesAsTooltip={ showTitlesAsTooltip }
category={ category }
isSelected={
!! activePattern && activePattern === pattern.name
}
/>
) ) }
{ pagingProps && <BlockPatternsPaging { ...pagingProps } /> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,29 @@
outline: $border-width solid rgba($black, 0.1);
outline-offset: -$border-width;
border-radius: $radius-medium;

transition: outline 0.1s linear;
@include reduce-motion("transition");
}
}

&:hover:not(:focus) .block-editor-block-preview__container::after {
// Selected
&.is-selected .block-editor-block-preview__container::after {
outline-color: $gray-900;
outline-width: var(--wp-admin-border-width-focus);
outline-offset: calc(-1 * var(--wp-admin-border-width-focus));
}

// Hover state
&:hover .block-editor-block-preview__container::after {
outline-color: rgba($black, 0.3);
}

&:focus .block-editor-block-preview__container::after {
// Focused state
&[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");
outline-offset: calc(-1 * var(--wp-admin-border-width-focus));
}

.block-editor-patterns__pattern-details:not(:empty) {
Expand All @@ -68,6 +78,7 @@
.block-editor-patterns__pattern-icon-wrapper {
min-width: 24px;
height: 24px;

.block-editor-patterns__pattern-icon {
fill: var(--wp-block-synced-color);
}
Expand Down

0 comments on commit 443ce89

Please sign in to comment.