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

add: docs for storybook #9120

Merged
merged 2 commits into from
Oct 28, 2018
Merged

add: docs for storybook #9120

merged 2 commits into from
Oct 28, 2018

Conversation

kkemple
Copy link
Contributor

@kkemple kkemple commented Oct 15, 2018

Added docs for using Storybook with Gatsby!

@kkemple kkemple self-assigned this Oct 15, 2018
@kkemple kkemple requested a review from a team October 15, 2018 13:18
@kkemple kkemple requested a review from a team as a code owner October 15, 2018 13:18
Copy link
Contributor

@DSchau DSchau left a comment

Choose a reason for hiding this comment

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

Looks good! Would be kinda nice if we could slightly clean up the webpack config generation, but works well enough 🤷‍♂️

Thanks for this!


```js
module.exports = (baseConfig, env, defaultConfig) => {
// Transpile Gatsby module because Gastby includes un-transpiled ES6 code.
Copy link
Contributor

Choose a reason for hiding this comment

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

We have an open issue for this. Maybe I'll fix this today and add a transpiled main field?

See #8821

Copy link
Contributor

Choose a reason for hiding this comment

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

Once #9123 is merged, we can remove this 🎉

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed!

Copy link
Contributor

Choose a reason for hiding this comment

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

#9123 did fix my situation where i was unit testing in a context that needed common-js, but i'm still seeing raw jsx in the module defined by the gatsby package, which causes problems for my storybook instance that was working before upgrading to v2.

normally module is still transpiled to some degree so that that it is at least valid js (which jsx is not) at some lowest common denominator, but still uses es module import/export. i normally handle producing es-module for module and common-js for main using rollup. if this were in place, there shouldn't be a need to transpile the gatsby package further when depending on it in a storybook project, etc.

if the team would be open to a build step that would produce both main and module with a process similar to this, i'd be happy to contribute. thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

i opened a PR with a start toward this type of config to give a little more detail around the approach i typically use

title: Visual Testing with Storybook
---

Knowing your components look as intended in every permutation is not only a great way to test them visually, but also provides "living documentation" for them. This makes it easier for teams to 1) know what components are available to them in a given project and 2) what props those components accept and what all of the states of that component are. As your project grows over time having this information available will be invaluable.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a quick one line defining what Storybook is

Copy link
Contributor

Choose a reason for hiding this comment

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

Could just copy directly from https://storybook.js.org/basics/introduction/

@travi
Copy link
Contributor

travi commented Oct 16, 2018

not sure if you're interested in including information about automating this further, but Percy provides a nice integration to very easily use their service with an existing storybook setup.

@Robdel12
Copy link
Contributor

If anyone needs help / info with Percy I'd love to help! I'm starting at the support manager later this month. :)

Copy link
Contributor

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

A few little corrections, and some suggestions to make things a bit less wordy, as people generally don't read long text on-screen.


## Setting up your environment

In order to set up Storybook you will need to install a few dependencies and then do some custom configuration to make Storybook work with your Gatsby environment. The first thing is to get the Storybook CLI installed if you don't have it already.
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be less wordy, perhaps:

Suggested change
In order to set up Storybook you will need to install a few dependencies and then do some custom configuration to make Storybook work with your Gatsby environment. The first thing is to get the Storybook CLI installed if you don't have it already.
To set up Storybook you need to install dependencies and do some custom configuration. First, install the Storybook CLI.

}
```

Next we need up make some adjustments to Storybook's default `webpack` configuration so that we can tranpile Gatsby source files, as well as ensure we have all the necessary `babel` plugins we need to transpile Gatsby components.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Next we need up make some adjustments to Storybook's default `webpack` configuration so that we can tranpile Gatsby source files, as well as ensure we have all the necessary `babel` plugins we need to transpile Gatsby components.
Next we make some adjustments to Storybook's default `webpack` configuration so we can transpile Gatsby source files, and to ensure we have the necessary `babel` plugins to transpile Gatsby components.


A full guide to writing stories is beyond the scope of this guide, but we'll take a look at creating a story.

First, create the story file. Storybook looks for all files with a `.story.js` extension and loads them into Storybook for you. Generally you will want your stories near where the component is defined, however since this Gatsby, if you want stories for your pages, you will have to create those files outside of the `pages` directory.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
First, create the story file. Storybook looks for all files with a `.story.js` extension and loads them into Storybook for you. Generally you will want your stories near where the component is defined, however since this Gatsby, if you want stories for your pages, you will have to create those files outside of the `pages` directory.
First, create the story file. Storybook looks for all files with a `.story.js` extension and loads them into Storybook for you. Generally you will want your stories near where the component is defined, however since this is Gatsby, if you want stories for your pages, you will have to create those files outside of the `pages` directory.

@calcsam
Copy link
Contributor

calcsam commented Oct 28, 2018

This has been hanging out for a while, so I incorporated @KyleAMathews' changes and am going to merge this in. Thanks @kkemple! @hugovk thanks for the suggestions -- perhaps you can open a PR with them and tag @kkemple or @shannonbux ?

@hugovk
Copy link
Contributor

hugovk commented Oct 28, 2018

@calcsam Done, please see PR #9494.

@kkemple
Copy link
Contributor Author

kkemple commented Oct 29, 2018

@travi I think Percy docs would be great! Might make sense to make it it's own thing though

DSchau pushed a commit that referenced this pull request Oct 29, 2018
…xt on-screen (#9494)

As suggested by @calcsam in #9120 (comment), here's my review comments in its own PR.

Follows https://www.gatsbyjs.org/docs/gatsby-style-guide/#write-concisely

cc @kkemple @shannonbux

Also use “you” as the pronoun, following the [style guide](https://www.gatsbyjs.org/docs/gatsby-style-guide/#use-you-as-the-pronoun).

<!--
  Q. Which branch should I use for my pull request?
  A. Use `master` branch (probably).

  Q. Which branch if my change is a bug fix for Gatsby v1?
  A. In this case, you should use the `v1` branch

  Q. Which branch if I'm still not sure?
  A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :)

  Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2.

  Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/
-->
jedrichards pushed a commit to jedrichards/gatsby that referenced this pull request Nov 1, 2018
* add: docs for storybook

* Update visual-testing-with-storybook.md
jedrichards pushed a commit to jedrichards/gatsby that referenced this pull request Nov 1, 2018
…xt on-screen (gatsbyjs#9494)

As suggested by @calcsam in gatsbyjs#9120 (comment), here's my review comments in its own PR.

Follows https://www.gatsbyjs.org/docs/gatsby-style-guide/#write-concisely

cc @kkemple @shannonbux

Also use “you” as the pronoun, following the [style guide](https://www.gatsbyjs.org/docs/gatsby-style-guide/#use-you-as-the-pronoun).

<!--
  Q. Which branch should I use for my pull request?
  A. Use `master` branch (probably).

  Q. Which branch if my change is a bug fix for Gatsby v1?
  A. In this case, you should use the `v1` branch

  Q. Which branch if I'm still not sure?
  A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :)

  Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2.

  Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/
-->
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
* add: docs for storybook

* Update visual-testing-with-storybook.md
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
…xt on-screen (gatsbyjs#9494)

As suggested by @calcsam in gatsbyjs#9120 (comment), here's my review comments in its own PR.

Follows https://www.gatsbyjs.org/docs/gatsby-style-guide/#write-concisely

cc @kkemple @shannonbux

Also use “you” as the pronoun, following the [style guide](https://www.gatsbyjs.org/docs/gatsby-style-guide/#use-you-as-the-pronoun).

<!--
  Q. Which branch should I use for my pull request?
  A. Use `master` branch (probably).

  Q. Which branch if my change is a bug fix for Gatsby v1?
  A. In this case, you should use the `v1` branch

  Q. Which branch if I'm still not sure?
  A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :)

  Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2.

  Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants