mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 02:01:48 +08:00
49 lines
1.0 KiB
Plaintext
49 lines
1.0 KiB
Plaintext
```ts
|
|
// Table.stories.ts
|
|
|
|
import type { Meta, StoryObj } from '@storybook/web-components';
|
|
|
|
import { html } from 'lit-html';
|
|
import { repeat } from 'lit/directives/repeat.js';
|
|
|
|
const meta: Meta = {
|
|
title: 'Custom Table',
|
|
component: 'custom-table',
|
|
};
|
|
|
|
export default meta;
|
|
type Story = StoryObj;
|
|
|
|
/*
|
|
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
|
|
* See https://storybook.js.org/docs/7.0/web-components/api/csf
|
|
* to learn how to use render functions.
|
|
*/
|
|
export const TableStory: Story = {
|
|
render: ({ data, size }) => {
|
|
return html`
|
|
<table>
|
|
<tbody>
|
|
${repeat(
|
|
data,
|
|
(row, rowIndex) =>
|
|
html`
|
|
<tr>
|
|
${repeat(row, (col, colIndex) => html`<td>${data[rowIndex][colIndex]}</td>`)}
|
|
</tr>
|
|
`
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
`;
|
|
},
|
|
args: {
|
|
data: [
|
|
[1, 2, 3],
|
|
[4, 5, 6],
|
|
],
|
|
size: 'large',
|
|
},
|
|
};
|
|
```
|