-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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 React Styleguidist #2044
Add React Styleguidist #2044
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,9 @@ You can find the most recent version of this guide [here](https://github.com/fac | |
- [Disabling jsdom](#disabling-jsdom) | ||
- [Snapshot Testing](#snapshot-testing) | ||
- [Editor Integration](#editor-integration) | ||
- [Developing Components in Isolation](#developing-components-in-isolation) | ||
- [Getting Started with Storybook](#getting-started-with-storybook) | ||
- [Getting Started with Styleguidist](#getting-started-with-styleguidist) | ||
- [Making a Progressive Web App](#making-a-progressive-web-app) | ||
- [Offline-First Considerations](#offline-first-considerations) | ||
- [Progressive Web App Metadata](#progressive-web-app-metadata) | ||
|
@@ -1377,14 +1380,15 @@ For an example, a simple button component could have following states: | |
|
||
Usually, it’s hard to see these states without running a sample app or some examples. | ||
|
||
Create React App doesn’t include any tools for this by default, but you can easily add [Storybook for React](https://storybook.js.org) ([source](https://github.com/storybooks/storybook)) to your project. **It is a third-party tool that lets you develop components and see all their states in isolation from your app**. | ||
Create React App doesn’t include any tools for this by default, but you can easily add [Storybook for React](https://storybook.js.org) ([source](https://github.com/storybooks/storybook)) or [React Styleguidist](https://react-styleguidist.js.org/) ([source](https://github.com/styleguidist/react-styleguidist)) to your project. **These are third-party tools that let you develop components and see all their states in isolation from your app**. | ||
|
||
![Storybook for React Demo](http://i.imgur.com/7CIAWpB.gif) | ||
|
||
A storybook can also be deployed as a static app. | ||
This way, everyone in your team can view and review different states of UI components without starting a backend server or creating an account in your app. | ||
You can also deploy your Storybook or style guide as a static app. This way, everyone in your team can view and review different states of UI components without starting a backend server or creating an account in your app. | ||
|
||
### Setup your app with Storybook | ||
### Getting Started with Storybook | ||
|
||
Storybook is a development environment for React UI components. It allows you to browse a component library, view the different states of each component, and interactively develop and test components. | ||
|
||
First, install the following npm package globally: | ||
|
||
|
@@ -1407,6 +1411,40 @@ Learn more about React Storybook: | |
* [Documentation](https://storybook.js.org/basics/introduction/) | ||
* [Snapshot Testing UI](https://github.com/storybooks/storybook/tree/master/addons/storyshots) with Storybook + addon/storyshot | ||
|
||
### Getting Started with Styleguidist | ||
|
||
Styleguidist combines of a style guide, where all your components are presented on a single page with their props documentation and usage examples, with an environment for developing components in isolation, similar to Storybook. In Styleguidist you write examples in Markdown, where each code snippet is rendered as a live editable playground. | ||
|
||
First install Styleguidist and peer dependencies from npm: | ||
|
||
```sh | ||
npm install --save-dev react-styleguidist webpack | ||
``` | ||
|
||
Then, add these scripts to your `package.json`: | ||
|
||
```sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a shell file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True ;-| |
||
{ | ||
"scripts": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User naïvely following this instruction will replace the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would you recommend here? |
||
"styleguide": "styleguidist server", | ||
"styleguide:build": "styleguidist build" | ||
} | ||
} | ||
``` | ||
|
||
Then, run the following command inside your app’s directory: | ||
|
||
```sh | ||
npm run styleguide | ||
``` | ||
|
||
After that, follow the instructions on the screen. | ||
|
||
Learn more about React Styleguidist: | ||
|
||
* [GitHub Repo](https://github.com/styleguidist/react-styleguidist) | ||
* [Documentation](https://react-styleguidist.js.org/docs/getting-started.html) | ||
|
||
## Making a Progressive Web App | ||
|
||
By default, the production build is a fully functional, offline-first | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed this. This is a bit scary.
People had a lot of issues trying to install webpack directly into CRA projects. Things would randomly break, and they would be running a wrong or incompatible version.
Why is it required for Styleguidist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's possible to not make it a peer, and just rely on it existing, this would be awesome. It's always going to exist in CRA projects, but making it a peer puts user in charge of managing webpack versions which goes directly against goals of this project, and will break people's setups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that users should be able to choose their own version of webpack (if it’s supported by Styleguidist of course). What if we add it as a dependency with a range like
>=1 <4
? Would npm properly dedupe them and use the same webpack version for Styleguidist and the host project or CRA?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully yes but I'd prefer to avoid relying on this. It doesn't always work.
In my practice peers are often just not worth it either. You can put require in a try catch and show a graceful crash message if you'd like. IMO this is a more solid way to accomplish what you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, we already has a webpack version check so we could just use it to show a warning if it’s not installed or version is not supported. I guess majority of our users already have webpack anyway ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind making this in a patch today? so I can remove this instruction before cutting a release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m going to make a release as soon as I test this fix ;-)