import { ScrollingModule } from "@angular/cdk/scrolling";
import { Meta, moduleMetadata, Story } from "@storybook/angular";
import { countries } from "../form/countries";
import { TableDataSource } from "./table-data-source";
import { TableModule } from "./table.module";
export default {
title: "Component Library/Table",
decorators: [
moduleMetadata({
imports: [TableModule, ScrollingModule],
}),
],
argTypes: {
alignRowContent: {
options: ["top", "middle", "bottom", "baseline"],
control: { type: "select" },
},
},
parameters: {
design: {
type: "figma",
url: "https://www.figma.com/file/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?node-id=1881%3A18371",
},
},
} as Meta;
const Template: Story = (args) => ({
props: args,
template: `
| Header 1 |
Header 2 |
Header 3 |
| Cell 1 |
Cell 2 Multiline Cell |
Cell 3 |
| Cell 4 |
Cell 5 |
Cell 6 |
Cell 7 Multiline Cell |
Cell 8 |
Cell 9 |
`,
});
export const Default = Template.bind({});
Default.args = {
alignRowContent: "baseline",
};
const data = new TableDataSource<{ id: number; name: string; other: string }>();
data.data = [...Array(5).keys()].map((i) => ({
id: i,
name: `name-${i}`,
other: `other-${i}`,
}));
const DataSourceTemplate: Story = (args) => ({
props: {
dataSource: data,
sortFn: (a: any, b: any) => a.id - b.id,
},
template: `
| Id |
Name |
Other |
| {{ r.id }} |
{{ r.name }} |
{{ r.other }} |
`,
});
export const DataSource = DataSourceTemplate.bind({});
const data2 = new TableDataSource<{ id: number; name: string; other: string }>();
data2.data = [...Array(100).keys()].map((i) => ({
id: i,
name: `name-${i}`,
other: `other-${i}`,
}));
const ScrollableTemplate: Story = (args) => ({
props: {
dataSource: data2,
sortFn: (a: any, b: any) => a.id - b.id,
},
template: `
| Id |
Name |
Other |
| {{ r.id }} |
{{ r.name }} |
{{ r.other }} |
`,
});
export const Scrollable = ScrollableTemplate.bind({});
const data3 = new TableDataSource<{ value: string; name: string }>();
// Chromatic has a max page size, lowering the number of entries to ensure we don't hit it
data3.data = countries.slice(0, 100);
const FilterableTemplate: Story = (args) => ({
props: {
dataSource: data3,
sortFn: (a: any, b: any) => a.id - b.id,
},
template: `
| Name |
Value |
| {{ r.name }} |
{{ r.value }} |
`,
});
export const Filterable = FilterableTemplate.bind({});