@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.
- package/README.md +16 -0
- package/dist/index.cjs +3231 -3270
- package/dist/index.js +3232 -3271
- package/package.json +4 -4
- package/src/components/accordion/Accordion.tsx +4 -1
- package/src/components/accordion/accordion.django.html +1 -1
- package/src/components/accordion/config.json +1 -0
- package/src/components/banner/Banner.tsx +3 -1
- package/src/components/banner/banner.django.html +1 -1
- package/src/components/banner/config.json +1 -0
- package/src/components/carousel/carousel.django-snapshot.html +0 -40
- package/src/components/carousel/carousel.react-snapshot.html +0 -38
- package/src/components/character-count/CharacterCount.tsx +3 -0
- package/src/components/character-count/character-count.django-snapshot.html +43 -0
- package/src/components/character-count/character-count.django.html +2 -2
- package/src/components/character-count/character-count.react-snapshot.html +37 -0
- package/src/components/character-count/config.json +9 -0
- package/src/components/checkbox/Checkbox.tsx +17 -13
- package/src/components/checkbox/checkbox.django-snapshot.html +18 -0
- package/src/components/checkbox/checkbox.django.html +6 -4
- package/src/components/checkbox/checkbox.react-snapshot.html +14 -0
- package/src/components/checkbox/config.json +10 -1
- package/src/components/checkbox-group/checkbox-group.django-snapshot.html +54 -0
- package/src/components/checkbox-group/checkbox-group.react-snapshot.html +45 -0
- package/src/components/combobox/Combobox.tsx +6 -1
- package/src/components/combobox/combobox.django-snapshot.html +141 -0
- package/src/components/combobox/combobox.django.html +2 -2
- package/src/components/combobox/combobox.react-snapshot.html +76 -0
- package/src/components/combobox/config.json +9 -0
- package/src/components/data-table/DataTable.tsx +180 -0
- package/src/components/data-table/README.md +42 -0
- package/src/components/data-table/TableBody.tsx +123 -0
- package/src/components/{table → data-table}/TableCell.tsx +6 -3
- package/src/components/data-table/TableContext.tsx +49 -0
- package/src/components/{table → data-table}/TableFoot.tsx +8 -7
- package/src/components/data-table/TableGroup.tsx +62 -0
- package/src/components/data-table/TableHead.tsx +126 -0
- package/src/components/data-table/TableRow.tsx +24 -0
- package/src/components/data-table/cells.ts +49 -0
- package/src/components/data-table/columns.ts +15 -0
- package/src/components/data-table/config.json +379 -0
- package/src/components/data-table/data-table.django-snapshot.html +13560 -0
- package/src/components/data-table/data-table.django.html +13 -0
- package/src/components/data-table/data-table.html +34 -0
- package/src/components/data-table/data-table.react-snapshot.html +12033 -0
- package/src/components/{table → data-table}/table-body.django.html +12 -12
- package/src/components/{table → data-table}/table-foot.django.html +6 -6
- package/src/components/data-table/table-group.django.html +24 -0
- package/src/components/data-table/table-head.django.html +21 -0
- package/src/components/data-table/table-row.django.html +57 -0
- package/src/components/{table → data-table}/types.ts +48 -5
- package/src/components/date-picker/DatePicker.tsx +6 -1
- package/src/components/date-picker/config.json +9 -0
- package/src/components/date-picker/date-picker.django-snapshot.html +23 -0
- package/src/components/date-picker/date-picker.django.html +4 -4
- package/src/components/date-picker/date-picker.react-snapshot.html +19 -0
- package/src/components/date-range-picker/DateRangePicker.tsx +11 -2
- package/src/components/date-range-picker/config.json +14 -0
- package/src/components/date-range-picker/date-range-picker.django-snapshot.html +47 -0
- package/src/components/date-range-picker/date-range-picker.django.html +5 -5
- package/src/components/date-range-picker/date-range-picker.react-snapshot.html +38 -0
- package/src/components/drawer/Drawer.tsx +3 -1
- package/src/components/drawer/config.json +4 -0
- package/src/components/drawer/drawer.django.html +1 -1
- package/src/components/file-input/FileInput.tsx +7 -2
- package/src/components/file-input/_contents.django.html +2 -1
- package/src/components/file-input/config.json +4 -0
- package/src/components/header/Header.tsx +15 -9
- package/src/components/header/config.json +1 -0
- package/src/components/header/header.django-snapshot.html +24 -0
- package/src/components/header/header.django.html +8 -4
- package/src/components/header/header.html +20 -0
- package/src/components/header/header.react-snapshot.html +20 -0
- package/src/components/in-page-nav/InPageNav.tsx +3 -0
- package/src/components/in-page-nav/config.json +1 -0
- package/src/components/in-page-nav/in-page-nav.django.html +1 -1
- package/src/components/input/Input.tsx +3 -0
- package/src/components/input/config.json +10 -0
- package/src/components/input/input.django-snapshot.html +24 -0
- package/src/components/input/input.django.html +4 -4
- package/src/components/input/input.react-snapshot.html +22 -0
- package/src/components/language-selector/LanguageSelector.tsx +10 -5
- package/src/components/language-selector/config.json +1 -0
- package/src/components/language-selector/language-selector.django.html +2 -2
- package/src/components/layout/Layout.tsx +3 -1
- package/src/components/layout/config.json +4 -0
- package/src/components/layout/layout.django.html +1 -1
- package/src/components/memorable-date/MemorableDate.tsx +18 -3
- package/src/components/memorable-date/config.json +15 -0
- package/src/components/memorable-date/memorable-date.django-snapshot.html +82 -0
- package/src/components/memorable-date/memorable-date.django.html +14 -14
- package/src/components/memorable-date/memorable-date.react-snapshot.html +70 -0
- package/src/components/modal/Modal.tsx +3 -0
- package/src/components/modal/config.json +1 -0
- package/src/components/modal/modal.django.html +1 -1
- package/src/components/pagination/Pagination.tsx +7 -1
- package/src/components/pagination/config.json +8 -0
- package/src/components/pagination/navigation/PaginationNavigation.tsx +10 -0
- package/src/components/pagination/step-options/PaginationStepOptions.tsx +3 -0
- package/src/components/popover/Popover.tsx +3 -0
- package/src/components/popover/config.json +4 -0
- package/src/components/popover/popover.django-snapshot.html +30 -0
- package/src/components/popover/popover.django.html +1 -0
- package/src/components/radio-buttons/RadioButtons.tsx +41 -27
- package/src/components/radio-buttons/config.json +19 -1
- package/src/components/radio-buttons/radio-buttons.django-snapshot.html +93 -60
- package/src/components/radio-buttons/radio-buttons.django.html +16 -28
- package/src/components/radio-buttons/radio-buttons.react-snapshot.html +53 -0
- package/src/components/range-slider/RangeSlider.tsx +4 -2
- package/src/components/range-slider/config.json +1 -0
- package/src/components/range-slider/range-slider.django-snapshot.html +17 -0
- package/src/components/range-slider/range-slider.django.html +4 -4
- package/src/components/range-slider/range-slider.react-snapshot.html +16 -0
- package/src/components/search/Search.tsx +6 -1
- package/src/components/search/config.json +5 -0
- package/src/components/search/search.django-snapshot.html +683 -563
- package/src/components/search/search.django.html +1 -1
- package/src/components/search/search.react-snapshot.html +25 -0
- package/src/components/select/Select.tsx +3 -1
- package/src/components/select/config.json +5 -0
- package/src/components/select/select.django-snapshot.html +15 -0
- package/src/components/select/select.django.html +2 -2
- package/src/components/select/select.react-snapshot.html +11 -0
- package/src/components/switch/Switch.tsx +13 -70
- package/src/components/switch/config.json +60 -23
- package/src/components/switch/switch.django-snapshot.html +507 -56
- package/src/components/switch/switch.django.html +23 -26
- package/src/components/switch/switch.html +425 -33
- package/src/components/switch/switch.react-snapshot.html +447 -58
- package/src/components/table/Table.tsx +66 -334
- package/src/components/table/config.json +22 -339
- package/src/components/table/table.django-snapshot.html +712 -1482
- package/src/components/table/table.django.html +14 -59
- package/src/components/table/table.html +7 -2364
- package/src/components/table/table.react-snapshot.html +711 -2085
- package/src/components/text-area/TextArea.tsx +3 -1
- package/src/components/text-area/config.json +5 -0
- package/src/components/text-area/text-area.django-snapshot.html +18 -0
- package/src/components/text-area/text-area.django.html +4 -4
- package/src/components/text-area/text-area.react-snapshot.html +16 -0
- package/src/components/theme-picker/ThemePicker.tsx +3 -1
- package/src/components/theme-picker/config.json +14 -1
- package/src/components/theme-picker/theme-picker.django-snapshot.html +64 -0
- package/src/components/theme-picker/theme-picker.django.html +2 -2
- package/src/components/theme-picker/theme-picker.react-snapshot.html +52 -0
- package/src/components/time-picker/TimePicker.tsx +6 -1
- package/src/components/time-picker/config.json +9 -0
- package/src/components/time-picker/time-picker.django-snapshot.html +26 -0
- package/src/components/time-picker/time-picker.django.html +4 -4
- package/src/components/time-picker/time-picker.react-snapshot.html +22 -0
- package/src/index.js +1 -0
- package/src/components/table/TableBody.tsx +0 -256
- package/src/components/table/TableContext.tsx +0 -87
- package/src/components/table/TableGroup.tsx +0 -69
- package/src/components/table/TableHead.tsx +0 -139
- package/src/components/table/TableRow.tsx +0 -56
- package/src/components/table/hooks/useRowDetails.ts +0 -34
- package/src/components/table/hooks/useTableGroups.ts +0 -61
- package/src/components/table/hooks/useTableSelect.ts +0 -82
- package/src/components/table/hooks/useTableSort.ts +0 -60
- package/src/components/table/table-group.django.html +0 -40
- package/src/components/table/table-head.django.html +0 -85
- package/src/components/table/table-row.django.html +0 -98
- package/src/components/table/table_helper.py +0 -298
- /package/src/components/{table → data-table}/table-detail-row.django.html +0 -0
|
@@ -1,350 +1,82 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import classnames from 'classnames';
|
|
3
|
-
import Pagination from '../pagination/Pagination';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
// Data
|
|
13
|
+
export interface TableProps extends Omit<React.TableHTMLAttributes<HTMLTableElement>, 'children'> {
|
|
14
|
+
extraAttributes?: Record<string, unknown>;
|
|
67
15
|
columns?: TableColumn[];
|
|
68
|
-
data?:
|
|
69
|
-
|
|
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
|
-
/**
|
|
80
|
-
|
|
81
|
-
responsive?: Responsive;
|
|
22
|
+
/** Fixed height of the scroll container, when scrollable. */
|
|
23
|
+
scrollHeight?: string;
|
|
82
24
|
stickyHeader?: boolean;
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
});
|