Skip to content

Commit a5ff2a0

Browse files
committed
feat: migrate components in circular progress to runes
1 parent 605ca35 commit a5ff2a0

File tree

6 files changed

+58
-40
lines changed

6 files changed

+58
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Svelte 5 Runes mode is being migrated to slowly. This is the todo list of compon
190190
- [x] Menu
191191
- [x] Paper
192192
- Progress Indicators
193-
- [ ] Circular Progress
193+
- [x] Circular Progress
194194
- [ ] Linear Progress
195195
- [ ] Snackbar
196196
- [ ] Kitchen

packages/circular-progress/src/CircularProgress.svelte

Lines changed: 55 additions & 29 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}
@@ -15,7 +15,7 @@
1515
aria-valuemax={1}
1616
aria-valuenow={indeterminate ? undefined : progress}
1717
{...internalAttrs}
18-
{...$$restProps}
18+
{...restProps}
1919
>
2020
<div class="mdc-circular-progress__determinate-container">
2121
<svg
@@ -117,46 +117,72 @@
117117
import { classMap, useActions } from '@smui/common/internal';
118118
119119
type OwnProps = {
120+
/**
121+
* An array of Action or [Action, ActionProps] to be applied to the element.
122+
*/
120123
use?: ActionArray;
124+
/**
125+
* A space separated list of CSS classes.
126+
*/
121127
class?: string;
128+
/**
129+
* Whether to show indeterminate progress.
130+
*/
122131
indeterminate?: boolean;
132+
/**
133+
* Whether the progress indicator is closed.
134+
*
135+
* Closed progress indicators animate out, then still take up space in the
136+
* UI.
137+
*/
123138
closed?: boolean;
139+
/**
140+
* The current progress (between 0 and 1).
141+
*/
124142
progress?: number;
143+
/**
144+
* Show the four color loop animation.
145+
*/
125146
fourColor?: boolean;
126147
};
127-
type $$Props = OwnProps & SmuiAttrs<'div', keyof OwnProps>;
128-
129-
// Remember to update $$Props if you add/remove/rename props.
130-
export let use: ActionArray = [];
131-
let className = '';
132-
export { className as class };
133-
export let indeterminate = false;
134-
export let closed = false;
135-
export let progress = 0;
136-
export let fourColor = false;
148+
let {
149+
use = [],
150+
class: className = '',
151+
indeterminate = false,
152+
closed = false,
153+
progress = 0,
154+
fourColor = false,
155+
...restProps
156+
}: OwnProps & SmuiAttrs<'div', keyof OwnProps> = $props();
137157
138158
let element: HTMLDivElement;
139-
let instance: MDCCircularProgressFoundation;
140-
let internalClasses: { [k: string]: boolean } = {};
141-
let internalAttrs: { [k: string]: string | undefined } = {};
142-
let determinateCircleAttrs: { [k: string]: string | undefined } = {};
159+
let instance: MDCCircularProgressFoundation | undefined = $state();
160+
let internalClasses: { [k: string]: boolean } = $state({});
161+
let internalAttrs: { [k: string]: string | undefined } = $state({});
162+
let determinateCircleAttrs: { [k: string]: string | undefined } = $state({});
143163
let determinateCircle: SVGCircleElement;
144164
145-
$: if (instance && instance.isDeterminate() !== !indeterminate) {
146-
instance.setDeterminate(!indeterminate);
147-
}
165+
$effect(() => {
166+
if (instance && instance.isDeterminate() !== !indeterminate) {
167+
instance.setDeterminate(!indeterminate);
168+
}
169+
});
148170
149-
$: if (instance && instance.getProgress() !== progress) {
150-
instance.setProgress(progress);
151-
}
171+
$effect(() => {
172+
if (instance && instance.getProgress() !== progress) {
173+
instance.setProgress(progress);
174+
}
175+
});
152176
153-
$: if (instance) {
154-
if (closed) {
155-
instance.close();
156-
} else {
157-
instance.open();
177+
$effect(() => {
178+
if (instance) {
179+
if (closed) {
180+
instance.close();
181+
} else {
182+
instance.open();
183+
}
158184
}
159-
}
185+
});
160186
161187
onMount(() => {
162188
instance = new MDCCircularProgressFoundation({
@@ -172,7 +198,7 @@
172198
instance.init();
173199
174200
return () => {
175-
instance.destroy();
201+
instance?.destroy();
176202
};
177203
});
178204

packages/site/src/routes/demo/circular-progress/_Colored.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
<div style="display: flex; justify-content: center">
42
<CircularProgress
53
class="my-colored-circle"

packages/site/src/routes/demo/circular-progress/_FourColor.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
<div style="display: flex; justify-content: center">
42
<CircularProgress
53
class="my-four-colors"

packages/site/src/routes/demo/circular-progress/_Indeterminate.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
<div style="display: flex; justify-content: center">
42
<CircularProgress style="height: 32px; width: 32px;" indeterminate />
53
</div>

packages/site/src/routes/demo/circular-progress/_Simple.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<svelte:options runes={false} />
2-
31
<div style="display: flex; justify-content: center">
42
<CircularProgress style="height: 48px; width: 48px;" {progress} {closed} />
53
</div>
@@ -22,8 +20,8 @@
2220
import FormField from '@smui/form-field';
2321
import Button from '@smui/button';
2422
25-
let progress = 0;
26-
let closed = false;
23+
let progress = $state(0);
24+
let closed = $state(false);
2725
let timer: NodeJS.Timer;
2826
2927
onMount(reset);

0 commit comments

Comments
 (0)