Skip to content

Commit

Permalink
Add image count
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Aug 10, 2023
1 parent 0094db2 commit 51bd450
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import useBlockDisplayTitle from '../block-title/use-block-display-title';
import ListViewExpander from './expander';
import { useBlockLock } from '../block-lock';
import { store as blockEditorStore } from '../../store';
import useListViewImages from './use-list-view-images';
import useListViewImages, { MAX_IMAGES } from './use-list-view-images';

function ListViewBlockSelectButton(
{
Expand Down Expand Up @@ -187,17 +187,31 @@ function ListViewBlockSelectButton(
</Tooltip>
) }
{ images.length ? (
<span className="block-editor-list-view-block-select-button__images">
{ images.map( ( image, index ) => (
<span
className="block-editor-list-view-block-select-button__image"
key={ index }
style={ {
backgroundImage: `url(${ image.url })`,
zIndex: images.length - index, // Ensure the first image is on top, and subsequent images are behind.
} }
/>
) ) }
<span
className="block-editor-list-view-block-select-button__images"
aria-hidden
>
{ images
.slice( 0, MAX_IMAGES )
.map( ( image, index ) => (
<span
className="block-editor-list-view-block-select-button__image"
key={ `img-${ image.url }` }
style={ {
backgroundImage: `url(${ image.url })`,
zIndex: images.length - index, // Ensure the first image is on top, and subsequent images are behind.
} }
/>
) ) }
{ images.length > MAX_IMAGES && (
<span className="block-editor-list-view-block-select-button__image-count">
{ sprintf(
/* translators: %d: Number of additional images within a block. */
__( '+%d' ),
images.length - MAX_IMAGES
) }
</span>
) }
</span>
) : null }
{ isLocked && (
Expand Down
6 changes: 6 additions & 0 deletions packages/block-editor/src/components/list-view/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@
}
}

.block-editor-list-view-block-select-button__image-count {
font-size: $helptext-font-size;
margin-left: $grid-unit-05;
opacity: 0.6;
}

&.is-selected .block-editor-list-view-block-select-button__image {
box-shadow: 0 0 0 $radius-block-ui var(--wp-admin-theme-color);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '../../store';

// Maximum number of images to display in a list view row.
const MAX_IMAGES = 5;
export const MAX_IMAGES = 5;

function getImageUrl( block ) {
if ( block.name !== 'core/image' ) {
Expand All @@ -34,9 +34,6 @@ function getImagesFromGallery( block ) {
if ( img ) {
images.push( img );
}
if ( images.length >= MAX_IMAGES ) {
return images;
}
}

return images;
Expand Down

0 comments on commit 51bd450

Please sign in to comment.