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

[Data Views] Grid layout keyboard/mouse interaction changes #58802

Closed
wants to merge 8 commits into from
Closed
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
11 changes: 7 additions & 4 deletions packages/dataviews/src/dataviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ export default function DataViews( {
( v ) => v.type === view.type
).component;
const _fields = useMemo( () => {
return fields.map( ( field ) => ( {
...field,
render: field.render || field.getValue,
} ) );
return fields.map( ( field ) => {
const renderField = field.render || field.getValue;
const render = ( { ref: refAsProp, ...props } = {}, ref ) =>
renderField?.( props, ref ?? refAsProp );

return { ...field, render };
} );
}, [ fields ] );
return (
<div className="dataviews-wrapper">
Expand Down
19 changes: 15 additions & 4 deletions packages/dataviews/src/item-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useMemo, useState } from '@wordpress/element';
import { forwardRef, useMemo, useState } from '@wordpress/element';
import { moreVertical } from '@wordpress/icons';

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ function ActionsDropdownMenuGroup( { actions, item } ) {
);
}

export default function ItemActions( { item, actions, isCompact } ) {
function ItemActions( { item, actions, isCompact, ...props }, ref ) {
const { primaryActions, secondaryActions } = useMemo( () => {
return actions.reduce(
( accumulator, action ) => {
Expand All @@ -129,6 +129,8 @@ export default function ItemActions( { item, actions, isCompact } ) {
item={ item }
primaryActions={ primaryActions }
secondaryActions={ secondaryActions }
{ ...props }
ref={ ref }
/>
);
}
Expand Down Expand Up @@ -164,10 +166,12 @@ export default function ItemActions( { item, actions, isCompact } ) {
<DropdownMenu
trigger={
<Button
{ ...props }
size="compact"
icon={ moreVertical }
label={ __( 'Actions' ) }
disabled={ ! secondaryActions.length }
ref={ ref }
/>
}
placement="bottom-end"
Expand All @@ -181,17 +185,24 @@ export default function ItemActions( { item, actions, isCompact } ) {
);
}

function CompactItemActions( { item, primaryActions, secondaryActions } ) {
export default forwardRef( ItemActions );

const CompactItemActions = forwardRef( function CompactItemActions(
{ item, primaryActions, secondaryActions, ...props },
ref
) {
return (
<DropdownMenu
trigger={
<Button
{ ...props }
size="compact"
icon={ moreVertical }
label={ __( 'Actions' ) }
disabled={
! primaryActions.length && ! secondaryActions.length
}
ref={ ref }
/>
}
placement="bottom-end"
Expand All @@ -210,4 +221,4 @@ function CompactItemActions( { item, primaryActions, secondaryActions } ) {
) }
</DropdownMenu>
);
}
} );
80 changes: 69 additions & 11 deletions packages/dataviews/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -243,32 +243,65 @@
}

.dataviews-view-grid {
margin-bottom: $grid-unit-30;
grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(17em, 1fr));
grid-template-rows: max-content;
padding: 0 $grid-unit-40;

@include break-xlarge() {
grid-template-columns: repeat(3, minmax(0, 1fr)) !important; // Todo: eliminate !important dependency
}
margin: 0 $grid-unit-40 $grid-unit-30;
position: relative;
gap: 1em;

@include break-huge() {
grid-template-columns: repeat(4, minmax(0, 1fr)) !important; // Todo: eliminate !important dependency
.dataviews-view-grid__row {
display: contents;
}

.dataviews-view-grid__card {
border-radius: $radius-block-ui * 2;
border: 1px solid $gray-200;
height: 100%;
justify-content: flex-start;
scroll-margin-top: 5em;
max-width: 26em;

&:focus-visible {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
}

.dataviews-view-grid__title-actions {
padding: $grid-unit-05 $grid-unit $grid-unit-05 $grid-unit-05;
}

.dataviews-view-grid__primary-field {
min-height: $grid-unit-50;

a,
button.components-button.is-link {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general we should avoid overriding components styles like that. Additionally they seem too specific that a consumer could use a Button component. What these styles do?

&::before {
content: "";
position: absolute;
top: -1px;
left: -1px;
right: -1px;
min-height: 200px;
aspect-ratio: 1000/999;
border-radius: 3px 3px 0 0;
}

&:focus {
box-shadow: none;
}

&:focus-visible {
text-decoration: underline;
text-decoration-color: var(--wp-admin-theme-color);
text-decoration-thickness: var(--wp-admin-border-width-focus);

&::before {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
}
}
}
}

&.is-selected {
border-color: var(--wp-admin-theme-color);
background-color: rgba(var(--wp-admin-theme-color--rgb), 0.04);
Expand All @@ -286,11 +319,17 @@
border-bottom: 1px solid $gray-200;
background-color: $gray-100;
border-radius: 3px 3px 0 0;
overflow: hidden;
cursor: pointer;

img {
object-fit: cover;
width: 100%;
height: 100%;
border-radius: inherit;
position: relative;
z-index: 1;
cursor: inherit;
}
}

Expand Down Expand Up @@ -493,9 +532,28 @@
margin-left: $grid-unit-10;
}

.dataviews-view-grid__card.has-no-pointer-events * {
pointer-events: none;
.dataviews-view-grid__card {
position: relative;

&.has-no-pointer-events {
&::after {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
cursor: default;
z-index: 2;
}

* {
pointer-events: none;
}
}
}

.dataviews-filter-summary__popover {
.components-popover__content {
width: 230px;
Expand Down
Loading
Loading