|
| 1 | +import { |
| 2 | + defaultFlowbiteTableConfig, |
| 3 | + Table, |
| 4 | + TableBody, |
| 5 | + TableFoot, |
| 6 | + TableHead, |
| 7 | +} from 'flowbite-angular/table'; |
| 8 | + |
| 9 | +import type { Meta, StoryObj } from '@storybook/angular'; |
| 10 | +import { argsToTemplate, moduleMetadata } from '@storybook/angular'; |
| 11 | + |
| 12 | +type StoryType = Table; |
| 13 | + |
| 14 | +export default { |
| 15 | + title: 'Component/Table', |
| 16 | + component: Table, |
| 17 | + decorators: [ |
| 18 | + moduleMetadata({ |
| 19 | + imports: [TableHead, TableBody, TableFoot], |
| 20 | + }), |
| 21 | + ], |
| 22 | + argTypes: { |
| 23 | + color: { |
| 24 | + control: 'select', |
| 25 | + type: 'string', |
| 26 | + options: ['default', 'info', 'failure', 'success', 'warning', 'primary'], |
| 27 | + table: { |
| 28 | + category: 'Input', |
| 29 | + defaultValue: { |
| 30 | + summary: JSON.stringify(defaultFlowbiteTableConfig.color), |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + striped: { |
| 35 | + control: 'boolean', |
| 36 | + type: 'boolean', |
| 37 | + table: { |
| 38 | + category: 'Input', |
| 39 | + defaultValue: { |
| 40 | + summary: JSON.stringify(defaultFlowbiteTableConfig.striped), |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + data: { |
| 45 | + control: 'object', |
| 46 | + type: 'symbol', |
| 47 | + table: { |
| 48 | + category: 'Input', |
| 49 | + defaultValue: { |
| 50 | + summary: JSON.stringify([]), |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + customTheme: { |
| 55 | + control: 'object', |
| 56 | + type: 'symbol', |
| 57 | + table: { |
| 58 | + category: 'Input', |
| 59 | + defaultValue: { |
| 60 | + summary: JSON.stringify(defaultFlowbiteTableConfig.customTheme), |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | +} as Meta<StoryType>; |
| 66 | + |
| 67 | +export const Default: StoryObj<StoryType> = { |
| 68 | + name: 'Default', |
| 69 | + args: { |
| 70 | + color: defaultFlowbiteTableConfig.color, |
| 71 | + striped: defaultFlowbiteTableConfig.striped, |
| 72 | + data: Array.from({ length: 5 }, (_, i) => i++).map((x) => ({ |
| 73 | + name: `Product ${x}`, |
| 74 | + qty: x, |
| 75 | + price: x * x, |
| 76 | + })), |
| 77 | + customTheme: defaultFlowbiteTableConfig.customTheme, |
| 78 | + }, |
| 79 | + render: (args) => ({ |
| 80 | + props: args, |
| 81 | + template: ` |
| 82 | + <table flowbiteTable [tableHead]="tableHeader" [tableBody]="tableBody" [tableFoot]="tableFooter" ${argsToTemplate(args)}> |
| 83 | + <ng-template #tableHeader> |
| 84 | + <tr flowbiteTableHead> |
| 85 | + <th scope="col" class="px-6 py-3 rounded-s-lg"> |
| 86 | + Product name |
| 87 | + </th> |
| 88 | + <th scope="col" class="px-6 py-3"> |
| 89 | + Qty |
| 90 | + </th> |
| 91 | + <th scope="col" class="px-6 py-3 rounded-e-lg"> |
| 92 | + Price |
| 93 | + </th> |
| 94 | + </tr> |
| 95 | + </ng-template> |
| 96 | + <ng-template #tableBody let-data> |
| 97 | + <tr flowbiteTableBody> |
| 98 | + <td scope="row" class="px-6 py-4"> |
| 99 | + {{ data.name }} |
| 100 | + </td> |
| 101 | + <td class="px-6 py-4"> |
| 102 | + {{ data.qty }} |
| 103 | + </td> |
| 104 | + <td class="px-6 py-4"> |
| 105 | + {{ data.price }} |
| 106 | + </td> |
| 107 | + </tr> |
| 108 | + </ng-template> |
| 109 | + <ng-template #tableFooter> |
| 110 | + <tr flowbiteTableFoot> |
| 111 | + <td scope="row" class="px-6 py-4"> |
| 112 | + Total |
| 113 | + </td> |
| 114 | + <td class="px-6 py-4"> |
| 115 | + 10 |
| 116 | + </td> |
| 117 | + <td class="px-6 py-4"> |
| 118 | + 30 |
| 119 | + </td> |
| 120 | + </tr> |
| 121 | + </ng-template> |
| 122 | + </table> |
| 123 | + `, |
| 124 | + }), |
| 125 | +}; |
0 commit comments