@wordpress/grid 0.10.0 → 0.11.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 +525 -632
- 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 +494 -576
- 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 +11 -11
- package/src/dashboard-grid/grid-item.tsx +1 -1
- package/src/dashboard-grid/index.tsx +11 -12
- 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 +11 -11
- package/src/dashboard-lanes/lanes-item.tsx +1 -1
- 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.11.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",
|
|
@@ -46,22 +46,22 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@dnd-kit/core": "^6.3.1",
|
|
48
48
|
"@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.
|
|
49
|
+
"@wordpress/compose": "^9.1.0",
|
|
50
|
+
"@wordpress/element": "^10.1.0",
|
|
51
|
+
"@wordpress/react-inert-value": "^2.1.0",
|
|
52
|
+
"@wordpress/style-runtime": "^0.15.0",
|
|
53
|
+
"@wordpress/ui": "^0.26.0",
|
|
54
54
|
"clsx": "^2.1.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@storybook/react-vite": "^10.6.
|
|
57
|
+
"@storybook/react-vite": "^10.6.5",
|
|
58
58
|
"@testing-library/dom": "^10.4.2",
|
|
59
59
|
"@testing-library/jest-dom": "^7.0.1",
|
|
60
60
|
"@testing-library/react": "^16.3.3",
|
|
61
|
-
"@wordpress/icons": "^
|
|
61
|
+
"@wordpress/icons": "^20.0.0",
|
|
62
62
|
"@wordpress/ui": "file:../ui",
|
|
63
|
-
"storybook": "^10.6.
|
|
64
|
-
"vitest": "^5.0.
|
|
63
|
+
"storybook": "^10.6.5",
|
|
64
|
+
"vitest": "^5.0.5",
|
|
65
65
|
"vitest-browser-react": "^2.3.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "9b70363b9f93cff0583a1f3153738d383cf5a49e"
|
|
81
81
|
}
|
|
@@ -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';
|
|
@@ -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';
|
|
@@ -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;
|