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

CLI: Component-driven React / Vue / Angular / Preact / Svelte templates #11505

Merged
merged 23 commits into from
Jul 16, 2020

Conversation

shilman
Copy link
Member

@shilman shilman commented Jul 11, 2020

Issue: #10723

What I did

What's next

  • Discussion here (comments welcome!)
  • Apply to other frameworks (help pls @tooppaaa @yannbf ?)

How to test

Modify scripts/run-e2e.ts:

await exec(`node ../../storybook/lib/cli/dist/generate init`, { cwd });
// await exec(`npx -p @storybook/cli sb init --yes ${type}`, { cwd });

Then run:

yarn test:e2e-framework react

@shilman
Copy link
Member Author

shilman commented Jul 11, 2020

@tmeasday @tooppaaa @domyen I've updated the button to use CSS and it's working. If it looks good, I'll update the other ones. I'm not really up on CSS best practices.

@tmeasday the action stuff is already set up by @tooppaaa. i made it a little bit more specific and added an onClick propType to the template and it works.

@tooppaaa
Copy link
Contributor

tooppaaa commented Jul 11, 2020

E2E added that covers

  • should have Welcome story displayed
  • should have 4 Button stories (check on classnames)
  • should have 2 Header stories (check on button text content)
  • should have 2 Page stories (check on button text + page content text)
  • should display onClick when clicking on primary button

I applied a bit of changes and extended your work @shilman on CSS.
Happy to make changes but the earliest possible as we can start working on others framework using E2E green as target !

@shilman
Copy link
Member Author

shilman commented Jul 12, 2020

@tooppaaa These changes look great. 💯

type="button"
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
style={backgroundColor && { backgroundColor }}
{...props}
Copy link
Member

Choose a reason for hiding this comment

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

Won't typescript complain about this? ButtonProps does not contain all possible props for a button element, I might be wrong but I think you'd need to do something like:

export interface ButtonProps extends React.DetailedHTMLProps<
    React.ButtonHTMLAttributes<HTMLButtonElement>,
    HTMLButtonElement
  > {
    primary?: boolean;
    ....
}

};

export const LoggedOut = Template.bind({});
LoggedOut.args = {};
Copy link
Member

Choose a reason for hiding this comment

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

Is the empty args here just to show people they can use it or is it necessary? There's already an example in LoggedIn, so no need to add it, right? It might lead to people thinking that they always need to add an empty args to every story

@@ -20,7 +18,7 @@ function configureMain(addons: string[], custom?: any) {
function configurePreview(framework: SupportedFrameworks) {
const parameters = `
export const parameters = {
actions: { argTypesRegex: "^on.*" },
actions: { argTypesRegex: "^on[A-Z].*" },
Copy link
Member

Choose a reason for hiding this comment

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

do you think it would be nice to add a small comment telling people that they can change this to other stuff like "^(on|handle)[A-Z].*" in case they use a different pattern, or even already just add that regex because it might useful anyway?

<ul>
<li>
Use a higher-level connected component. Storybook helps you compose such data from the
"args" of child component stories
Copy link
Member

Choose a reason for hiding this comment

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

maybe a hyperlink in the args would be useful for reference?

@yannbf
Copy link
Member

yannbf commented Jul 13, 2020 via email

@shilman
Copy link
Member Author

shilman commented Jul 14, 2020

@tooppaaa @yannbf When I run the sample app (react, react_typescript) locally it looks like the CSS is not being applied properly. The "JS" props (backgroundColor, label, onClick) are working, but the CSS props (primary, size) are not. Tho the story is getting re-rendered and the DOM is changing AFAICT. I'm sure that this was working on my initial commits, but it doesn't seem to be working on rollback, so maybe it's due to a change elsewhere in SB .. or in CRA?

Example___Button_-_Small_⋅_Storybook

@tmeasday
Copy link
Member

We should probably get the https sorted too huh

@tmeasday
Copy link
Member

Fixed now, try https://componentdriven.org

@shilman shilman changed the title CLI: Update React JS template with Header/Page stories CLI: Add Header/Page stories to React/Vue templates Jul 14, 2020
@shilman
Copy link
Member Author

shilman commented Jul 15, 2020

I fixed a bunch of Vue/Angular bugs and this is pretty much ready to go.

Waiting on #11561 and discussion with @tmeasday to make sure this is the direction we want to go before merging, since it might be incompatible with storyshots.

@shilman shilman changed the title CLI: Add Header/Page stories to React/Vue templates CLI: Component-driven templates for React / Vue / Angular / Preact / Svelte Jul 16, 2020
@shilman shilman changed the title CLI: Component-driven templates for React / Vue / Angular / Preact / Svelte CLI: Component-driven React / Vue / Angular / Preact / Svelte templates Jul 16, 2020
@shilman shilman merged commit 7a60d78 into next Jul 16, 2020
@shilman shilman mentioned this pull request Jul 16, 2020
2 tasks
@patrick-mcdougle
Copy link
Contributor

This adds a hidden dependency on prop-types which is not installed during the CLI install process.

@stof stof deleted the 10723-update-cli-template-stories branch May 25, 2022 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants