Skip to content

Commit 94a4b92

Browse files
authored
🌸 Add warn and new assertion when rows=0 and collision !== 'none (#86)
1 parent 177239f commit 94a4b92

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

‎src/lib/Grid.svelte‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
xs: 320
8888
};
8989
90-
$: assertGridOptions({ cols, rows, itemSize });
90+
$: assertGridOptions({ cols, rows, itemSize, collision });
9191
9292
/**
9393
* Bound the grid items to the grid container.
@@ -175,7 +175,7 @@
175175
}
176176
177177
$: if (collision !== 'none') {
178-
rows = 0;
178+
_rows = 0;
179179
}
180180
181181
/**

‎src/lib/utils/assert.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
import type { GridSize, ItemSize } from '$lib/types';
1+
import type { Collision, GridSize, ItemSize } from '$lib/types';
22

33
export type GridOptions = {
44
cols: GridSize;
55
rows: GridSize;
66
itemSize: Partial<ItemSize>;
7+
collision?: Collision;
78
};
89

910
export function assertGridOptions(options: GridOptions) {
10-
const { cols, rows, itemSize } = options;
11+
const { cols, rows, itemSize, collision } = options;
12+
13+
if (rows !== 0 && collision && collision !== 'none') {
14+
console.warn('`rows` is ignored and setted to 0 when `collision` is not `none`');
15+
}
16+
17+
if (collision && collision !== 'none' && itemSize?.height === undefined) {
18+
throw new Error(
19+
'If `collision` is not `none`, the `itemSize.height` parameter must be specified'
20+
);
21+
}
22+
1123
if (
1224
(cols === 0 && itemSize?.width === undefined) ||
1325
(typeof cols === 'object' && Object.values(cols).includes(0) && itemSize?.width === undefined)

0 commit comments

Comments
 (0)