INIT
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { AvatarFallbackProps } from "../types.js";
|
||||
import { AvatarFallbackState } from "../avatar.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
...restProps
|
||||
}: AvatarFallbackProps = $props();
|
||||
|
||||
const fallbackState = AvatarFallbackState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, fallbackState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<span {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</span>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { AvatarFallbackProps } from "../types.js";
|
||||
declare const AvatarFallback: import("svelte").Component<AvatarFallbackProps, {}, "ref">;
|
||||
type AvatarFallback = ReturnType<typeof AvatarFallback>;
|
||||
export default AvatarFallback;
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { AvatarImageProps } from "../types.js";
|
||||
import { AvatarImageState } from "../avatar.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
src,
|
||||
child,
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
crossorigin = undefined,
|
||||
referrerpolicy = undefined,
|
||||
...restProps
|
||||
}: AvatarImageProps = $props();
|
||||
|
||||
const imageState = AvatarImageState.create({
|
||||
src: boxWith(() => src),
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
crossOrigin: boxWith(() => crossorigin),
|
||||
referrerPolicy: boxWith(() => referrerpolicy),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, imageState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<img {...mergedProps} {src} />
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { AvatarImageProps } from "../types.js";
|
||||
declare const AvatarImage: import("svelte").Component<AvatarImageProps, {}, "ref">;
|
||||
type AvatarImage = ReturnType<typeof AvatarImage>;
|
||||
export default AvatarImage;
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { AvatarRootProps } from "../types.js";
|
||||
import { AvatarRootState } from "../avatar.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
delayMs = 0,
|
||||
loadingStatus = $bindable("loading"),
|
||||
onLoadingStatusChange,
|
||||
child,
|
||||
children,
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
...restProps
|
||||
}: AvatarRootProps = $props();
|
||||
|
||||
const rootState = AvatarRootState.create({
|
||||
delayMs: boxWith(() => delayMs),
|
||||
loadingStatus: boxWith(
|
||||
() => loadingStatus,
|
||||
(v) => {
|
||||
if (loadingStatus !== v) {
|
||||
loadingStatus = v;
|
||||
onLoadingStatusChange?.(v);
|
||||
}
|
||||
}
|
||||
),
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, rootState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<div {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { AvatarRootProps } from "../types.js";
|
||||
declare const Avatar: import("svelte").Component<AvatarRootProps, {}, "ref" | "loadingStatus">;
|
||||
type Avatar = ReturnType<typeof Avatar>;
|
||||
export default Avatar;
|
||||
Reference in New Issue
Block a user