|
1 |
| -<svelte:options runes={false} /> |
| 1 | +<svelte:options runes /> |
2 | 2 |
|
3 | 3 | <div
|
4 | 4 | bind:this={element}
|
|
20 | 20 | aria-valuemax={1}
|
21 | 21 | aria-valuenow={indeterminate ? undefined : progress}
|
22 | 22 | {...internalAttrs}
|
23 |
| - {...$$restProps} |
| 23 | + {...restProps} |
24 | 24 | ontransitionend={(e) => {
|
25 | 25 | if (instance) {
|
26 | 26 | instance.handleTransitionEnd();
|
27 | 27 | }
|
28 |
| - $$restProps.ontransitionend?.(e); |
| 28 | + restProps.ontransitionend?.(e); |
29 | 29 | }}
|
30 | 30 | >
|
31 | 31 | <div class="mdc-linear-progress__buffer">
|
|
60 | 60 | import { classMap, useActions } from '@smui/common/internal';
|
61 | 61 |
|
62 | 62 | type OwnProps = {
|
| 63 | + /** |
| 64 | + * An array of Action or [Action, ActionProps] to be applied to the element. |
| 65 | + */ |
63 | 66 | use?: ActionArray;
|
| 67 | + /** |
| 68 | + * A space separated list of CSS classes. |
| 69 | + */ |
64 | 70 | class?: string;
|
| 71 | + /** |
| 72 | + * A list of CSS styles. |
| 73 | + */ |
65 | 74 | style?: string;
|
| 75 | + /** |
| 76 | + * Whether to show indeterminate progress (a throbber). |
| 77 | + */ |
66 | 78 | indeterminate?: boolean;
|
| 79 | + /** |
| 80 | + * Whether the progress indicator is closed. |
| 81 | + * |
| 82 | + * Closed progress indicators animate out, then still take up space in the |
| 83 | + * UI. |
| 84 | + */ |
67 | 85 | closed?: boolean;
|
| 86 | + /** |
| 87 | + * The current progress (between 0 and 1). |
| 88 | + */ |
68 | 89 | progress?: number;
|
| 90 | + /** |
| 91 | + * An optional buffer section of the progress bar. |
| 92 | + * |
| 93 | + * This can be used to show when, for example, a video has a current |
| 94 | + * position and a buffered position. |
| 95 | + */ |
69 | 96 | buffer?: number | undefined;
|
70 | 97 | };
|
71 |
| - type $$Props = OwnProps & SmuiAttrs<'div', keyof OwnProps>; |
72 |
| -
|
73 |
| - // Remember to update $$Props if you add/remove/rename props. |
74 |
| - export let use: ActionArray = []; |
75 |
| - let className = ''; |
76 |
| - export { className as class }; |
77 |
| - export let style = ''; |
78 |
| - export let indeterminate = false; |
79 |
| - export let closed = false; |
80 |
| - export let progress = 0; |
81 |
| - export let buffer: number | undefined = undefined; |
| 98 | + let { |
| 99 | + use = [], |
| 100 | + class: className = '', |
| 101 | + style = '', |
| 102 | + indeterminate = false, |
| 103 | + closed = false, |
| 104 | + progress = 0, |
| 105 | + buffer = undefined, |
| 106 | + ...restProps |
| 107 | + }: OwnProps & SmuiAttrs<'div', keyof OwnProps> = $props(); |
82 | 108 |
|
83 | 109 | let element: HTMLDivElement;
|
84 |
| - let instance: MDCLinearProgressFoundation; |
85 |
| - let internalClasses: { [k: string]: boolean } = {}; |
86 |
| - let internalAttrs: { [k: string]: string | undefined } = {}; |
87 |
| - let internalStyles: { [k: string]: string } = {}; |
88 |
| - let bufferBarStyles: { [k: string]: string } = {}; |
89 |
| - let primaryBarStyles: { [k: string]: string } = {}; |
| 110 | + let instance: MDCLinearProgressFoundation | undefined = $state(); |
| 111 | + let internalClasses: { [k: string]: boolean } = $state({}); |
| 112 | + let internalAttrs: { [k: string]: string | undefined } = $state({}); |
| 113 | + let internalStyles: { [k: string]: string } = $state({}); |
| 114 | + let bufferBarStyles: { [k: string]: string } = $state({}); |
| 115 | + let primaryBarStyles: { [k: string]: string } = $state({}); |
90 | 116 | let context = getContext<string | undefined>('SMUI:linear-progress:context');
|
91 | 117 | let closedStore = getContext<Writable<boolean> | undefined>(
|
92 | 118 | 'SMUI:linear-progress:closed',
|
93 | 119 | );
|
94 | 120 |
|
95 |
| - $: if (closedStore) { |
96 |
| - $closedStore = closed; |
97 |
| - } |
| 121 | + $effect(() => { |
| 122 | + if (closedStore) { |
| 123 | + $closedStore = closed; |
| 124 | + } |
| 125 | + }); |
98 | 126 |
|
99 |
| - $: if (instance && instance.isDeterminate() !== !indeterminate) { |
100 |
| - instance.setDeterminate(!indeterminate); |
101 |
| - } |
| 127 | + $effect(() => { |
| 128 | + if (instance && instance.isDeterminate() !== !indeterminate) { |
| 129 | + instance.setDeterminate(!indeterminate); |
| 130 | + } |
| 131 | + }); |
102 | 132 |
|
103 |
| - $: if (instance && instance.getProgress() !== progress) { |
104 |
| - instance.setProgress(progress); |
105 |
| - } |
| 133 | + $effect(() => { |
| 134 | + if (instance && instance.getProgress() !== progress) { |
| 135 | + instance.setProgress(progress); |
| 136 | + } |
| 137 | + }); |
106 | 138 |
|
107 |
| - $: if (instance) { |
108 |
| - if (buffer == null) { |
109 |
| - instance.setBuffer(1); |
110 |
| - } else { |
111 |
| - instance.setBuffer(buffer); |
| 139 | + $effect(() => { |
| 140 | + if (instance) { |
| 141 | + if (buffer == null) { |
| 142 | + instance.setBuffer(1); |
| 143 | + } else { |
| 144 | + instance.setBuffer(buffer); |
| 145 | + } |
112 | 146 | }
|
113 |
| - } |
| 147 | + }); |
114 | 148 |
|
115 |
| - $: if (instance) { |
116 |
| - if (closed) { |
117 |
| - instance.close(); |
118 |
| - } else { |
119 |
| - instance.open(); |
| 149 | + $effect(() => { |
| 150 | + if (instance) { |
| 151 | + if (closed) { |
| 152 | + instance.close(); |
| 153 | + } else { |
| 154 | + instance.open(); |
| 155 | + } |
120 | 156 | }
|
121 |
| - } |
| 157 | + }); |
122 | 158 |
|
123 | 159 | onMount(() => {
|
124 | 160 | instance = new MDCLinearProgressFoundation({
|
|
151 | 187 | instance.init();
|
152 | 188 |
|
153 | 189 | return () => {
|
154 |
| - instance.destroy(); |
| 190 | + instance?.destroy(); |
155 | 191 | };
|
156 | 192 | });
|
157 | 193 |
|
|
0 commit comments