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

Docs: Add CSF factory API documentation #30343

Open
wants to merge 1 commit into
base: kasper/csf-factories
Choose a base branch
from

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Jan 22, 2025

Closes #30342
Closes #30329

What I did

This PR introduces documentation for the CSF Factory format.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

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.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

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
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

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

const Secondary = meta.story({
args: {
// 👇 Access args from another story using its `composed` property
...Primary.composed.args,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: spreading Primary.composed.args and then overriding label with the same value ('Button') appears redundant since it's the same as the Primary story

Comment on lines +10 to +14
const Primary = meta.story({
args: {
label: 'Button',
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider adding export statements to make these stories available to Storybook

Comment on lines +10 to +14
const Primary = meta.story({
args: {
label: 'Button',
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Primary story should be exported to be visible in Storybook

// Import all stories from the stories file
import * as stories from './Button.stories';

const { Primary, Secondary } = stories;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Secondary is destructured but never used in the tests. Remove unused variable.

});

test('renders primary button with overridden props', async () => {
// You can override props by passing them in the context argument of the play function
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The comment about 'context argument of the play function' is incorrect - this example shows prop overrides, not play function usage.

const { Primary, Secondary } = stories;

test('renders primary button with default args', async () => {
// The run function will mount the componetn and run all of Storybook's lifecycle hooks
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: 'componetn' is misspelled in the comment

// Import all stories from the stories file
import * as stories from './Button.stories';

const { Primary, Secondary } = stories;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Secondary is destructured but never used in the test file

test('renders primary button with default args', async () => {
// The run function will mount the componetn and run all of Storybook's lifecycle hooks
await Primary.run();
const buttonElement = screen.getByText('Text coming from args in stories file!');
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The hardcoded text 'Text coming from args in stories file!' should match what's actually defined in the Button.stories file

import preview from '../../../.storybook/preview';
```

For more details, refer to the [subpath imports documentation](../writing-stories/mocking-modules#subpath-imports).
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: The link to subpath imports documentation is incorrect. The URL should be ../writing-stories/mocking-modules.mdx#subpath-imports (missing .mdx extension)

Comment on lines +21 to +23
<Callout variant="warning">
If you are using the CSF Factory format, you don't need to use the portable stories API. Instead, you can use the [CSF Factory API](../../api/csf.mdx).
</Callout>
Copy link
Contributor

Choose a reason for hiding this comment

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

style: link to CSF Factory API should be more specific - consider linking directly to the CSF Factory section of the CSF documentation

Copy link

nx-cloud bot commented Jan 22, 2025

View your CI Pipeline Execution ↗ for commit 75670d5.

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

☁️ Nx Cloud last updated this comment at 2025-01-22 14:40:45 UTC

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants