storybook/docs/snippets/web-components/table-story-fully-customize-controls.ts.mdx
2023-01-05 14:53:03 +00:00

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',
},
};
```