Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
@storybook/addon-docs
Advanced tools
The @storybook/addon-docs package is a Storybook addon that allows developers to write documentation alongside their stories. It uses MDX (Markdown with JSX) to let you document components in a rich, interactive way. It can generate documentation automatically based on your stories and supports a wide range of component frameworks.
MDX Documentation
Allows writing documentation using MDX, which can include both Markdown and JSX. You can define metadata, write narrative documentation, and showcase live examples and prop tables.
import { Meta, Story, ArgsTable, Canvas } from '@storybook/addon-docs/blocks';
<Meta title='MyComponent' />
# MyComponent
This is a **custom documentation** for `MyComponent`.
<Canvas>
<Story name='Basic' args={{ label: 'Hello World' }}>
{args => <MyComponent {...args} />}
</Story>
</Canvas>
<ArgsTable story='Basic' />
Automatic Props Table
Generates a table of the component's props automatically. This table includes the prop names, types, default values, and descriptions if they are specified in the component's propTypes or TypeScript definitions.
import { Meta, Story, ArgsTable } from '@storybook/addon-docs/blocks';
<Meta title='MyComponent' />
<Story name='Basic'>
<MyComponent />
</Story>
<ArgsTable of={MyComponent} />
Embedding Stories
Allows embedding live Storybook stories within the documentation. This provides an interactive example of the component in use.
import { Meta, Story } from '@storybook/addon-docs/blocks';
<Meta title='MyComponent' />
<Story name='Basic'>
<MyComponent />
</Story>
React Styleguidist is a component development environment with a living style guide. It allows developers to document components with Markdown and showcase usage examples. It differs from @storybook/addon-docs in that it is a standalone tool rather than an addon to Storybook, and it focuses more on the style guide aspect.
Docz leverages MDX to allow developers to write documentation and demos for their components. It is similar to @storybook/addon-docs in its use of MDX, but it is a standalone documentation tool that provides its own UI and does not require Storybook.
Docusaurus is a static site generator that can be used to create documentation websites. It supports Markdown and MDX and can be used to document React components, but it is not specifically tied to component stories like @storybook/addon-docs. It is more general-purpose and can be used for a wide range of documentation needs.
Storybook Docs transforms your Storybook stories into world-class component documentation.
DocsPage. Out of the box, all your stories get a DocsPage
. DocsPage
is a zero-config aggregation of your component stories, text descriptions, docgen comments, props tables, and code examples into simple, easy-to-read pages.
MDX. If you want more control, MDX
allows you to write long-form markdown documentation and stories in one file. You can also use it to write pure documentation pages and embed them inside your Storybook alongside your stories.
Just like Storybook, Docs supports every major view layer including React, Vue, Angular, HTML, Web components, Svelte, and many more.
Read on to learn more:
When you install Docs, every story gets a DocsPage
. DocsPage
pulls information from your stories, components, source code, and story metadata to construct a sensible, zero-config default.
Click on the Docs
tab to see it:
For more information on how it works, see the DocsPage
reference.
MDX
is a syntax for writing long-form documentation and stories side-by-side in the same file. In contrast to DocsPage
, which provides smart documentation out of the box, MDX
gives you full control over your component documentation.
Here's an example file:
import { Meta, Story, Preview } from '@storybook/addon-docs/blocks';
import { Checkbox } from './Checkbox';
<Meta title="MDX|Checkbox" component={Checkbox} />
# Checkbox
With `MDX` we can define a story for `Checkbox` right in the middle of our
markdown documentation.
<Preview>
<Story name="all checkboxes">
<form>
<Checkbox id="Unchecked" label="Unchecked" />
<Checkbox id="Checked" label="Checked" checked />
<Checkbox appearance="secondary" id="second" label="Secondary" checked />
</form>
</Story>
</Preview>
And here's how that's rendered in Storybook:
For more information on MDX
, see the MDX
reference.
Storybook Docs supports all view layers that Storybook supports except for React Native (currently). There are some view-layer specific features as well. This chart captures the current state of support
React | Vue | Angular | HTML | Svelte | Polymer | Marko | Mithril | Riot | Ember | Preact | |
---|---|---|---|---|---|---|---|---|---|---|---|
MDX stories | + | + | + | + | + | + | + | + | + | + | + |
CSF stories | + | + | + | + | + | + | + | + | + | + | + |
StoriesOf stories | + | + | + | + | + | + | + | + | + | + | + |
Source | + | + | + | + | + | + | + | + | + | + | + |
Notes / Info | + | + | + | + | + | + | + | + | + | + | + |
Props table | + | # | # | ||||||||
Docgen | + | # | # | ||||||||
Inline stories | + | # |
Note: #
= WIP support
First add the package. Make sure that the versions for your @storybook/*
packages match:
yarn add -D @storybook/addon-docs
Docs has peer dependencies on react
and babel-loader
. If you want to write stories in MDX, you may need to add these dependencies as well:
yarn add -D react babel-loader
Then add the following to your .storybook/presets.js
exports:
module.exports = ['@storybook/addon-docs/react/preset'];
If you're not using react
, replace it with your framework of choice corresponding to the Storybook package name, e.g. angular
for @storybook/angular
etc.
Configure. If you're migrating from an earlier version of Storybook and want to use MDX
, you need to upgrade your Storybook config:
import { configure } from '@storybook/react';
configure(require.context('../src', true, /\.stories\.(js|mdx)$/), module);
For more information on the new configure
, see "Loading stories" in the Storybook documentation.
The addon-docs
preset has a few configuration options that can be used to configure its babel/webpack loading behavior. Here's an example of how to use the preset with options:
module.exports = [
{
name: '@storybook/addon-docs/react/preset',
options: {
configureJSX: true,
babelOptions: {},
sourceLoaderOptions: null,
},
},
];
The configureJsx
option is useful when you're writing your docs in MDX and your project's babel config isn't already set up to handle JSX files. babelOptions
is a way to further configure the babel processor when you're using configureJSX
.
sourceLoaderOptions
is an object for configuring @storybook/source-loader
. When set to null
it tells docs not to run the source-loader
at all, which can be used as an optimization, or if you're already using source-loader
in your webpack.config.js
.
If you don't want to use the preset, and prefer to configure "the long way", first register the addon in .storybook/addons.js
:
import '@storybook/addon-docs/register';
Then configure Storybook's webpack loader in .storybook/webpack.config.js
to understand MDX story files and annotate TS/JS story files with source code using source-loader
:
const createCompiler = require('@storybook/addon-docs/mdx-compiler-plugin');
module.exports = async ({ config }) => {
config.module.rules.push({
test: /\.(stories|story)\.mdx$/,
use: [
{
loader: 'babel-loader',
// may or may not need this line depending on your app's setup
options: {
plugins: ['@babel/plugin-transform-react-jsx'],
},
},
{
loader: '@mdx-js/loader',
options: {
compilers: [createCompiler({})],
},
},
],
});
config.module.rules.push({
test: /\.(stories|story)\.[tj]sx?$/,
loader: require.resolve('@storybook/source-loader'),
exclude: [/node_modules/],
enforce: 'pre',
});
return config;
};
Finally, you'll need to set up DocsPage in .storybook/config.js
:
import { addParameters } from '@storybook/react';
import { DocsPage, DocsContainer } from '@storybook/addon-docs/blocks';
addParameters({
docs: {
container: DocsContainer,
page: DocsPage,
},
});
SB Docs for React uses babel-plugin-react-docgen
to extract Docgen comments from your code automatically. However, if you're using TypeScript, some extra configuration maybe required to get this information included in your docs.
react-docgen-typescript-loader
.Install the preset with care. If you've already configured Typescript manually, that configuration may conflict with the preset. You can debug your final webpack configuration with --debug-webpack
.
Want to learn more? Here are some more articles on Storybook Docs:
FAQs
Document component usage and properties in Markdown
The npm package @storybook/addon-docs receives a total of 4,105,125 weekly downloads. As such, @storybook/addon-docs popularity was classified as popular.
We found that @storybook/addon-docs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.