Skip to content

Commit 2a806f5

Browse files
committed
feat: migrate components in layout grid to runes
1 parent 9b7063b commit 2a806f5

File tree

10 files changed

+85
-52
lines changed

10 files changed

+85
-52
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Svelte 5 Runes mode is being migrated to slowly. This is the todo list of compon
184184
- [x] Text Field Character Counter
185185
- [x] Text Field Helper Text
186186
- [x] Text Field Icon
187-
- [ ] Layout Grid
187+
- [x] Layout Grid
188188
- [x] List
189189
- [x] Menu Surface
190190
- [x] Menu

packages/layout-grid/src/Cell.svelte

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<svelte:options runes={false} />
1+
<svelte:options runes />
22

33
<div
44
bind:this={element}
@@ -16,42 +16,63 @@
1616
]),
1717
),
1818
})}
19-
{...$$restProps}
19+
{...restProps}
2020
>
21-
<slot />
21+
{@render children?.()}
2222
</div>
2323

2424
<script lang="ts">
25+
import type { Snippet } from 'svelte';
2526
import type { SmuiAttrs } from '@smui/common';
2627
import type { ActionArray } from '@smui/common/internal';
2728
import { classMap, useActions } from '@smui/common/internal';
2829
2930
type OwnProps = {
31+
/**
32+
* An array of Action or [Action, ActionProps] to be applied to the element.
33+
*/
3034
use?: ActionArray;
35+
/**
36+
* A space separated list of CSS classes.
37+
*/
3138
class?: string;
39+
/**
40+
* Where to align this cell, vertically.
41+
*/
3242
align?: 'top' | 'middle' | 'bottom' | undefined;
43+
/**
44+
* Change the order of this cell.
45+
*/
3346
order?: number | undefined;
47+
/**
48+
* How many columns this cell should span.
49+
*
50+
* This number is out of 12 on desktop, 8 on tablet, and 4 on mobile.
51+
*/
3452
span?: number | undefined;
53+
/**
54+
* How many columns this cell should span on different size screens.
55+
*
56+
* This number is out of 12 on desktop, 8 on tablet, and 4 on mobile.
57+
*/
3558
spanDevices?: {
3659
desktop?: number;
3760
tablet?: number;
3861
phone?: number;
3962
};
40-
};
41-
type $$Props = OwnProps & SmuiAttrs<'div', keyof OwnProps>;
4263
43-
// Remember to update $$Props if you add/remove/rename props.
44-
export let use: ActionArray = [];
45-
let className = '';
46-
export { className as class };
47-
export let align: 'top' | 'middle' | 'bottom' | undefined = undefined;
48-
export let order: number | undefined = undefined;
49-
export let span: number | undefined = undefined;
50-
export let spanDevices: {
51-
desktop?: number;
52-
tablet?: number;
53-
phone?: number;
54-
} = {};
64+
children?: Snippet;
65+
};
66+
let {
67+
use = [],
68+
class: className = '',
69+
align = undefined,
70+
order = undefined,
71+
span = undefined,
72+
spanDevices = {},
73+
children,
74+
...restProps
75+
}: OwnProps & SmuiAttrs<'div', keyof OwnProps> = $props();
5576
5677
let element: HTMLDivElement;
5778

packages/layout-grid/src/InnerGrid.svelte

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<svelte:options runes={false} />
1+
<svelte:options runes />
22

33
<div
44
bind:this={element}
@@ -7,25 +7,35 @@
77
[className]: true,
88
'mdc-layout-grid__inner': true,
99
})}
10+
{...restProps}
1011
>
11-
<slot />
12+
{@render children?.()}
1213
</div>
1314

1415
<script lang="ts">
16+
import type { Snippet } from 'svelte';
1517
import type { SmuiAttrs } from '@smui/common';
1618
import type { ActionArray } from '@smui/common/internal';
1719
import { classMap, useActions } from '@smui/common/internal';
1820
1921
type OwnProps = {
22+
/**
23+
* An array of Action or [Action, ActionProps] to be applied to the element.
24+
*/
2025
use?: ActionArray;
26+
/**
27+
* A space separated list of CSS classes.
28+
*/
2129
class?: string;
22-
};
23-
type $$Props = OwnProps & SmuiAttrs<'div', keyof OwnProps>;
2430
25-
// Remember to update $$Props if you add/remove/rename props.
26-
export let use: ActionArray = [];
27-
let className = '';
28-
export { className as class };
31+
children?: Snippet;
32+
};
33+
let {
34+
use = [],
35+
class: className = '',
36+
children,
37+
...restProps
38+
}: OwnProps & SmuiAttrs<'div', keyof OwnProps> = $props();
2939
3040
let element: HTMLDivElement;
3141

packages/layout-grid/src/LayoutGrid.svelte

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<svelte:options runes={false} />
1+
<svelte:options runes />
22

33
<div
44
bind:this={element}
@@ -9,15 +9,15 @@
99
'mdc-layout-grid--fixed-column-width': fixedColumnWidth,
1010
['mdc-layout-grid--align-' + align]: align != null,
1111
})}
12-
{...exclude($$restProps, ['innerGrid$'])}
12+
{...exclude(restProps, ['innerGrid$'])}
1313
>
14-
<InnerGrid {...prefixFilter($$restProps, 'innerGrid$')}>
15-
<slot />
14+
<InnerGrid {...prefixFilter(restProps, 'innerGrid$')}>
15+
{@render children?.()}
1616
</InnerGrid>
1717
</div>
1818

1919
<script lang="ts">
20-
import type { ComponentProps } from 'svelte';
20+
import type { ComponentProps, Snippet } from 'svelte';
2121
import type { SmuiAttrs } from '@smui/common';
2222
import type { ActionArray } from '@smui/common/internal';
2323
import {
@@ -30,24 +30,38 @@
3030
import InnerGrid from './InnerGrid.svelte';
3131
3232
type OwnProps = {
33+
/**
34+
* An array of Action or [Action, ActionProps] to be applied to the element.
35+
*/
3336
use?: ActionArray;
37+
/**
38+
* A space separated list of CSS classes.
39+
*/
3440
class?: string;
41+
/**
42+
* Whether to use a fixed column width instead of variable.
43+
*/
3544
fixedColumnWidth?: boolean;
45+
/**
46+
* Where to align the cells horizontally, if not default.
47+
*/
3648
align?: 'left' | 'right' | undefined;
49+
50+
children?: Snippet;
3751
};
38-
type $$Props = OwnProps &
52+
let {
53+
use = [],
54+
class: className = '',
55+
fixedColumnWidth = false,
56+
align = undefined,
57+
children,
58+
...restProps
59+
}: OwnProps &
3960
SmuiAttrs<'div', keyof OwnProps> & {
4061
[k in keyof ComponentProps<
4162
typeof InnerGrid
4263
> as `innerGrid\$${k}`]?: ComponentProps<typeof InnerGrid>[k];
43-
};
44-
45-
// Remember to update $$Props if you add/remove/rename props.
46-
export let use: ActionArray = [];
47-
let className = '';
48-
export { className as class };
49-
export let fixedColumnWidth = false;
50-
export let align: 'left' | 'right' | undefined = undefined;
64+
} = $props();
5165
5266
let element: HTMLDivElement;
5367

packages/site/src/routes/demo/layout-grid/_Align.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<svelte:options runes={false} />
2-
31
<LayoutGrid
42
align="right"
53
style="border: 1px solid var(--mdc-theme-secondary, #333);"

packages/site/src/routes/demo/layout-grid/_FixedColumnWidth.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<svelte:options runes={false} />
2-
31
<LayoutGrid fixedColumnWidth>
42
{#each Array(9) as _unused, i}
53
<Cell>

packages/site/src/routes/demo/layout-grid/_Nested.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<svelte:options runes={false} />
2-
31
<LayoutGrid>
42
{#each Array(9) as _unused, i}
53
<Cell>

packages/site/src/routes/demo/layout-grid/_Order.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<svelte:options runes={false} />
2-
31
<LayoutGrid>
42
{#each Array(9) as _unused, i}
53
<Cell order={10 - i}>

packages/site/src/routes/demo/layout-grid/_Simple.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<svelte:options runes={false} />
2-
31
<LayoutGrid>
42
{#each Array(9) as _unused, i}
53
<Cell>

packages/site/src/routes/demo/layout-grid/_Span.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<svelte:options runes={false} />
2-
31
<LayoutGrid>
42
{#each Array(2) as _unused, _i}
53
<Cell span={6}>

0 commit comments

Comments
 (0)