Loading...
Loading...
Best practices for building and documenting component libraries with Storybook
npx skill4agent add mindrally/skills storybookComponentName.stories.tsximport type { Meta, StoryObj } from '@storybook/react';
import { Component } from './Component';
const meta: Meta<typeof Component> = {
title: 'Category/Component',
component: Component,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
// Define arg types here
},
};
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {
// Default props
},
};
export const Variant: Story = {
args: {
variant: 'secondary',
},
};argTypes: {
variant: {
control: 'select',
options: ['primary', 'secondary', 'tertiary'],
description: 'Visual style variant',
table: {
defaultValue: { summary: 'primary' },
},
},
size: {
control: 'radio',
options: ['sm', 'md', 'lg'],
},
disabled: {
control: 'boolean',
},
onClick: {
action: 'clicked',
},
}decorators: [
(Story) => (
<ThemeProvider theme={defaultTheme}>
<Story />
</ThemeProvider>
),
],parameters: {
layout: 'centered', // or 'fullscreen', 'padded'
backgrounds: {
default: 'light',
values: [
{ name: 'light', value: '#ffffff' },
{ name: 'dark', value: '#1a1a1a' },
],
},
viewport: {
defaultViewport: 'responsive',
},
},import { within, userEvent } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
export const Clickable: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const button = canvas.getByRole('button');
await userEvent.click(button);
await expect(button).toHaveFocus();
},
};// .storybook/main.ts
const config: StorybookConfig = {
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-essentials',
'@storybook/addon-a11y',
'@storybook/addon-interactions',
],
framework: {
name: '@storybook/react-vite',
options: {},
},
};
export default config;