diff --git a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx index 86f0bb6db0ba8..e019739ed9d2f 100644 --- a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx +++ b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx @@ -65,7 +65,7 @@ export function useHasAPossibleBulkAction< Item >( item: Item ) { return useMemo( () => { - return actions.some( ( action ) => { + return actions?.some( ( action ) => { return ( action.supportsBulk && ( ! action.isEligible || action.isEligible( item ) ) diff --git a/packages/dataviews/src/dataviews-layouts/grid/index.tsx b/packages/dataviews/src/dataviews-layouts/grid/index.tsx index e8f8a46002ebd..4619346c497d0 100644 --- a/packages/dataviews/src/dataviews-layouts/grid/index.tsx +++ b/packages/dataviews/src/dataviews-layouts/grid/index.tsx @@ -13,6 +13,7 @@ import { Spinner, Flex, FlexItem, + Composite, privateApis as componentsPrivateApis, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; @@ -56,6 +57,14 @@ interface GridItemProps< Item > { hasBulkActions: boolean; } +function chunk( array: any, size: any ) { + const chunks = []; + for ( let i = 0, j = array.length; i < j; i += size ) { + chunks.push( array.slice( i, i + size ) ); + } + return chunks; +} + function GridItem< Item >( { view, selection, @@ -120,6 +129,7 @@ function GridItem< Item >( { ( { const updatedPreviewSize = useUpdatedPreviewSizeOnViewportChange(); const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data ); const usedPreviewSize = updatedPreviewSize || view.layout?.previewSize; - const gridStyle = usedPreviewSize - ? { - gridTemplateColumns: `repeat(${ usedPreviewSize }, minmax(0, 1fr))`, - } - : {}; return ( <> { hasData && ( - - { data.map( ( item ) => { - return ( - - ); - } ) } - + + { chunk( data, usedPreviewSize ).map( ( row, i ) => ( + + + { row.map( ( item: any ) => ( + + + + } + /> + ) ) } + + + ) ) } + + ) } { ! hasData && (
{ const previewSize = view.layout?.previewSize; - let newPreviewSize; if ( ! previewSize ) { - return; + // For mobile, we want the `min` value as the default. + const breakValueProp = viewport === 'mobile' ? 'min' : 'default'; + return viewportBreaks[ viewport ][ breakValueProp ]; } + let newPreviewSize; const breakValues = viewportBreaks[ viewport ]; if ( previewSize < breakValues.min ) { newPreviewSize = breakValues.min; diff --git a/packages/dataviews/src/dataviews-layouts/grid/style.scss b/packages/dataviews/src/dataviews-layouts/grid/style.scss index 333e6e9a4caf9..d60eb8372878a 100644 --- a/packages/dataviews/src/dataviews-layouts/grid/style.scss +++ b/packages/dataviews/src/dataviews-layouts/grid/style.scss @@ -1,6 +1,8 @@ .dataviews-view-grid { + display: flex; + align-items: flex-start; + justify-content: center; margin-bottom: auto; - grid-template-rows: max-content; padding: 0 $grid-unit-60 $grid-unit-30; transition: padding ease-out 0.1s; container-type: inline-size; @@ -116,27 +118,10 @@ } .dataviews-view-grid.dataviews-view-grid { - /** - * Breakpoints were adjusted from media queries breakpoints to account for - * the sidebar width. This was done to match the existing styles we had. - */ @container (max-width: 480px) { - grid-template-columns: repeat(1, minmax(0, 1fr)); padding-left: $grid-unit-30; padding-right: $grid-unit-30; } - @container (min-width: 480px) { - grid-template-columns: repeat(2, minmax(0, 1fr)); - } - @container (min-width: 780px) { - grid-template-columns: repeat(3, minmax(0, 1fr)); - } - @container (min-width: 1140px) { - grid-template-columns: repeat(4, minmax(0, 1fr)); - } - @container (min-width: 1520px) { - grid-template-columns: repeat(5, minmax(0, 1fr)); - } } .dataviews-view-grid__field-value:empty, @@ -160,3 +145,23 @@ .dataviews-view-grid__media--clickable { cursor: pointer; } + + +.dataviews-view-grid__row { + .dataviews-view-grid__row__gridcell { + outline: 0; + outline-style: solid; + // outline-offset: calc(-1 * var(--wp-admin-border-width-focus)); + border-radius: $grid-unit-10; + + &[data-focus-visible] { + outline-color: var(--wp-admin-theme-color); + outline-width: var(--wp-admin-border-width-focus); + } + + &:hover { + outline-color: rgba($black, 0.3); + outline-width: var(--wp-admin-border-width-focus); + } + } +}