mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 09:31:47 +08:00
46 lines
983 B
Plaintext
46 lines
983 B
Plaintext
```tsx
|
|
// Table.stories.ts|tsx
|
|
|
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
|
|
import { Table } from './Table';
|
|
import { TD } from './TableDataCell';
|
|
import { TR } from './TableRow';
|
|
|
|
const meta = {
|
|
/* 👇 The title prop is optional.
|
|
* See https://storybook.js.org/docs/7.0/react/configure/overview#configure-story-loading
|
|
* to learn how to generate automatic titles
|
|
*/
|
|
title: 'Custom Table',
|
|
|
|
component: Table,
|
|
} satisfies Meta<typeof Table>;
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof meta>;
|
|
|
|
export const TableStory: Story = {
|
|
render: ({ data, ...args }) => (
|
|
<Table {...args}>
|
|
{data.map((row) => (
|
|
<TR>
|
|
{row.map((item) => (
|
|
<TD>{item}</TD>
|
|
))}
|
|
</TR>
|
|
))}
|
|
</Table>
|
|
),
|
|
args: {
|
|
//👇 This arg is for the story component
|
|
data: [
|
|
[1, 2, 3],
|
|
[4, 5, 6],
|
|
],
|
|
//👇 The remaining args get passed to the `Table` component
|
|
size: 'large',
|
|
},
|
|
};
|
|
```
|