Storybook args
What are args?
“Args” are Storybook’s mechanism for defining the set of arguments that define how the component should render.
Args can be defined for all stories:
// Button.stories.js|jsx
import { Button } from './Button';
export default {
title: 'Button',
component: Button,
//👇 Creates specific argTypes
argTypes: {
disabled: { control: 'boolean' },
variant: { control: 'select', options: ['primary', 'secondary'] },
},
args: {
//👇 Default values
disabled: false,
variant: 'primary',
},
};
or defined for a single story:
import { Button } from './Button';
export default {
title: 'Button',
component: Button,
};
export const Playground = {
//👇 Creates specific argTypes
argTypes: {
disabled: { control: 'boolean' },
variant: { control: 'select', options: ['primary', 'secondary'] },
},
//👇 Default values
args: {
disabled: false,
variant: 'primary',
},
};
Learn more about args on Storybook’s documentation
When to use argTypes
On some frameworks, Storybook can infer argTypes automatically from types (in TypeScript) or
PropTypes (in JavaScript).
story.to.design needs
argTypesto infer possible values for a specific arg when using the Basic mode for importing variants but it’s also used in some cases of Advanced mode. SeevariantProperties APIfor more details.
Supported argTypes
When importing in Basic mode, the arg with the following types will be presented to the user of story.to.design for creating variants.
| DataType | Control | Support | Example |
|---|---|---|---|
| boolean | boolean | ✅ | argTypes:{ active: { control: 'boolean' }} |
| enum | radio | ✅ | argTypes: { variant: { control: 'radio', options: ['primary', 'secondary'] }} |
inline-radio | ✅ | argTypes: { variant: { control: 'inline-radio', options: ['primary', 'secondary'] }} | |
check | ✅ | argTypes: { variant: { control: 'check', options: ['primary', 'secondary'] }} | |
inline-check | ✅ | argTypes: { variant: { control: 'inline-check', options: ['primary', 'secondary'] }} | |
select | ✅ | argTypes: { variant: { control: 'select', options: ['primary', 'secondary'] }} | |
multi-select | ✅ | argTypes: { variant: { control: 'multi-select', options: ['primary', 'secondary'] }} | |
| number | number | ❌ | |
range | ❌ | ||
| string | text | ❌ | |
color | ❌ | ||
date | ❌ | ||
| object | object | ❌ | |
| array | object | ❌ | |
file | ❌ |
If args are not defined properly in your story, story.to.design will show No args found.
If args are defined properly but none of them are supported, story.to.design will show No supported args found.