mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
165 lines
3.4 KiB
Markdown
165 lines
3.4 KiB
Markdown
```jsx filename="MyComponent.stories.js|jsx" renderer="common" language="js"
|
|
import { ColorItem, ColorPalette } from '@storybook/blocks';
|
|
|
|
import { MyComponent } from './MyComponent';
|
|
|
|
export default {
|
|
component: MyComponent,
|
|
};
|
|
|
|
const theme = {
|
|
colors: {
|
|
primaryDark: {
|
|
value: '#1C1C1C',
|
|
},
|
|
primaryRegular: {
|
|
value: '#363636',
|
|
},
|
|
primaryLight1: {
|
|
value: '#4D4D4D',
|
|
},
|
|
primaryLight2: {
|
|
value: '#878787',
|
|
},
|
|
primaryLight3: {
|
|
value: '#D1D1D1',
|
|
},
|
|
primaryLight4: {
|
|
value: '#EDEDED',
|
|
},
|
|
},
|
|
};
|
|
|
|
// ❌ Don't use the Doc Blocks inside your stories. It will break Storybook with a cryptic error.
|
|
export const Colors = {
|
|
render: () => (
|
|
<ColorPalette>
|
|
{Object.entries(theme.colors).map(([key, { value }]) => (
|
|
<ColorItem
|
|
colors={{
|
|
[key]: value,
|
|
}}
|
|
key={key}
|
|
subtitle={`theme.colors.${key}`}
|
|
title={key}
|
|
/>
|
|
))}
|
|
</ColorPalette>
|
|
),
|
|
};
|
|
```
|
|
|
|
```tsx filename="MyComponent.stories.ts|tsx" renderer="common" language="ts-4-9"
|
|
// Replace your-framework with the name of your framework
|
|
import type { Meta } from '@storybook/your-framework';
|
|
|
|
import { ColorItem, ColorPalette } from '@storybook/blocks';
|
|
|
|
import { MyComponent } from './MyComponent';
|
|
|
|
const meta = {
|
|
component: MyComponent,
|
|
} satisfies Meta<typeof MyComponent>;
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof meta>;
|
|
|
|
const theme = {
|
|
colors: {
|
|
primaryDark: {
|
|
value: '#1C1C1C',
|
|
},
|
|
primaryRegular: {
|
|
value: '#363636',
|
|
},
|
|
primaryLight1: {
|
|
value: '#4D4D4D',
|
|
},
|
|
primaryLight2: {
|
|
value: '#878787',
|
|
},
|
|
primaryLight3: {
|
|
value: '#D1D1D1',
|
|
},
|
|
primaryLight4: {
|
|
value: '#EDEDED',
|
|
},
|
|
},
|
|
};
|
|
|
|
// ❌ Don't use the Doc Blocks inside your stories. It will break Storybook with a cryptic error.
|
|
export const Colors: Story = {
|
|
render: () => (
|
|
<ColorPalette>
|
|
{Object.entries(theme.colors).map(([key, { value }]) => (
|
|
<ColorItem
|
|
colors={{
|
|
[key]: value,
|
|
}}
|
|
key={key}
|
|
subtitle={`theme.colors.${key}`}
|
|
title={key}
|
|
/>
|
|
))}
|
|
</ColorPalette>
|
|
),
|
|
};
|
|
```
|
|
|
|
```tsx filename="MyComponent.stories.ts|tsx" renderer="common" language="ts"
|
|
// Replace your-framework with the name of your framework
|
|
import type { Meta, StoryObj } from '@storybook/your-framework';
|
|
|
|
import { ColorItem, ColorPalette } from '@storybook/blocks';
|
|
|
|
import { MyComponent } from './MyComponent';
|
|
|
|
const meta: Meta<typeof MyComponent> = {
|
|
component: MyComponent,
|
|
};
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof MyComponent>;
|
|
|
|
const theme = {
|
|
colors: {
|
|
primaryDark: {
|
|
value: '#1C1C1C',
|
|
},
|
|
primaryRegular: {
|
|
value: '#363636',
|
|
},
|
|
primaryLight1: {
|
|
value: '#4D4D4D',
|
|
},
|
|
primaryLight2: {
|
|
value: '#878787',
|
|
},
|
|
primaryLight3: {
|
|
value: '#D1D1D1',
|
|
},
|
|
primaryLight4: {
|
|
value: '#EDEDED',
|
|
},
|
|
},
|
|
};
|
|
|
|
// ❌ Don't use the Doc Blocks inside your stories. It will break Storybook with a cryptic error.
|
|
export const Colors: Story = {
|
|
render: () => (
|
|
<ColorPalette>
|
|
{Object.entries(theme.colors).map(([key, { value }]) => (
|
|
<ColorItem
|
|
colors={{
|
|
[key]: value,
|
|
}}
|
|
key={key}
|
|
subtitle={`theme.colors.${key}`}
|
|
title={key}
|
|
/>
|
|
))}
|
|
</ColorPalette>
|
|
),
|
|
};
|
|
```
|