-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Addon-docs: Angular docs readme #8674
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<center> | ||
<img src="../docs/media/angular-hero.png" width="100%" /> | ||
</center> | ||
|
||
# Storybook Docs for Angular | ||
|
||
Storybook Docs transforms your Storybook stories into world-class component documentation. Storybook Docs for Angular supports [DocsPage](../docs/docspage.md) for auto-generated docs, and [MDX](../docs/mdx.md) for rich long-form docs. | ||
|
||
To learn more about Storybook Docs, read the [general documentation](../README.md). To learn the Angular specifics, read on! | ||
|
||
- [Installation](#installation) | ||
- [DocsPage](#docspage) | ||
- [MDX](#mdx) | ||
- [IFrame height](#iframe-height) | ||
- [More resources](#more-resources) | ||
|
||
## Installation | ||
|
||
First add the package. Make sure that the versions for your `@storybook/*` packages match: | ||
|
||
```sh | ||
yarn add -D @storybook/addon-docs@next | ||
``` | ||
|
||
Then add the following to your `.storybook/presets.js` exports: | ||
|
||
```js | ||
module.exports = ['@storybook/addon-docs/angular/preset']; | ||
``` | ||
|
||
## DocsPage | ||
|
||
When you [install docs](#installation) you should get basic [DocsPage](../docs/docspage.md) documentation automagically for all your Angular stories, available in the `Docs` tab of the Storybook UI. | ||
|
||
Pops tables for your components requires a few more steps. Docs for Angular relies on [Compodoc](https://compodoc.app/), the excellent API documentation tool. It supports `inputs`, `outputs`, `properties`, `methods`, `view/content child/children` as first class prop types. | ||
|
||
To get this, you'll first need to install Compodoc: | ||
|
||
```sh | ||
yarn add -D @compodoc/compodoc | ||
``` | ||
|
||
Then you'll need to configure Compodoc to generate a `documentation.json` file. Adding the following snippet to your `package.json` creates a metadata file `./documentation.json` each time you run storybook: | ||
|
||
```json | ||
{ | ||
... | ||
"scripts": { | ||
"docs:json": "compodoc -p ./tsconfig.json -e json -d .", | ||
"storybook": "npm run docs:json && start-storybook -p 9008 -s src/assets", | ||
... | ||
}, | ||
} | ||
``` | ||
|
||
Unfortunately, it's not currently possible to update this dynamically as you edit your components, but [there's an open issue](https://github.com/storybookjs/storybook/issues/8672) to support this with improvements to Compodoc. | ||
|
||
Next, add the following to your `.storybook/config.json` to load the Compodoc-generated file: | ||
|
||
```js | ||
import { setCompodocJson } from '@storybook/addon-docs/angular'; | ||
import docJson from '../documentation.json'; | ||
setCompodocJson(docJson); | ||
``` | ||
|
||
Finally, be sure to fill in the `component` field in your story metadata: | ||
|
||
```ts | ||
import { AppComponent } from './app.component'; | ||
|
||
export default { | ||
title: 'App Component', | ||
component: AppComponent, | ||
}; | ||
``` | ||
|
||
If you haven't upgraded from `storiesOf`, you can use a parameter to do the same thing: | ||
|
||
```ts | ||
import { storiesOf } from '@storybook/angular'; | ||
import { AppComponent } from './app.component'; | ||
|
||
storiesOf('App Component', module) | ||
.addParameters({ component: AppComponent }) | ||
.add( ... ); | ||
``` | ||
|
||
## MDX | ||
|
||
[MDX](../docs/mdx.md) is a convenient way to document your components in Markdown and embed documentation components, such as stories and props tables, inline. | ||
|
||
Docs has peer dependencies on `react`, `react-is`, and `babel-loader`. If you want to write stories in MDX, you'll need to add these dependencies as well: | ||
|
||
```sh | ||
yarn add -D react react-is babel-loader | ||
``` | ||
|
||
Then update your `.storybook/config.ts` to make sure you load MDX files: | ||
|
||
```ts | ||
configure(require.context('../src/stories', true, /\.stories\.(ts|mdx)$/), module); | ||
``` | ||
|
||
Finally, you can create MDX files like this: | ||
|
||
```md | ||
import { Meta, Story, Props } from '@storybook/docs/blocks'; | ||
import { AppComponent } from './app.component'; | ||
|
||
<Meta title="'App Component" component={AppComponent} /> | ||
|
||
# App Component | ||
|
||
Some **markdown** description, or whatever you want. | ||
|
||
<Story name='basic' height='400px'>{{ | ||
component: AppComponent, | ||
props: {}, | ||
}}</Story> | ||
|
||
## Props | ||
|
||
<Props of={AppComponent} /> | ||
``` | ||
|
||
Yes, it's redundant to declare `component` twice. [Coming soon](https://github.com/storybookjs/storybook/issues/8673). | ||
|
||
Also, to use the `Props` doc block, you need to set up Compodoc, [as described above](#docspage). | ||
|
||
## IFrame height | ||
|
||
Storybook Docs renders all Angular stories inside IFrames, with a default height of `60px`. You can update this default globally, or modify the IFrame height locally per story in `DocsPage` and `MDX`. | ||
|
||
To update the global default, modify `.storybook/config.ts`: | ||
|
||
```ts | ||
import { addParameters } from '@storybook/angular'; | ||
|
||
addParameters({ docs: { iframeHeight: 400 } }); | ||
``` | ||
|
||
For `DocsPage`, you need to update the parameter locally in a story: | ||
|
||
```ts | ||
export const basic = () => ... | ||
basic.story = { | ||
parameters: { docs: { iframeHeight: 400 } } | ||
} | ||
``` | ||
|
||
And for `MDX` you can modify it as an attribute on the `Story` element: | ||
|
||
```md | ||
<Story name='basic' height='400px'>{...}</Story> | ||
``` | ||
|
||
## More resources | ||
|
||
Want to learn more? Here are some more articles on Storybook Docs: | ||
|
||
- References: [DocsPage](../docs/docspage.md) / [MDX](../docs/mdx.md) / [FAQ](../docs/faq.md) / [Recipes](../docs/recipes.md) / [Theming](../docs/theming.md) | ||
- Vision: [Storybook Docs sneak peak](https://medium.com/storybookjs/storybook-docs-sneak-peak-5be78445094a) | ||
- Announcement: [DocsPage](https://medium.com/storybookjs/storybook-docspage-e185bc3622bf) | ||
- Example: [Storybook Design System](https://github.com/storybookjs/design-system) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
examples/angular-cli/src/stories/doc-button/doc-button.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
<button [ngClass]="classes" #buttonRef>{{ label }}</button> | ||
<button [ngClass]="classes" #buttonRef> | ||
<img | ||
width="100" | ||
src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxOS4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCAyNTAgMjUwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyNTAgMjUwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPg0KCS5zdDB7ZmlsbDojREQwMDMxO30NCgkuc3Qxe2ZpbGw6I0MzMDAyRjt9DQoJLnN0MntmaWxsOiNGRkZGRkY7fQ0KPC9zdHlsZT4NCjxnPg0KCTxwb2x5Z29uIGNsYXNzPSJzdDAiIHBvaW50cz0iMTI1LDMwIDEyNSwzMCAxMjUsMzAgMzEuOSw2My4yIDQ2LjEsMTg2LjMgMTI1LDIzMCAxMjUsMjMwIDEyNSwyMzAgMjAzLjksMTg2LjMgMjE4LjEsNjMuMiAJIi8+DQoJPHBvbHlnb24gY2xhc3M9InN0MSIgcG9pbnRzPSIxMjUsMzAgMTI1LDUyLjIgMTI1LDUyLjEgMTI1LDE1My40IDEyNSwxNTMuNCAxMjUsMjMwIDEyNSwyMzAgMjAzLjksMTg2LjMgMjE4LjEsNjMuMiAxMjUsMzAgCSIvPg0KCTxwYXRoIGNsYXNzPSJzdDIiIGQ9Ik0xMjUsNTIuMUw2Ni44LDE4Mi42aDBoMjEuN2gwbDExLjctMjkuMmg0OS40bDExLjcsMjkuMmgwaDIxLjdoMEwxMjUsNTIuMUwxMjUsNTIuMUwxMjUsNTIuMUwxMjUsNTIuMQ0KCQlMMTI1LDUyLjF6IE0xNDIsMTM1LjRIMTA4bDE3LTQwLjlMMTQyLDEzNS40eiIvPg0KPC9nPg0KPC9zdmc+DQo=" | ||
/> | ||
{{ label }} | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we need a list of supported types? I would expect to get all these from an API doc tool without reading this.
We can leave it as is. I just think it's another place we need to maintain if we add missing types.