Sorry, but you either have no stories or none are selected somehow.
If the problem persists, check the browser console, or the terminal you've run Storybook from.
Stories the are building blocks of Storybook, they represent a snapshot or slice of the component at a particular state, rendered onto a "playground" or "sandbox" for anyone to interact with. In turn, we can take these stories and embed them into MDX files (like the one you're reading right now) and turn them into living documentation.
For example, the WithSuccess
story from input.stories.js
gets rendered as:
We can interact with this component as we would in our actual application.
By modifying the args
property, we can specify any combination of states
for this component.
Storybook automatically parses the default and named exports from every *.stories.js
file
to generate stories, this is known as the Component Story Format
Default export is where the metadata and configuration for all of the stories contained within
the same *.stories.js
file are defined. It also provides fields for addon configuration for said stories.
Where parameters holds the configuration for addons and decorators are templates that wrap our stories.
Named exports are the individual stories that show up in the sidebar of storybooks
When writing stories, it's good practice to create a Template
variable that is not exported which binds
all of the props, events, and data that we want for all of our stories. It acts as the harness for which our
components are held. The Template
is reused in each story as named exports and we can simply specify the
args field to set props.
To write stories, we first import the component that we wish to write stories for:
Then we will define the Default Export
for the simplest use case (No configuration):
The title
field will tell Storybook to put the stories in a category called Components
.
We can add more levels of nesting by adding more /
.
For example, Component/Folder/Input
will result in the following:
Nothing will appear yet, this is because we now need to add our named exports.
First we will define the harness that will render our component:
Since Template
returns a Vue component that wraps our component, we need to pass through all of the props
that our component expects so Storybook can interact with our component's internals using its UI:
As you can imagine, depending on the component, this can get quite tedious, luckily, the Template
method
takes in 2 arguments. We can also use the generateTemplate
method to bind all props for us:
Another option is to use an actual Vue Single-File Component as your template. This can be useful if you are rendering a more complex component and you would prefer to have code highlighting and the ability to use any of the advanced features of a .vue component. Below is an example usage of this in a stories.js file:
In order to address a current storybook bug where props that share the same name as a slot are not displayed in the
sidebar controls we must define the slots controls in argTypesData
as seen in the example below.
And here is what the vue component NoticeDefault.story.vue looks like. Note that for these types of components that are used only for rendering components, we suffix them .story.vue, and keep them in the same folder as the corresponding stories.js file. In this case it is in the same folder as notice.stories.js:
Now that we have the Template
, we can create our named exports. Usually the Default
named export represents our component in it's default state. Specifying the args
property
will on other named exports will create stories with those props set.
TODO
Sometimes we don't want specific exports to be parsed as a story. This may occur if we want to export some
data property to be reused in composite stories. This can be accomplished by specifying the excludeStories
field in the default export