Skip to content

Commit 735c7b6

Browse files
committed
Reverts previous commit, fixes prop types
- Previous commit only reset loading status and reloaded the image correctly if the `src` prop was changed. If `delayMs` wash change, the loading status was reset, but `onload()` never fired. Reverting to using `getters` - Add `MaybeGetter` to Avatar props
1 parent 49c92db commit 735c7b6

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

docs/src/api.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@
574574
},
575575
{
576576
"name": "onLoadingStatusChange",
577-
"type": "((value: 'loading' | 'loaded' | 'error') => void) | undefined",
577+
"type": "MaybeGetter<((value: 'loading' | 'loaded' | 'error') => void) | undefined>",
578578
"description": "Callback fired when the loading status changes",
579579
"defaultValue": "undefined",
580580
"optional": true
@@ -596,6 +596,6 @@
596596
"type": "{\n readonly \"data-melt-avatar-fallback\": \"\"\n readonly style: string | undefined\n readonly hidden: boolean | undefined\n}"
597597
}
598598
],
599-
"propsAlt": "export type AvatarProps = {\n /**\n * The source of the image to display.\n */\n src?: string;\n\n /**\n * The amount of time in milliseconds to wait before displaying the image.\n *\n * @default 0\n */\n delayMs?: number;\n\n /**\n * A callback invoked when the loading status store of the avatar changes.\n */\n onLoadingStatusChange?: (value: ImageLoadingStatus) => void;\n};"
599+
"propsAlt": "export type AvatarProps = {\n /**\n * The source of the image to display.\n */\n src?: MaybeGetter<string | undefined>;\n\n /**\n * The amount of time in milliseconds to wait before displaying the image.\n *\n * @default 0\n */\n delayMs?: MaybeGetter<number | undefined>;\n\n /**\n * A callback invoked when the loading status store of the avatar changes.\n */\n onLoadingStatusChange?: MaybeGetter<(value: ImageLoadingStatus) => void | undefined>;\n};"
600600
}
601601
}

packages/melt/src/lib/builders/Avatar.svelte.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Synced } from "$lib/Synced.svelte";
33
import { createDataIds } from "$lib/utils/identifiers";
44
import { styleAttr } from "$lib/utils/attribute";
55
import { inBrowser } from "$lib/utils/browser";
6+
import { MaybeGetter } from "$lib/types";
67

78
const identifiers = createDataIds("avatar", ["image", "fallback"]);
89

@@ -12,19 +13,19 @@ export type AvatarProps = {
1213
/**
1314
* The source of the image to display.
1415
*/
15-
src?: string;
16+
src?: MaybeGetter<string | undefined>;
1617

1718
/**
1819
* The amount of time in milliseconds to wait before displaying the image.
1920
*
2021
* @default 0
2122
*/
22-
delayMs?: number;
23+
delayMs?: MaybeGetter<number | undefined>;
2324

2425
/**
2526
* A callback invoked when the loading status store of the avatar changes.
2627
*/
27-
onLoadingStatusChange?: (value: ImageLoadingStatus) => void;
28+
onLoadingStatusChange?: MaybeGetter<(value: ImageLoadingStatus) => void | undefined>;
2829
};
2930

3031
export class Avatar {

packages/melt/src/lib/components/Avatar.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import { Avatar, type AvatarProps } from "../builders/Avatar.svelte";
33
import { type Snippet } from "svelte";
44
import type { ComponentProps } from "../types";
5+
import { getters } from "$lib/builders";
56
67
type Props = ComponentProps<AvatarProps> & {
78
children: Snippet<[Avatar]>;
89
};
910
1011
let { children, ...rest }: Props = $props();
1112
12-
const avatar = $derived(new Avatar({ ...rest }));
13+
const avatar = new Avatar(getters({ ...rest }));
1314
</script>
1415

1516
{@render children(avatar)}

0 commit comments

Comments
 (0)