@appdirect/design-system 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/bin/ad-sync-design-md.mjs +0 -0
  2. package/dist/ComplexComponents/DashboardWidget/DashboardWidget.js +15 -51
  3. package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +91 -139
  4. package/dist/ComplexComponents/DataTable/CellHoverReveal/CellHoverReveal.module.css +25 -0
  5. package/dist/ComplexComponents/DataTable/CellHoverReveal/index.js +24 -0
  6. package/dist/ComplexComponents/DataTable/CellHoverReveal/index.tsx +44 -0
  7. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +7 -0
  8. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +25 -77
  9. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +101 -157
  10. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +14 -7
  11. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +13 -7
  12. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/CustomToolbarAlertBannerContent.module.css +4 -0
  13. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +8 -20
  14. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +40 -58
  15. package/dist/ComplexComponents/DataTable/CustomTopToolbar/CustomTopToolbar.module.css +7 -0
  16. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/DateRangeSelectorFilter.module.css +3 -0
  17. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +50 -154
  18. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +59 -205
  19. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.js +48 -0
  20. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.ts +51 -0
  21. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +5 -25
  22. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +7 -28
  23. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.js +16 -0
  24. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.tsx +26 -0
  25. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +26 -28
  26. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +38 -38
  27. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +8 -18
  28. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.module.css +3 -0
  29. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +25 -37
  30. package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +67 -378
  31. package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +170 -711
  32. package/dist/ComplexComponents/DataTable/DataTable.js +74 -393
  33. package/dist/ComplexComponents/DataTable/DataTable.tsx +229 -546
  34. package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +85 -0
  35. package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +46 -0
  36. package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +143 -0
  37. package/dist/ComplexComponents/DataTable/DataTableShell/DataTableShell.module.css +38 -0
  38. package/dist/ComplexComponents/DataTable/DataTableShell/index.js +9 -0
  39. package/dist/ComplexComponents/DataTable/DataTableShell/index.tsx +47 -0
  40. package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +6 -6
  41. package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +53 -24
  42. package/dist/ComplexComponents/DataTable/SelectCheckbox/index.js +33 -0
  43. package/dist/ComplexComponents/DataTable/SelectCheckbox/index.tsx +63 -0
  44. package/dist/ComplexComponents/DataTable/SortableHeaderCell/SortableHeaderCell.module.css +3 -0
  45. package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +43 -21
  46. package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +62 -38
  47. package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.js +18 -0
  48. package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.tsx +47 -0
  49. package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.js +19 -0
  50. package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.tsx +59 -0
  51. package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/ToolbarAlertBanner.module.css +15 -0
  52. package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.js +8 -0
  53. package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.tsx +20 -0
  54. package/dist/ComplexComponents/DataTable/hooks/useClickOutside.js +27 -0
  55. package/dist/ComplexComponents/DataTable/hooks/useClickOutside.ts +39 -0
  56. package/dist/ComplexComponents/DataTable/index.js +5 -1
  57. package/dist/ComplexComponents/DataTable/index.ts +13 -2
  58. package/dist/ComplexComponents/DataTable/table.module.css +9 -0
  59. package/dist/ComplexComponents/DataTable/tableFeatures.js +6 -0
  60. package/dist/ComplexComponents/DataTable/tableFeatures.ts +7 -0
  61. package/dist/ComplexComponents/DataTable/translations/en.js +16 -4
  62. package/dist/ComplexComponents/DataTable/translations/en.ts +16 -4
  63. package/dist/ComplexComponents/DataTable/translations/index.js +5 -0
  64. package/dist/ComplexComponents/DataTable/translations/index.ts +11 -1
  65. package/dist/ComplexComponents/DataTable/types.js +5 -0
  66. package/dist/ComplexComponents/DataTable/types.ts +17 -0
  67. package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.js +3 -0
  68. package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.ts +4 -0
  69. package/dist/ComplexComponents/KeyInsight/index.ts +1 -1
  70. package/dist/DESIGN.md +9 -10
  71. package/dist/contracts/DashboardWidget.json +92 -0
  72. package/dist/contracts/DataTable.json +83 -6
  73. package/dist/contracts/index.json +6 -1
  74. package/dist/css/foundations.css +4 -0
  75. package/dist/css/mantine.css +173 -7
  76. package/dist/css/tokens.css +3195 -0
  77. package/dist/index.js +3 -0
  78. package/dist/index.ts +14 -1
  79. package/dist/stories/ComplexComponents/DashboardWidget/DashboardWidget.stories.tsx +76 -1
  80. package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +216 -458
  81. package/dist/stories/index.json +16 -15
  82. package/package.json +5 -3
  83. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +0 -31
  84. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +0 -76
  85. package/dist/hooks/useTableHandlers.js +0 -136
  86. package/dist/hooks/useTableHandlers.ts +0 -179
  87. package/dist/hooks/useTableRenderFunctions.js +0 -164
  88. package/dist/hooks/useTableRenderFunctions.tsx +0 -283
  89. package/dist/hooks/useTableState.js +0 -70
  90. package/dist/hooks/useTableState.ts +0 -81
@@ -1,502 +1,260 @@
1
1
  import type { Meta, StoryObj } from '@storybook/nextjs-vite';
2
- import { useState, useMemo } from 'react';
2
+ import { useMemo, useState } from 'react';
3
3
  import { Stack } from '@mantine/core';
4
- import { Inline, DataTable, Title, Text, Button, Badge } from '@appdirect/design-system';
5
- import {
6
- MRT_ColumnDef as ColumnDef,
7
- MRT_PaginationState as PaginationState,
8
- MRT_RowSelectionState as RowSelectionState,
9
- } from 'mantine-react-table-open';
4
+ import { DataTable, createDataTableColumnHelper, SortableHeaderCell, SortDirection, CellHoverReveal, Title } from '@appdirect/design-system';
5
+ import type { Filters, DensityState, PaginationState, RowSelectionState } from '@appdirect/design-system';
10
6
 
11
- // Sample data types
12
- interface User {
13
- id: string;
14
- name: string;
15
- email: string;
16
- status: 'Active' | 'Inactive' | 'Pending';
17
- department: string;
18
- role: string;
19
- lastLogin: string;
20
- joinDate: string;
21
- }
7
+ // ========================== SAMPLE DATA ==========================
22
8
 
23
- interface Product {
9
+ interface Person {
24
10
  id: string;
25
11
  name: string;
26
- category: string;
27
- price: number;
28
- stock: number;
29
- status: 'In Stock' | 'Low Stock' | 'Out of Stock';
30
- supplier: string;
12
+ age: number;
13
+ city: string;
14
+ appliedOn: string;
31
15
  }
32
16
 
33
- // Sample data generators
34
- const generateUsers = (count: number): User[] => {
35
- const departments = ['Engineering', 'Sales', 'Marketing', 'HR', 'Finance'];
36
- const roles = ['Manager', 'Senior', 'Junior', 'Lead', 'Director'];
37
- const statuses: User['status'][] = ['Active', 'Inactive', 'Pending'];
38
-
39
- return Array.from({ length: count }, (_, i) => ({
40
- id: `user-${i + 1}`,
41
- name: `User ${i + 1}`,
42
- email: `user${i + 1}@company.com`,
43
- status: statuses[i % statuses.length],
44
- department: departments[i % departments.length],
45
- role: roles[i % roles.length],
46
- lastLogin: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000).toLocaleDateString(),
47
- joinDate: new Date(Date.now() - Math.random() * 365 * 24 * 60 * 60 * 1000).toLocaleDateString(),
48
- }));
49
- };
17
+ const CITIES = ['New York', 'Los Angeles', 'Denver'];
50
18
 
51
- const generateProducts = (count: number): Product[] => {
52
- const categories = ['Electronics', 'Clothing', 'Books', 'Home & Garden', 'Sports'];
53
- const suppliers = ['Supplier A', 'Supplier B', 'Supplier C', 'Supplier D'];
54
- const statuses: Product['status'][] = ['In Stock', 'Low Stock', 'Out of Stock'];
55
-
56
- return Array.from({ length: count }, (_, i) => ({
57
- id: `product-${i + 1}`,
58
- name: `Product ${i + 1}`,
59
- category: categories[i % categories.length],
60
- price: Math.floor(Math.random() * 1000) + 10,
61
- stock: Math.floor(Math.random() * 100),
62
- status: statuses[i % statuses.length],
63
- supplier: suppliers[i % suppliers.length],
19
+ const generatePeople = (count: number): Person[] =>
20
+ Array.from({ length: count }, (_, i) => ({
21
+ id: `person-${i + 1}`,
22
+ name: `Person ${i + 1} with a name long enough to truncate in a narrow column`,
23
+ age: 20 + (i % 40),
24
+ city: CITIES[i % CITIES.length],
25
+ appliedOn: new Date(2026, i % 12, (i % 27) + 1).toLocaleDateString(),
64
26
  }));
27
+
28
+ // ========================== DEMO HARNESS ==========================
29
+
30
+ /**
31
+ * DataTable is controlled: the page owns state, exactly like micro-ui-ts `Table`.
32
+ * This harness keeps that state locally and slices an in-memory array to stand in for the
33
+ * server (cursor pagination, server-side sort and filter in production).
34
+ */
35
+ interface DemoProps {
36
+ rowCount?: number;
37
+ isLoading?: boolean;
38
+ isError?: boolean;
39
+ initialDensity?: DensityState;
40
+ initialSelection?: RowSelectionState;
41
+ initialShowFilters?: boolean;
42
+ }
43
+
44
+ const DemoTable = ({
45
+ rowCount = 47,
46
+ isLoading = false,
47
+ isError = false,
48
+ initialDensity = 'md',
49
+ initialSelection = {},
50
+ initialShowFilters = true,
51
+ }: DemoProps) => {
52
+ const [pagination, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 5 });
53
+ const [rowSelection, setRowSelection] = useState<RowSelectionState>(initialSelection);
54
+ const [density, setDensity] = useState<DensityState>(initialDensity);
55
+ const [isFullScreen, setIsFullScreen] = useState(false);
56
+ const [showFilters, setShowFilters] = useState(initialShowFilters);
57
+ const [filters, setFilters] = useState<Filters>({ city: null, dateRange: null, searchTerm: '' });
58
+ const [sorting, setSorting] = useState<{ field?: string; direction: SortDirection }>({
59
+ field: undefined,
60
+ direction: SortDirection.DEFAULT,
61
+ });
62
+
63
+ const all = useMemo(() => generatePeople(rowCount), [rowCount]);
64
+
65
+ const filtered = useMemo(() => {
66
+ let rows = all.filter(
67
+ person =>
68
+ (!filters.city || person.city === filters.city) &&
69
+ (!filters.searchTerm ||
70
+ person.name.toLowerCase().includes(filters.searchTerm.toLowerCase()))
71
+ );
72
+ if (sorting.field && sorting.direction !== SortDirection.DEFAULT) {
73
+ const key = sorting.field as keyof Person;
74
+ const factor = sorting.direction === SortDirection.ASC ? 1 : -1;
75
+ rows = [...rows].sort((a, b) => (a[key] > b[key] ? factor : -factor));
76
+ }
77
+ return rows;
78
+ }, [all, filters, sorting]);
79
+
80
+ const start = pagination.pageIndex * pagination.pageSize;
81
+ const pageRows = isError ? [] : filtered.slice(start, start + pagination.pageSize);
82
+
83
+ const columnHelper = createDataTableColumnHelper<Person>();
84
+ const columns = useMemo(
85
+ () => [
86
+ columnHelper.accessor('name', {
87
+ header: ({ header }) => (
88
+ <SortableHeaderCell
89
+ id={header.id}
90
+ sortingState={sorting}
91
+ onSort={setSorting}
92
+ label="Name"
93
+ />
94
+ ),
95
+ size: 220,
96
+ cell: ({ getValue }) => <CellHoverReveal>{getValue()}</CellHoverReveal>,
97
+ }),
98
+ columnHelper.accessor('age', {
99
+ header: ({ header }) => (
100
+ <SortableHeaderCell
101
+ id={header.id}
102
+ sortingState={sorting}
103
+ onSort={setSorting}
104
+ label="Age"
105
+ />
106
+ ),
107
+ }),
108
+ columnHelper.accessor('city', { header: 'City' }),
109
+ columnHelper.accessor('appliedOn', { header: 'Applied on' }),
110
+ ],
111
+ // eslint-disable-next-line react-hooks/exhaustive-deps
112
+ [sorting]
113
+ );
114
+
115
+ const resetPage = () => setPagination(prev => ({ ...prev, pageIndex: 0 }));
116
+
117
+ return (
118
+ <DataTable
119
+ data={pageRows}
120
+ columns={columns}
121
+ totalCount={isError ? 0 : filtered.length}
122
+ isLoading={isLoading}
123
+ isError={isError}
124
+ onRetry={() => undefined}
125
+ pagination={pagination}
126
+ pageInfo={{
127
+ hasPreviousPage: pagination.pageIndex > 0,
128
+ hasNextPage: start + pagination.pageSize < filtered.length,
129
+ }}
130
+ onPreviousPage={() => setPagination(prev => ({ ...prev, pageIndex: prev.pageIndex - 1 }))}
131
+ onNextPage={() => setPagination(prev => ({ ...prev, pageIndex: prev.pageIndex + 1 }))}
132
+ onPageSizeChange={pageSize => setPagination({ pageIndex: 0, pageSize })}
133
+ rowSelection={rowSelection}
134
+ onRowSelectionChange={setRowSelection}
135
+ selectionActions={[
136
+ {
137
+ label: 'Delete',
138
+ onClick: () => console.log(`Deleting row ids: ${Object.keys(rowSelection)}`),
139
+ },
140
+ ]}
141
+ density={density}
142
+ onDensityChange={setDensity}
143
+ isFullScreen={isFullScreen}
144
+ onFullScreenChange={setIsFullScreen}
145
+ filters={filters}
146
+ onFiltersChange={next => {
147
+ setFilters(prev => ({ ...prev, ...next }));
148
+ resetPage();
149
+ setRowSelection({});
150
+ }}
151
+ onResetFilters={() => {
152
+ setFilters({ city: null, dateRange: null, searchTerm: '' });
153
+ resetPage();
154
+ }}
155
+ showFilters={showFilters}
156
+ onFilterToggleChange={() => setShowFilters(prev => !prev)}
157
+ locale="en"
158
+ />
159
+ );
65
160
  };
66
161
 
67
- const meta: Meta<typeof DataTable> = {
162
+ // ========================== META ==========================
163
+
164
+ const meta: Meta<typeof DemoTable> = {
68
165
  title: 'Design System/Complex Components/DataTable',
69
- component: DataTable,
166
+ component: DemoTable,
70
167
  parameters: {
71
168
  layout: 'padded',
72
169
  docs: {
73
170
  description: {
74
- component: 'A powerful, feature-rich data table component built on top of Mantine React Table. Supports pagination, sorting, filtering, row selection, density controls, and more. Perfect for displaying large datasets with complex interaction requirements.',
171
+ component:
172
+ 'Controlled table built on TanStack Table v9 and the micro-ui-ts table pieces (shell, grid, toolbars). The consumer owns all state (pagination, selection, density, filters, sorting), matching the production `Table` page in micro-ui-ts. Prototype code therefore ports to marketplace code by swapping the data source.',
75
173
  },
76
174
  },
77
175
  },
78
176
  tags: ['autodocs', 'code-connected'],
79
177
  argTypes: {
80
- isLoading: {
81
- control: 'boolean',
82
- description: 'Whether the table is currently loading data',
83
- },
84
- isError: {
85
- control: 'boolean',
86
- description: 'Whether an error has occurred while loading data',
87
- },
88
- showFilters: {
89
- control: 'boolean',
90
- description: 'Whether to show the filters panel',
91
- },
92
- showSearch: {
93
- control: 'boolean',
94
- description: 'Whether to show the global search input',
95
- },
96
- showDensityToggle: {
97
- control: 'boolean',
98
- description: 'Whether to show the density toggle button',
99
- },
100
- showFullScreenToggle: {
101
- control: 'boolean',
102
- description: 'Whether to show the fullscreen toggle button',
103
- },
178
+ rowCount: { control: { type: 'number', min: 0, max: 200 } },
179
+ isLoading: { control: 'boolean' },
180
+ isError: { control: 'boolean' },
181
+ initialDensity: { control: 'inline-radio', options: ['xs', 'md', 'xl'] },
182
+ initialShowFilters: { control: 'boolean' },
104
183
  },
105
184
  };
106
185
 
107
186
  export default meta;
108
- type Story = StoryObj<typeof meta>;
187
+ type Story = StoryObj<typeof DemoTable>;
109
188
 
110
- // User table columns
111
- const userColumns: ColumnDef<User>[] = [
112
- {
113
- accessorKey: 'name',
114
- header: 'Name',
115
- size: 150,
116
- },
117
- {
118
- accessorKey: 'email',
119
- header: 'Email',
120
- size: 200,
121
- },
122
- {
123
- accessorKey: 'status',
124
- header: 'Status',
125
- size: 100,
126
- Cell: ({ cell }) => {
127
- const status = cell.getValue<string>();
128
- const color = status === 'Active' ? 'success' : status === 'Pending' ? 'pending' : 'danger';
129
- return <Badge color={color} size="sm">{status}</Badge>;
130
- },
131
- },
132
- {
133
- accessorKey: 'department',
134
- header: 'Department',
135
- size: 120,
136
- },
137
- {
138
- accessorKey: 'role',
139
- header: 'Role',
140
- size: 100,
141
- },
142
- {
143
- accessorKey: 'lastLogin',
144
- header: 'Last Login',
145
- size: 120,
146
- },
147
- ];
189
+ const Frame = ({ children, title }: { children: React.ReactNode; title: string }) => (
190
+ <Stack gap="lg" w="100%">
191
+ <Title order={3} size="md">
192
+ {title}
193
+ </Title>
194
+ {children}
195
+ </Stack>
196
+ );
148
197
 
149
- // Product table columns
150
- const productColumns: ColumnDef<Product>[] = [
151
- {
152
- accessorKey: 'name',
153
- header: 'Product Name',
154
- size: 200,
155
- },
156
- {
157
- accessorKey: 'category',
158
- header: 'Category',
159
- size: 120,
160
- },
161
- {
162
- accessorKey: 'price',
163
- header: 'Price',
164
- size: 100,
165
- Cell: ({ cell }) => `$${cell.getValue<number>().toFixed(2)}`,
166
- },
167
- {
168
- accessorKey: 'stock',
169
- header: 'Stock',
170
- size: 80,
171
- },
172
- {
173
- accessorKey: 'status',
174
- header: 'Status',
175
- size: 120,
176
- Cell: ({ cell }) => {
177
- const status = cell.getValue<string>();
178
- const color = status === 'In Stock' ? 'success' : status === 'Low Stock' ? 'pending' : 'danger';
179
- return <Badge color={color} size="sm">{status}</Badge>;
180
- },
181
- },
182
- {
183
- accessorKey: 'supplier',
184
- header: 'Supplier',
185
- size: 120,
186
- },
187
- ];
198
+ // ========================== STORIES ==========================
188
199
 
189
200
  export const Default: Story = {
190
- render: () => {
191
- const data = useMemo(() => generateUsers(10), []);
192
-
193
- return (
194
- <Stack gap="lg" w="100%">
195
- <Title order={3} size="md">Basic Table</Title>
196
- <DataTable
197
- data={data}
198
- columns={userColumns}
199
- totalCount={data.length}
200
- />
201
- </Stack>
202
- );
203
- },
204
- parameters: {
205
- docs: {
206
- description: {
207
- story: 'Basic table with minimal configuration showing user data.',
208
- },
209
- },
210
- },
201
+ render: args => (
202
+ <Frame title="Default">
203
+ <DemoTable {...args} />
204
+ </Frame>
205
+ ),
211
206
  };
212
207
 
213
- export const WithPagination: Story = {
214
- render: () => {
215
- const allData = useMemo(() => generateUsers(50), []);
216
- const [pagination, setPagination] = useState<PaginationState>({
217
- pageIndex: 0,
218
- pageSize: 10,
219
- });
220
-
221
- const data = useMemo(() => {
222
- const start = pagination.pageIndex * pagination.pageSize;
223
- const end = start + pagination.pageSize;
224
- return allData.slice(start, end);
225
- }, [allData, pagination]);
226
-
227
- return (
228
- <Stack gap="lg" w="100%">
229
- <Title order={3} size="md">Table with Pagination</Title>
230
- <Text size="sm" c="dimmed">
231
- Showing {data.length} of {allData.length} users
232
- </Text>
233
- <DataTable
234
- data={data}
235
- columns={userColumns}
236
- totalCount={allData.length}
237
- onPaginationChange={setPagination}
238
- defaultPageSize={10}
239
- />
240
- </Stack>
241
- );
242
- },
243
- parameters: {
244
- docs: {
245
- description: {
246
- story: 'Table with pagination controls and page size selection.',
247
- },
248
- },
249
- },
208
+ export const Loading: Story = {
209
+ args: { isLoading: true },
210
+ render: args => (
211
+ <Frame title="Loading">
212
+ <DemoTable {...args} />
213
+ </Frame>
214
+ ),
250
215
  };
251
216
 
252
- export const WithSelection: Story = {
253
- render: () => {
254
- const data = useMemo(() => generateUsers(15), []);
255
- const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
256
-
257
- const selectedCount = Object.keys(rowSelection).length;
258
-
259
- return (
260
- <Stack gap="lg" w="100%">
261
- <Title order={3} size="md">Table with Row Selection</Title>
262
- <Inline gap="sm">
263
- <Text size="sm">Selected rows: {selectedCount}</Text>
264
- {selectedCount > 0 && (
265
- <Button
266
- size="xs"
267
- variant="outline"
268
- onClick={() => setRowSelection({})}
269
- >
270
- Clear Selection
271
- </Button>
272
- )}
273
- </Inline>
274
- <DataTable
275
- data={data}
276
- columns={userColumns}
277
- totalCount={data.length}
278
- onRowSelectionChange={setRowSelection}
279
- />
280
- </Stack>
281
- );
282
- },
283
- parameters: {
284
- docs: {
285
- description: {
286
- story: 'Table with row selection checkboxes and selection management.',
287
- },
288
- },
289
- },
290
- };
291
-
292
- export const LoadingState: Story = {
293
- render: () => {
294
- const data = useMemo(() => generateUsers(5), []);
295
-
296
- return (
297
- <Stack gap="lg" w="100%">
298
- <Title order={3} size="md">Loading State</Title>
299
- <DataTable
300
- data={data}
301
- columns={userColumns}
302
- totalCount={data.length}
303
- isLoading={true}
304
- />
305
- </Stack>
306
- );
307
- },
308
- parameters: {
309
- docs: {
310
- description: {
311
- story: 'Table in loading state with skeleton placeholders.',
312
- },
313
- },
314
- },
217
+ export const Empty: Story = {
218
+ args: { rowCount: 0 },
219
+ render: args => (
220
+ <Frame title="Empty">
221
+ <DemoTable {...args} />
222
+ </Frame>
223
+ ),
315
224
  };
316
225
 
317
226
  export const ErrorState: Story = {
318
- render: () => {
319
- return (
320
- <Stack gap="lg" w="100%">
321
- <Title order={3} size="md">Error State</Title>
322
- <DataTable
323
- data={[]}
324
- columns={userColumns}
325
- totalCount={0}
326
- isError={true}
327
- error="Failed to load user data. Please try again."
328
- onRetry={() => console.log('Retry clicked')}
329
- />
330
- </Stack>
331
- );
332
- },
333
- parameters: {
334
- docs: {
335
- description: {
336
- story: 'Table in error state with retry functionality.',
337
- },
338
- },
339
- },
227
+ args: { isError: true },
228
+ render: args => (
229
+ <Frame title="Error">
230
+ <DemoTable {...args} />
231
+ </Frame>
232
+ ),
340
233
  };
341
234
 
342
- export const EmptyState: Story = {
343
- render: () => {
344
- return (
345
- <Stack gap="lg" w="100%">
346
- <Title order={3} size="md">Empty State</Title>
347
- <DataTable
348
- data={[]}
349
- columns={userColumns}
350
- totalCount={0}
351
- />
352
- </Stack>
353
- );
354
- },
355
- parameters: {
356
- docs: {
357
- description: {
358
- story: 'Table with no data showing empty state message.',
359
- },
360
- },
361
- },
235
+ export const WithSelection: Story = {
236
+ args: { initialSelection: { 'person-1': true, 'person-2': true, 'person-3': true } },
237
+ render: args => (
238
+ <Frame title="With selection">
239
+ <DemoTable {...args} />
240
+ </Frame>
241
+ ),
362
242
  };
363
243
 
364
- export const ProductTable: Story = {
365
- render: () => {
366
- const data = useMemo(() => generateProducts(20), []);
367
- const [pagination, setPagination] = useState<PaginationState>({
368
- pageIndex: 0,
369
- pageSize: 8,
370
- });
371
-
372
- const paginatedData = useMemo(() => {
373
- const start = pagination.pageIndex * pagination.pageSize;
374
- const end = start + pagination.pageSize;
375
- return data.slice(start, end);
376
- }, [data, pagination]);
377
-
378
- return (
379
- <Stack gap="lg" w="100%">
380
- <Title order={3} size="md">Product Inventory Table</Title>
381
- <Text size="sm" c="dimmed">
382
- Product catalog with pricing, stock levels, and supplier information
383
- </Text>
384
- <DataTable
385
- data={paginatedData}
386
- columns={productColumns}
387
- totalCount={data.length}
388
- onPaginationChange={setPagination}
389
- defaultPageSize={8}
390
- />
391
- </Stack>
392
- );
393
- },
394
- parameters: {
395
- docs: {
396
- description: {
397
- story: 'Product inventory table with custom cell renderers and formatting.',
398
- },
399
- },
400
- },
244
+ export const Compact: Story = {
245
+ args: { initialDensity: 'xs' },
246
+ render: args => (
247
+ <Frame title="Density xs (10px)">
248
+ <DemoTable {...args} />
249
+ </Frame>
250
+ ),
401
251
  };
402
252
 
403
- export const FullFeatured: Story = {
404
- render: () => {
405
- const allData = useMemo(() => generateUsers(100), []);
406
- const [pagination, setPagination] = useState<PaginationState>({
407
- pageIndex: 0,
408
- pageSize: 15,
409
- });
410
- const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
411
- const [filters, setFilters] = useState({});
412
-
413
- const data = useMemo(() => {
414
- const start = pagination.pageIndex * pagination.pageSize;
415
- const end = start + pagination.pageSize;
416
- return allData.slice(start, end);
417
- }, [allData, pagination]);
418
-
419
- const selectedCount = Object.keys(rowSelection).length;
420
-
421
- return (
422
- <Stack gap="lg" w="100%">
423
- <Title order={3} size="md">Full-Featured Table</Title>
424
- <Text size="sm" c="dimmed">
425
- Complete table with all features: pagination, selection, filtering, sorting, density controls, and fullscreen mode
426
- </Text>
427
-
428
- {selectedCount > 0 && (
429
- <Inline gap="sm">
430
- <Text size="sm" fw={500}>
431
- {selectedCount} row{selectedCount !== 1 ? 's' : ''} selected
432
- </Text>
433
- <Button size="xs" variant="outline" onClick={() => setRowSelection({})}>
434
- Clear Selection
435
- </Button>
436
- <Button size="xs" variant="primary">
437
- Bulk Action
438
- </Button>
439
- </Inline>
440
- )}
441
-
442
- <DataTable
443
- data={data}
444
- columns={userColumns}
445
- totalCount={allData.length}
446
- onPaginationChange={setPagination}
447
- onRowSelectionChange={setRowSelection}
448
- filtersState={filters}
449
- onFiltersChange={setFilters}
450
- defaultPageSize={15}
451
- showFilters={true}
452
- showSearch={true}
453
- showDensityToggle={true}
454
- showFullScreenToggle={true}
455
- />
456
- </Stack>
457
- );
458
- },
459
- parameters: {
460
- docs: {
461
- description: {
462
- story: 'Full-featured table demonstrating all available functionality and controls.',
463
- },
464
- },
465
- },
253
+ export const Comfortable: Story = {
254
+ args: { initialDensity: 'xl' },
255
+ render: args => (
256
+ <Frame title="Density xl (32px)">
257
+ <DemoTable {...args} />
258
+ </Frame>
259
+ ),
466
260
  };
467
-
468
- export const Interactive: Story = {
469
- args: {
470
- isLoading: false,
471
- isError: false,
472
- showFilters: true,
473
- showSearch: true,
474
- showDensityToggle: true,
475
- showFullScreenToggle: true,
476
- },
477
- render: (args) => {
478
- const data = useMemo(() => generateUsers(12), []);
479
-
480
- return (
481
- <Stack gap="lg" w="100%">
482
- <Title order={3} size="md">Interactive Table</Title>
483
- <Text size="sm" c="dimmed">
484
- Use the controls below to customize the table behavior and appearance
485
- </Text>
486
- <DataTable
487
- {...args}
488
- data={data}
489
- columns={userColumns}
490
- totalCount={data.length}
491
- />
492
- </Stack>
493
- );
494
- },
495
- parameters: {
496
- docs: {
497
- description: {
498
- story: 'Use the controls below to interact with the Table and see different combinations.',
499
- },
500
- },
501
- },
502
- };