|
| 1 | +```js filename="Button.stories.js|jsx" renderer="react" language="js" tabTitle="CSF 3" |
| 2 | +import { Button } from './Button'; |
| 3 | + |
| 4 | +export default { |
| 5 | + component: Button, |
| 6 | +}; |
| 7 | + |
| 8 | +// ✅ Good - shows the default state |
| 9 | +export const Basic = {}; |
| 10 | + |
| 11 | +// ✅ Good - demonstrates a specific use case |
| 12 | +export const Primary = { |
| 13 | + args: { primary: true }, |
| 14 | +}; |
| 15 | + |
| 16 | +// ✅ Good - even though this story renders more than one button, |
| 17 | +// they both demonstrate the same concept of a disabled button |
| 18 | +export const Disabled = { |
| 19 | + args: { disabled: true }, |
| 20 | + render: (args) => ( |
| 21 | + <> |
| 22 | + <Button {...args}>Disabled Button</Button> |
| 23 | + <Button {...args} primary> |
| 24 | + Disabled Primary Button |
| 25 | + </Button> |
| 26 | + </> |
| 27 | + ), |
| 28 | +}; |
| 29 | + |
| 30 | +// ❌ Bad - demonstrates too many concepts at once, making |
| 31 | +// it less clear and less useful as a reference for agents |
| 32 | +export const SizesAndVariants = { |
| 33 | + render: () => ( |
| 34 | + <> |
| 35 | + <Button size="small">Small Button</Button> |
| 36 | + <Button>Medium Button</Button> |
| 37 | + <Button size="large">Large Button</Button> |
| 38 | + <Button variant="outline">Outline Button</Button> |
| 39 | + <Button variant="text">Text Button</Button> |
| 40 | + </> |
| 41 | + ), |
| 42 | +}; |
| 43 | +``` |
| 44 | + |
| 45 | +```ts filename="Button.stories.ts|tsx" renderer="react" language="ts" tabTitle="CSF 3" |
| 46 | +// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, nextjs-vite, etc. |
| 47 | +import type { Meta, StoryObj } from '@storybook/your-framework'; |
| 48 | + |
| 49 | +import { Button } from './Button'; |
| 50 | + |
| 51 | +const meta = { |
| 52 | + component: Button, |
| 53 | +} satisfies Meta<typeof Button>; |
| 54 | + |
| 55 | +export default meta; |
| 56 | + |
| 57 | +type Story = StoryObj<typeof meta>; |
| 58 | + |
| 59 | +// ✅ Good to show the default state |
| 60 | +export const Basic: Story = {}; |
| 61 | + |
| 62 | +// ✅ Good to demonstrate a specific use case |
| 63 | +export const Primary: Story = { |
| 64 | + args: { primary: true }, |
| 65 | +}; |
| 66 | + |
| 67 | +// ✅ Good - even though this story renders more than one button, |
| 68 | +// they both demonstrate the same concept of a disabled button |
| 69 | +export const Disabled: Story = { |
| 70 | + args: { disabled: true }, |
| 71 | + render: (args) => ( |
| 72 | + <> |
| 73 | + <Button {...args}>Disabled Button</Button> |
| 74 | + <Button {...args} primary> |
| 75 | + Disabled Primary Button |
| 76 | + </Button> |
| 77 | + </> |
| 78 | + ), |
| 79 | +}; |
| 80 | + |
| 81 | +// ❌ Bad - demonstrates too many concepts at once, making |
| 82 | +// it less clear and less useful as a reference for agents |
| 83 | +export const SizesAndVariants: Story = { |
| 84 | + render: () => ( |
| 85 | + <> |
| 86 | + <Button size="small">Small Button</Button> |
| 87 | + <Button>Medium Button</Button> |
| 88 | + <Button size="large">Large Button</Button> |
| 89 | + <Button variant="outline">Outline Button</Button> |
| 90 | + <Button variant="text">Text Button</Button> |
| 91 | + </> |
| 92 | + ), |
| 93 | +}; |
| 94 | +``` |
| 95 | + |
| 96 | +```ts filename="Button.stories.ts|tsx" renderer="react" language="ts" tabTitle="CSF Next 🧪" |
| 97 | +import preview from '../.storybook/preview'; |
| 98 | + |
| 99 | +import { Button } from './Button'; |
| 100 | + |
| 101 | +const meta = preview.meta({ |
| 102 | + component: Button, |
| 103 | +}); |
| 104 | + |
| 105 | +// ✅ Good to show the default state |
| 106 | +export const Basic = meta.story(); |
| 107 | + |
| 108 | +// ✅ Good to demonstrate a specific use case |
| 109 | +export const Primary = meta.story({ |
| 110 | + args: { primary: true }, |
| 111 | +}); |
| 112 | + |
| 113 | +// ✅ Good - even though this story renders more than one button, |
| 114 | +// they both demonstrate the same concept of a disabled button |
| 115 | +export const Disabled = meta.story({ |
| 116 | + args: { disabled: true }, |
| 117 | + render: (args) => ( |
| 118 | + <> |
| 119 | + <Button {...args}>Disabled Button</Button> |
| 120 | + <Button {...args} primary> |
| 121 | + Disabled Primary Button |
| 122 | + </Button> |
| 123 | + </> |
| 124 | + ), |
| 125 | +}); |
| 126 | + |
| 127 | +// ❌ Bad - demonstrates too many concepts at once, making |
| 128 | +// it less clear and less useful as a reference for agents |
| 129 | +export const SizesAndVariants = meta.story({ |
| 130 | + render: () => ( |
| 131 | + <> |
| 132 | + <Button size="small">Small Button</Button> |
| 133 | + <Button>Medium Button</Button> |
| 134 | + <Button size="large">Large Button</Button> |
| 135 | + <Button variant="outline">Outline Button</Button> |
| 136 | + <Button variant="text">Text Button</Button> |
| 137 | + </> |
| 138 | + ), |
| 139 | +}); |
| 140 | +``` |
| 141 | + |
| 142 | +<!-- JS snippets still needed while providing both CSF 3 & Next --> |
| 143 | + |
| 144 | +```js filename="Button.stories.js|jsx" renderer="react" language="js" tabTitle="CSF Next 🧪" |
| 145 | +import preview from '../.storybook/preview'; |
| 146 | + |
| 147 | +import { Button } from './Button'; |
| 148 | + |
| 149 | +const meta = preview.meta({ |
| 150 | + component: Button, |
| 151 | +}); |
| 152 | + |
| 153 | +// ✅ Good to show the default state |
| 154 | +export const Basic = meta.story(); |
| 155 | + |
| 156 | +// ✅ Good to demonstrate a specific use case |
| 157 | +export const Primary = meta.story({ |
| 158 | + args: { primary: true }, |
| 159 | +}); |
| 160 | + |
| 161 | +// ✅ Good - even though this story renders more than one button, |
| 162 | +// they both demonstrate the same concept of a disabled button |
| 163 | +export const Disabled = meta.story({ |
| 164 | + args: { disabled: true }, |
| 165 | + render: (args) => ( |
| 166 | + <> |
| 167 | + <Button {...args}>Disabled Button</Button> |
| 168 | + <Button {...args} primary> |
| 169 | + Disabled Primary Button |
| 170 | + </Button> |
| 171 | + </> |
| 172 | + ), |
| 173 | +}); |
| 174 | + |
| 175 | +// ❌ Bad - demonstrates too many concepts at once, making |
| 176 | +// it less clear and less useful as a reference for agents |
| 177 | +export const SizesAndVariants = meta.story({ |
| 178 | + render: () => ( |
| 179 | + <> |
| 180 | + <Button size="small">Small Button</Button> |
| 181 | + <Button>Medium Button</Button> |
| 182 | + <Button size="large">Large Button</Button> |
| 183 | + <Button variant="outline">Outline Button</Button> |
| 184 | + <Button variant="text">Text Button</Button> |
| 185 | + </> |
| 186 | + ), |
| 187 | +}); |
| 188 | +``` |
0 commit comments