@solexllc/usx-react 0.8.0 → 0.10.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 (165) hide show
  1. package/README.md +16 -0
  2. package/dist/index.cjs +3231 -3270
  3. package/dist/index.js +3232 -3271
  4. package/package.json +4 -4
  5. package/src/components/accordion/Accordion.tsx +4 -1
  6. package/src/components/accordion/accordion.django.html +1 -1
  7. package/src/components/accordion/config.json +1 -0
  8. package/src/components/banner/Banner.tsx +3 -1
  9. package/src/components/banner/banner.django.html +1 -1
  10. package/src/components/banner/config.json +1 -0
  11. package/src/components/carousel/carousel.django-snapshot.html +0 -40
  12. package/src/components/carousel/carousel.react-snapshot.html +0 -38
  13. package/src/components/character-count/CharacterCount.tsx +3 -0
  14. package/src/components/character-count/character-count.django-snapshot.html +43 -0
  15. package/src/components/character-count/character-count.django.html +2 -2
  16. package/src/components/character-count/character-count.react-snapshot.html +37 -0
  17. package/src/components/character-count/config.json +9 -0
  18. package/src/components/checkbox/Checkbox.tsx +17 -13
  19. package/src/components/checkbox/checkbox.django-snapshot.html +18 -0
  20. package/src/components/checkbox/checkbox.django.html +6 -4
  21. package/src/components/checkbox/checkbox.react-snapshot.html +14 -0
  22. package/src/components/checkbox/config.json +10 -1
  23. package/src/components/checkbox-group/checkbox-group.django-snapshot.html +54 -0
  24. package/src/components/checkbox-group/checkbox-group.react-snapshot.html +45 -0
  25. package/src/components/combobox/Combobox.tsx +6 -1
  26. package/src/components/combobox/combobox.django-snapshot.html +141 -0
  27. package/src/components/combobox/combobox.django.html +2 -2
  28. package/src/components/combobox/combobox.react-snapshot.html +76 -0
  29. package/src/components/combobox/config.json +9 -0
  30. package/src/components/data-table/DataTable.tsx +180 -0
  31. package/src/components/data-table/README.md +42 -0
  32. package/src/components/data-table/TableBody.tsx +123 -0
  33. package/src/components/{table → data-table}/TableCell.tsx +6 -3
  34. package/src/components/data-table/TableContext.tsx +49 -0
  35. package/src/components/{table → data-table}/TableFoot.tsx +8 -7
  36. package/src/components/data-table/TableGroup.tsx +62 -0
  37. package/src/components/data-table/TableHead.tsx +126 -0
  38. package/src/components/data-table/TableRow.tsx +24 -0
  39. package/src/components/data-table/cells.ts +49 -0
  40. package/src/components/data-table/columns.ts +15 -0
  41. package/src/components/data-table/config.json +379 -0
  42. package/src/components/data-table/data-table.django-snapshot.html +13560 -0
  43. package/src/components/data-table/data-table.django.html +13 -0
  44. package/src/components/data-table/data-table.html +34 -0
  45. package/src/components/data-table/data-table.react-snapshot.html +12033 -0
  46. package/src/components/{table → data-table}/table-body.django.html +12 -12
  47. package/src/components/{table → data-table}/table-foot.django.html +6 -6
  48. package/src/components/data-table/table-group.django.html +24 -0
  49. package/src/components/data-table/table-head.django.html +21 -0
  50. package/src/components/data-table/table-row.django.html +57 -0
  51. package/src/components/{table → data-table}/types.ts +48 -5
  52. package/src/components/date-picker/DatePicker.tsx +6 -1
  53. package/src/components/date-picker/config.json +9 -0
  54. package/src/components/date-picker/date-picker.django-snapshot.html +23 -0
  55. package/src/components/date-picker/date-picker.django.html +4 -4
  56. package/src/components/date-picker/date-picker.react-snapshot.html +19 -0
  57. package/src/components/date-range-picker/DateRangePicker.tsx +11 -2
  58. package/src/components/date-range-picker/config.json +14 -0
  59. package/src/components/date-range-picker/date-range-picker.django-snapshot.html +47 -0
  60. package/src/components/date-range-picker/date-range-picker.django.html +5 -5
  61. package/src/components/date-range-picker/date-range-picker.react-snapshot.html +38 -0
  62. package/src/components/drawer/Drawer.tsx +3 -1
  63. package/src/components/drawer/config.json +4 -0
  64. package/src/components/drawer/drawer.django.html +1 -1
  65. package/src/components/file-input/FileInput.tsx +7 -2
  66. package/src/components/file-input/_contents.django.html +2 -1
  67. package/src/components/file-input/config.json +4 -0
  68. package/src/components/header/Header.tsx +15 -9
  69. package/src/components/header/config.json +1 -0
  70. package/src/components/header/header.django-snapshot.html +24 -0
  71. package/src/components/header/header.django.html +8 -4
  72. package/src/components/header/header.html +20 -0
  73. package/src/components/header/header.react-snapshot.html +20 -0
  74. package/src/components/in-page-nav/InPageNav.tsx +3 -0
  75. package/src/components/in-page-nav/config.json +1 -0
  76. package/src/components/in-page-nav/in-page-nav.django.html +1 -1
  77. package/src/components/input/Input.tsx +3 -0
  78. package/src/components/input/config.json +10 -0
  79. package/src/components/input/input.django-snapshot.html +24 -0
  80. package/src/components/input/input.django.html +4 -4
  81. package/src/components/input/input.react-snapshot.html +22 -0
  82. package/src/components/language-selector/LanguageSelector.tsx +10 -5
  83. package/src/components/language-selector/config.json +1 -0
  84. package/src/components/language-selector/language-selector.django.html +2 -2
  85. package/src/components/layout/Layout.tsx +3 -1
  86. package/src/components/layout/config.json +4 -0
  87. package/src/components/layout/layout.django.html +1 -1
  88. package/src/components/memorable-date/MemorableDate.tsx +18 -3
  89. package/src/components/memorable-date/config.json +15 -0
  90. package/src/components/memorable-date/memorable-date.django-snapshot.html +82 -0
  91. package/src/components/memorable-date/memorable-date.django.html +14 -14
  92. package/src/components/memorable-date/memorable-date.react-snapshot.html +70 -0
  93. package/src/components/modal/Modal.tsx +3 -0
  94. package/src/components/modal/config.json +1 -0
  95. package/src/components/modal/modal.django.html +1 -1
  96. package/src/components/pagination/Pagination.tsx +7 -1
  97. package/src/components/pagination/config.json +8 -0
  98. package/src/components/pagination/navigation/PaginationNavigation.tsx +10 -0
  99. package/src/components/pagination/step-options/PaginationStepOptions.tsx +3 -0
  100. package/src/components/popover/Popover.tsx +3 -0
  101. package/src/components/popover/config.json +4 -0
  102. package/src/components/popover/popover.django-snapshot.html +30 -0
  103. package/src/components/popover/popover.django.html +1 -0
  104. package/src/components/radio-buttons/RadioButtons.tsx +41 -27
  105. package/src/components/radio-buttons/config.json +19 -1
  106. package/src/components/radio-buttons/radio-buttons.django-snapshot.html +93 -60
  107. package/src/components/radio-buttons/radio-buttons.django.html +16 -28
  108. package/src/components/radio-buttons/radio-buttons.react-snapshot.html +53 -0
  109. package/src/components/range-slider/RangeSlider.tsx +4 -2
  110. package/src/components/range-slider/config.json +1 -0
  111. package/src/components/range-slider/range-slider.django-snapshot.html +17 -0
  112. package/src/components/range-slider/range-slider.django.html +4 -4
  113. package/src/components/range-slider/range-slider.react-snapshot.html +16 -0
  114. package/src/components/search/Search.tsx +6 -1
  115. package/src/components/search/config.json +5 -0
  116. package/src/components/search/search.django-snapshot.html +683 -563
  117. package/src/components/search/search.django.html +1 -1
  118. package/src/components/search/search.react-snapshot.html +25 -0
  119. package/src/components/select/Select.tsx +3 -1
  120. package/src/components/select/config.json +5 -0
  121. package/src/components/select/select.django-snapshot.html +15 -0
  122. package/src/components/select/select.django.html +2 -2
  123. package/src/components/select/select.react-snapshot.html +11 -0
  124. package/src/components/switch/Switch.tsx +13 -70
  125. package/src/components/switch/config.json +60 -23
  126. package/src/components/switch/switch.django-snapshot.html +507 -56
  127. package/src/components/switch/switch.django.html +23 -26
  128. package/src/components/switch/switch.html +425 -33
  129. package/src/components/switch/switch.react-snapshot.html +447 -58
  130. package/src/components/table/Table.tsx +66 -334
  131. package/src/components/table/config.json +22 -339
  132. package/src/components/table/table.django-snapshot.html +712 -1482
  133. package/src/components/table/table.django.html +14 -59
  134. package/src/components/table/table.html +7 -2364
  135. package/src/components/table/table.react-snapshot.html +711 -2085
  136. package/src/components/text-area/TextArea.tsx +3 -1
  137. package/src/components/text-area/config.json +5 -0
  138. package/src/components/text-area/text-area.django-snapshot.html +18 -0
  139. package/src/components/text-area/text-area.django.html +4 -4
  140. package/src/components/text-area/text-area.react-snapshot.html +16 -0
  141. package/src/components/theme-picker/ThemePicker.tsx +3 -1
  142. package/src/components/theme-picker/config.json +14 -1
  143. package/src/components/theme-picker/theme-picker.django-snapshot.html +64 -0
  144. package/src/components/theme-picker/theme-picker.django.html +2 -2
  145. package/src/components/theme-picker/theme-picker.react-snapshot.html +52 -0
  146. package/src/components/time-picker/TimePicker.tsx +6 -1
  147. package/src/components/time-picker/config.json +9 -0
  148. package/src/components/time-picker/time-picker.django-snapshot.html +26 -0
  149. package/src/components/time-picker/time-picker.django.html +4 -4
  150. package/src/components/time-picker/time-picker.react-snapshot.html +22 -0
  151. package/src/index.js +1 -0
  152. package/src/components/table/TableBody.tsx +0 -256
  153. package/src/components/table/TableContext.tsx +0 -87
  154. package/src/components/table/TableGroup.tsx +0 -69
  155. package/src/components/table/TableHead.tsx +0 -139
  156. package/src/components/table/TableRow.tsx +0 -56
  157. package/src/components/table/hooks/useRowDetails.ts +0 -34
  158. package/src/components/table/hooks/useTableGroups.ts +0 -61
  159. package/src/components/table/hooks/useTableSelect.ts +0 -82
  160. package/src/components/table/hooks/useTableSort.ts +0 -60
  161. package/src/components/table/table-group.django.html +0 -40
  162. package/src/components/table/table-head.django.html +0 -85
  163. package/src/components/table/table-row.django.html +0 -98
  164. package/src/components/table/table_helper.py +0 -298
  165. /package/src/components/{table → data-table}/table-detail-row.django.html +0 -0
@@ -1,350 +1,82 @@
1
- import React, { useMemo, useState, useEffect, useId } from 'react';
1
+ import React from 'react';
2
2
  import classnames from 'classnames';
3
- import Pagination from '../pagination/Pagination';
4
3
 
5
- import { TableContext } from './TableContext';
6
- import type { TableContextValue } from './TableContext';
7
- import TableHead from './TableHead';
8
- import TableBody from './TableBody';
9
- import TableFoot from './TableFoot';
10
- import TableRow from './TableRow';
11
- import TableCell from './TableCell';
12
- import TableGroup from './TableGroup';
13
-
14
- import { useTableSort } from './hooks/useTableSort';
15
- import { useTableSelect } from './hooks/useTableSelect';
16
- import { useTableGroups } from './hooks/useTableGroups';
17
- import { useRowDetails } from './hooks/useRowDetails';
18
-
19
- import type {
20
- GroupBy,
21
- PaginateConfig,
22
- Responsive,
23
- RowDetails,
24
- RowKey,
25
- SelectionMode,
26
- SortState,
27
- TableColumn,
28
- TableRowData,
29
- } from './types';
30
-
31
- export type {
32
- Align,
33
- Aggregate,
34
- GroupBy,
35
- GroupByConfig,
36
- PaginateConfig,
37
- Responsive,
38
- RowDetails,
39
- RowDetailsConfig,
40
- RowKey,
41
- SelectionMode,
42
- SortDirection,
43
- SortState,
44
- TableColumn,
45
- TableRowData,
46
- } from './types';
47
-
48
- function countLeafCols(columns: TableColumn[]): number {
49
- return columns.reduce((sum, col) => {
50
- if (col.hidden) return sum;
51
- if (col.columns?.length) return sum + countLeafCols(col.columns);
52
- return sum + 1;
53
- }, 0);
54
- }
55
-
56
- function Caption({ className = '', children, ...rest }: React.HTMLAttributes<HTMLTableCaptionElement>) {
57
- return (
58
- <caption className={classnames('usx-table__caption', className)} {...rest}>
59
- {children}
60
- </caption>
61
- );
4
+ export interface TableColumn {
5
+ key: string;
6
+ header: React.ReactNode;
7
+ /** Render this column's cells as row headers. */
8
+ primary?: boolean;
9
+ /** Allow the USWDS table script to sort this column. */
10
+ sortable?: boolean;
62
11
  }
63
12
 
64
- // `placeholder`/`onSelect` exist on HTMLAttributes with DOM types; the table API redefines them.
65
- export interface TableProps extends Omit<React.TableHTMLAttributes<HTMLTableElement>, 'children' | 'placeholder' | 'onSelect'> {
66
- // Data
13
+ export interface TableProps extends Omit<React.TableHTMLAttributes<HTMLTableElement>, 'children'> {
14
+ extraAttributes?: Record<string, unknown>;
67
15
  columns?: TableColumn[];
68
- data?: TableRowData[];
69
- /** Row field used as the unique key (default `id`). */
70
- primaryKey?: string;
71
-
72
- // USWDS variants
16
+ data?: Record<string, React.ReactNode>[];
17
+ caption?: React.ReactNode;
73
18
  striped?: boolean;
74
19
  borderless?: boolean;
75
20
  compact?: boolean;
76
-
77
- // Layout / responsive
78
21
  scrollable?: boolean;
79
- /** Max height (CSS value); implies a scroll wrapper. */
80
- height?: string;
81
- responsive?: Responsive;
22
+ /** Fixed height of the scroll container, when scrollable. */
23
+ scrollHeight?: string;
82
24
  stickyHeader?: boolean;
83
- stickyFirstColumn?: boolean;
84
- caption?: React.ReactNode;
85
-
86
- // Sorting
87
- /** Make every column sortable unless it sets `sortable: false`. */
88
- sortable?: boolean;
89
- /** Controlled sort state. */
90
- sort?: SortState | null;
91
- onSort?: (next: SortState) => void;
92
-
93
- // Selection
94
- selectionMode?: SelectionMode;
95
- selectionPosition?: 'left' | 'right';
96
- /** Controlled selected keys. */
97
- select?: RowKey[] | null;
98
- onSelect?: (selected: RowKey[]) => void;
99
- allowSelectAll?: boolean;
100
- /** Keys of rows that cannot be selected. */
101
- disabled?: RowKey[];
102
-
103
- // Row interaction
104
- onClickRow?: TableContextValue['onClickRow'];
105
-
106
- // Groups / details
107
- groupBy?: GroupBy;
108
- rowDetails?: RowDetails;
109
-
110
- showFooter?: boolean;
111
-
112
- // Pagination
113
- paginate?: boolean | PaginateConfig;
114
- /** Infinite scroll: called when the sentinel row scrolls into view. */
115
- onMore?: (() => void) | null;
116
- /** Show a loading row (e.g. while fetching the next page). */
117
- loading?: boolean;
118
-
119
- /** Content of the single row shown when `data` is empty. */
120
- placeholder?: React.ReactNode;
121
- /** Compound mode: render your own Table.Head / Table.Body / … */
25
+ responsive?: false | 'stack' | 'stack-header';
26
+ /** Use children for hand-authored USWDS table markup instead of columns and data. */
122
27
  children?: React.ReactNode;
123
28
  }
124
29
 
125
- /**
126
- * Table — USX design system table.
127
- * Primary API: data-driven via `columns` + `data`.
128
- * Escape hatch: compound mode via Table.Head / Table.Body / Table.Row / Table.Cell.
129
- */
130
- function Table({
131
- id: idProp,
132
- columns = [],
133
- data = [],
134
- primaryKey = 'id',
135
- striped = false,
136
- borderless = false,
137
- compact = false,
138
- scrollable = false,
139
- height,
140
- responsive = false,
141
- stickyHeader = false,
142
- stickyFirstColumn = false,
143
- caption,
144
- sortable: sortableAll = false,
145
- sort: sortProp,
146
- onSort,
147
- selectionMode = null,
148
- selectionPosition = 'left',
149
- select: selectProp,
150
- onSelect,
151
- allowSelectAll = true,
152
- disabled = [],
153
- onClickRow = null,
154
- groupBy,
155
- rowDetails,
156
- showFooter = false,
157
- paginate,
158
- onMore = null,
159
- loading = false,
160
- placeholder,
161
- className = '',
162
- children,
163
- ...props
30
+ /** A themeable USWDS table. Sorting is supplied by USWDS's table script. */
31
+ export default function Table({
32
+ columns = [], data = [], caption, striped = false, borderless = false,
33
+ compact = false, scrollable = false, scrollHeight, stickyHeader = false, responsive = false,
34
+ className, children, extraAttributes, ...props
164
35
  }: TableProps) {
165
- const generatedId = useId();
166
- const id = idProp ?? `usx-table-${generatedId}`;
167
-
168
- const resolvedColumns = useMemo(() => {
169
- if (!sortableAll) return columns;
170
- return columns.map((col) => ({ ...col, sortable: col.sortable !== false }));
171
- }, [columns, sortableAll]);
172
-
173
- const { sortState, handleSort, sortedData } = useTableSort({ sortProp, onSort, columns: resolvedColumns, data });
174
-
175
- // ── Pagination ──────────────────────────────────────────────────────────────
176
- const isPaginated = !!paginate;
177
- const paginateConfig: PaginateConfig = paginate === true ? {} : paginate || {};
178
- const defaultPageSize = paginateConfig.pageSize || 10;
179
- const isServerSide = !!paginateConfig.totalCount;
180
-
181
- const [currentPage, setCurrentPage] = useState(1);
182
- const [pageSize, setPageSize] = useState(defaultPageSize);
183
-
184
- // Back to page 1 whenever sort changes so the user isn't stranded mid-table.
185
- useEffect(() => {
186
- if (isPaginated) setCurrentPage(1);
187
- }, [isPaginated, sortState.key, sortState.direction]);
188
-
189
- const totalItems = isServerSide ? paginateConfig.totalCount! : sortedData.length;
190
- const activeData =
191
- isPaginated && !isServerSide ? sortedData.slice((currentPage - 1) * pageSize, currentPage * pageSize) : sortedData;
192
-
193
- const { selectedKeys, handleSelect, handleSelectAll, isSelected, isAllSelected, isIndeterminate } = useTableSelect({
194
- selectionMode,
195
- selectProp,
196
- onSelect,
197
- data: activeData,
198
- primaryKey,
199
- disabled,
200
- allowSelectAll,
201
- });
202
-
203
- const { groups, expandedGroups, toggleGroup, isGroupExpanded } = useTableGroups({ groupBy, data: activeData });
204
- const { expandedRows, toggleRow, isRowExpanded } = useRowDetails({ rowDetails });
205
-
206
- const totalCols = useMemo(
207
- () => countLeafCols(resolvedColumns) + (selectionMode ? 1 : 0) + (rowDetails ? 1 : 0),
208
- [resolvedColumns, selectionMode, rowDetails]
209
- );
210
-
211
- const contextValue = useMemo<TableContextValue>(
212
- () => ({
213
- id,
214
- columns: resolvedColumns,
215
- data: activeData,
216
- primaryKey,
217
- sortState,
218
- handleSort,
219
- selectionMode,
220
- selectionPosition,
221
- selectedKeys,
222
- handleSelect,
223
- handleSelectAll,
224
- isSelected,
225
- isAllSelected,
226
- isIndeterminate,
227
- allowSelectAll,
228
- disabled,
229
- onClickRow,
230
- groupBy,
231
- groups,
232
- expandedGroups,
233
- toggleGroup,
234
- isGroupExpanded,
235
- expandedRows,
236
- toggleRow,
237
- isRowExpanded,
238
- rowDetails,
239
- responsive,
240
- stickyFirstColumn,
241
- totalCols,
242
- placeholder,
243
- onMore,
244
- loading,
245
- }),
246
- [
247
- id, resolvedColumns, activeData, primaryKey,
248
- sortState, handleSort,
249
- selectionMode, selectionPosition, selectedKeys, handleSelect, handleSelectAll,
250
- isSelected, isAllSelected, isIndeterminate, allowSelectAll, disabled,
251
- onClickRow,
252
- groupBy, groups, expandedGroups, toggleGroup, isGroupExpanded,
253
- expandedRows, toggleRow, isRowExpanded, rowDetails,
254
- responsive, stickyFirstColumn, totalCols,
255
- placeholder, onMore, loading,
256
- ]
257
- );
258
-
259
- const tableClasses = classnames(
260
- 'usa-table',
261
- striped && 'usa-table--striped',
262
- borderless && 'usa-table--borderless',
263
- compact && 'usa-table--compact',
264
- stickyHeader && 'usa-table--sticky-header',
265
- responsive === 'stack' && 'usa-table--stacked',
266
- responsive === 'stack-header' && 'usa-table--stacked-header',
267
- 'usx-table',
268
- stickyFirstColumn && 'usx-table--sticky-first-col',
269
- className
270
- );
271
-
272
- const tableEl = (
273
- <table id={idProp} className={tableClasses} {...props}>
274
- {caption && <Caption>{caption}</Caption>}
275
- {children || (
276
- <>
277
- <TableHead />
278
- <TableBody />
279
- {showFooter && <TableFoot />}
280
- </>
281
- )}
282
- </table>
283
- );
284
-
285
- const needsScrollWrapper = scrollable || !!height;
286
- const wrapped = needsScrollWrapper ? (
287
- <div
288
- className="usa-table-container--scrollable usx-table-container--scrollable"
289
- tabIndex={0}
290
- style={height ? { maxHeight: height, overflow: 'auto' } : undefined}
291
- >
292
- {tableEl}
293
- </div>
294
- ) : (
295
- tableEl
296
- );
297
-
298
- return (
299
- <TableContext.Provider value={contextValue}>
300
- {wrapped}
301
- {isPaginated && (
302
- <div
303
- onClick={(event) => {
304
- const link = (event.target as Element).closest<HTMLAnchorElement>('[data-usx-pagination-page]');
305
- if (!link || link.getAttribute('aria-disabled') === 'true') return;
306
- event.preventDefault();
307
- const page = Number(link.dataset.usxPaginationPage);
308
- if (!Number.isInteger(page) || page < 1 || page === currentPage) return;
309
- setCurrentPage(page);
310
- if (isServerSide) paginateConfig.onPageChange?.(page, pageSize);
311
- }}
312
- onChange={(event) => {
313
- const target: EventTarget = event.target;
314
- if (!(target instanceof HTMLSelectElement)) return;
315
- const select = target;
316
- if (!select.matches('.usx-pagination__step-options select')) return;
317
- const size = Number(select.value);
318
- if (!Number.isInteger(size) || size < 1) return;
319
- const page = Math.min(currentPage, Math.max(1, Math.ceil(totalItems / size)));
320
- setPageSize(size);
321
- setCurrentPage(page);
322
- if (isServerSide) paginateConfig.onPageChange?.(page, size);
323
- }}
324
- >
325
- <Pagination
326
- key={`${sortState.key}-${sortState.direction}`}
327
- currentPage={currentPage}
328
- pageSize={pageSize}
329
- totalItems={totalItems}
330
- {...(paginateConfig.pageSizeOptions ? { pageSizeOptions: paginateConfig.pageSizeOptions } : {})}
331
- {...(paginateConfig.showStepOptions !== undefined ? { showStepOptions: paginateConfig.showStepOptions } : {})}
332
- {...(paginateConfig.showSummary !== undefined ? { showSummary: paginateConfig.showSummary } : {})}
333
- />
334
- </div>
335
- )}
336
- </TableContext.Provider>
36
+ const hasSorting = !children && columns.some((column) => column.sortable);
37
+ const table = (
38
+ <>
39
+ <table
40
+ {...props}
41
+ {...extraAttributes}
42
+ className={classnames(
43
+ 'usa-table', 'usx-table',
44
+ striped && 'usa-table--striped',
45
+ borderless && 'usa-table--borderless',
46
+ compact && 'usa-table--compact',
47
+ stickyHeader && 'usa-table--sticky-header',
48
+ responsive === 'stack' && 'usa-table--stacked',
49
+ responsive === 'stack-header' && 'usa-table--stacked-header',
50
+ className
51
+ )}
52
+ >
53
+ {children ?? (
54
+ <>
55
+ <caption className="usx-table__caption">{caption || 'Data table'}</caption>
56
+ <thead><tr>{columns.map((column) => (
57
+ <th key={column.key} scope="col" data-sortable={column.sortable ? '' : undefined}>
58
+ {column.header}
59
+ </th>
60
+ ))}</tr></thead>
61
+ <tbody>{data.map((row, index) => (
62
+ <tr key={index}>{columns.map((column) => {
63
+ const Cell = column.primary ? 'th' : 'td';
64
+ const value = row[column.key];
65
+ return <Cell
66
+ key={column.key}
67
+ scope={column.primary ? 'row' : undefined}
68
+ data-label={responsive ? String(column.header) : undefined}
69
+ >{value ?? ''}</Cell>;
70
+ })}</tr>
71
+ ))}</tbody>
72
+ </>
73
+ )}
74
+ </table>
75
+ {hasSorting && <div className="usa-sr-only usa-table__announcement-region" aria-live="polite" />}
76
+ </>
337
77
  );
78
+ return scrollable
79
+ ? <div className="usa-table-container--scrollable" tabIndex={0}
80
+ style={scrollHeight ? { height: scrollHeight, overflow: 'auto' } : undefined}>{table}</div>
81
+ : table;
338
82
  }
339
-
340
- // ── Compound sub-components ───────────────────────────────────────────────────
341
-
342
- export default Object.assign(Table, {
343
- Head: TableHead,
344
- Body: TableBody,
345
- Foot: TableFoot,
346
- Row: TableRow,
347
- Cell: TableCell,
348
- Group: TableGroup,
349
- Caption,
350
- });