StoryMate is a Visual Studio Code extension that automatically generates Storybook stories for React components.
- Automatically generates
.stories.tsx
files for new React components. - Configurable directories to watch for new files.
You can configure the directories to watch for new files by adding the following settings to your settings.json
:
- storyMate.watchDirectories
- storyMate.templatePath
- storyMate.fileExtensions
Defaults are configured as follows:
{
"storyMate.watchDirectories": ["ui/src/components"],
"storyMate.templatePath": "apps/storybook/.storybook/storyTemplate.hbs",
"storyMate.fileExtensions": [".tsx", ".jsx"]
}
Tip
Use vscode file nesting for nice organization without folders.
Create a new React component file (e.g., Button.tsx
) in one of the configured directories.
The extension will automatically generate a companion .stories.tsx
file (e.g., Button.stories.tsx
) in the same directory.
Note
It is expected that addon-designs is installed and configured in Storybook
Given a component file Button.tsx
in the ui/src/components/interactions
directory, the extension will generate a Button.stories.tsx
file with the following content:
import type { Meta, StoryObj } from "@storybook/react";
import Button, { BUTTON_VARIANTS } from "./Button";
const meta = {
title: "Interactions/Button",
component: Button,
argTypes: {
variant: {
options: BUTTON_VARIANTS,
control: "select",
},
onPress: { action: "Pressed" },
},
args: {
children: "Default Text",
},
} satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Basic: Story = {
parameters: {
design: {
type: "figma",
url: "REPLACE_WITH_FIGMA_URL",
allowFullscreen: true,
},
},
};
Note
It is expected that the Button.tsx
will have BUTTON_VARIANTS
exported.
Export BUTTON_VARIANTS
as follows:
export type ButtonVariant = "primary" | "secondary" | "tertiary";
export const BUTTON_VARIANTS: ButtonVariant[] = ["primary", "secondary", "tertiary"];
storiesFilePath
: Full path of the new.stories.tsx
filecomponentName
: Name of the component (e.g., "Button")componentVariants
: Component variants constant (e.g., "BUTTON_VARIANTS")formattedDirName
: Capitalized directory name (e.g., "Interactions")
Contributions are welcome! Please open an issue or submit a pull request.
- auto-edit story on save
- read
variants
anddefaultVariants
(and props from Component.tsx ?) - add
variants
anddefaultVariants
to story - make sure the current story figma url isn't overwritten
- make sure the current story args children string isn't overwritten
- add folder-based story title
- read
- update README
- add available handlebars
- bundle extension
- add import
defaultStoryTemplate.hbs
toextension.ts
- check if
settings.json
configuration works - check if custom template can be read from custom path
- move functions to separate files (cleaner code)
- make sure the current story isn't overwritten (update only
argTypes
andargs
)