@wordpress/grid 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -14
- package/build/dashboard-grid/grid-item.cjs +232 -295
- package/build/dashboard-grid/grid-item.cjs.map +1 -7
- package/build/dashboard-grid/index.cjs +526 -633
- package/build/dashboard-grid/index.cjs.map +1 -7
- package/build/dashboard-grid/resolve-fill-widths.cjs +159 -203
- package/build/dashboard-grid/resolve-fill-widths.cjs.map +1 -7
- package/build/dashboard-grid/types.cjs +4 -18
- package/build/dashboard-lanes/index.cjs +495 -577
- package/build/dashboard-lanes/index.cjs.map +1 -7
- package/build/dashboard-lanes/lane-placement.cjs +77 -100
- package/build/dashboard-lanes/lane-placement.cjs.map +1 -7
- package/build/dashboard-lanes/lanes-item.cjs +222 -278
- package/build/dashboard-lanes/lanes-item.cjs.map +1 -7
- package/build/dashboard-lanes/types.cjs +4 -18
- package/build/dashboard-lanes/use-lane-placement.cjs +172 -198
- package/build/dashboard-lanes/use-lane-placement.cjs.map +1 -7
- package/build/index.cjs +16 -31
- package/build/shared/array-move-with-pinned.cjs +29 -45
- package/build/shared/array-move-with-pinned.cjs.map +1 -7
- package/build/shared/column-policy.cjs +58 -0
- package/build/shared/column-policy.cjs.map +1 -0
- package/build/shared/drag-overlay-drop-animation.cjs +40 -66
- package/build/shared/drag-overlay-drop-animation.cjs.map +1 -7
- package/build/shared/grid-item-key.cjs +12 -29
- package/build/shared/grid-item-key.cjs.map +1 -7
- package/build/shared/grid-overlay.cjs +163 -164
- package/build/shared/grid-overlay.cjs.map +1 -7
- package/build/shared/item-exit-overlay.cjs +132 -134
- package/build/shared/item-exit-overlay.cjs.map +1 -7
- package/build/shared/resize-handle.cjs +213 -197
- package/build/shared/resize-handle.cjs.map +1 -7
- package/build/shared/resize-snap.cjs +116 -121
- package/build/shared/resize-snap.cjs.map +1 -7
- package/build/shared/types.cjs +4 -18
- package/build/shared/use-item-exit-animation.cjs +96 -143
- package/build/shared/use-item-exit-animation.cjs.map +1 -7
- package/build/shared/use-layout-shift-animation.cjs +121 -150
- package/build/shared/use-layout-shift-animation.cjs.map +1 -7
- package/build/shared/use-span-bounds.cjs +65 -79
- package/build/shared/use-span-bounds.cjs.map +1 -7
- package/build-module/dashboard-grid/grid-item.mjs +209 -265
- package/build-module/dashboard-grid/grid-item.mjs.map +1 -7
- package/build-module/dashboard-grid/index.mjs +502 -623
- package/build-module/dashboard-grid/index.mjs.map +1 -7
- package/build-module/dashboard-grid/resolve-fill-widths.mjs +155 -179
- package/build-module/dashboard-grid/resolve-fill-widths.mjs.map +1 -7
- package/build-module/dashboard-grid/types.mjs +0 -1
- package/build-module/dashboard-lanes/index.mjs +470 -567
- package/build-module/dashboard-lanes/index.mjs.map +1 -7
- package/build-module/dashboard-lanes/lane-placement.mjs +73 -76
- package/build-module/dashboard-lanes/lane-placement.mjs.map +1 -7
- package/build-module/dashboard-lanes/lanes-item.mjs +199 -248
- package/build-module/dashboard-lanes/lanes-item.mjs.map +1 -7
- package/build-module/dashboard-lanes/types.mjs +0 -1
- package/build-module/dashboard-lanes/use-lane-placement.mjs +167 -173
- package/build-module/dashboard-lanes/use-lane-placement.mjs.map +1 -7
- package/build-module/index.mjs +1 -6
- package/build-module/shared/array-move-with-pinned.mjs +25 -21
- package/build-module/shared/array-move-with-pinned.mjs.map +1 -7
- package/build-module/shared/column-policy.mjs +52 -0
- package/build-module/shared/column-policy.mjs.map +1 -0
- package/build-module/shared/drag-overlay-drop-animation.mjs +35 -44
- package/build-module/shared/drag-overlay-drop-animation.mjs.map +1 -7
- package/build-module/shared/grid-item-key.mjs +8 -5
- package/build-module/shared/grid-item-key.mjs.map +1 -7
- package/build-module/shared/grid-overlay.mjs +143 -136
- package/build-module/shared/grid-overlay.mjs.map +1 -7
- package/build-module/shared/item-exit-overlay.mjs +128 -110
- package/build-module/shared/item-exit-overlay.mjs.map +1 -7
- package/build-module/shared/resize-handle.mjs +191 -171
- package/build-module/shared/resize-handle.mjs.map +1 -7
- package/build-module/shared/resize-snap.mjs +108 -93
- package/build-module/shared/resize-snap.mjs.map +1 -7
- package/build-module/shared/types.mjs +0 -1
- package/build-module/shared/use-item-exit-animation.mjs +92 -124
- package/build-module/shared/use-item-exit-animation.mjs.map +1 -7
- package/build-module/shared/use-layout-shift-animation.mjs +114 -123
- package/build-module/shared/use-layout-shift-animation.mjs.map +1 -7
- package/build-module/shared/use-span-bounds.mjs +60 -57
- package/build-module/shared/use-span-bounds.mjs.map +1 -7
- package/build-types/dashboard-grid/index.d.ts.map +1 -1
- package/build-types/dashboard-grid/types.d.ts +9 -5
- package/build-types/dashboard-grid/types.d.ts.map +1 -1
- package/build-types/dashboard-lanes/index.d.ts.map +1 -1
- package/build-types/dashboard-lanes/types.d.ts +9 -5
- package/build-types/dashboard-lanes/types.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/shared/column-policy.d.ts +43 -0
- package/build-types/shared/column-policy.d.ts.map +1 -0
- package/package.json +14 -12
- package/src/dashboard-grid/grid-item.tsx +1 -1
- package/src/dashboard-grid/{grid.module.css → grid.module.scss} +10 -19
- package/src/dashboard-grid/index.tsx +12 -13
- package/src/dashboard-grid/stories/index.story.tsx +129 -50
- package/src/dashboard-grid/test/item-interactions.browser.test.tsx +1 -1
- package/src/dashboard-grid/types.ts +9 -5
- package/src/dashboard-lanes/index.tsx +13 -13
- package/src/dashboard-lanes/lanes-item.tsx +1 -1
- package/src/dashboard-lanes/{lanes.module.css → lanes.module.scss} +10 -19
- package/src/dashboard-lanes/stories/index.story.tsx +124 -28
- package/src/dashboard-lanes/test/item-interactions.browser.test.tsx +1 -1
- package/src/dashboard-lanes/types.ts +9 -5
- package/src/index.ts +1 -0
- package/src/shared/column-policy.ts +100 -0
- package/src/shared/test/column-policy.test.ts +215 -0
- package/src/shared/test/sortable-semantics.browser.test.tsx +122 -0
- package/build/dashboard-grid/types.cjs.map +0 -7
- package/build/dashboard-lanes/types.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/shared/types.cjs.map +0 -7
- package/build-module/dashboard-grid/types.mjs.map +0 -7
- package/build-module/dashboard-lanes/types.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/shared/types.mjs.map +0 -7
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column count per container width. Each key is the inline size in pixels
|
|
3
|
+
* from which its count applies: `{ 0: 1, 600: 2, 960: 4 }` is one column
|
|
4
|
+
* from 0px, two from 600px, four from 960px, and below the smallest key
|
|
5
|
+
* that step's count applies. An `'auto'` step lifts the cap from its
|
|
6
|
+
* width up and leaves the count to `minColumnWidth`; with no floor set,
|
|
7
|
+
* the step is skipped and the count below it holds.
|
|
8
|
+
*/
|
|
9
|
+
export type ColumnSteps = Record<number, number | 'auto'>;
|
|
10
|
+
/**
|
|
11
|
+
* Column policy shared by the surfaces: a count at every width, or a count
|
|
12
|
+
* per container width, with an optional per-column floor in pixels.
|
|
13
|
+
*/
|
|
14
|
+
export interface ColumnPolicy {
|
|
15
|
+
columns?: number | ColumnSteps;
|
|
16
|
+
minColumnWidth?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The count the policy asks for at a container width, before the floor.
|
|
20
|
+
* Counts are rounded down and never below one; a count that is not a
|
|
21
|
+
* finite number, or a step that is neither a count nor `'auto'`, is
|
|
22
|
+
* ignored.
|
|
23
|
+
*
|
|
24
|
+
* @param policy Column policy.
|
|
25
|
+
* @param containerWidth Measured inline size of the surface in pixels.
|
|
26
|
+
* @return The count, or `undefined` when none applies: no count was set, or
|
|
27
|
+
* an `'auto'` step lifts the cap over a floor.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveColumnCap(policy: ColumnPolicy, containerWidth: number): number | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Resolves the count a surface renders: the policy's count at the container
|
|
32
|
+
* width, lowered by the floor so no column is narrower than
|
|
33
|
+
* `minColumnWidth`. A floor with no count fits as many columns as the
|
|
34
|
+
* container allows.
|
|
35
|
+
*
|
|
36
|
+
* @param policy Column policy.
|
|
37
|
+
* @param containerWidth Measured inline size of the surface in pixels.
|
|
38
|
+
* @param gapPx Column gap in pixels.
|
|
39
|
+
* @param defaultColumns Count used when the policy sets neither field.
|
|
40
|
+
* @return Column count, at least one.
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveColumnCount(policy: ColumnPolicy, containerWidth: number, gapPx: number, defaultColumns: number): number;
|
|
43
|
+
//# sourceMappingURL=column-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-policy.d.ts","sourceRoot":"","sources":["../../src/shared/column-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAE,CAAC;AAE5D;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAgBD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,YAAY,EACpB,cAAc,EAAE,MAAM,GACpB,MAAM,GAAG,SAAS,CAsBpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,YAAY,EACpB,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,GACpB,MAAM,CAWR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/grid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Grid layout components for arranging tiles in dashboard-style surfaces, with drag-to-reorder and tile resizing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -41,27 +41,29 @@
|
|
|
41
41
|
"wpScript": false,
|
|
42
42
|
"types": "build-types",
|
|
43
43
|
"sideEffects": [
|
|
44
|
-
"src/**/*.module.css"
|
|
44
|
+
"src/**/*.module.css",
|
|
45
|
+
"src/**/*.module.scss"
|
|
45
46
|
],
|
|
46
47
|
"dependencies": {
|
|
47
48
|
"@dnd-kit/core": "^6.3.1",
|
|
48
49
|
"@dnd-kit/sortable": "^10.0.0",
|
|
49
|
-
"@wordpress/compose": "^9.
|
|
50
|
-
"@wordpress/element": "^10.
|
|
51
|
-
"@wordpress/react-inert-value": "^2.
|
|
52
|
-
"@wordpress/style-runtime": "^0.
|
|
53
|
-
"@wordpress/ui": "^0.
|
|
50
|
+
"@wordpress/compose": "^9.2.0",
|
|
51
|
+
"@wordpress/element": "^10.2.0",
|
|
52
|
+
"@wordpress/react-inert-value": "^2.2.0",
|
|
53
|
+
"@wordpress/style-runtime": "^0.16.0",
|
|
54
|
+
"@wordpress/ui": "^0.27.0",
|
|
54
55
|
"clsx": "^2.1.1"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
|
-
"@storybook/react-vite": "^10.6.
|
|
58
|
+
"@storybook/react-vite": "^10.6.6",
|
|
58
59
|
"@testing-library/dom": "^10.4.2",
|
|
59
60
|
"@testing-library/jest-dom": "^7.0.1",
|
|
60
61
|
"@testing-library/react": "^16.3.3",
|
|
61
|
-
"@wordpress/
|
|
62
|
+
"@wordpress/base-styles": "^15.1.0",
|
|
63
|
+
"@wordpress/icons": "^21.0.0",
|
|
62
64
|
"@wordpress/ui": "file:../ui",
|
|
63
|
-
"storybook": "^10.6.
|
|
64
|
-
"vitest": "^5.0
|
|
65
|
+
"storybook": "^10.6.6",
|
|
66
|
+
"vitest": "^5.1.0",
|
|
65
67
|
"vitest-browser-react": "^2.3.0"
|
|
66
68
|
},
|
|
67
69
|
"peerDependencies": {
|
|
@@ -77,5 +79,5 @@
|
|
|
77
79
|
"publishConfig": {
|
|
78
80
|
"access": "public"
|
|
79
81
|
},
|
|
80
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "1000cdf1dffd5b5e69f75cc4360aa76db8252264"
|
|
81
83
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/variables";
|
|
2
|
+
|
|
1
3
|
.grid {
|
|
2
4
|
display: grid;
|
|
3
5
|
gap: var(--wp-grid-gap, var(--wpds-dimension-gap-xl));
|
|
@@ -14,22 +16,11 @@
|
|
|
14
16
|
* the shadow strengthens while dragging so it reads above edit tiles.
|
|
15
17
|
*/
|
|
16
18
|
.drag-preview-frame {
|
|
17
|
-
--_wp-grid-elevation-xs:
|
|
18
|
-
0 1px 1px rgba(0, 0, 0, 0.03),
|
|
19
|
-
0 1px 2px rgba(0, 0, 0, 0.02),
|
|
20
|
-
0 3px 3px rgba(0, 0, 0, 0.02),
|
|
21
|
-
0 4px 4px rgba(0, 0, 0, 0.01);
|
|
22
|
-
--_wp-grid-elevation-md:
|
|
23
|
-
0 2px 3px rgba(0, 0, 0, 0.05),
|
|
24
|
-
0 4px 5px rgba(0, 0, 0, 0.04),
|
|
25
|
-
0 12px 12px rgba(0, 0, 0, 0.03),
|
|
26
|
-
0 16px 16px rgba(0, 0, 0, 0.02);
|
|
27
|
-
|
|
28
19
|
height: 100%;
|
|
29
20
|
border-radius: var(--wp-grid-drag-preview-radius, 0);
|
|
30
21
|
cursor: grabbing;
|
|
31
22
|
pointer-events: none;
|
|
32
|
-
box-shadow:
|
|
23
|
+
box-shadow: variables.$elevation-medium;
|
|
33
24
|
}
|
|
34
25
|
|
|
35
26
|
.drag-preview-frame__lift {
|
|
@@ -55,11 +46,11 @@
|
|
|
55
46
|
@media not (prefers-reduced-motion: reduce) {
|
|
56
47
|
@keyframes wp-grid-drag-preview-shadow-enter {
|
|
57
48
|
from {
|
|
58
|
-
box-shadow:
|
|
49
|
+
box-shadow: variables.$elevation-x-small;
|
|
59
50
|
}
|
|
60
51
|
|
|
61
52
|
to {
|
|
62
|
-
box-shadow:
|
|
53
|
+
box-shadow: variables.$elevation-medium;
|
|
63
54
|
}
|
|
64
55
|
}
|
|
65
56
|
|
|
@@ -98,11 +89,11 @@
|
|
|
98
89
|
|
|
99
90
|
@keyframes wp-grid-drag-preview-shadow-exit {
|
|
100
91
|
from {
|
|
101
|
-
box-shadow:
|
|
92
|
+
box-shadow: variables.$elevation-medium;
|
|
102
93
|
}
|
|
103
94
|
|
|
104
95
|
to {
|
|
105
|
-
box-shadow:
|
|
96
|
+
box-shadow: variables.$elevation-x-small;
|
|
106
97
|
}
|
|
107
98
|
}
|
|
108
99
|
|
|
@@ -118,7 +109,7 @@
|
|
|
118
109
|
}
|
|
119
110
|
|
|
120
111
|
.drag-preview-frame.is-exiting {
|
|
121
|
-
box-shadow:
|
|
112
|
+
box-shadow: variables.$elevation-x-small;
|
|
122
113
|
}
|
|
123
114
|
|
|
124
115
|
.drag-preview-frame.is-exiting .drag-preview-frame__lift {
|
|
@@ -127,7 +118,7 @@
|
|
|
127
118
|
|
|
128
119
|
@media (prefers-reduced-motion: reduce) {
|
|
129
120
|
.drag-preview-frame {
|
|
130
|
-
box-shadow:
|
|
121
|
+
box-shadow: variables.$elevation-medium;
|
|
131
122
|
}
|
|
132
123
|
|
|
133
124
|
.drag-preview-frame__lift {
|
|
@@ -135,7 +126,7 @@
|
|
|
135
126
|
}
|
|
136
127
|
|
|
137
128
|
.drag-preview-frame.is-exiting {
|
|
138
|
-
box-shadow:
|
|
129
|
+
box-shadow: variables.$elevation-x-small;
|
|
139
130
|
transition: none;
|
|
140
131
|
}
|
|
141
132
|
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from '@wordpress/element';
|
|
26
26
|
import { GridItem } from './grid-item';
|
|
27
27
|
import { arrayMoveWithPinned } from '../shared/array-move-with-pinned';
|
|
28
|
+
import { resolveColumnCount } from '../shared/column-policy';
|
|
28
29
|
import { GridOverlay } from '../shared/grid-overlay';
|
|
29
30
|
import { clampSpan, gridSpanToPixelSize } from '../shared/resize-snap';
|
|
30
31
|
import { useResizePixelLimits, useSpanBounds } from '../shared/use-span-bounds';
|
|
@@ -40,7 +41,7 @@ import type { DashboardGridLayoutItem, DashboardGridProps } from './types';
|
|
|
40
41
|
import type { ResizeSnapSize } from '../shared/resize-snap';
|
|
41
42
|
import type { ResizeDelta } from '../shared/types';
|
|
42
43
|
import { createDashboardDragDropAnimation } from '../shared/drag-overlay-drop-animation';
|
|
43
|
-
import styles from './grid.module.
|
|
44
|
+
import styles from './grid.module.scss';
|
|
44
45
|
|
|
45
46
|
const dashboardDragDropAnimation = createDashboardDragDropAnimation(
|
|
46
47
|
styles[ 'drag-preview-frame' ],
|
|
@@ -199,18 +200,16 @@ export const DashboardGrid = forwardRef< HTMLDivElement, DashboardGridProps >(
|
|
|
199
200
|
setGapPx( parsed );
|
|
200
201
|
}
|
|
201
202
|
}, [ gridRoot ] );
|
|
202
|
-
const effectiveColumns = useMemo(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return columns !== undefined ? Math.min( columns, maxFit ) : maxFit;
|
|
213
|
-
}, [ minColumnWidth, gapPx, containerWidth, columns ] );
|
|
203
|
+
const effectiveColumns = useMemo(
|
|
204
|
+
() =>
|
|
205
|
+
resolveColumnCount(
|
|
206
|
+
{ columns, minColumnWidth },
|
|
207
|
+
containerWidth,
|
|
208
|
+
gapPx,
|
|
209
|
+
DEFAULT_COLUMNS
|
|
210
|
+
),
|
|
211
|
+
[ minColumnWidth, gapPx, containerWidth, columns ]
|
|
212
|
+
);
|
|
214
213
|
const columnWidth =
|
|
215
214
|
( containerWidth - ( effectiveColumns - 1 ) * gapPx ) /
|
|
216
215
|
effectiveColumns;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
-
import { useState, useMemo } from '@wordpress/element';
|
|
2
|
+
import { useId, useState, useMemo } from '@wordpress/element';
|
|
3
3
|
import { close, justifyStretch, stretchFullWidth } from '@wordpress/icons';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
Icon,
|
|
6
|
+
// eslint-disable-next-line @wordpress/use-recommended-components -- @wordpress/grid consumes @wordpress/ui in story examples only.
|
|
7
|
+
IconButton,
|
|
8
|
+
Stack,
|
|
9
|
+
} from '@wordpress/ui';
|
|
6
10
|
import { DashboardGrid } from '..';
|
|
7
11
|
import type { DashboardGridLayoutItem } from '../types';
|
|
8
12
|
import type {
|
|
@@ -25,12 +29,13 @@ const meta: Meta< typeof DashboardGrid > = {
|
|
|
25
29
|
children: { control: false },
|
|
26
30
|
columns: {
|
|
27
31
|
control: { type: 'number', min: 1, max: 24, step: 1 },
|
|
28
|
-
description:
|
|
32
|
+
description:
|
|
33
|
+
'Column count, or the cap when `minColumnWidth` is set.',
|
|
29
34
|
},
|
|
30
35
|
minColumnWidth: {
|
|
31
36
|
control: { type: 'number', min: 80, max: 600, step: 8 },
|
|
32
37
|
description:
|
|
33
|
-
'
|
|
38
|
+
'Per-column floor in pixels. Lowers the count on narrow containers, down to one.',
|
|
34
39
|
},
|
|
35
40
|
rowHeight: {
|
|
36
41
|
control: { type: 'number', min: 24, max: 400, step: 4 },
|
|
@@ -281,90 +286,163 @@ export const Default: Story = {
|
|
|
281
286
|
},
|
|
282
287
|
};
|
|
283
288
|
|
|
289
|
+
function TileControls( { title }: { title: string } ) {
|
|
290
|
+
const metricId = useId();
|
|
291
|
+
return (
|
|
292
|
+
<Stack direction="column" gap="sm" align="flex-start">
|
|
293
|
+
<strong>{ title }</strong>
|
|
294
|
+
<a href="#details">Details</a>
|
|
295
|
+
<button type="button">Refresh</button>
|
|
296
|
+
<label htmlFor={ metricId }>
|
|
297
|
+
Metric{ ' ' }
|
|
298
|
+
<select id={ metricId }>
|
|
299
|
+
<option>Views</option>
|
|
300
|
+
<option>Clicks</option>
|
|
301
|
+
</select>
|
|
302
|
+
</label>
|
|
303
|
+
</Stack>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
284
307
|
/**
|
|
285
|
-
*
|
|
286
|
-
* width using `minColumnWidth` as the lower bound per column. A
|
|
287
|
-
* `ResizeObserver` recomputes the count on container resize.
|
|
308
|
+
* Tiles with their own links, buttons and form controls. The a11y addon checks that the grid does not wrap them in drag semantics. In edit mode, the first tile is pinned (`draggable: false`) and its controls keep their semantics.
|
|
288
309
|
*/
|
|
289
|
-
export const
|
|
310
|
+
export const InteractiveContent: Story = {
|
|
290
311
|
args: {
|
|
291
312
|
layout: [
|
|
292
|
-
{ key: '
|
|
293
|
-
{ key: '
|
|
294
|
-
{ key: '
|
|
295
|
-
{ key: 'd', width: 1, order: 4 },
|
|
296
|
-
{ key: 'e', width: 2, order: 5 },
|
|
297
|
-
{ key: 'f', width: 2, order: 6 },
|
|
313
|
+
{ key: 'pinned', width: 2, draggable: false },
|
|
314
|
+
{ key: 'a', width: 2 },
|
|
315
|
+
{ key: 'b', width: 2 },
|
|
298
316
|
],
|
|
317
|
+
columns: 6,
|
|
318
|
+
rowHeight: 160,
|
|
319
|
+
children: [
|
|
320
|
+
<Tile key="pinned" tone="neutral">
|
|
321
|
+
<TileControls title="Pinned" />
|
|
322
|
+
</Tile>,
|
|
323
|
+
<Tile key="a" tone="info">
|
|
324
|
+
<TileControls title="Tile" />
|
|
325
|
+
</Tile>,
|
|
326
|
+
<Tile key="b" tone="success">
|
|
327
|
+
<TileControls title="Tile" />
|
|
328
|
+
</Tile>,
|
|
329
|
+
],
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* `columns` and `minColumnWidth` compose. `columns` alone fixes the count.
|
|
335
|
+
* `minColumnWidth` alone fits as many columns of at least that width as
|
|
336
|
+
* the container allows. Together, `columns` caps what the floor fits:
|
|
337
|
+
* up to four columns here, none narrower than 240px, down to one. The
|
|
338
|
+
* layout mixes fixed, `fill`, `full` and two-row tiles so the repacking
|
|
339
|
+
* is visible at every count: a `fill` takes the free run of the row it
|
|
340
|
+
* lands in, and the tall tile's shadow shortens the runs below it. Open
|
|
341
|
+
* the story full screen and resize the browser to walk the counts.
|
|
342
|
+
*/
|
|
343
|
+
export const Columns: Story = {
|
|
344
|
+
args: {
|
|
345
|
+
columns: 4,
|
|
346
|
+
minColumnWidth: 240,
|
|
299
347
|
rowHeight: 96,
|
|
300
|
-
|
|
348
|
+
layout: [
|
|
349
|
+
{ key: 'a', width: 1 },
|
|
350
|
+
{ key: 'b', width: 'fill' },
|
|
351
|
+
{ key: 'c', width: 1, height: 2 },
|
|
352
|
+
{ key: 'd', width: 1 },
|
|
353
|
+
{ key: 'e', width: 'fill' },
|
|
354
|
+
{ key: 'f', width: 'full' },
|
|
355
|
+
],
|
|
301
356
|
children: [
|
|
302
357
|
<Tile key="a" tone="brand">
|
|
303
|
-
|
|
358
|
+
1
|
|
304
359
|
</Tile>,
|
|
305
360
|
<Tile key="b" tone="info">
|
|
306
|
-
|
|
361
|
+
fill
|
|
307
362
|
</Tile>,
|
|
308
363
|
<Tile key="c" tone="success">
|
|
309
|
-
|
|
364
|
+
1 · 2 rows
|
|
310
365
|
</Tile>,
|
|
311
366
|
<Tile key="d" tone="warning">
|
|
312
|
-
|
|
367
|
+
1
|
|
313
368
|
</Tile>,
|
|
314
369
|
<Tile key="e" tone="error">
|
|
315
|
-
|
|
370
|
+
fill
|
|
316
371
|
</Tile>,
|
|
317
372
|
<Tile key="f" tone="neutral">
|
|
318
|
-
|
|
373
|
+
full
|
|
319
374
|
</Tile>,
|
|
320
375
|
],
|
|
321
376
|
},
|
|
322
377
|
};
|
|
323
378
|
|
|
324
379
|
/**
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* on narrow ones whenever fitting all of them would push tiles
|
|
329
|
-
* below `minColumnWidth`. Resize the preview to see the cap apply
|
|
330
|
-
* on wide widths and the floor reduce the count on narrow widths.
|
|
380
|
+
* `columns` as a map: one column from 0px, two from 600px, four from
|
|
381
|
+
* 960px. The count steps at those container widths regardless of how
|
|
382
|
+
* wide each column ends up; add `minColumnWidth` to lower it further.
|
|
331
383
|
*/
|
|
332
|
-
export const
|
|
384
|
+
export const ColumnSteps: Story = {
|
|
385
|
+
argTypes: {
|
|
386
|
+
columns: { control: 'object' },
|
|
387
|
+
},
|
|
333
388
|
args: {
|
|
389
|
+
columns: { 0: 1, 600: 2, 960: 4 },
|
|
390
|
+
rowHeight: 96,
|
|
334
391
|
layout: [
|
|
335
|
-
{ key: '
|
|
336
|
-
{ key: '
|
|
337
|
-
{ key: '
|
|
338
|
-
{ key: '
|
|
339
|
-
{ key: '
|
|
340
|
-
{ key: '
|
|
392
|
+
{ key: 'fixed-1', width: 1, height: 1 },
|
|
393
|
+
{ key: 'fixed-2', width: 2, height: 2 },
|
|
394
|
+
{ key: 'fill-1', width: 'fill' },
|
|
395
|
+
{ key: 'fixed-3', width: 1, height: 1 },
|
|
396
|
+
{ key: 'fixed-4', width: 1, height: 2 },
|
|
397
|
+
{ key: 'fixed-5', width: 2, height: 1 },
|
|
398
|
+
{ key: 'fill-2', width: 'fill' },
|
|
399
|
+
{ key: 'full-1', width: 'full' },
|
|
341
400
|
],
|
|
342
|
-
rowHeight: 96,
|
|
343
|
-
columns: 6,
|
|
344
|
-
minColumnWidth: 240,
|
|
345
401
|
children: [
|
|
346
|
-
<Tile key="
|
|
347
|
-
width: 1
|
|
402
|
+
<Tile key="fixed-1" tone="brand">
|
|
403
|
+
width: <strong>1</strong> · height: <strong>1</strong>
|
|
348
404
|
</Tile>,
|
|
349
|
-
<Tile key="
|
|
350
|
-
width: 2
|
|
405
|
+
<Tile key="fixed-2" tone="info">
|
|
406
|
+
width: <strong>2</strong> · height: <strong>2</strong>
|
|
351
407
|
</Tile>,
|
|
352
|
-
<Tile key="
|
|
353
|
-
width:
|
|
408
|
+
<Tile key="fill-1" tone="info">
|
|
409
|
+
width: <strong>fill</strong>
|
|
354
410
|
</Tile>,
|
|
355
|
-
<Tile key="
|
|
356
|
-
width: 1
|
|
411
|
+
<Tile key="fixed-3" tone="success">
|
|
412
|
+
width: <strong>1</strong> · height: <strong>1</strong>
|
|
357
413
|
</Tile>,
|
|
358
|
-
<Tile key="
|
|
359
|
-
width: 2
|
|
414
|
+
<Tile key="fixed-4" tone="warning">
|
|
415
|
+
width: <strong>1</strong> · height: <strong>2</strong>
|
|
360
416
|
</Tile>,
|
|
361
|
-
<Tile key="
|
|
362
|
-
width: 2
|
|
417
|
+
<Tile key="fixed-5" tone="error">
|
|
418
|
+
width: <strong>2</strong> · height: <strong>1</strong>
|
|
419
|
+
</Tile>,
|
|
420
|
+
<Tile key="fill-2" tone="error">
|
|
421
|
+
width: <strong>fill</strong>
|
|
422
|
+
</Tile>,
|
|
423
|
+
<Tile key="full-1" tone="neutral">
|
|
424
|
+
width: <strong>full</strong>
|
|
363
425
|
</Tile>,
|
|
364
426
|
],
|
|
365
427
|
},
|
|
366
428
|
};
|
|
367
429
|
|
|
430
|
+
/**
|
|
431
|
+
* A step can be `'auto'`: from that width up there is no cap and the
|
|
432
|
+
* floor alone decides the count. Here the steps fix one and two columns
|
|
433
|
+
* below 960px, and 240px columns fill the container above it.
|
|
434
|
+
*/
|
|
435
|
+
export const ColumnStepsWithFloor: Story = {
|
|
436
|
+
argTypes: {
|
|
437
|
+
columns: { control: 'object' },
|
|
438
|
+
},
|
|
439
|
+
args: {
|
|
440
|
+
...ColumnSteps.args,
|
|
441
|
+
columns: { 0: 1, 600: 2, 960: 'auto' },
|
|
442
|
+
minColumnWidth: 240,
|
|
443
|
+
},
|
|
444
|
+
};
|
|
445
|
+
|
|
368
446
|
/**
|
|
369
447
|
* A `width: 'fill'` item expands to cover the remaining columns in
|
|
370
448
|
* its row. Mix it with fixed-width items on either side to build
|
|
@@ -504,6 +582,7 @@ export const EditMode: Story = {
|
|
|
504
582
|
width: 1,
|
|
505
583
|
height: 1,
|
|
506
584
|
order: 1,
|
|
585
|
+
draggable: false,
|
|
507
586
|
tone: 'success',
|
|
508
587
|
},
|
|
509
588
|
{
|
|
@@ -36,7 +36,7 @@ describe( 'DashboardGrid item interactions', () => {
|
|
|
36
36
|
const { activator, resizeHandle } = await renderItem( {
|
|
37
37
|
draggable: false,
|
|
38
38
|
} );
|
|
39
|
-
expect( activator ).
|
|
39
|
+
expect( activator ).toBeNull();
|
|
40
40
|
expect( resizeHandle ).not.toBeNull();
|
|
41
41
|
} );
|
|
42
42
|
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
ResizeDelta,
|
|
6
6
|
ResizeHandleRenderProps,
|
|
7
7
|
} from '../shared/types';
|
|
8
|
+
import type { ColumnSteps } from '../shared/column-policy';
|
|
8
9
|
import type { ResizeSnapSize } from '../shared/resize-snap';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -188,7 +189,8 @@ export type GridItemProps = {
|
|
|
188
189
|
* the grid root.
|
|
189
190
|
*
|
|
190
191
|
* `columns` and `minColumnWidth` compose as a layered model:
|
|
191
|
-
* - `columns` alone:
|
|
192
|
+
* - `columns` alone: the count at every width, or a count per container
|
|
193
|
+
* width when given as `ColumnSteps`; each tile scales with the container.
|
|
192
194
|
* - `minColumnWidth` alone: column count derives from container width,
|
|
193
195
|
* floored by the per-tile minimum, down to 1 column.
|
|
194
196
|
* - Both together: `columns` caps the count, `minColumnWidth` enforces a
|
|
@@ -295,11 +297,13 @@ export interface DashboardGridProps extends Omit<
|
|
|
295
297
|
renderGridOverlay?: React.ComponentType< GridOverlayRenderProps >;
|
|
296
298
|
|
|
297
299
|
/**
|
|
298
|
-
*
|
|
299
|
-
* `
|
|
300
|
-
*
|
|
300
|
+
* Column count, used as a cap. A number applies at every width; a
|
|
301
|
+
* `ColumnSteps` map applies a count from each container width up, and
|
|
302
|
+
* an `'auto'` step lifts the cap from its width up.
|
|
303
|
+
* Defaults to six when neither `columns` nor `minColumnWidth` is set;
|
|
304
|
+
* with `minColumnWidth` set it can resolve lower on narrow containers.
|
|
301
305
|
*/
|
|
302
|
-
columns?: number;
|
|
306
|
+
columns?: number | ColumnSteps;
|
|
303
307
|
|
|
304
308
|
/**
|
|
305
309
|
* Per-tile minimum width in pixels. Enables responsive mode: the
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
import { LanesItem } from './lanes-item';
|
|
27
27
|
import { useLanePlacement } from './use-lane-placement';
|
|
28
28
|
import { arrayMoveWithPinned } from '../shared/array-move-with-pinned';
|
|
29
|
+
import { resolveColumnCount } from '../shared/column-policy';
|
|
29
30
|
import { GridOverlay } from '../shared/grid-overlay';
|
|
30
31
|
import { clampSpan, gridSpanToPixelSize } from '../shared/resize-snap';
|
|
31
32
|
import { useResizePixelLimits, useSpanBounds } from '../shared/use-span-bounds';
|
|
@@ -41,7 +42,7 @@ import type { DashboardLanesLayoutItem, DashboardLanesProps } from './types';
|
|
|
41
42
|
import type { ResizeSnapSize } from '../shared/resize-snap';
|
|
42
43
|
import type { ResizeDelta } from '../shared/types';
|
|
43
44
|
import { createDashboardDragDropAnimation } from '../shared/drag-overlay-drop-animation';
|
|
44
|
-
import styles from './lanes.module.
|
|
45
|
+
import styles from './lanes.module.scss';
|
|
45
46
|
|
|
46
47
|
const dashboardDragDropAnimation = createDashboardDragDropAnimation(
|
|
47
48
|
styles[ 'drag-preview-frame' ],
|
|
@@ -177,17 +178,16 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
|
|
|
177
178
|
setGapPx( parsed );
|
|
178
179
|
}
|
|
179
180
|
}, [ container ] );
|
|
180
|
-
const effectiveColumns = useMemo(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}, [ minColumnWidth, gapPx, containerWidth, columns ] );
|
|
181
|
+
const effectiveColumns = useMemo(
|
|
182
|
+
() =>
|
|
183
|
+
resolveColumnCount(
|
|
184
|
+
{ columns, minColumnWidth },
|
|
185
|
+
containerWidth,
|
|
186
|
+
gapPx,
|
|
187
|
+
DEFAULT_COLUMNS
|
|
188
|
+
),
|
|
189
|
+
[ minColumnWidth, gapPx, containerWidth, columns ]
|
|
190
|
+
);
|
|
191
191
|
const columnWidth =
|
|
192
192
|
( containerWidth - ( effectiveColumns - 1 ) * gapPx ) /
|
|
193
193
|
effectiveColumns;
|
|
@@ -600,7 +600,7 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
|
|
|
600
600
|
...style,
|
|
601
601
|
gridTemplateColumns: `repeat(${ effectiveColumns }, minmax(0, 1fr))`,
|
|
602
602
|
// `column-gap` and `row-gap` are set in
|
|
603
|
-
// `lanes.module.
|
|
603
|
+
// `lanes.module.scss` from the
|
|
604
604
|
// design-system gap token, with an
|
|
605
605
|
// `@supports` block that zeroes `row-gap`
|
|
606
606
|
// in polyfill mode (the skyline already
|