Skip to content

Commit 95fbdc2

Browse files
committed
fix: finish some migration steps, update readme
1 parent c4f2909 commit 95fbdc2

File tree

49 files changed

+94
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+94
-177
lines changed

MIGRATING.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ This doc contains information that will help you migrate your code from an older
44

55
# SMUI 7 -> SMUI 8
66

7+
SMUI 8 has migrated to Svelte 5's new Runes mode. As such, it expects things like snippets and only some props are bindable.
8+
9+
Note to Devs: update `indexOf()` with `$state` arrays or items to `findIndex()` to avoid bugs.
10+
11+
Note to Devs: remove `x = x;` statements after `push()` and the like. They aren't needed anymore with Svelte 5's new $state rune.
12+
713
## Breaking Changes
814

915
- Svelte 5 is required! Svelte 4 will not work.

README.md

-60
Original file line numberDiff line numberDiff line change
@@ -144,66 +144,6 @@ Click a component/package below to go to the documentation. (Note that this docu
144144

145145
- Labels and icons are named exports in the components that use them, or you can use the 'Label' and 'Icon' exports from '@smui/common'. (Except for chips labels and icons, textfield icons, and select icons, because they are special snowflakes.)
146146

147-
# Migration to Runes
148-
149-
Svelte 5 Runes mode is being migrated to slowly. This is the todo list of components as they are migrated.
150-
151-
- [x] Accordion
152-
- Action Buttons
153-
- [x] Button
154-
- [x] Floating Action Button
155-
- [x] Icon Button
156-
- App Bars
157-
- [x] Bottom App Bar
158-
- [x] Top App Bar
159-
- [x] Badge
160-
- [x] Banner
161-
- [x] Card
162-
- [x] Common
163-
- [x] Data Table
164-
- [x] Dialog
165-
- [x] Drawer
166-
- [x] Image List
167-
- Inputs and Controls
168-
- [x] Autocomplete
169-
- [x] Checkbox
170-
- [x] Chips
171-
- [x] Chip Input
172-
- [x] Floating Label
173-
- [x] Form Field
174-
- [x] Line Ripple
175-
- [x] Notched Outline
176-
- [x] Radio Button
177-
- [x] Segmented Button
178-
- [x] Select Menu
179-
- [x] Select Helper Text
180-
- [x] Select Icon
181-
- [x] Slider
182-
- [x] Switch
183-
- [x] Text Field
184-
- [x] Text Field Character Counter
185-
- [x] Text Field Helper Text
186-
- [x] Text Field Icon
187-
- [x] Layout Grid
188-
- [x] List
189-
- [x] Menu Surface
190-
- [x] Menu
191-
- [x] Paper
192-
- Progress Indicators
193-
- [x] Circular Progress
194-
- [x] Linear Progress
195-
- [x] Snackbar
196-
- [x] Kitchen
197-
- Tabs
198-
- [x] Tab
199-
- [x] Tab Bar
200-
- [x] Tooltip
201-
- [x] Touch Target
202-
203-
Note to Devs: update `indexOf()` on any `$state` array to `findIndex()`.
204-
205-
Note to Devs: remove `x = x;` statements after `push()` and the like. They aren't needed anymore with Svelte 5's new $state rune.
206-
207147
# License
208148

209149
Copyright 2019-2024 Hunter Perrin

packages/accordion/src/Header.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
if (internalStyles[name] != value) {
149149
if (value === '' || value == null) {
150150
delete internalStyles[name];
151-
internalStyles = internalStyles;
152151
} else {
153152
internalStyles[name] = value;
154153
}

packages/banner/src/Banner.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@
287287
if (internalStyles[name] != value) {
288288
if (value === '' || value == null) {
289289
delete internalStyles[name];
290-
internalStyles = internalStyles;
291290
} else {
292291
internalStyles[name] = value;
293292
}

packages/bottom-app-bar/src/AutoAdjust.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
if (internalStyles[name] != value) {
103103
if (value === '' || value == null) {
104104
delete internalStyles[name];
105-
internalStyles = internalStyles;
106105
} else {
107106
internalStyles[name] = value;
108107
}

packages/bottom-app-bar/src/BottomAppBar.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
if (internalStyles[name] != value) {
122122
if (value === '' || value == null) {
123123
delete internalStyles[name];
124-
internalStyles = internalStyles;
125124
} else {
126125
internalStyles[name] = value;
127126
}

packages/button/src/Button.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@
196196
if (internalStyles[name] != value) {
197197
if (value === '' || value == null) {
198198
delete internalStyles[name];
199-
internalStyles = internalStyles;
200199
} else {
201200
internalStyles[name] = value;
202201
}

packages/card/src/PrimaryAction.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
if (internalStyles[name] != value) {
101101
if (value === '' || value == null) {
102102
delete internalStyles[name];
103-
internalStyles = internalStyles;
104103
} else {
105104
internalStyles[name] = value;
106105
}

packages/checkbox/src/Checkbox.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@
390390
if (internalStyles[name] != value) {
391391
if (value === '' || value == null) {
392392
delete internalStyles[name];
393-
internalStyles = internalStyles;
394393
} else {
395394
internalStyles[name] = value;
396395
}

packages/chip-input/src/ChipInput.svelte

-4
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@
340340
if (chips.findIndex((chip) => chip === event.detail) === -1) {
341341
chips.push(event.detail);
342342
}
343-
chips = chips;
344343
}
345344
}
346345
@@ -364,7 +363,6 @@
364363
if (chips.findIndex((chip) => chip === text) === -1) {
365364
chips.push(text);
366365
}
367-
chips = chips;
368366
text = '';
369367
}
370368
}
@@ -391,7 +389,6 @@
391389
if (chips.findIndex((chip) => chip === text) === -1) {
392390
chips.push(text);
393391
}
394-
chips = chips;
395392
text = '';
396393
floatingLabel?.float(false);
397394
}
@@ -409,7 +406,6 @@
409406
}
410407
411408
function handleChipRemoval(chip: any) {
412-
chips = chips;
413409
dispatch(getElement(), 'SMUIChipInputRemove', { chip });
414410
}
415411

packages/chips/src/Chip.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@
402402
if (internalStyles[name] != value) {
403403
if (value === '' || value == null) {
404404
delete internalStyles[name];
405-
internalStyles = internalStyles;
406405
} else {
407406
internalStyles[name] = value;
408407
}

packages/chips/src/Set.svelte

+2-8
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@
159159
160160
let element: HTMLDivElement;
161161
let instance: deprecated.MDCChipSetFoundation | undefined = $state();
162-
let chipAccessorMap: Record<string, SMUIChipsChipAccessor> = $state({});
163-
let chipAccessorWeakMap = $state.raw(
164-
new WeakMap<Object, SMUIChipsChipAccessor>(),
165-
);
162+
let chipAccessorMap: Record<string, SMUIChipsChipAccessor> = {};
163+
let chipAccessorWeakMap = new WeakMap<Object, SMUIChipsChipAccessor>();
166164
let initialSelected = chips.map(
167165
(chipId) =>
168166
(choice &&
@@ -292,12 +290,10 @@
292290
);
293291
if (selIndex !== -1) {
294292
(selected as ChipKey[]).splice(selIndex, 1);
295-
selected = selected;
296293
}
297294
}
298295
// Now remove it from the chips.
299296
chips.splice(index, 1);
300-
chips = chips;
301297
}
302298
},
303299
removeFocusFromChipAtIndex: (index) => {
@@ -315,10 +311,8 @@
315311
);
316312
if (selectedValue && selIndex === -1) {
317313
(selected as ChipKey[]).push(chips[index]);
318-
selected = selected;
319314
} else if (!selectedValue && selIndex !== -1) {
320315
(selected as ChipKey[]).splice(selIndex, 1);
321-
selected = selected;
322316
}
323317
} else if (
324318
choice &&

packages/chips/src/TrailingAction.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@
189189
if (internalStyles[name] != value) {
190190
if (value === '' || value == null) {
191191
delete internalStyles[name];
192-
internalStyles = internalStyles;
193192
} else {
194193
internalStyles[name] = value;
195194
}

packages/common/README.md

+57-24
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Build a class string from a map of class names to conditions. This is useful whe
177177
178178
export let condition = true;
179179
180-
let internalClasses: { [k: string]: boolean } = {};
180+
let internalClasses: { [k: string]: boolean } = $state({});
181181
182182
export function addClass(className: string) {
183183
if (!internalClasses[className]) {
@@ -240,21 +240,34 @@ Exclude a set of properties from an object. It differs from normal `omit` functi
240240

241241
```svelte
242242
<!-- MyComponent.svelte -->
243-
<div class="my-component {className}" {...exclude($$restProps, ['button$'])}>
244-
<button
245-
class="button {button$class}"
246-
{...prefixFilter($$restProps, 'button$')}
247-
>
248-
<slot />
243+
<div class="my-component {className}" {...exclude(restProps, ['button$'])}>
244+
<button class="button {button$class}" {...prefixFilter(restProps, 'button$')}>
245+
{@render children?.()}
249246
</button>
250247
</div>
251248
252249
<script lang="ts">
250+
import type { Snippet } from 'svelte';
251+
import type { SmuiAttrs } from '@smui/common';
253252
import { exclude, prefixFilter } from '@smui/common/internal';
254253
255-
let className = '';
256-
export { className as class };
257-
export let button$class = '';
254+
type OwnProps = {
255+
class?: string;
256+
button$class?: string;
257+
children?: Snippet;
258+
};
259+
let {
260+
class: className = '',
261+
button$class = '',
262+
children,
263+
...restProps
264+
}: OwnProps &
265+
SmuiAttrs<'div', keyof OwnProps> & {
266+
[k in keyof SmuiAttrs<
267+
'button',
268+
keyof OwnProps
269+
> as `button\$${k}`]?: SmuiAttrs<'button', keyof OwnProps>[k];
270+
} = $props();
258271
</script>
259272
```
260273

@@ -270,7 +283,7 @@ Exclude a set of properties from an object. It differs from normal `omit` functi
270283
<script lang="ts">
271284
import MyComponent from './MyComponent.svelte';
272285
273-
let disabled = false;
286+
let disabled = $state(false);
274287
</script>
275288
```
276289

@@ -280,21 +293,34 @@ Filter an object for only properties with a certain prefix. It is usually used a
280293

281294
```svelte
282295
<!-- MyComponent.svelte -->
283-
<div class="my-component {className}" {...exclude($$restProps, ['button$'])}>
284-
<button
285-
class="button {button$class}"
286-
{...prefixFilter($$restProps, 'button$')}
287-
>
288-
<slot />
296+
<div class="my-component {className}" {...exclude(restProps, ['button$'])}>
297+
<button class="button {button$class}" {...prefixFilter(restProps, 'button$')}>
298+
{@render children?.()}
289299
</button>
290300
</div>
291301
292302
<script lang="ts">
303+
import type { Snippet } from 'svelte';
304+
import type { SmuiAttrs } from '@smui/common';
293305
import { exclude, prefixFilter } from '@smui/common/internal';
294306
295-
let className = '';
296-
export { className as class };
297-
export let button$class = '';
307+
type OwnProps = {
308+
class?: string;
309+
button$class?: string;
310+
children?: Snippet;
311+
};
312+
let {
313+
class: className = '',
314+
button$class = '',
315+
children,
316+
...restProps
317+
}: OwnProps &
318+
SmuiAttrs<'div', keyof OwnProps> & {
319+
[k in keyof SmuiAttrs<
320+
'button',
321+
keyof OwnProps
322+
> as `button\$${k}`]?: SmuiAttrs<'button', keyof OwnProps>[k];
323+
} = $props();
298324
</script>
299325
```
300326

@@ -310,7 +336,7 @@ Filter an object for only properties with a certain prefix. It is usually used a
310336
<script lang="ts">
311337
import MyComponent from './MyComponent.svelte';
312338
313-
let disabled = false;
339+
let disabled = $state(false);
314340
</script>
315341
```
316342

@@ -321,14 +347,21 @@ An action that takes actions and runs them on the element. Used to allow actions
321347
```svelte
322348
<!-- MyComponent.svelte -->
323349
<div use:useActions={use}>
324-
<slot />
350+
{@render children?.()}
325351
</div>
326352
327353
<script lang="ts">
354+
import type { Snippet } from 'svelte';
328355
import type { ActionArray } from '@smui/common/internal';
329356
import { useActions } from '@smui/common/internal';
330357
331-
export let use: ActionArray = [];
358+
let {
359+
use = [],
360+
children,
361+
}: {
362+
use?: ActionArray;
363+
children?: Snippet;
364+
} = $props();
332365
</script>
333366
```
334367

@@ -373,7 +406,7 @@ These components are not exported in the index file, but are available to be imp
373406

374407
## ContextFragment.svelte
375408

376-
A fragment component (only contains a `<slot />`) used to define a Svelte context with a Svelte store.
409+
A fragment component (only contains a `{@render children?.()}`) used to define a Svelte context with a Svelte store.
377410

378411
### Props / Defaults
379412

packages/data-table/src/Body.svelte

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@
5757
setContext(
5858
'SMUI:data-table:row:unmount',
5959
(accessor: SMUIDataTableRowAccessor) => {
60-
const idx = rows.indexOf(accessor);
60+
const idx = rows.findIndex((a) => a === accessor);
6161
if (idx !== -1) {
6262
rows.splice(idx, 1);
63-
rows = rows;
6463
}
6564
rowAccessorMap.delete(accessor.element);
6665
},

packages/data-table/src/Head.svelte

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@
6161
setContext(
6262
'SMUI:data-table:cell:unmount',
6363
(accessor: SMUIDataTableCellAccessor) => {
64-
const idx = cells.indexOf(accessor);
64+
const idx = cells.findIndex((a) => a === accessor);
6565
if (idx !== -1) {
6666
cells.splice(idx, 1);
67-
cells = cells;
6867
}
6968
cellAccessorMap.delete(accessor.element);
7069
},

0 commit comments

Comments
 (0)