Skip to content

Commit afaecc8

Browse files
committed
refactor(svelte): merge props
1 parent 68242f0 commit afaecc8

File tree

7 files changed

+23
-13
lines changed

7 files changed

+23
-13
lines changed

packages/svelte/src/lib/components/avatar/avatar-fallback.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
<script lang="ts">
99
import { useAvatarContext } from './use-avatar-context'
10+
import { mergeProps } from '@zag-js/svelte'
1011
1112
const props: AvatarFallbackProps = $props()
13+
1214
const avatar = useAvatarContext()
13-
// const mergedProps = mergeProps(() => avatar().getFallbackProps(), props)
15+
const mergedProps = $derived(mergeProps(avatar().getFallbackProps(), props))
1416
</script>
1517

16-
<div {...avatar().getFallbackProps()} {...props}>
18+
<div {...mergedProps}>
1719
{@render props.children?.()}
1820
</div>

packages/svelte/src/lib/components/avatar/avatar-image.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
<script lang="ts">
99
import { useAvatarContext } from './use-avatar-context'
10+
import { mergeProps } from '@zag-js/svelte'
1011
1112
const props: AvatarImageProps = $props()
1213
const avatar = useAvatarContext()
13-
// const mergedProps = mergeProps(() => avatar().getImageProps(), props)
14+
const mergedProps = $derived(mergeProps(avatar().getImageProps(), props))
1415
</script>
1516

16-
<img {...avatar().getImageProps()} {...props} />
17+
<img {...mergedProps} />

packages/svelte/src/lib/components/avatar/avatar-root-provider.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313

1414
<script lang="ts">
1515
import { createSplitProps } from '$lib/utils/create-split-props'
16+
import { mergeProps } from '@zag-js/svelte'
1617
import { AvatarProvider } from './use-avatar-context'
1718
1819
const props: AvatarRootProviderProps = $props()
1920
const [{ value: avatar }, localProps] = createSplitProps<RootProviderProps>()(props, ['value'])
2021
2122
AvatarProvider(avatar)
23+
24+
const mergedProps = $derived(mergeProps(avatar().getRootProps(), localProps))
2225
</script>
2326

24-
<div {...avatar().getRootProps()} {...localProps}>
27+
<div {...mergedProps}>
2528
{@render props.children?.()}
2629
</div>

packages/svelte/src/lib/components/avatar/avatar-root.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</script>
88

99
<script lang="ts">
10+
import { mergeProps } from '@zag-js/svelte'
1011
import { createSplitProps } from '../../utils/create-split-props'
1112
import { AvatarProvider } from './use-avatar-context'
1213
import { useAvatar } from './use-avatar.svelte'
@@ -17,12 +18,13 @@
1718
'ids',
1819
'onStatusChange',
1920
])
21+
2022
const avatar = useAvatar(useAvatarProps)
21-
// const mergedProps = mergeProps(() => avatar().getRootProps(), localProps)
23+
const mergedProps = $derived(mergeProps(avatar().getRootProps(), localProps))
2224
2325
AvatarProvider(avatar)
2426
</script>
2527

26-
<div {...avatar().getRootProps()} {...localProps}>
28+
<div {...mergedProps}>
2729
{@render props.children?.()}
2830
</div>

packages/svelte/src/lib/components/avatar/examples/basic.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
<Avatar.Root>
66
<Avatar.Fallback>PA</Avatar.Fallback>
7-
<Avatar.Image src="https://i.pravatar.cc/3000" alt="avatar" />
7+
<Avatar.Image src="https://i.pravatar.cc/3000?u=a" alt="avatar" />
88
</Avatar.Root>

packages/svelte/src/lib/components/avatar/examples/context.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
</Avatar.Fallback>
1515
{/snippet}
1616
</Avatar.Context>
17-
<Avatar.Image src="https://i.pravatar.cc/3000" alt="avatar" />
17+
<Avatar.Image src="https://i.pravatar.cc/3000?u=b" alt="avatar" />
1818
</Avatar.Root>

packages/svelte/src/lib/components/avatar/examples/root-provider.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
console.log('status', status)
77
},
88
})
9+
10+
// biome-ignore lint/style/useConst: <explanation>
11+
let counter = $state(0)
12+
const src = $derived(`https://i.pravatar.cc/300?u=${counter}`)
913
</script>
1014

11-
<button onclick={() => avatar().setSrc('https://avatars.githubusercontent.com/u/6916170?v=4')}>
12-
Change Avatar
13-
</button>
15+
<button onclick={() => counter++}>Change Avatar</button>
1416

1517
<Avatar.RootProvider value={avatar}>
1618
<Avatar.Fallback>PA</Avatar.Fallback>
17-
<Avatar.Image src="https://avatars.githubusercontent.com/u/1846056?v=4" alt="avatar" />
19+
<Avatar.Image {src} alt="avatar" />
1820
</Avatar.RootProvider>

0 commit comments

Comments
 (0)