Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use components with slot variable. #119

Closed
scorsi opened this issue Aug 8, 2023 · 3 comments
Closed

How to use components with slot variable. #119

scorsi opened this issue Aug 8, 2023 · 3 comments

Comments

@scorsi
Copy link

scorsi commented Aug 8, 2023

Hello,

This title may be not clear... An example may be better:

I have this component which declares a slot and gives two slot variable which are in fact components

<script lang="ts">
	import AvatarImage from './AvatarImage.svelte';
	import AvatarFallback from './AvatarFallback.svelte';
</script>
<div>
	<slot {AvatarImage} {AvatarFallback} />
</div>

We use it like so:

<Avatar let:AvatarImage let:AvatarFallback>
	<AvatarImage src="https://randomuser.me/api/portraits/women/33.jpg" />
	<AvatarFallback>👩‍💻</AvatarFallback>
</Avatar>

I wonder how to use that inside the svelte addon because I tried multiple things and still got this error

this={...} of <svelte:component> should specify a Svelte component.

Here how I use it (which doesn't work)

<Meta title="Avatar" component={Avatar} />

<Template let:args> <!-- also tried here -->
	<Avatar {...args} />
</Template>

<Story name="Example" let:AvatarImage let:AvatarFallback>
	<AvatarImage src="https://randomuser.me/api/portraits/women/33.jpg" />
	<AvatarFallback>👩‍💻</AvatarFallback>
</Story>

I guess it works similar has if it was:

<script>
  let active = false;
</script>
<slot {active} />
@Tyneor
Copy link

Tyneor commented Aug 16, 2023

Hello,

You have to use your component in the Template or in the Story, like so :

<Story name="Example">
  <Avatar let:AvatarImage let:AvatarFallback>
    <AvatarImage src="https://randomuser.me/api/portraits/women/33.jpg" />
    <AvatarFallback>👩‍💻</AvatarFallback>
  </Avatar>
</Story>

It worked on my side, hope this helps !

@benmccann
Copy link
Contributor

It looks like this was answered

@scorsi
Copy link
Author

scorsi commented Aug 23, 2023

Hello,

You have to use your component in the Template or in the Story, like so :

<Story name="Example">
  <Avatar let:AvatarImage let:AvatarFallback>
    <AvatarImage src="https://randomuser.me/api/portraits/women/33.jpg" />
    <AvatarFallback>👩‍💻</AvatarFallback>
  </Avatar>
</Story>

It worked on my side, hope this helps !

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants