banhaten 0.1.0

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 (201) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +361 -0
  3. package/banhaten.config.example.json +13 -0
  4. package/package.json +59 -0
  5. package/registry/assets/activity-feed-avatar.png +0 -0
  6. package/registry/assets/avatars/avatar-01.jpg +0 -0
  7. package/registry/assets/avatars/avatar-02.jpg +0 -0
  8. package/registry/assets/avatars/avatar-03.jpg +0 -0
  9. package/registry/assets/avatars/avatar-04.jpg +0 -0
  10. package/registry/assets/avatars/avatar-05.jpg +0 -0
  11. package/registry/assets/avatars/avatar-06.jpg +0 -0
  12. package/registry/assets/avatars/avatar-07.jpg +0 -0
  13. package/registry/assets/avatars/avatar-08.jpg +0 -0
  14. package/registry/assets/avatars/avatar-09.jpg +0 -0
  15. package/registry/assets/avatars/avatar-10.jpg +0 -0
  16. package/registry/assets/avatars/avatar-11.jpg +0 -0
  17. package/registry/assets/avatars/avatar-12.jpg +0 -0
  18. package/registry/assets/avatars/avatar-13.jpg +0 -0
  19. package/registry/assets/avatars/avatar-14.jpg +0 -0
  20. package/registry/assets/avatars/avatar-15.jpg +0 -0
  21. package/registry/assets/avatars/avatar-16.jpg +0 -0
  22. package/registry/assets/avatars/avatar-17.jpg +0 -0
  23. package/registry/assets/avatars/avatar-18.jpg +0 -0
  24. package/registry/assets/avatars/avatar-19.jpg +0 -0
  25. package/registry/assets/avatars/avatar-20.jpg +0 -0
  26. package/registry/assets/avatars/avatar-21.jpg +0 -0
  27. package/registry/assets/avatars/avatar-22.jpg +0 -0
  28. package/registry/assets/avatars/avatar-23.jpg +0 -0
  29. package/registry/assets/avatars/avatar-24.jpg +0 -0
  30. package/registry/assets/avatars/avatar-25.jpg +0 -0
  31. package/registry/assets/avatars/avatar-26.jpg +0 -0
  32. package/registry/assets/avatars/avatar-27.jpg +0 -0
  33. package/registry/assets/avatars/avatar-28.jpg +0 -0
  34. package/registry/assets/avatars/avatar-29.jpg +0 -0
  35. package/registry/assets/avatars/avatar-30.jpg +0 -0
  36. package/registry/assets/avatars/avatar-31.jpg +0 -0
  37. package/registry/assets/avatars/avatar-32.jpg +0 -0
  38. package/registry/assets/avatars/avatar-33.jpg +0 -0
  39. package/registry/assets/avatars/avatar-34.jpg +0 -0
  40. package/registry/assets/avatars/avatar-35.jpg +0 -0
  41. package/registry/assets/image-assets.json +744 -0
  42. package/registry/assets/images/art-01.jpg +0 -0
  43. package/registry/assets/images/art-02.jpg +0 -0
  44. package/registry/assets/images/art-03.jpg +0 -0
  45. package/registry/assets/images/art-04.jpg +0 -0
  46. package/registry/assets/images/art-05.jpg +0 -0
  47. package/registry/assets/images/art-06.jpg +0 -0
  48. package/registry/assets/images/art-07.jpg +0 -0
  49. package/registry/assets/images/art-08.jpg +0 -0
  50. package/registry/assets/images/art-09.jpg +0 -0
  51. package/registry/assets/images/art-10.jpg +0 -0
  52. package/registry/assets/images/art-11.jpg +0 -0
  53. package/registry/assets/images/art-12.jpg +0 -0
  54. package/registry/assets/images/art-13.jpg +0 -0
  55. package/registry/assets/images/art-14.jpg +0 -0
  56. package/registry/assets/images/art-15.jpg +0 -0
  57. package/registry/assets/images/art-16.jpg +0 -0
  58. package/registry/assets/images/art-17.jpg +0 -0
  59. package/registry/assets/images/art-18.jpg +0 -0
  60. package/registry/assets/images/art-19.jpg +0 -0
  61. package/registry/assets/images/art-20.jpg +0 -0
  62. package/registry/assets/images/art-21.jpg +0 -0
  63. package/registry/assets/images/art-22.jpg +0 -0
  64. package/registry/assets/images/art-23.jpg +0 -0
  65. package/registry/assets/images/art-24.jpg +0 -0
  66. package/registry/assets/images/art-25.jpg +0 -0
  67. package/registry/assets/images/art-26.jpg +0 -0
  68. package/registry/assets/images/art-27.jpg +0 -0
  69. package/registry/assets/images/nature-01.jpg +0 -0
  70. package/registry/assets/images/nature-02.jpg +0 -0
  71. package/registry/assets/images/nature-03.jpg +0 -0
  72. package/registry/assets/images/nature-04.jpg +0 -0
  73. package/registry/assets/images/nature-05.jpg +0 -0
  74. package/registry/assets/images/nature-06.jpg +0 -0
  75. package/registry/assets/images/nature-07.jpg +0 -0
  76. package/registry/assets/images/nature-08.jpg +0 -0
  77. package/registry/assets/images/nature-09.jpg +0 -0
  78. package/registry/assets/images/nature-10.jpg +0 -0
  79. package/registry/assets/images/nature-11.jpg +0 -0
  80. package/registry/assets/images/nature-12.jpg +0 -0
  81. package/registry/assets/images/nature-13.jpg +0 -0
  82. package/registry/assets/images/nature-14.jpg +0 -0
  83. package/registry/assets/images/nature-15.jpg +0 -0
  84. package/registry/assets/images/nature-16.jpg +0 -0
  85. package/registry/assets/images/nature-17.jpg +0 -0
  86. package/registry/assets/images/nature-18.jpg +0 -0
  87. package/registry/assets/images/nature-19.jpg +0 -0
  88. package/registry/assets/images/nature-20.jpg +0 -0
  89. package/registry/components/accordion.tsx +119 -0
  90. package/registry/components/alert.tsx +282 -0
  91. package/registry/components/attribute.tsx +452 -0
  92. package/registry/components/avatar.tsx +142 -0
  93. package/registry/components/badge.tsx +567 -0
  94. package/registry/components/button-group.tsx +246 -0
  95. package/registry/components/button.tsx +102 -0
  96. package/registry/components/card.tsx +613 -0
  97. package/registry/components/checkbox.tsx +244 -0
  98. package/registry/components/date-picker.tsx +1143 -0
  99. package/registry/components/divider.tsx +82 -0
  100. package/registry/components/expanded/ActivityFeed.tsx +226 -0
  101. package/registry/components/expanded/Banner.tsx +145 -0
  102. package/registry/components/expanded/BannerBoard.tsx +225 -0
  103. package/registry/components/expanded/Breadcrumbs.tsx +156 -0
  104. package/registry/components/expanded/CatalogComponentsShowcase.tsx +211 -0
  105. package/registry/components/expanded/CatalogDivider.tsx +48 -0
  106. package/registry/components/expanded/CatalogTag.tsx +92 -0
  107. package/registry/components/expanded/CommandBar.tsx +406 -0
  108. package/registry/components/expanded/FileUpload.tsx +231 -0
  109. package/registry/components/expanded/IconExplorer.tsx +612 -0
  110. package/registry/components/expanded/OnboardingStepListItem.tsx +67 -0
  111. package/registry/components/expanded/PageHeader.tsx +184 -0
  112. package/registry/components/expanded/Slideout.tsx +514 -0
  113. package/registry/components/expanded/Steps.tsx +266 -0
  114. package/registry/components/expanded/Table.tsx +1014 -0
  115. package/registry/components/expanded/Tabs.tsx +86 -0
  116. package/registry/components/expanded/Timeline.tsx +235 -0
  117. package/registry/components/expanded/TimelineShowcase.tsx +158 -0
  118. package/registry/components/expanded/activityFeed.css +292 -0
  119. package/registry/components/expanded/banner.css +312 -0
  120. package/registry/components/expanded/breadcrumbs.css +140 -0
  121. package/registry/components/expanded/catalogComponentsShowcase.css +87 -0
  122. package/registry/components/expanded/commandBar.css +473 -0
  123. package/registry/components/expanded/divider.css +75 -0
  124. package/registry/components/expanded/fileUpload.css +228 -0
  125. package/registry/components/expanded/iconExplorer.css +764 -0
  126. package/registry/components/expanded/iconPacks.ts +866 -0
  127. package/registry/components/expanded/onboardingStepListItem.css +126 -0
  128. package/registry/components/expanded/pageHeader.css +287 -0
  129. package/registry/components/expanded/slideout.css +955 -0
  130. package/registry/components/expanded/steps.css +329 -0
  131. package/registry/components/expanded/table.css +607 -0
  132. package/registry/components/expanded/tabs.css +197 -0
  133. package/registry/components/expanded/tag.css +148 -0
  134. package/registry/components/expanded/timeline.css +282 -0
  135. package/registry/components/input-content.ts +106 -0
  136. package/registry/components/input.tsx +866 -0
  137. package/registry/components/menu.tsx +758 -0
  138. package/registry/components/modal.tsx +799 -0
  139. package/registry/components/pagination.tsx +543 -0
  140. package/registry/components/progress-slider.tsx +216 -0
  141. package/registry/components/progress.tsx +367 -0
  142. package/registry/components/radio-card.tsx +654 -0
  143. package/registry/components/radio-group.tsx +570 -0
  144. package/registry/components/select-content.tsx +313 -0
  145. package/registry/components/select.tsx +871 -0
  146. package/registry/components/slider.tsx +380 -0
  147. package/registry/components/social-button.tsx +360 -0
  148. package/registry/components/spinner.tsx +31 -0
  149. package/registry/components/tag.tsx +423 -0
  150. package/registry/components/textarea.tsx +625 -0
  151. package/registry/components/toggle.tsx +272 -0
  152. package/registry/components/toolbar.tsx +467 -0
  153. package/registry/components/tooltip.tsx +427 -0
  154. package/registry/examples/accordion-demo.tsx +34 -0
  155. package/registry/examples/alert-demo.tsx +14 -0
  156. package/registry/examples/attribute-demo.tsx +65 -0
  157. package/registry/examples/avatar-demo.tsx +74 -0
  158. package/registry/examples/badge-demo.tsx +53 -0
  159. package/registry/examples/button-demo.tsx +83 -0
  160. package/registry/examples/button-group-demo.tsx +42 -0
  161. package/registry/examples/card-demo.tsx +48 -0
  162. package/registry/examples/checkbox-demo.tsx +67 -0
  163. package/registry/examples/date-picker-demo.tsx +74 -0
  164. package/registry/examples/divider-demo.tsx +17 -0
  165. package/registry/examples/expanded/activity-feed-demo.tsx +22 -0
  166. package/registry/examples/expanded/banner-demo.tsx +23 -0
  167. package/registry/examples/expanded/catalog-components-demo.tsx +5 -0
  168. package/registry/examples/expanded/command-bar-demo.tsx +10 -0
  169. package/registry/examples/expanded/icons-demo.tsx +5 -0
  170. package/registry/examples/expanded/onboarding-step-demo.tsx +11 -0
  171. package/registry/examples/expanded/page-header-demo.tsx +19 -0
  172. package/registry/examples/expanded/slideout-demo.tsx +15 -0
  173. package/registry/examples/expanded/steps-demo.tsx +18 -0
  174. package/registry/examples/expanded/tabs-demo.tsx +13 -0
  175. package/registry/examples/expanded/timeline-demo.tsx +18 -0
  176. package/registry/examples/input-demo.tsx +87 -0
  177. package/registry/examples/menu-demo.tsx +109 -0
  178. package/registry/examples/modal-demo.tsx +16 -0
  179. package/registry/examples/pagination-demo.tsx +17 -0
  180. package/registry/examples/progress-demo.tsx +37 -0
  181. package/registry/examples/progress-slider-demo.tsx +29 -0
  182. package/registry/examples/radio-card-demo.tsx +51 -0
  183. package/registry/examples/radio-group-demo.tsx +62 -0
  184. package/registry/examples/select-demo.tsx +73 -0
  185. package/registry/examples/slider-demo.tsx +31 -0
  186. package/registry/examples/social-button-demo.tsx +51 -0
  187. package/registry/examples/tag-demo.tsx +29 -0
  188. package/registry/examples/textarea-demo.tsx +79 -0
  189. package/registry/examples/toggle-demo.tsx +59 -0
  190. package/registry/examples/toolbar-demo.tsx +80 -0
  191. package/registry/examples/tooltip-demo.tsx +115 -0
  192. package/registry/hooks/use-direction.ts +27 -0
  193. package/registry/index.json +1213 -0
  194. package/registry/styles/globals.css +4600 -0
  195. package/registry/utils/cn.ts +6 -0
  196. package/src/cli/index.js +826 -0
  197. package/tokens/Color mode.zip +0 -0
  198. package/tokens/Numbers.zip +0 -0
  199. package/tokens/Radius.zip +0 -0
  200. package/tokens/Theme.zip +0 -0
  201. package/tokens/banhaten.tokens.json +5525 -0
@@ -0,0 +1,1014 @@
1
+ import { useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react";
2
+ import { Pagination, type PaginationPage, type PaginationProps } from "@/components/ui/pagination";
3
+ import { Spinner } from "@/components/ui/spinner";
4
+ import {
5
+ Toolbar,
6
+ ToolbarBadge,
7
+ ToolbarButton,
8
+ ToolbarSearch,
9
+ ToolbarSection,
10
+ ToolbarText,
11
+ type ToolbarButtonProps,
12
+ } from "@/components/ui/toolbar";
13
+ import "./table.css";
14
+
15
+ export type TableDirection = "ltr" | "rtl";
16
+ export type TableSize = "sm" | "lg";
17
+ export type TableRowState = "default" | "selected" | "disabled";
18
+ export type TableSortDirection = "asc" | "desc";
19
+ export type TableSortValue = string | number | boolean | Date | null | undefined;
20
+ export type TableSortState = {
21
+ columnId: string;
22
+ direction: TableSortDirection;
23
+ } | null;
24
+
25
+ export type TableRowBase = {
26
+ id: string;
27
+ state?: TableRowState;
28
+ };
29
+
30
+ export type TableColumn<Row extends TableRowBase> = {
31
+ align?: "start" | "center" | "end";
32
+ header?: string;
33
+ id: string;
34
+ item?: TableItemFactory<Row>;
35
+ kind?: "data" | "selection" | "actions";
36
+ minWidth?: number;
37
+ renderCell?: (row: Row) => ReactNode;
38
+ searchValue?: (row: Row) => string;
39
+ sortable?: boolean;
40
+ sortValue?: (row: Row) => TableSortValue;
41
+ width?: number | "fill";
42
+ };
43
+
44
+ export type TableItemFactory<Row extends TableRowBase> = (row: Row) => TableItem;
45
+
46
+ export type BadgeItem = {
47
+ dot?: boolean;
48
+ label: string;
49
+ tone?: "blue" | "fuchsia" | "amber" | "neutral" | "success" | "warning" | "danger";
50
+ };
51
+
52
+ export type AvatarItem = {
53
+ alt: string;
54
+ src?: string;
55
+ };
56
+
57
+ export type TableAction = {
58
+ icon: "view" | "edit" | "delete" | "more";
59
+ label: string;
60
+ onAction?: () => void;
61
+ };
62
+
63
+ export type TableItem =
64
+ | { type: "checkbox"; checked: boolean; indeterminate?: boolean }
65
+ | { type: "text"; tone?: "default" | "subtle"; value: string; weight?: "regular" | "medium" }
66
+ | { type: "avatarText"; caption?: string; name: string; src?: string; status?: "top" | "bottom" }
67
+ | { type: "rating"; max?: 5; value: number }
68
+ | { type: "progress"; label?: string; tone?: "success" | "brand"; value: number }
69
+ | { type: "toggle"; checked: boolean; disabled?: boolean }
70
+ | { type: "badges"; items: BadgeItem[]; maxVisible?: number }
71
+ | { type: "onlyAvatar"; alt: string; src?: string }
72
+ | { type: "avatarStack"; avatars: AvatarItem[]; canAdd?: boolean; count?: number }
73
+ | { type: "tags"; items: string[]; maxVisible?: number }
74
+ | { type: "file"; label?: string }
75
+ | { type: "brandLogoText"; label: string; logoSrc?: string }
76
+ | { type: "payment"; brand: string; label?: string }
77
+ | { type: "image"; label: string; src: string }
78
+ | { type: "action"; icon: TableAction["icon"]; label: string; onAction?: () => void }
79
+ | { type: "actionGroup"; actions: TableAction[] };
80
+
81
+ export type TableProps<Row extends TableRowBase> = {
82
+ columns: TableColumn<Row>[];
83
+ dir?: TableDirection;
84
+ onSelectedRowIdsChange?: (rowIds: string[]) => void;
85
+ onSortChange?: (sort: TableSortState) => void;
86
+ rows: Row[];
87
+ selectedRowIds?: string[];
88
+ size?: TableSize;
89
+ sort?: TableSortState;
90
+ };
91
+
92
+ export type DataTableAction = {
93
+ ariaLabel?: string;
94
+ disabled?: boolean;
95
+ label: string;
96
+ onAction?: () => void;
97
+ variant?: ToolbarButtonProps["variant"];
98
+ };
99
+
100
+ export type DataTableFilter<Row extends TableRowBase> = {
101
+ active?: boolean;
102
+ id: string;
103
+ label: string;
104
+ onAction?: () => void;
105
+ predicate?: (row: Row) => boolean;
106
+ value?: string;
107
+ };
108
+
109
+ export type DataTableSearch<Row extends TableRowBase> =
110
+ | boolean
111
+ | {
112
+ defaultValue?: string;
113
+ disabled?: boolean;
114
+ getRowText?: (row: Row) => string;
115
+ label?: string;
116
+ onValueChange?: (value: string) => void;
117
+ placeholder?: string;
118
+ value?: string;
119
+ };
120
+
121
+ export type DataTablePagination = {
122
+ defaultPage?: number;
123
+ manual?: boolean;
124
+ onPageChange?: (page: number) => void;
125
+ page?: number;
126
+ pageSize?: number;
127
+ pages?: PaginationPage[];
128
+ showCaption?: boolean;
129
+ totalRows?: number;
130
+ type?: PaginationProps["type"];
131
+ variant?: PaginationProps["variant"];
132
+ };
133
+
134
+ export type DataTableState = {
135
+ action?: DataTableAction;
136
+ description?: ReactNode;
137
+ title?: ReactNode;
138
+ };
139
+
140
+ export type DataTableLabels = {
141
+ emptyDescription: ReactNode;
142
+ emptyTitle: ReactNode;
143
+ errorDescription: ReactNode;
144
+ errorTitle: ReactNode;
145
+ loadingDescription: ReactNode;
146
+ loadingTitle: ReactNode;
147
+ resultsSummary: (summary: { from: number; to: number; total: number }) => ReactNode;
148
+ searchPlaceholder: string;
149
+ selectedCount: (count: number) => ReactNode;
150
+ };
151
+
152
+ export type DataTableProps<Row extends TableRowBase> = Omit<TableProps<Row>, "onSortChange" | "rows" | "sort"> & {
153
+ actions?: DataTableAction[];
154
+ bulkActions?: DataTableAction[];
155
+ className?: string;
156
+ defaultSort?: TableSortState;
157
+ description?: ReactNode;
158
+ emptyState?: DataTableState;
159
+ error?: boolean | string | DataTableState;
160
+ filters?: DataTableFilter<Row>[];
161
+ getRowSearchText?: (row: Row) => string;
162
+ labels?: Partial<DataTableLabels>;
163
+ loading?: boolean;
164
+ onSortChange?: (sort: TableSortState) => void;
165
+ pagination?: false | DataTablePagination;
166
+ rows: Row[];
167
+ search?: DataTableSearch<Row>;
168
+ sort?: TableSortState;
169
+ title?: ReactNode;
170
+ };
171
+
172
+ function cx(...classes: Array<string | false | undefined>) {
173
+ return classes.filter(Boolean).join(" ");
174
+ }
175
+
176
+ export function Table<Row extends TableRowBase>({
177
+ columns,
178
+ dir = "ltr",
179
+ onSelectedRowIdsChange,
180
+ onSortChange,
181
+ rows,
182
+ selectedRowIds = [],
183
+ size = "sm",
184
+ sort = null,
185
+ }: TableProps<Row>) {
186
+ const selectableRows = rows.filter((row) => row.state !== "disabled");
187
+ const allSelected = selectableRows.length > 0 && selectableRows.every((row) => selectedRowIds.includes(row.id));
188
+ const someSelected = selectableRows.some((row) => selectedRowIds.includes(row.id)) && !allSelected;
189
+
190
+ function toggleAll(checked: boolean) {
191
+ onSelectedRowIdsChange?.(checked ? selectableRows.map((row) => row.id) : []);
192
+ }
193
+
194
+ function toggleRow(row: Row, checked: boolean) {
195
+ if (row.state === "disabled") return;
196
+ const next = checked
197
+ ? Array.from(new Set([...selectedRowIds, row.id]))
198
+ : selectedRowIds.filter((rowId) => rowId !== row.id);
199
+ onSelectedRowIdsChange?.(next);
200
+ }
201
+
202
+ return (
203
+ <div className={`ds-table-wrap ds-table-wrap--${size}`} dir={dir}>
204
+ <table className="ds-table">
205
+ <thead>
206
+ <tr>
207
+ {columns.map((column) => (
208
+ <th
209
+ aria-sort={column.sortable ? getAriaSort(sort, column.id) : undefined}
210
+ className={columnClass(column)}
211
+ key={column.id}
212
+ style={columnStyle(column)}
213
+ scope="col"
214
+ >
215
+ {column.kind === "selection" ? (
216
+ <SelectionCheckbox
217
+ checked={allSelected}
218
+ indeterminate={someSelected}
219
+ label="Select all rows"
220
+ onChange={toggleAll}
221
+ />
222
+ ) : column.header ? (
223
+ column.sortable ? (
224
+ onSortChange ? (
225
+ <button
226
+ aria-label={`Sort by ${column.header}`}
227
+ className={cx(
228
+ "ds-table__sort",
229
+ sort?.columnId === column.id && `ds-table__sort--${sort.direction}`,
230
+ )}
231
+ onClick={() => onSortChange(getNextSort(sort, column.id))}
232
+ type="button"
233
+ >
234
+ <span>{column.header}</span>
235
+ <SortIcon direction={sort?.columnId === column.id ? sort.direction : undefined} />
236
+ </button>
237
+ ) : (
238
+ <span className="ds-table__sort ds-table__sort--static">
239
+ <span>{column.header}</span>
240
+ <SortIcon />
241
+ </span>
242
+ )
243
+ ) : (
244
+ column.header
245
+ )
246
+ ) : null}
247
+ </th>
248
+ ))}
249
+ </tr>
250
+ </thead>
251
+ <tbody>
252
+ {rows.map((row) => {
253
+ const selected = selectedRowIds.includes(row.id);
254
+ const state = row.state === "disabled" ? "disabled" : selected ? "selected" : row.state ?? "default";
255
+
256
+ return (
257
+ <tr aria-selected={selected || undefined} className={`ds-table__row ds-table__row--${state}`} key={row.id}>
258
+ {columns.map((column) => (
259
+ <td className={columnClass(column)} key={column.id} style={columnStyle(column)}>
260
+ {column.kind === "selection" ? (
261
+ <SelectionCheckbox
262
+ checked={selected}
263
+ disabled={row.state === "disabled"}
264
+ label={`Select row ${row.id}`}
265
+ onChange={(checked) => toggleRow(row, checked)}
266
+ />
267
+ ) : column.renderCell ? (
268
+ column.renderCell(row)
269
+ ) : column.item ? (
270
+ renderTableItem(column.item(row))
271
+ ) : null}
272
+ </td>
273
+ ))}
274
+ </tr>
275
+ );
276
+ })}
277
+ </tbody>
278
+ </table>
279
+ </div>
280
+ );
281
+ }
282
+
283
+ const defaultDataTablePagination: DataTablePagination = {};
284
+
285
+ const defaultDataTableLabels: DataTableLabels = {
286
+ emptyDescription: "Try adjusting the search or filters.",
287
+ emptyTitle: "No rows found",
288
+ errorDescription: "Refresh the table or try again later.",
289
+ errorTitle: "Table unavailable",
290
+ loadingDescription: "Please wait while the table updates.",
291
+ loadingTitle: "Loading rows",
292
+ resultsSummary: ({ from, to, total }) => (total === 0 ? "Showing 0 rows" : `Showing ${from} to ${to} of ${total} rows`),
293
+ searchPlaceholder: "Search rows...",
294
+ selectedCount: (count) => `${count} selected`,
295
+ };
296
+
297
+ export function DataTable<Row extends TableRowBase>({
298
+ actions = [],
299
+ bulkActions = [],
300
+ className,
301
+ columns,
302
+ defaultSort = null,
303
+ description,
304
+ dir = "ltr",
305
+ emptyState,
306
+ error = false,
307
+ filters = [],
308
+ getRowSearchText,
309
+ labels: labelOverrides,
310
+ loading = false,
311
+ onSelectedRowIdsChange,
312
+ onSortChange,
313
+ pagination = defaultDataTablePagination,
314
+ rows,
315
+ search = true,
316
+ selectedRowIds = [],
317
+ size = "sm",
318
+ sort,
319
+ title,
320
+ }: DataTableProps<Row>) {
321
+ const labels: DataTableLabels = { ...defaultDataTableLabels, ...labelOverrides };
322
+ const searchConfig = search === true ? {} : search && typeof search === "object" ? search : null;
323
+ const paginationConfig = pagination === false ? null : pagination;
324
+ const [uncontrolledSearch, setUncontrolledSearch] = useState(() => searchConfig?.defaultValue ?? "");
325
+ const [uncontrolledSort, setUncontrolledSort] = useState<TableSortState>(() => sort ?? defaultSort);
326
+ const [uncontrolledPage, setUncontrolledPage] = useState(() => paginationConfig?.page ?? paginationConfig?.defaultPage ?? 1);
327
+ const selectedSort = sort !== undefined ? sort : uncontrolledSort;
328
+ const searchValue = searchConfig?.value ?? uncontrolledSearch;
329
+ const normalizedSearchValue = searchValue.trim().toLowerCase();
330
+
331
+ const processedRows = useMemo(() => {
332
+ let nextRows = rows;
333
+
334
+ if (normalizedSearchValue) {
335
+ nextRows = nextRows.filter((row) =>
336
+ getDataTableSearchText({
337
+ columns,
338
+ getRowSearchText: getRowSearchText ?? searchConfig?.getRowText,
339
+ row,
340
+ })
341
+ .toLowerCase()
342
+ .includes(normalizedSearchValue),
343
+ );
344
+ }
345
+
346
+ for (const filter of filters) {
347
+ if (filter.active && filter.predicate) {
348
+ nextRows = nextRows.filter(filter.predicate);
349
+ }
350
+ }
351
+
352
+ return sortDataTableRows(nextRows, columns, selectedSort);
353
+ }, [columns, filters, getRowSearchText, normalizedSearchValue, rows, searchConfig?.getRowText, selectedSort]);
354
+
355
+ const pageSize = Math.max(1, paginationConfig?.pageSize ?? 10);
356
+ const totalRows = paginationConfig?.totalRows ?? processedRows.length;
357
+ const pageCount = Math.max(1, Math.ceil(Math.max(totalRows, 0) / pageSize));
358
+ const currentPage = paginationConfig ? clampNumber(paginationConfig.page ?? uncontrolledPage, 1, pageCount) : 1;
359
+ const startIndex = (currentPage - 1) * pageSize;
360
+ const displayedRows = paginationConfig?.manual ? processedRows : paginationConfig ? processedRows.slice(startIndex, startIndex + pageSize) : processedRows;
361
+ const visibleFrom = totalRows === 0 ? 0 : startIndex + 1;
362
+ const visibleTo = paginationConfig?.manual ? Math.min(currentPage * pageSize, totalRows) : Math.min(startIndex + displayedRows.length, totalRows);
363
+ const hasHeader = Boolean(title || description || actions.length > 0);
364
+ const hasToolbar = Boolean(searchConfig || filters.length > 0 || selectedRowIds.length > 0 || bulkActions.length > 0);
365
+ const activeBulkActions = selectedRowIds.length > 0 ? bulkActions : [];
366
+ const state = getDataTableState({
367
+ emptyState,
368
+ error,
369
+ labels,
370
+ loading,
371
+ rowCount: processedRows.length,
372
+ });
373
+
374
+ function setDataTablePage(nextPage: number) {
375
+ if (!paginationConfig) return;
376
+
377
+ const safePage = clampNumber(nextPage, 1, pageCount);
378
+ if (paginationConfig.page === undefined) {
379
+ setUncontrolledPage(safePage);
380
+ }
381
+ paginationConfig.onPageChange?.(safePage);
382
+ }
383
+
384
+ function resetPagination() {
385
+ setDataTablePage(1);
386
+ }
387
+
388
+ function handleSearchChange(value: string) {
389
+ if (searchConfig?.value === undefined) {
390
+ setUncontrolledSearch(value);
391
+ }
392
+ searchConfig?.onValueChange?.(value);
393
+ resetPagination();
394
+ }
395
+
396
+ function handleSortChange(nextSort: TableSortState) {
397
+ if (sort === undefined) {
398
+ setUncontrolledSort(nextSort);
399
+ }
400
+ onSortChange?.(nextSort);
401
+ resetPagination();
402
+ }
403
+
404
+ return (
405
+ <section className={cx("ds-data-table", className)} dir={dir}>
406
+ {hasHeader && (
407
+ <header className="ds-data-table__header">
408
+ <div className="ds-data-table__heading">
409
+ {title && <h2>{title}</h2>}
410
+ {description && <p>{description}</p>}
411
+ </div>
412
+ {actions.length > 0 && (
413
+ <div className="ds-data-table__actions">
414
+ {actions.map((action) => (
415
+ <DataTableActionButton action={action} key={action.label} />
416
+ ))}
417
+ </div>
418
+ )}
419
+ </header>
420
+ )}
421
+
422
+ {hasToolbar && (
423
+ <Toolbar className="ds-data-table__toolbar" dir={dir} layout="split" wrap>
424
+ <ToolbarSection grow wrap>
425
+ {searchConfig && (
426
+ <ToolbarSearch
427
+ aria-label={searchConfig.label ?? "Search table rows"}
428
+ disabled={searchConfig.disabled}
429
+ onChange={(event) => handleSearchChange(event.currentTarget.value)}
430
+ placeholder={searchConfig.placeholder ?? labels.searchPlaceholder}
431
+ value={searchValue}
432
+ width="full"
433
+ />
434
+ )}
435
+ {filters.map((filter) => (
436
+ <ToolbarButton
437
+ aria-pressed={filter.active || undefined}
438
+ key={filter.id}
439
+ onClick={() => {
440
+ filter.onAction?.();
441
+ resetPagination();
442
+ }}
443
+ size="sm"
444
+ variant={filter.active ? "default" : "soft"}
445
+ >
446
+ {filter.value ? `${filter.label}: ${filter.value}` : filter.label}
447
+ </ToolbarButton>
448
+ ))}
449
+ </ToolbarSection>
450
+ {(selectedRowIds.length > 0 || activeBulkActions.length > 0) && (
451
+ <ToolbarSection align="end" wrap>
452
+ {selectedRowIds.length > 0 && <ToolbarBadge variant="brand">{labels.selectedCount(selectedRowIds.length)}</ToolbarBadge>}
453
+ {activeBulkActions.map((action) => (
454
+ <DataTableActionButton action={action} key={action.label} />
455
+ ))}
456
+ </ToolbarSection>
457
+ )}
458
+ </Toolbar>
459
+ )}
460
+
461
+ <div className="ds-data-table__body">
462
+ <Table
463
+ columns={columns}
464
+ dir={dir}
465
+ onSelectedRowIdsChange={onSelectedRowIdsChange}
466
+ onSortChange={handleSortChange}
467
+ rows={state ? [] : displayedRows}
468
+ selectedRowIds={selectedRowIds}
469
+ size={size}
470
+ sort={selectedSort}
471
+ />
472
+ {state && <DataTableStateView loading={loading} state={state} />}
473
+ </div>
474
+
475
+ {paginationConfig && (
476
+ <footer className="ds-data-table__footer">
477
+ <ToolbarText>{labels.resultsSummary({ from: visibleFrom, to: visibleTo, total: totalRows })}</ToolbarText>
478
+ <Pagination
479
+ dir={dir}
480
+ nextDisabled={currentPage >= pageCount}
481
+ onPageChange={setDataTablePage}
482
+ page={currentPage}
483
+ pages={paginationConfig.pages ?? getDataTablePaginationPages(currentPage, pageCount)}
484
+ previousDisabled={currentPage <= 1}
485
+ showCaption={paginationConfig.showCaption ?? false}
486
+ summary={labels.resultsSummary({ from: visibleFrom, to: visibleTo, total: totalRows })}
487
+ type={paginationConfig.type ?? "numeric"}
488
+ variant={paginationConfig.variant ?? "soft"}
489
+ />
490
+ </footer>
491
+ )}
492
+ </section>
493
+ );
494
+ }
495
+
496
+ function columnClass<Row extends TableRowBase>(column: TableColumn<Row>) {
497
+ return cx(
498
+ "ds-table__cell",
499
+ column.width === "fill" && "ds-table__cell--fill",
500
+ column.align && `ds-table__cell--${column.align}`,
501
+ column.kind === "selection" && "ds-table__cell--selection",
502
+ column.kind === "actions" && "ds-table__cell--actions",
503
+ );
504
+ }
505
+
506
+ function columnStyle<Row extends TableRowBase>(column: TableColumn<Row>): CSSProperties {
507
+ return {
508
+ minWidth: column.minWidth,
509
+ width: typeof column.width === "number" ? column.width : undefined,
510
+ };
511
+ }
512
+
513
+ type ResolvedDataTableState = DataTableState & {
514
+ tone: "danger" | "default" | "loading";
515
+ };
516
+
517
+ function DataTableActionButton({ action }: { action: DataTableAction }) {
518
+ return (
519
+ <ToolbarButton
520
+ aria-label={action.ariaLabel}
521
+ disabled={action.disabled}
522
+ onClick={action.onAction}
523
+ size="sm"
524
+ variant={action.variant ?? "soft"}
525
+ >
526
+ {action.label}
527
+ </ToolbarButton>
528
+ );
529
+ }
530
+
531
+ function DataTableStateView({ loading, state }: { loading: boolean; state: ResolvedDataTableState }) {
532
+ return (
533
+ <div className={`ds-data-table__state ds-data-table__state--${state.tone}`} role={state.tone === "danger" ? "alert" : "status"}>
534
+ <div className="ds-data-table__state-copy">
535
+ {loading && <Spinner className="ds-data-table__spinner" />}
536
+ {state.title && <strong>{state.title}</strong>}
537
+ {state.description && <p>{state.description}</p>}
538
+ </div>
539
+ {state.action && (
540
+ <div className="ds-data-table__state-action">
541
+ <DataTableActionButton action={state.action} />
542
+ </div>
543
+ )}
544
+ </div>
545
+ );
546
+ }
547
+
548
+ function getDataTableState({
549
+ emptyState,
550
+ error,
551
+ labels,
552
+ loading,
553
+ rowCount,
554
+ }: {
555
+ emptyState?: DataTableState;
556
+ error: boolean | string | DataTableState;
557
+ labels: DataTableLabels;
558
+ loading: boolean;
559
+ rowCount: number;
560
+ }): ResolvedDataTableState | null {
561
+ if (loading) {
562
+ return {
563
+ description: labels.loadingDescription,
564
+ title: labels.loadingTitle,
565
+ tone: "loading",
566
+ };
567
+ }
568
+
569
+ if (error) {
570
+ if (typeof error === "string") {
571
+ return {
572
+ description: error,
573
+ title: labels.errorTitle,
574
+ tone: "danger",
575
+ };
576
+ }
577
+
578
+ if (typeof error === "object") {
579
+ return {
580
+ action: error.action,
581
+ description: error.description ?? labels.errorDescription,
582
+ title: error.title ?? labels.errorTitle,
583
+ tone: "danger",
584
+ };
585
+ }
586
+
587
+ return {
588
+ description: labels.errorDescription,
589
+ title: labels.errorTitle,
590
+ tone: "danger",
591
+ };
592
+ }
593
+
594
+ if (rowCount === 0) {
595
+ return {
596
+ action: emptyState?.action,
597
+ description: emptyState?.description ?? labels.emptyDescription,
598
+ title: emptyState?.title ?? labels.emptyTitle,
599
+ tone: "default",
600
+ };
601
+ }
602
+
603
+ return null;
604
+ }
605
+
606
+ function getDataTableSearchText<Row extends TableRowBase>({
607
+ columns,
608
+ getRowSearchText,
609
+ row,
610
+ }: {
611
+ columns: TableColumn<Row>[];
612
+ getRowSearchText?: (row: Row) => string;
613
+ row: Row;
614
+ }) {
615
+ const values = [row.id, getRowSearchText?.(row)];
616
+
617
+ for (const column of columns) {
618
+ const columnValue = column.searchValue?.(row) ?? (column.item ? getTableItemText(column.item(row)) : undefined);
619
+ if (columnValue) values.push(columnValue);
620
+ }
621
+
622
+ return values.filter(Boolean).join(" ");
623
+ }
624
+
625
+ function sortDataTableRows<Row extends TableRowBase>(rows: Row[], columns: TableColumn<Row>[], sort: TableSortState) {
626
+ if (!sort) return rows;
627
+
628
+ const column = columns.find((item) => item.id === sort.columnId);
629
+ if (!column) return rows;
630
+
631
+ const direction = sort.direction === "asc" ? 1 : -1;
632
+
633
+ return [...rows].sort((left, right) => {
634
+ const result = compareTableSortValues(getColumnSortValue(column, left), getColumnSortValue(column, right));
635
+ return result * direction;
636
+ });
637
+ }
638
+
639
+ function getColumnSortValue<Row extends TableRowBase>(column: TableColumn<Row>, row: Row): TableSortValue {
640
+ if (column.sortValue) return column.sortValue(row);
641
+ if (column.item) return getTableItemSortValue(column.item(row));
642
+ return undefined;
643
+ }
644
+
645
+ function compareTableSortValues(left: TableSortValue, right: TableSortValue) {
646
+ if (left === right) return 0;
647
+ if (left === null || left === undefined) return 1;
648
+ if (right === null || right === undefined) return -1;
649
+
650
+ const normalizedLeft = normalizeTableSortValue(left);
651
+ const normalizedRight = normalizeTableSortValue(right);
652
+
653
+ if (typeof normalizedLeft === "number" && typeof normalizedRight === "number") {
654
+ return normalizedLeft - normalizedRight;
655
+ }
656
+
657
+ return String(normalizedLeft).localeCompare(String(normalizedRight), undefined, {
658
+ numeric: true,
659
+ sensitivity: "base",
660
+ });
661
+ }
662
+
663
+ function normalizeTableSortValue(value: Exclude<TableSortValue, null | undefined>) {
664
+ if (value instanceof Date) return value.getTime();
665
+ if (typeof value === "boolean") return value ? 1 : 0;
666
+ return value;
667
+ }
668
+
669
+ function getTableItemSortValue(item: TableItem): TableSortValue {
670
+ switch (item.type) {
671
+ case "avatarText":
672
+ return item.name;
673
+ case "badges":
674
+ return item.items.map((badge) => badge.label).join(" ");
675
+ case "brandLogoText":
676
+ return item.label;
677
+ case "file":
678
+ return item.label;
679
+ case "image":
680
+ return item.label;
681
+ case "payment":
682
+ return item.label ?? item.brand;
683
+ case "progress":
684
+ case "rating":
685
+ return item.value;
686
+ case "tags":
687
+ return item.items.join(" ");
688
+ case "text":
689
+ return item.value;
690
+ case "toggle":
691
+ return item.checked;
692
+ default:
693
+ return undefined;
694
+ }
695
+ }
696
+
697
+ function getTableItemText(item: TableItem) {
698
+ const value = getTableItemSortValue(item);
699
+ return value === null || value === undefined ? "" : String(value);
700
+ }
701
+
702
+ function getDataTablePaginationPages(currentPage: number, pageCount: number): PaginationPage[] {
703
+ if (pageCount <= 5) {
704
+ return Array.from({ length: pageCount }, (_, index) => index + 1);
705
+ }
706
+
707
+ const pages: PaginationPage[] = [1];
708
+ const start = Math.max(2, currentPage - 1);
709
+ const end = Math.min(pageCount - 1, currentPage + 1);
710
+
711
+ if (start > 2) pages.push("ellipsis");
712
+ for (let page = start; page <= end; page += 1) {
713
+ pages.push(page);
714
+ }
715
+ if (end < pageCount - 1) pages.push("ellipsis");
716
+ pages.push(pageCount);
717
+
718
+ return pages;
719
+ }
720
+
721
+ function getAriaSort(sort: TableSortState, columnId: string) {
722
+ if (sort?.columnId !== columnId) return "none";
723
+ return sort.direction === "asc" ? "ascending" : "descending";
724
+ }
725
+
726
+ function getNextSort(sort: TableSortState, columnId: string): TableSortState {
727
+ if (sort?.columnId !== columnId) {
728
+ return { columnId, direction: "asc" };
729
+ }
730
+
731
+ return {
732
+ columnId,
733
+ direction: sort.direction === "asc" ? "desc" : "asc",
734
+ };
735
+ }
736
+
737
+ function clampNumber(value: number, min: number, max: number) {
738
+ if (!Number.isFinite(value)) return min;
739
+ return Math.min(max, Math.max(min, Math.floor(value)));
740
+ }
741
+
742
+ function renderTableItem(item: TableItem) {
743
+ switch (item.type) {
744
+ case "checkbox":
745
+ return <SelectionCheckbox checked={item.checked} indeterminate={item.indeterminate} label="Select row" onChange={() => undefined} />;
746
+ case "text":
747
+ return <span className={`ds-table-item-text ds-table-item-text--${item.tone ?? "default"} ds-table-item-text--${item.weight ?? "regular"}`}>{item.value}</span>;
748
+ case "avatarText":
749
+ return (
750
+ <span className="ds-table-avatar-text">
751
+ <Avatar name={item.name} src={item.src} />
752
+ <span>
753
+ <strong>{item.name}</strong>
754
+ {item.caption && <em>{item.caption}</em>}
755
+ </span>
756
+ </span>
757
+ );
758
+ case "rating":
759
+ return <Rating value={item.value} max={item.max ?? 5} />;
760
+ case "progress":
761
+ return <Progress value={item.value} label={item.label} tone={item.tone ?? "success"} />;
762
+ case "toggle":
763
+ return <button aria-pressed={item.checked} className="ds-table-toggle" disabled={item.disabled} type="button"><span /></button>;
764
+ case "badges":
765
+ return <BadgeList items={item.items} maxVisible={item.maxVisible} />;
766
+ case "onlyAvatar":
767
+ return <Avatar name={item.alt} src={item.src} />;
768
+ case "avatarStack":
769
+ return <AvatarStack avatars={item.avatars} count={item.count} canAdd={item.canAdd} />;
770
+ case "tags":
771
+ return <TagList items={item.items} maxVisible={item.maxVisible} />;
772
+ case "file":
773
+ return item.label ? <IconLabel icon={<FileIcon />} label={item.label} /> : null;
774
+ case "brandLogoText":
775
+ return <IconLabel icon={item.logoSrc ? <img alt="" src={item.logoSrc} /> : <BrandIcon />} label={item.label} />;
776
+ case "payment":
777
+ return <IconLabel icon={<PaymentIcon />} label={item.label ?? item.brand} />;
778
+ case "image":
779
+ return <IconLabel icon={<img alt="" src={item.src} />} label={item.label} />;
780
+ case "action":
781
+ return <IconButton icon={item.icon} label={item.label} onClick={item.onAction} />;
782
+ case "actionGroup":
783
+ return (
784
+ <span className="ds-table-action-group">
785
+ {item.actions.map((action) => (
786
+ <IconButton key={action.label} icon={action.icon} label={action.label} onClick={action.onAction} />
787
+ ))}
788
+ </span>
789
+ );
790
+ default:
791
+ return null;
792
+ }
793
+ }
794
+
795
+ function SelectionCheckbox({
796
+ checked,
797
+ disabled = false,
798
+ indeterminate = false,
799
+ label,
800
+ onChange,
801
+ }: {
802
+ checked: boolean;
803
+ disabled?: boolean;
804
+ indeterminate?: boolean;
805
+ label: string;
806
+ onChange: (checked: boolean) => void;
807
+ }) {
808
+ const inputRef = useRef<HTMLInputElement | null>(null);
809
+
810
+ useEffect(() => {
811
+ if (inputRef.current) {
812
+ inputRef.current.indeterminate = indeterminate;
813
+ }
814
+ }, [indeterminate]);
815
+
816
+ return (
817
+ <label className="ds-table-checkbox">
818
+ <input
819
+ aria-checked={indeterminate ? "mixed" : checked}
820
+ aria-label={label}
821
+ checked={checked}
822
+ disabled={disabled}
823
+ onChange={(event) => onChange(event.currentTarget.checked)}
824
+ ref={inputRef}
825
+ type="checkbox"
826
+ />
827
+ <span aria-hidden="true">
828
+ {indeterminate ? <IndeterminateIcon /> : <CheckIcon />}
829
+ </span>
830
+ </label>
831
+ );
832
+ }
833
+
834
+ function Avatar({ name, src }: { name: string; src?: string }) {
835
+ const initials = name
836
+ .split(" ")
837
+ .map((part) => part[0])
838
+ .slice(0, 2)
839
+ .join("")
840
+ .toUpperCase();
841
+
842
+ return src ? <img alt="" className="ds-table-avatar" src={src} /> : <span className="ds-table-avatar">{initials}</span>;
843
+ }
844
+
845
+ function AvatarStack({ avatars, canAdd, count }: { avatars: AvatarItem[]; canAdd?: boolean; count?: number }) {
846
+ return (
847
+ <span className="ds-table-avatar-stack">
848
+ {avatars.slice(0, 3).map((avatar) => (
849
+ <Avatar key={avatar.alt} name={avatar.alt} src={avatar.src} />
850
+ ))}
851
+ {count ? <span className="ds-table-avatar ds-table-avatar--count">+{count}</span> : null}
852
+ {canAdd ? <button aria-label="Add person" type="button">+</button> : null}
853
+ </span>
854
+ );
855
+ }
856
+
857
+ function BadgeList({ items, maxVisible = items.length }: { items: BadgeItem[]; maxVisible?: number }) {
858
+ const visible = items.slice(0, maxVisible);
859
+ const overflow = items.length - visible.length;
860
+
861
+ return (
862
+ <span className="ds-table-badges">
863
+ {visible.map((item, index) => (
864
+ <span className={`ds-table-badge ds-table-badge--${item.tone ?? "neutral"}`} key={`${item.label}-${index}`}>
865
+ {item.dot && <i />}
866
+ {item.label}
867
+ </span>
868
+ ))}
869
+ {overflow > 0 && <span className="ds-table-badge">+{overflow}</span>}
870
+ </span>
871
+ );
872
+ }
873
+
874
+ function TagList({ items, maxVisible = items.length }: { items: string[]; maxVisible?: number }) {
875
+ const visible = items.slice(0, maxVisible);
876
+ const overflow = items.length - visible.length;
877
+
878
+ return (
879
+ <span className="ds-table-tags">
880
+ {visible.map((item, index) => (
881
+ <span key={`${item}-${index}`}>{item}</span>
882
+ ))}
883
+ {overflow > 0 && <span>+{overflow}</span>}
884
+ </span>
885
+ );
886
+ }
887
+
888
+ function Progress({ label, tone, value }: { label?: string; tone: "success" | "brand"; value: number }) {
889
+ const safeValue = Math.max(0, Math.min(100, value));
890
+
891
+ return (
892
+ <span className={`ds-table-progress ds-table-progress--${tone}`}>
893
+ <span aria-hidden="true">
894
+ <i style={{ width: `${safeValue}%` }} />
895
+ </span>
896
+ <em>{label ?? `${safeValue}%`}</em>
897
+ </span>
898
+ );
899
+ }
900
+
901
+ function Rating({ max, value }: { max: number; value: number }) {
902
+ return (
903
+ <span className="ds-table-rating" aria-label={`${value} out of ${max}`}>
904
+ {Array.from({ length: max }, (_, index) => (
905
+ <span className={index < value ? "is-filled" : undefined} key={index}>*</span>
906
+ ))}
907
+ </span>
908
+ );
909
+ }
910
+
911
+ function IconLabel({ icon, label }: { icon: ReactNode; label: string }) {
912
+ return (
913
+ <span className="ds-table-icon-label">
914
+ <span aria-hidden="true">{icon}</span>
915
+ <span>{label}</span>
916
+ </span>
917
+ );
918
+ }
919
+
920
+ function IconButton({ icon, label, onClick }: { icon: TableAction["icon"]; label: string; onClick?: () => void }) {
921
+ return (
922
+ <button aria-label={label} className="ds-table-icon-button" onClick={onClick} type="button">
923
+ {renderActionIcon(icon)}
924
+ </button>
925
+ );
926
+ }
927
+
928
+ function renderActionIcon(icon: TableAction["icon"]) {
929
+ switch (icon) {
930
+ case "view":
931
+ return <ViewIcon />;
932
+ case "edit":
933
+ return <EditIcon />;
934
+ case "delete":
935
+ return <DeleteIcon />;
936
+ case "more":
937
+ default:
938
+ return <MoreIcon />;
939
+ }
940
+ }
941
+
942
+ function CheckIcon() {
943
+ return (
944
+ <svg viewBox="0 0 16 16">
945
+ <path d="m3.5 8 3 3 6-6.4" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.8" />
946
+ </svg>
947
+ );
948
+ }
949
+
950
+ function IndeterminateIcon() {
951
+ return (
952
+ <svg viewBox="0 0 16 16">
953
+ <path d="M4 8h8" fill="none" stroke="currentColor" strokeLinecap="round" strokeWidth="1.8" />
954
+ </svg>
955
+ );
956
+ }
957
+
958
+ function SortIcon({ direction }: { direction?: TableSortDirection }) {
959
+ return (
960
+ <svg aria-hidden="true" data-direction={direction ?? "none"} viewBox="0 0 16 16">
961
+ <path d="m5 6 3-3 3 3M11 10l-3 3-3-3" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" />
962
+ </svg>
963
+ );
964
+ }
965
+
966
+ function MoreIcon() {
967
+ return (
968
+ <svg aria-hidden="true" viewBox="0 0 20 20">
969
+ <path d="M5 10h.1M10 10h.1M15 10h.1" fill="none" stroke="currentColor" strokeLinecap="round" strokeWidth="2.4" />
970
+ </svg>
971
+ );
972
+ }
973
+
974
+ function ViewIcon() {
975
+ return (
976
+ <svg aria-hidden="true" viewBox="0 0 20 20">
977
+ <path d="M2.5 10s2.7-5 7.5-5 7.5 5 7.5 5-2.7 5-7.5 5-7.5-5-7.5-5Z" fill="none" stroke="currentColor" strokeLinejoin="round" strokeWidth="1.5" />
978
+ <circle cx="10" cy="10" r="2.2" fill="none" stroke="currentColor" strokeWidth="1.5" />
979
+ </svg>
980
+ );
981
+ }
982
+
983
+ function EditIcon() {
984
+ return (
985
+ <svg aria-hidden="true" viewBox="0 0 20 20">
986
+ <path d="m4 14.6-.5 2 2-.5L15 6.6 13.5 5 4 14.6Z" fill="none" stroke="currentColor" strokeLinejoin="round" strokeWidth="1.5" />
987
+ <path d="m12.4 6.1 1.5 1.5" fill="none" stroke="currentColor" strokeLinecap="round" strokeWidth="1.5" />
988
+ </svg>
989
+ );
990
+ }
991
+
992
+ function DeleteIcon() {
993
+ return (
994
+ <svg aria-hidden="true" viewBox="0 0 20 20">
995
+ <path d="M4 6h12M8 6V4h4v2m-6 0 .7 10h6.6L14 6" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" />
996
+ </svg>
997
+ );
998
+ }
999
+
1000
+ function FileIcon() {
1001
+ return (
1002
+ <svg viewBox="0 0 20 20">
1003
+ <path d="M6 3h5.3L15 6.7V17H6V3Z" fill="none" stroke="currentColor" strokeLinejoin="round" strokeWidth="1.5" />
1004
+ </svg>
1005
+ );
1006
+ }
1007
+
1008
+ function BrandIcon() {
1009
+ return <span className="ds-table-brand-icon" />;
1010
+ }
1011
+
1012
+ function PaymentIcon() {
1013
+ return <span className="ds-table-payment-icon" />;
1014
+ }