Skip to content
14 changes: 14 additions & 0 deletions packages/grid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
`--wp-grid-resize-preview-outline-style` CSS custom properties for
the drag-placeholder outline (default `dashed`) and resize-preview
border (default `solid`).
- Add `--wp-grid-drag-preview-radius` so consumers can round the
drag-preview functional frame without targeting package internals.
- Animate drag preview `box-shadow` from resting `xs` to `md` (same
motion tokens as scale) and apply static `md` when reduced motion
is requested, on the `.drag-preview-frame` wrapper (both surfaces).
Widget dashboard edit tiles use `xs` at rest and on hover so only
the drag preview elevates to `md`.
On drop, compose `@dnd-kit/core`'s default `DragOverlay` translation
with preview exit keyframes (via drop side effects). Split scale into
an inner `__lift` wrapper so drop translation does not fight the lift
transform.
- Defer placeholder fade and dashed outline until `data-wp-grid-dragging`
is set and the drag-preview enter animation completes (both surfaces).
- Set `data-wp-dashboard-grid-resizing` on the `DashboardGrid` root
element while any tile resize gesture is active, so consumers can
adjust styles when the pointer may still hover tiles ([#78234](https://github.com/WordPress/gutenberg/pull/78234)).
Expand Down Expand Up @@ -55,6 +68,7 @@
- Expose CSS custom properties for theming the lift scale,
placeholder opacity, placeholder outline color, and placeholder
radius (`--wp-grid-drag-preview-scale`,
`--wp-grid-drag-preview-radius`,
`--wp-grid-placeholder-opacity`,
`--wp-grid-placeholder-outline-color`,
`--wp-grid-placeholder-radius`).
Expand Down
1 change: 1 addition & 0 deletions packages/grid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ root itself via `style`). All values fall back to sensible defaults.
|----------|---------|------------|
| `--wp-grid-gap` | `var(--wpds-dimension-gap-xl)` | Gap between tiles on `DashboardGrid`, `DashboardLanes`, and the edit overlay. |
| `--wp-grid-drag-preview-scale` | `1.05` | Lift scale of the drag-preview functional frame. Set to `1` to disable the lift. |
| `--wp-grid-drag-preview-radius` | `0` | Border radius of the drag-preview functional frame so the lift shadow follows the consumer's tile shape. |
| `--wp-grid-placeholder-opacity` | `0.4` | Opacity of the placeholder tile (the original item while a drag is in flight). |
| `--wp-grid-placeholder-outline-style` | `dashed` | Outline style of the drag placeholder (for example `solid` or `dotted`). |
| `--wp-grid-resize-preview-outline-style` | `solid` | Border style of the resize-preview overlay (for example `dashed` or `dotted`). |
Expand Down
51 changes: 41 additions & 10 deletions packages/grid/src/dashboard-grid/grid-item.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,54 @@
/*
* During drag, the original item acts as a placeholder in its grid
* cell while `<DragOverlay>` renders a clone that follows the cursor.
* Fading the placeholder and outlining it makes
* the destination visible without any scaling or translation on the
* original element.
* Fading the placeholder and outlining it makes the destination visible
* without any scaling or translation on the original element.
*
* Placeholder chrome waits until `data-wp-grid-dragging` is set and the
* drag-preview enter animation (`--wpds-motion-duration-sm`) finishes
* so the dashed outline does not flash under the lifting clone.
*/
.is-dragging {
opacity: var(--wp-grid-placeholder-opacity, 0.4);
pointer-events: none;
outline:
var(--wpds-border-width-sm)
var(--wp-grid-placeholder-outline-style, dashed)
var(--wp-grid-placeholder-outline-color, var(--wpds-color-stroke-interactive-brand));
}

:global([data-wp-grid-dragging]) .is-dragging {
border-radius: var(--wp-grid-placeholder-radius, 0);
}

@media not (prefers-reduced-motion: reduce) {
:global([data-wp-grid-dragging]) .is-dragging {
opacity: 1;
outline-width: 0;
outline-style: var(--wp-grid-placeholder-outline-style, dashed);
outline-color: transparent;
animation:
wp-grid-item-placeholder-in 0ms linear
var(--wpds-motion-duration-sm) forwards;
}

@keyframes wp-grid-item-placeholder-in {
to {
opacity: var(--wp-grid-placeholder-opacity, 0.4);
outline-width: var(--wpds-border-width-sm);
outline-color: var(--wp-grid-placeholder-outline-color, var(--wpds-color-stroke-interactive-brand));
}
}
}

@media (prefers-reduced-motion: reduce) {
:global([data-wp-grid-dragging]) .is-dragging {
opacity: var(--wp-grid-placeholder-opacity, 0.4);
outline:
var(--wpds-border-width-sm)
var(--wp-grid-placeholder-outline-style, dashed)
var(--wp-grid-placeholder-outline-color, var(--wpds-color-stroke-interactive-brand));
}
}

@media (forced-colors: active) {
.is-dragging {
outline-color: Highlight;
:global([data-wp-grid-dragging]) .is-dragging {
--wp-grid-placeholder-outline-color: Highlight;
}
}

Expand Down
119 changes: 113 additions & 6 deletions packages/grid/src/dashboard-grid/grid.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,128 @@
/*
* Functional frame for the drag-preview clone inside `<DragOverlay>`.
* Always applied, including when the consumer passes a
* `renderDragPreview` wrapper. Owns the lift cue (`scale`), the
* pointer feedback (`cursor`), and the pointer pass-through during
* the gesture. Visual chrome (shadow, radius, padding) belongs to
* the consumer, either on the children passed to <DashboardGrid />
* or via `renderDragPreview`.
* `renderDragPreview` wrapper. The outer frame has no `transform` so
* @dnd-kit’s drop translation matches the placeholder; scale lives on
* `__lift` (see dnd-kit #398). Owns elevation, radius, cursor, and
* pointer pass-through. Further chrome belongs to the consumer. Drag
* elevation animates `xs` → `md` so it reads above edit tiles at `xs`.
*/
.drag-preview-frame {
height: 100%;
transform: scale(var(--wp-grid-drag-preview-scale, 1.05));
border-radius: var(--wp-grid-drag-preview-radius, 0);
cursor: grabbing;
pointer-events: none;
box-shadow: var(--wpds-elevation-md);
}

.drag-preview-frame__lift {
height: 100%;
transform: scale(var(--wp-grid-drag-preview-scale, 1.05));
transform-origin: center;
}

@media not (prefers-reduced-motion: reduce) {
.drag-preview-frame {
animation:
wp-grid-drag-preview-shadow-enter
var(--wpds-motion-duration-sm) var(--wpds-motion-easing-balanced) both;
}

.drag-preview-frame__lift {
animation:
wp-grid-drag-preview-scale-enter
var(--wpds-motion-duration-sm) var(--wpds-motion-easing-balanced) both;
}
}

@media not (prefers-reduced-motion: reduce) {
@keyframes wp-grid-drag-preview-shadow-enter {
from {
box-shadow: var(--wpds-elevation-xs);
}

to {
box-shadow: var(--wpds-elevation-md);
}
}

@keyframes wp-grid-drag-preview-scale-enter {
from {
transform: scale(1);
}

to {
transform: scale(var(--wp-grid-drag-preview-scale, 1.05));
}
}
}

/*
* Applied by @dnd-kit `DragOverlay` drop side-effects while the
* default overlay transform runs; duration matches
* `createDashboardDragDropAnimation` (200ms / md token). Use keyframed
* exit (not transition) so scale does not snap when the enter animation
* is replaced.
*/
@media not (prefers-reduced-motion: reduce) {
.drag-preview-frame.dragPreviewFrameExiting {
animation:
wp-grid-drag-preview-shadow-exit
var(--wpds-motion-duration-md) var(--wpds-motion-easing-balanced)
forwards;
}

.drag-preview-frame.dragPreviewFrameExiting .drag-preview-frame__lift {
animation:
wp-grid-drag-preview-scale-exit
var(--wpds-motion-duration-md) var(--wpds-motion-easing-balanced)
forwards;
}

@keyframes wp-grid-drag-preview-shadow-exit {
from {
box-shadow: var(--wpds-elevation-md);
}

to {
box-shadow: var(--wpds-elevation-xs);
}
}

@keyframes wp-grid-drag-preview-scale-exit {
from {
transform: scale(var(--wp-grid-drag-preview-scale, 1.05));
}

to {
transform: scale(1);
}
}
}

.drag-preview-frame.dragPreviewFrameExiting {
box-shadow: var(--wpds-elevation-xs);
}

.drag-preview-frame.dragPreviewFrameExiting .drag-preview-frame__lift {
transform: scale(1);
}

@media (prefers-reduced-motion: reduce) {
.drag-preview-frame {
box-shadow: var(--wpds-elevation-md);
}

.drag-preview-frame__lift {
transform: none;
}

.drag-preview-frame.dragPreviewFrameExiting {
box-shadow: var(--wpds-elevation-xs);
transition: none;
}

.drag-preview-frame.dragPreviewFrameExiting .drag-preview-frame__lift {
transition: none;
}
}
28 changes: 19 additions & 9 deletions packages/grid/src/dashboard-grid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ import { resolveFillWidths } from './resolve-fill-widths';
import type { DashboardGridLayoutItem, DashboardGridProps } from './types';
import type { ResizeSnapSize } from '../shared/resize-snap';
import type { ResizeDelta } from '../shared/types';
import { createDashboardDragDropAnimation } from '../shared/drag-overlay-drop-animation';
import styles from './grid.module.css';

const dashboardDragDropAnimation = createDashboardDragDropAnimation(
styles[ 'drag-preview-frame' ],
styles.dragPreviewFrameExiting
);

// Fallback gap in pixels for math that runs before the computed gap
// can be read from the DOM. Matches the `'xl'` step the surface
// resolves to in CSS (`--wpds-dimension-gap-xl`); the next layout
Expand Down Expand Up @@ -550,13 +556,15 @@ export const DashboardGrid = forwardRef< HTMLDivElement, DashboardGridProps >(
const dragOverlayContent =
activeId && activeClone ? (
<div className={ styles[ 'drag-preview-frame' ] }>
{ DragPreview ? (
<DragPreview itemId={ activeId }>
{ activeClone }
</DragPreview>
) : (
activeClone
) }
<div className={ styles[ 'drag-preview-frame__lift' ] }>
{ DragPreview ? (
<DragPreview itemId={ activeId }>
{ activeClone }
</DragPreview>
) : (
activeClone
) }
</div>
</div>
) : null;

Expand Down Expand Up @@ -634,8 +642,8 @@ export const DashboardGrid = forwardRef< HTMLDivElement, DashboardGridProps >(
onDragMove={ handleDragMove }
onDragEnd={ () => {
persistTemporaryLayout();
setActiveId( null );
lastReorderCursorRef.current = null;
setActiveId( null );
} }
>
{ /* No-op strategy: reorder comes from `temporaryLayout`
Expand Down Expand Up @@ -700,7 +708,9 @@ export const DashboardGrid = forwardRef< HTMLDivElement, DashboardGridProps >(
) ) }
</div>
</SortableContext>
<DragOverlay>{ dragOverlayContent }</DragOverlay>
<DragOverlay dropAnimation={ dashboardDragDropAnimation }>
{ dragOverlayContent }
</DragOverlay>
</DndContext>
);
}
Expand Down
25 changes: 8 additions & 17 deletions packages/grid/src/dashboard-grid/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -709,32 +709,23 @@ function CustomResizeHandle( {
}

/**
* Drop-in wrapper that bumps the dragged-clone shadow and clips its
* corners. The grid keeps the lift scale and the grabbing cursor on
* the functional frame; the consumer's wrapper sits inside it.
* Example `renderDragPreview` wrapper: keeps the clone height chain
* intact. Lift, shadow, and motion live on the grid
* `.drag-preview-frame`; set `--wp-grid-drag-preview-radius` on the
* surface when the lift shadow should match rounded tiles (see widget
* dashboard).
*/
function CustomDragPreview( { children }: DragPreviewRenderProps ) {
return (
<div
style={ {
height: '100%',
boxShadow: 'var(--wpds-elevation-lg)',
borderRadius: 'var(--wpds-border-radius-lg)',
overflow: 'hidden',
} }
>
Comment on lines -718 to -725

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice cleanup 👍

{ children }
</div>
);
return <div style={ { height: '100%' } }>{ children }</div>;
}

/**
* Exercises the three customization vectors on a single grid:
*
* 1. `renderResizeHandle` swaps the default corner triangle for a
* custom diagonal-arrow icon.
* 2. `renderDragPreview` wraps the dragged clone with extra chrome
* (stronger shadow, rounded corners, overflow clipping).
* 2. `renderDragPreview` wraps the dragged clone (here only for the
* height chain; lift and shadow stay on the grid frame).
* 3. CSS custom properties on an ancestor retheme the lift scale,
* placeholder opacity, placeholder outline color, and placeholder
* border-radius without touching the package.
Expand Down
28 changes: 19 additions & 9 deletions packages/grid/src/dashboard-lanes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ import { useItemExitAnimation } from '../shared/use-item-exit-animation';
import type { DashboardLanesLayoutItem, DashboardLanesProps } from './types';
import type { ResizeSnapSize } from '../shared/resize-snap';
import type { ResizeDelta } from '../shared/types';
import { createDashboardDragDropAnimation } from '../shared/drag-overlay-drop-animation';
import styles from './lanes.module.css';

const dashboardDragDropAnimation = createDashboardDragDropAnimation(
styles[ 'drag-preview-frame' ],
styles.dragPreviewFrameExiting
);

// Fallback gap in pixels for math that runs before the computed gap
// can be read from the DOM. Matches the `'xl'` step the surface
// resolves to in CSS (`--wpds-dimension-gap-xl`); the next layout
Expand Down Expand Up @@ -474,13 +480,15 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
const dragOverlayContent =
activeId && activeClone ? (
<div className={ styles[ 'drag-preview-frame' ] }>
{ DragPreview ? (
<DragPreview itemId={ activeId }>
{ activeClone }
</DragPreview>
) : (
activeClone
) }
<div className={ styles[ 'drag-preview-frame__lift' ] }>
{ DragPreview ? (
<DragPreview itemId={ activeId }>
{ activeClone }
</DragPreview>
) : (
activeClone
) }
</div>
</div>
) : null;

Expand Down Expand Up @@ -533,8 +541,8 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
onDragMove={ handleDragMove }
onDragEnd={ () => {
persistTemporaryLayout();
setActiveId( null );
lastReorderCursorRef.current = null;
setActiveId( null );
} }
>
<SortableContext items={ items } strategy={ NO_SORT_STRATEGY }>
Expand Down Expand Up @@ -615,7 +623,9 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
) ) }
</div>
</SortableContext>
<DragOverlay>{ dragOverlayContent }</DragOverlay>
<DragOverlay dropAnimation={ dashboardDragDropAnimation }>
{ dragOverlayContent }
</DragOverlay>
</DndContext>
);
}
Expand Down
Loading
Loading