How to get Svelte Slots working in Storybook. #20142
Replies: 4 comments 8 replies
-
I'm facing the same problem |
Beta Was this translation helpful? Give feedback.
-
@elkorman15 @TristanBrotherton it is not implemented as feature I guess let me check I may help on this part |
Beta Was this translation helpful? Give feedback.
-
@elkorman15 @TristanBrotherton I could manage to render one slot by changing the svelte renderer but the problem is that Svelte does not support dynamic slot names, meaning the slot attribute cannot be assigned a variable value. This is because when the component is compiled, the slot names need to be known at compile-time in order for the correct content to be rendered in the correct location. I managed to do something like this if you are interested I can share it with you, with PR first to be able to pass the slot from the controls Screen.Recording.2023-01-19.at.5.26.01.PM.mov |
Beta Was this translation helpful? Give feedback.
-
@chakAs3 Could you share the code of your Primary button story? |
Beta Was this translation helpful? Give feedback.
-
I am documenting Svelte components in Storybook. The Svelte format of
<span slot="foo">content</slot>
will result in Storybook not knowing there is a slot.<slot name="foo">content</slot>
will result in Storybook knowing there is a slot, but Svelte can not render it because its formatted incorrectly.The kludgy work-around seems to be to use
<slot name="foo" slot="foo">content</slot>
The following example is my hack at getting it to work, but it shows the slots as parameters I'd have to manually hide:
Hero.template.svelte
Hero.stories.ts
As you can see below - also note the slots shown in Storybook are not editable and are shown as JSON inputs, and you have to use the parameters to set the slot content:
What I'd like to be able to do is simply have the slots recognized in the native format and be able to edit them in Storybook not as parameters. If anyone has some input I'd be very grateful.
Beta Was this translation helpful? Give feedback.
All reactions