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

refactor!: Story children becomes static & add template prop #228

Open
wants to merge 12 commits into
base: next
Choose a base branch
from

Conversation

xeho91
Copy link
Collaborator

@xeho91 xeho91 commented Nov 8, 2024

Note

Concluded by feedback discussion thread on Discord


TODO

  • Update README
  • Update ERRORS
  • Update migration guide
  • Update examples/
  • Update tests & add new ones
  • Fix type issues 🫠
  • refactor transform analysis for the story content
  • Update pre-transform for legacy API runtime migration scripts
📦 Published PR as canary version: 5.0.0--canary.228.a0b0a96.0

✨ Test out this PR locally via:

npm install @storybook/[email protected]
# or 
yarn add @storybook/[email protected]

@xeho91 xeho91 self-assigned this Nov 8, 2024
@xeho91 xeho91 added major Increment the major version when merged next Related to the next version labels Nov 8, 2024
@xeho91 xeho91 marked this pull request as ready for review November 10, 2024 06:37
@xeho91
Copy link
Collaborator Author

xeho91 commented Nov 10, 2024

@JReinhold I need a second eye. I'm not sure if I have overlooked anything.

The only thing I didn't try to achieve in this PR is allowing passing a string to children arg - I believe this one needs a separate PR.

{#if children}
{@render children(renderer.args, renderer.storyContext)}
{:else if template}
{#if template && isSnippet(template)}
Copy link

@dominikg dominikg Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have 3 different props relevant here

template, children and component (via renderer.storyContext)

My understanding would be

  1. if template exists, render it and pass children along
  2. if component exists, render it and pass children along
  3. if children exists, render it

now this favors the component over a static story, the case where you have both component and children set is a bit of a conflict of interest, you have to take a guess if the user wants to render a static story overriding the default component or wants to pass the children prop into the default component.

Maybe this needs a <Story static> or <Story forwardChildren> prop to make it explicit/configurable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see if I understand what you're proposing.

With the following case:

<script module>
  import { defineMeta } from "@storybook/addon-svelte-csf";
  import Button from "./Button.svelte";
  <!--   👆 default component               👇 for the stories file -->
  const { Story } = defineMeta({ component: Button });
</script>

<Story name="Default">
  Click me
</Story>

The following piece:

<Story name="Default">
  <span>Click me</span>
</Story>

Will produce:

<Button>
  <span>Click me</span>
</Button>

Now, with the suggestion of adding a new static boolean flag prop to Story like this:

<Story name="Default" static>
  <span>Click me</span>
</Story>

Will produce:

<span>Click me</span>

Did I get this right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major Increment the major version when merged next Related to the next version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants