@appdirect/design-system 0.0.16 → 0.0.18
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.
- package/bin/ad-sync-design-md.mjs +0 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/CellHoverReveal.module.css +25 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.js +24 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.tsx +44 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +25 -77
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +101 -157
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +14 -7
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +13 -7
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/CustomToolbarAlertBannerContent.module.css +4 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +8 -20
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +40 -58
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/CustomTopToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/DateRangeSelectorFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +50 -154
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +59 -205
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.js +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.ts +51 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +5 -25
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +7 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.js +16 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +26 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +38 -38
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +8 -18
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +25 -37
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +67 -378
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +170 -711
- package/dist/ComplexComponents/DataTable/DataTable.js +74 -393
- package/dist/ComplexComponents/DataTable/DataTable.tsx +229 -546
- package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +85 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +46 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +143 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/DataTableShell.module.css +38 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.js +9 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +6 -6
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +53 -24
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.js +33 -0
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.tsx +63 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/SortableHeaderCell.module.css +3 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +43 -21
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +62 -38
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.js +18 -0
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.js +19 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.tsx +59 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/ToolbarAlertBanner.module.css +15 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.js +8 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.tsx +20 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.js +27 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.ts +39 -0
- package/dist/ComplexComponents/DataTable/index.js +5 -1
- package/dist/ComplexComponents/DataTable/index.ts +13 -2
- package/dist/ComplexComponents/DataTable/table.module.css +9 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.js +6 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.ts +7 -0
- package/dist/ComplexComponents/DataTable/translations/en.js +16 -4
- package/dist/ComplexComponents/DataTable/translations/en.ts +16 -4
- package/dist/ComplexComponents/DataTable/translations/index.js +5 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +11 -1
- package/dist/ComplexComponents/DataTable/types.js +5 -0
- package/dist/ComplexComponents/DataTable/types.ts +17 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.js +3 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.ts +4 -0
- package/dist/DESIGN.md +9 -10
- package/dist/contracts/DataTable.json +83 -6
- package/dist/contracts/index.json +1 -1
- package/dist/css/foundations.css +4 -0
- package/dist/css/mantine.css +1 -1
- package/dist/css/tokens.css +3145 -0
- package/dist/index.js +3 -0
- package/dist/index.ts +14 -1
- package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +216 -458
- package/dist/stories/index.json +13 -15
- package/package.json +5 -3
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +0 -31
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +0 -76
- package/dist/hooks/useTableHandlers.js +0 -136
- package/dist/hooks/useTableHandlers.ts +0 -179
- package/dist/hooks/useTableRenderFunctions.js +0 -164
- package/dist/hooks/useTableRenderFunctions.tsx +0 -283
- package/dist/hooks/useTableState.js +0 -70
- package/dist/hooks/useTableState.ts +0 -81
|
@@ -1,502 +1,260 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/nextjs-vite';
|
|
2
|
-
import {
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
3
|
import { Stack } from '@mantine/core';
|
|
4
|
-
import {
|
|
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
|
-
//
|
|
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
|
|
9
|
+
interface Person {
|
|
24
10
|
id: string;
|
|
25
11
|
name: string;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
162
|
+
// ========================== META ==========================
|
|
163
|
+
|
|
164
|
+
const meta: Meta<typeof DemoTable> = {
|
|
68
165
|
title: 'Design System/Complex Components/DataTable',
|
|
69
|
-
component:
|
|
166
|
+
component: DemoTable,
|
|
70
167
|
parameters: {
|
|
71
168
|
layout: 'padded',
|
|
72
169
|
docs: {
|
|
73
170
|
description: {
|
|
74
|
-
component:
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
|
|
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
|
|
187
|
+
type Story = StoryObj<typeof DemoTable>;
|
|
109
188
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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
|
-
};
|