Skip to content

Docs: Add CSF factory API documentation#30343

Merged
valentinpalkovic merged 9 commits into
nextfrom
yann/csf-factories-documentation
Feb 13, 2025
Merged

Docs: Add CSF factory API documentation#30343
valentinpalkovic merged 9 commits into
nextfrom
yann/csf-factories-documentation

Conversation

@yannbf

@yannbf yannbf commented Jan 22, 2025

Copy link
Copy Markdown
Member

Closes #30342
Closes #30329

What I did

This PR introduces documentation for the CSF Factory format.

Checklist for Contributors

Testing

Manual testing

  1. Check out this branch
  2. Run sync-docs in storybookjs/web locally
  3. Run the docs site locally
    • Make sure you've pulled the latest main, so the page-level tabs show up
  4. Visit http://localhost:3000/docs/api/csf/csf-factories

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

Greptile Summary

This PR introduces comprehensive documentation for the new CSF Factory API, providing examples and guidelines for creating and testing Storybook stories with improved type safety and reusability.

  • Added new defineMain and definePreview configuration examples in docs/_snippets/csf-factories-main-example.md and docs/_snippets/csf-factories-preview-example.md
  • Added story creation examples using preview.meta() and meta.story() in docs/_snippets/csf-factories-story-example.md
  • Added testing integration examples with Vitest in docs/_snippets/portable-stories-csf-factory-run.md
  • Updated portable stories documentation with warnings about CSF Factory API preference for React users
  • Added documentation for story composition and property reuse through the composed property

@yannbf yannbf added the ci:docs Run the CI jobs for documentation checks only. label Jan 22, 2025
@yannbf yannbf self-assigned this Jan 22, 2025

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

10 file(s) reviewed, 12 comment(s)
Edit PR Review Bot Settings | Greptile

Comment thread docs/_snippets/csf-factories-story-input-example.md Outdated
Comment thread docs/_snippets/csf-factories-story-input-example.md Outdated
Comment thread docs/_snippets/csf-factories-story-example.md Outdated
Comment thread docs/_snippets/portable-stories-csf-factory-render.md
Comment thread docs/_snippets/portable-stories-csf-factory-render.md Outdated
Comment thread docs/_snippets/portable-stories-csf-factory-run.md Outdated
Comment thread docs/_snippets/portable-stories-csf-factory-run.md
Comment thread docs/_snippets/portable-stories-csf-factory-run.md
Comment thread docs/api/csf.mdx Outdated
Comment thread docs/api/portable-stories/portable-stories-vitest.mdx Outdated
@nx-cloud

nx-cloud Bot commented Jan 22, 2025

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit e6e3952.

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 59s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-13 13:17:32 UTC

Comment thread docs/_snippets/csf-factories-main-example.md Outdated
Comment thread docs/_snippets/csf-factories-preview-example.md Outdated
Comment thread docs/_snippets/csf-factories-preview-example.md Outdated
Comment thread docs/_snippets/portable-stories-csf-factory-render.md Outdated
Comment thread docs/_snippets/portable-stories-csf-factory-run.md Outdated
Comment thread docs/api/csf/csf-factories.mdx
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx
Comment on lines +149 to +152
"#.storybook/preview": {
"default": "./.storybook/preview.ts",
},
"#*": ["./*", "./*.ts", "./*.tsx"],

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interesting 🤔 the codemod only adds "#*": ["./*", "./*.ts", "./*.tsx"] and assumes that users will write #.storybook/preview which will relate to <root>.storybook/preview and if they have the preview file somewhere else, they will have to adjust the import in each file to something like #some-dir/.storybook/preview.

This means users with multiple Storybooks could have multiple imports like #apps/.storybook/preview and #libs/.storybook/preview without having to change anything in their package.json.

Perhaps the codemod should set this more specific field like what Kyle wrote here instead? WDYT @kasperpeulen?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see! Thanks for explaining. That's tricky. I see why you did it the current way, but think the way I documented is perhaps a bit more informative? I like that if someone does a Find for #.storybook/preview, they'll come across this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's tricky, I'll leave @kasperpeulen to decide

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kasperpeulen — Did you have thoughts? I'm still inclined to think it should be the way I've documented here, because:

I like that if someone does a Find for #.storybook/preview, they'll come across this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure, I will let @shilman decide about this. :P

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fwiw, I'm 60/40 on my proposal here vs. what was implemented. So unless someone else strongly agrees with me, we can just keep it simple.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can see both sides. I prefer @kylegach 's proposal slightly in the name of being explicit. If we want to support multiple preview files like you describe @yannbf then we should make that explicit instead and document it here.

Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx
Comment thread docs/api/csf/csf-factories.mdx
@kylegach kylegach force-pushed the yann/csf-factories-documentation branch from 5f60838 to e6e01c1 Compare February 4, 2025 22:01
@kylegach kylegach force-pushed the yann/csf-factories-documentation branch from e6e01c1 to dcfab08 Compare February 4, 2025 22:02
@yannbf

yannbf commented Feb 5, 2025

Copy link
Copy Markdown
Member Author

@kylegach this all looks great, thanks for working on the revisions! I can't approve since I opened the PR, so please approve it for me!

@yannbf yannbf mentioned this pull request Feb 5, 2025
8 tasks

@jonniebigodes jonniebigodes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is shaping up nicely. Thank you for adding the documentation. I appreciate it 🙏 I left some items for you to look into when you can. Let me know, and we'll go from there.

Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Comment thread docs/_snippets/csf-factories-main-example.md Outdated
Comment thread docs/api/csf/csf-factories.mdx Outdated
Base automatically changed from kasper/csf-factories to next February 12, 2025 14:25
@valentinpalkovic valentinpalkovic merged commit 2429ddd into next Feb 13, 2025
@valentinpalkovic valentinpalkovic deleted the yann/csf-factories-documentation branch February 13, 2025 13:13
@github-actions github-actions Bot mentioned this pull request Feb 14, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:docs Run the CI jobs for documentation checks only. documentation

Projects

None yet

6 participants