@solexllc/usx-react 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 (359) hide show
  1. package/README.md +45 -0
  2. package/dist/index.cjs +6017 -0
  3. package/dist/index.js +6015 -0
  4. package/package.json +48 -0
  5. package/src/components/accordion/Accordion.jsx +170 -0
  6. package/src/components/accordion/accordion.django.html +47 -0
  7. package/src/components/accordion/accordion.html +304 -0
  8. package/src/components/accordion/config.json +31 -0
  9. package/src/components/alert/Alert.tsx +88 -0
  10. package/src/components/alert/alert.django.html +45 -0
  11. package/src/components/alert/alert.html +192 -0
  12. package/src/components/alert/config.json +70 -0
  13. package/src/components/attribution/Attribution.tsx +40 -0
  14. package/src/components/attribution/attribution.django.html +21 -0
  15. package/src/components/attribution/attribution.html +26 -0
  16. package/src/components/attribution/config.json +32 -0
  17. package/src/components/avatar/Avatar.tsx +85 -0
  18. package/src/components/avatar/avatar.django.html +27 -0
  19. package/src/components/avatar/avatar.html +101 -0
  20. package/src/components/avatar/config.json +59 -0
  21. package/src/components/avatar-group/AvatarGroup.tsx +43 -0
  22. package/src/components/avatar-group/avatar-group.django.html +8 -0
  23. package/src/components/avatar-group/avatar-group.html +208 -0
  24. package/src/components/avatar-group/config.json +60 -0
  25. package/src/components/back-to-top/BackToTop.tsx +60 -0
  26. package/src/components/back-to-top/back-to-top.django.html +38 -0
  27. package/src/components/back-to-top/back-to-top.html +107 -0
  28. package/src/components/back-to-top/config.json +44 -0
  29. package/src/components/banner/Banner.tsx +111 -0
  30. package/src/components/banner/banner.django.html +80 -0
  31. package/src/components/banner/banner.html +411 -0
  32. package/src/components/banner/config.json +47 -0
  33. package/src/components/block/Block.tsx +78 -0
  34. package/src/components/block/block.django.html +26 -0
  35. package/src/components/block/block.html +162 -0
  36. package/src/components/block/config.json +88 -0
  37. package/src/components/breadcrumb/Breadcrumb.tsx +83 -0
  38. package/src/components/breadcrumb/breadcrumb.django.html +24 -0
  39. package/src/components/breadcrumb/breadcrumb.html +108 -0
  40. package/src/components/breadcrumb/config.json +74 -0
  41. package/src/components/button/Button.tsx +121 -0
  42. package/src/components/button/button.django.html +58 -0
  43. package/src/components/button/button.html +363 -0
  44. package/src/components/button/config.json +103 -0
  45. package/src/components/button-group/ButtonGroup.tsx +33 -0
  46. package/src/components/button-group/button-group.django.html +9 -0
  47. package/src/components/button-group/button-group.html +159 -0
  48. package/src/components/button-group/config.json +25 -0
  49. package/src/components/calendar-date/CalendarDate.tsx +40 -0
  50. package/src/components/calendar-date/calendar-date.django.html +8 -0
  51. package/src/components/calendar-date/calendar-date.html +17 -0
  52. package/src/components/calendar-date/config.json +17 -0
  53. package/src/components/card/Card.tsx +137 -0
  54. package/src/components/card/card.django.html +40 -0
  55. package/src/components/card/card.html +67 -0
  56. package/src/components/card/config.json +115 -0
  57. package/src/components/card-group/CardGroup.tsx +23 -0
  58. package/src/components/card-group/card-group.django.html +6 -0
  59. package/src/components/card-group/card-group.html +164 -0
  60. package/src/components/card-group/config.json +21 -0
  61. package/src/components/carousel/Carousel.tsx +101 -0
  62. package/src/components/carousel/carousel.django.html +41 -0
  63. package/src/components/carousel/carousel.html +64 -0
  64. package/src/components/carousel/config.json +38 -0
  65. package/src/components/character-count/CharacterCount.tsx +77 -0
  66. package/src/components/character-count/character-count.django.html +19 -0
  67. package/src/components/character-count/character-count.html +110 -0
  68. package/src/components/character-count/config.json +78 -0
  69. package/src/components/checkbox/Checkbox.tsx +90 -0
  70. package/src/components/checkbox/checkbox.django.html +16 -0
  71. package/src/components/checkbox/checkbox.html +266 -0
  72. package/src/components/checkbox/config.json +71 -0
  73. package/src/components/checkbox-group/CheckboxGroup.tsx +67 -0
  74. package/src/components/checkbox-group/checkbox-group.django.html +12 -0
  75. package/src/components/checkbox-group/checkbox-group.html +36 -0
  76. package/src/components/checkbox-group/config.json +50 -0
  77. package/src/components/clickable/Clickable.tsx +78 -0
  78. package/src/components/clickable/clickable.django.html +5 -0
  79. package/src/components/clickable/clickable.html +133 -0
  80. package/src/components/clickable/config.json +26 -0
  81. package/src/components/code/Code.tsx +60 -0
  82. package/src/components/code/code.django.html +21 -0
  83. package/src/components/code/code.html +71 -0
  84. package/src/components/code/config.json +40 -0
  85. package/src/components/collection/Collection.tsx +99 -0
  86. package/src/components/collection/collection.django.html +48 -0
  87. package/src/components/collection/collection.html +384 -0
  88. package/src/components/collection/config.json +60 -0
  89. package/src/components/combobox/Combobox.tsx +114 -0
  90. package/src/components/combobox/combobox.django.html +61 -0
  91. package/src/components/combobox/combobox.html +509 -0
  92. package/src/components/combobox/config.json +80 -0
  93. package/src/components/copy-to-clipboard/CopyToClipboard.tsx +48 -0
  94. package/src/components/copy-to-clipboard/config.json +30 -0
  95. package/src/components/copy-to-clipboard/copy-to-clipboard.django.html +16 -0
  96. package/src/components/copy-to-clipboard/copy-to-clipboard.html +68 -0
  97. package/src/components/date-picker/DatePicker.jsx +83 -0
  98. package/src/components/date-picker/config.json +71 -0
  99. package/src/components/date-picker/date-picker.django.html +67 -0
  100. package/src/components/date-picker/date-picker.html +104 -0
  101. package/src/components/date-range-picker/DateRangePicker.jsx +113 -0
  102. package/src/components/date-range-picker/config.json +92 -0
  103. package/src/components/date-range-picker/date-range-picker.django.html +66 -0
  104. package/src/components/date-range-picker/date-range-picker.html +190 -0
  105. package/src/components/error-message/ErrorMessage.tsx +23 -0
  106. package/src/components/error-message/config.json +19 -0
  107. package/src/components/error-message/error-message.django.html +2 -0
  108. package/src/components/error-message/error-message.html +2 -0
  109. package/src/components/eyebrow/Eyebrow.tsx +15 -0
  110. package/src/components/eyebrow/config.json +15 -0
  111. package/src/components/eyebrow/eyebrow.django.html +4 -0
  112. package/src/components/eyebrow/eyebrow.html +4 -0
  113. package/src/components/fieldset/Fieldset.tsx +54 -0
  114. package/src/components/fieldset/config.json +47 -0
  115. package/src/components/fieldset/fieldset.django.html +22 -0
  116. package/src/components/fieldset/fieldset.html +17 -0
  117. package/src/components/file-input/FileInput.jsx +174 -0
  118. package/src/components/file-input/config.json +80 -0
  119. package/src/components/file-input/file-input.django.html +57 -0
  120. package/src/components/file-input/file-input.html +258 -0
  121. package/src/components/file-list/FileList.jsx +105 -0
  122. package/src/components/file-list/config.json +43 -0
  123. package/src/components/file-list/file-list.django.html +30 -0
  124. package/src/components/file-list/file-list.html +61 -0
  125. package/src/components/footer/Footer.tsx +365 -0
  126. package/src/components/footer/config.json +83 -0
  127. package/src/components/footer/footer.django.html +260 -0
  128. package/src/components/footer/footer.html +392 -0
  129. package/src/components/form-group/FormGroup.tsx +26 -0
  130. package/src/components/form-group/config.json +22 -0
  131. package/src/components/form-group/form-group.django.html +4 -0
  132. package/src/components/form-group/form-group.html +17 -0
  133. package/src/components/header/Branding.tsx +101 -0
  134. package/src/components/header/Header.tsx +229 -0
  135. package/src/components/header/HeaderBranding.jsx +4 -0
  136. package/src/components/header/config.json +58 -0
  137. package/src/components/header/header.django.html +194 -0
  138. package/src/components/header/header.html +823 -0
  139. package/src/components/hero/Hero.tsx +64 -0
  140. package/src/components/hero/config.json +70 -0
  141. package/src/components/hero/hero.django.html +22 -0
  142. package/src/components/hero/hero.html +75 -0
  143. package/src/components/hint/Hint.tsx +23 -0
  144. package/src/components/hint/config.json +19 -0
  145. package/src/components/hint/hint.django.html +2 -0
  146. package/src/components/hint/hint.html +2 -0
  147. package/src/components/icon/Icon.tsx +46 -0
  148. package/src/components/icon/config.json +60 -0
  149. package/src/components/icon/icon.django.html +26 -0
  150. package/src/components/icon/icon.html +289 -0
  151. package/src/components/icon/icons_list.json +247 -0
  152. package/src/components/icon-list/IconList.tsx +59 -0
  153. package/src/components/icon-list/config.json +86 -0
  154. package/src/components/icon-list/icon-list.django.html +17 -0
  155. package/src/components/icon-list/icon-list.html +227 -0
  156. package/src/components/identifier/Identifier.tsx +193 -0
  157. package/src/components/identifier/config.json +133 -0
  158. package/src/components/identifier/identifier.django.html +99 -0
  159. package/src/components/identifier/identifier.html +737 -0
  160. package/src/components/image/Image.tsx +106 -0
  161. package/src/components/image/config.json +64 -0
  162. package/src/components/image/image.django.html +62 -0
  163. package/src/components/image/image.html +53 -0
  164. package/src/components/in-page-nav/InPageNav.jsx +76 -0
  165. package/src/components/in-page-nav/config.json +69 -0
  166. package/src/components/in-page-nav/in-page-nav.django.html +28 -0
  167. package/src/components/in-page-nav/in-page-nav.html +183 -0
  168. package/src/components/indicator/Indicator.tsx +32 -0
  169. package/src/components/indicator/README.md +1 -0
  170. package/src/components/indicator/config.json +19 -0
  171. package/src/components/indicator/indicator.django.html +10 -0
  172. package/src/components/indicator/indicator.html +42 -0
  173. package/src/components/input/Input.tsx +85 -0
  174. package/src/components/input/config.json +73 -0
  175. package/src/components/input/input.django.html +55 -0
  176. package/src/components/input/input.html +59 -0
  177. package/src/components/label/Label.tsx +42 -0
  178. package/src/components/label/config.json +39 -0
  179. package/src/components/label/label.django.html +23 -0
  180. package/src/components/label/label.html +23 -0
  181. package/src/components/language-selector/LanguageSelector.jsx +224 -0
  182. package/src/components/language-selector/config.json +107 -0
  183. package/src/components/language-selector/language-selector.django.html +40 -0
  184. package/src/components/language-selector/language-selector.html +85 -0
  185. package/src/components/layout/Layout.tsx +131 -0
  186. package/src/components/layout/config.json +36 -0
  187. package/src/components/layout/layout.django.html +28 -0
  188. package/src/components/layout/layout.html +29 -0
  189. package/src/components/legend/Legend.tsx +34 -0
  190. package/src/components/legend/config.json +27 -0
  191. package/src/components/legend/legend.django.html +11 -0
  192. package/src/components/legend/legend.html +12 -0
  193. package/src/components/link/Link.tsx +45 -0
  194. package/src/components/link/config.json +39 -0
  195. package/src/components/link/link.django.html +8 -0
  196. package/src/components/link/link.html +47 -0
  197. package/src/components/list/List.tsx +82 -0
  198. package/src/components/list/_list-items.django.html +17 -0
  199. package/src/components/list/config.json +25 -0
  200. package/src/components/list/list.django.html +11 -0
  201. package/src/components/list/list.html +26 -0
  202. package/src/components/memorable-date/MemorableDate.jsx +167 -0
  203. package/src/components/memorable-date/config.json +104 -0
  204. package/src/components/memorable-date/memorable-date.django.html +86 -0
  205. package/src/components/memorable-date/memorable-date.html +275 -0
  206. package/src/components/misc-banner/MiscBanner.tsx +112 -0
  207. package/src/components/misc-banner/config.json +57 -0
  208. package/src/components/misc-banner/misc-banner.django.html +63 -0
  209. package/src/components/misc-banner/misc-banner.html +191 -0
  210. package/src/components/modal/Modal.tsx +71 -0
  211. package/src/components/modal/config.json +57 -0
  212. package/src/components/modal/modal.django.html +43 -0
  213. package/src/components/modal/modal.html +222 -0
  214. package/src/components/page/Page.jsx +34 -0
  215. package/src/components/page/config.json +34 -0
  216. package/src/components/page/page.django.html +5 -0
  217. package/src/components/page/page.html +23 -0
  218. package/src/components/pagination/Pagination.tsx +112 -0
  219. package/src/components/pagination/config.json +135 -0
  220. package/src/components/pagination/container/PaginationContainer.tsx +38 -0
  221. package/src/components/pagination/navigation/PaginationNavigation.tsx +219 -0
  222. package/src/components/pagination/navigation/pagination-navigation.django.html +64 -0
  223. package/src/components/pagination/pagination.django.html +48 -0
  224. package/src/components/pagination/pagination.html +613 -0
  225. package/src/components/pagination/step-options/PaginationStepOptions.tsx +43 -0
  226. package/src/components/pagination/step-options/pagination-step-options.django.html +7 -0
  227. package/src/components/pagination/summary/PaginationSummary.tsx +33 -0
  228. package/src/components/pagination/summary/pagination-summary.django.html +12 -0
  229. package/src/components/process-list/ProcessList.tsx +52 -0
  230. package/src/components/process-list/config.json +15 -0
  231. package/src/components/process-list/process-list.django.html +15 -0
  232. package/src/components/process-list/process-list.html +90 -0
  233. package/src/components/prose/Prose.tsx +32 -0
  234. package/src/components/prose/config.json +28 -0
  235. package/src/components/prose/prose.django.html +35 -0
  236. package/src/components/prose/prose.html +91 -0
  237. package/src/components/radio-buttons/RadioButtons.tsx +82 -0
  238. package/src/components/radio-buttons/config.json +57 -0
  239. package/src/components/radio-buttons/radio-buttons.django.html +28 -0
  240. package/src/components/radio-buttons/radio-buttons.html +189 -0
  241. package/src/components/range-slider/RangeSlider.jsx +84 -0
  242. package/src/components/range-slider/config.json +89 -0
  243. package/src/components/range-slider/range-slider.django.html +65 -0
  244. package/src/components/range-slider/range-slider.html +106 -0
  245. package/src/components/required/Required.tsx +25 -0
  246. package/src/components/required/config.json +20 -0
  247. package/src/components/required/required.django.html +2 -0
  248. package/src/components/required/required.html +6 -0
  249. package/src/components/search/Search.tsx +92 -0
  250. package/src/components/search/config.json +69 -0
  251. package/src/components/search/search.django.html +59 -0
  252. package/src/components/search/search.html +76 -0
  253. package/src/components/section/Section.tsx +28 -0
  254. package/src/components/section/config.json +27 -0
  255. package/src/components/section/section.django.html +5 -0
  256. package/src/components/section/section.html +16 -0
  257. package/src/components/select/Select.tsx +107 -0
  258. package/src/components/select/config.json +80 -0
  259. package/src/components/select/select.django.html +64 -0
  260. package/src/components/select/select.html +62 -0
  261. package/src/components/sidenav/SideNav.tsx +74 -0
  262. package/src/components/sidenav/config.json +45 -0
  263. package/src/components/sidenav/sidenav.django.html +29 -0
  264. package/src/components/sidenav/sidenav.html +84 -0
  265. package/src/components/site-alert/SiteAlert.tsx +101 -0
  266. package/src/components/site-alert/config.json +62 -0
  267. package/src/components/site-alert/site-alert.django.html +34 -0
  268. package/src/components/site-alert/site-alert.html +312 -0
  269. package/src/components/skipnav/Skipnav.tsx +41 -0
  270. package/src/components/skipnav/config.json +29 -0
  271. package/src/components/skipnav/skipnav.django.html +11 -0
  272. package/src/components/skipnav/skipnav.html +1 -0
  273. package/src/components/spinner/Spinner.tsx +46 -0
  274. package/src/components/spinner/config.json +44 -0
  275. package/src/components/spinner/spinner.django.html +8 -0
  276. package/src/components/spinner/spinner.html +219 -0
  277. package/src/components/status/Status.tsx +28 -0
  278. package/src/components/status/config.json +47 -0
  279. package/src/components/status/status.django.html +2 -0
  280. package/src/components/status/status.html +31 -0
  281. package/src/components/step-indicator/StepIndicator.tsx +80 -0
  282. package/src/components/step-indicator/config.json +54 -0
  283. package/src/components/step-indicator/step-indicator.django.html +29 -0
  284. package/src/components/step-indicator/step-indicator.html +243 -0
  285. package/src/components/summary-box/SummaryBox.tsx +41 -0
  286. package/src/components/summary-box/config.json +30 -0
  287. package/src/components/summary-box/summary-box.django.html +19 -0
  288. package/src/components/summary-box/summary-box.html +210 -0
  289. package/src/components/swap/Swap.tsx +47 -0
  290. package/src/components/swap/config.json +61 -0
  291. package/src/components/swap/swap.django.html +14 -0
  292. package/src/components/swap/swap.html +163 -0
  293. package/src/components/switch/Switch.tsx +73 -0
  294. package/src/components/switch/config.json +55 -0
  295. package/src/components/switch/switch.django.html +28 -0
  296. package/src/components/switch/switch.html +56 -0
  297. package/src/components/table/Table.tsx +334 -0
  298. package/src/components/table/TableBody.tsx +253 -0
  299. package/src/components/table/TableCell.tsx +37 -0
  300. package/src/components/table/TableContext.tsx +87 -0
  301. package/src/components/table/TableFoot.tsx +68 -0
  302. package/src/components/table/TableGroup.tsx +69 -0
  303. package/src/components/table/TableHead.tsx +139 -0
  304. package/src/components/table/TableRow.tsx +56 -0
  305. package/src/components/table/__pycache__/table_helper.cpython-312.pyc +0 -0
  306. package/src/components/table/config.json +297 -0
  307. package/src/components/table/hooks/useRowDetails.ts +34 -0
  308. package/src/components/table/hooks/useTableGroups.ts +61 -0
  309. package/src/components/table/hooks/useTableSelect.ts +82 -0
  310. package/src/components/table/hooks/useTableSort.ts +60 -0
  311. package/src/components/table/table-body.django.html +68 -0
  312. package/src/components/table/table-detail-row.django.html +14 -0
  313. package/src/components/table/table-foot.django.html +31 -0
  314. package/src/components/table/table-group.django.html +40 -0
  315. package/src/components/table/table-head.django.html +85 -0
  316. package/src/components/table/table-row.django.html +98 -0
  317. package/src/components/table/table.django.html +60 -0
  318. package/src/components/table/table.html +1186 -0
  319. package/src/components/table/table_helper.py +298 -0
  320. package/src/components/table/types.ts +68 -0
  321. package/src/components/tag/Tag.tsx +75 -0
  322. package/src/components/tag/config.json +54 -0
  323. package/src/components/tag/tag.django.html +39 -0
  324. package/src/components/tag/tag.html +45 -0
  325. package/src/components/tag-group/TagGroup.tsx +35 -0
  326. package/src/components/tag-group/config.json +24 -0
  327. package/src/components/tag-group/tag-group.django.html +11 -0
  328. package/src/components/tag-group/tag-group.html +36 -0
  329. package/src/components/task-list/TaskList.tsx +40 -0
  330. package/src/components/task-list/config.json +41 -0
  331. package/src/components/task-list/task-list.django.html +21 -0
  332. package/src/components/task-list/task-list.html +24 -0
  333. package/src/components/text-area/TextArea.tsx +78 -0
  334. package/src/components/text-area/config.json +78 -0
  335. package/src/components/text-area/text-area.django.html +53 -0
  336. package/src/components/text-area/text-area.html +59 -0
  337. package/src/components/theme-picker/ThemePicker.tsx +106 -0
  338. package/src/components/theme-picker/config.json +39 -0
  339. package/src/components/theme-picker/theme-picker.django.html +32 -0
  340. package/src/components/theme-picker/theme-picker.html +67 -0
  341. package/src/components/time-picker/TimePicker.jsx +87 -0
  342. package/src/components/time-picker/config.json +76 -0
  343. package/src/components/time-picker/time-picker.django.html +67 -0
  344. package/src/components/time-picker/time-picker.html +123 -0
  345. package/src/components/toggle/Toggle.tsx +80 -0
  346. package/src/components/toggle/config.json +69 -0
  347. package/src/components/toggle/toggle.django.html +19 -0
  348. package/src/components/toggle/toggle.html +85 -0
  349. package/src/components/tooltip/Tooltip.tsx +33 -0
  350. package/src/components/tooltip/config.json +33 -0
  351. package/src/components/tooltip/tooltip.django.html +5 -0
  352. package/src/components/tooltip/tooltip.html +57 -0
  353. package/src/components/villain/Villain.tsx +47 -0
  354. package/src/components/villain/config.json +44 -0
  355. package/src/components/villain/villain.django.html +19 -0
  356. package/src/components/villain/villain.html +39 -0
  357. package/src/declarations.d.ts +1 -0
  358. package/src/index.js +82 -0
  359. package/src/styles/core.scss +12 -0
@@ -0,0 +1,334 @@
1
+ import React, { useMemo, useState, useEffect, useId } from 'react';
2
+ import classnames from 'classnames';
3
+ import Pagination from '../pagination/Pagination';
4
+
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
+ );
62
+ }
63
+
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
67
+ columns?: TableColumn[];
68
+ data?: TableRowData[];
69
+ /** Row field used as the unique key (default `id`). */
70
+ primaryKey?: string;
71
+
72
+ // USWDS variants
73
+ striped?: boolean;
74
+ borderless?: boolean;
75
+ compact?: boolean;
76
+
77
+ // Layout / responsive
78
+ scrollable?: boolean;
79
+ /** Max height (CSS value); implies a scroll wrapper. */
80
+ height?: string;
81
+ responsive?: Responsive;
82
+ 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 / … */
122
+ children?: React.ReactNode;
123
+ }
124
+
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
164
+ }: 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
+ <Pagination
303
+ key={`${sortState.key}-${sortState.direction}`}
304
+ initialPage={1}
305
+ initialPageSize={pageSize}
306
+ totalItems={totalItems}
307
+ onPageChange={(page) => {
308
+ setCurrentPage(page);
309
+ if (isServerSide) paginateConfig.onPageChange?.(page, pageSize);
310
+ }}
311
+ onPageSizeChange={(size, page) => {
312
+ setPageSize(size);
313
+ setCurrentPage(page);
314
+ }}
315
+ {...(paginateConfig.pageSizeOptions ? { pageSizeOptions: paginateConfig.pageSizeOptions } : {})}
316
+ {...(paginateConfig.showStepOptions !== undefined ? { showStepOptions: paginateConfig.showStepOptions } : {})}
317
+ {...(paginateConfig.showSummary !== undefined ? { showSummary: paginateConfig.showSummary } : {})}
318
+ />
319
+ )}
320
+ </TableContext.Provider>
321
+ );
322
+ }
323
+
324
+ // ── Compound sub-components ───────────────────────────────────────────────────
325
+
326
+ export default Object.assign(Table, {
327
+ Head: TableHead,
328
+ Body: TableBody,
329
+ Foot: TableFoot,
330
+ Row: TableRow,
331
+ Cell: TableCell,
332
+ Group: TableGroup,
333
+ Caption,
334
+ });
@@ -0,0 +1,253 @@
1
+ import React, { useRef, useEffect, useId } from 'react';
2
+ import classnames from 'classnames';
3
+ import { useTableContext } from './TableContext';
4
+ import TableRow from './TableRow';
5
+ import TableGroup from './TableGroup';
6
+ import Icon from '../icon/Icon';
7
+ import Spinner from '../spinner/Spinner';
8
+ import Checkbox from '../checkbox/Checkbox';
9
+ import type { RowKey, TableColumn, TableRowData } from './types';
10
+
11
+ // ─── Infinite scroll sentinel ─────────────────────────────────────────────────
12
+
13
+ function OnMoreSentinel({ onMore }: { onMore: () => void }) {
14
+ const sentinelRef = useRef<HTMLTableRowElement>(null);
15
+ useEffect(() => {
16
+ if (!sentinelRef.current) return;
17
+ const observer = new IntersectionObserver(
18
+ (entries) => {
19
+ if (entries[0].isIntersecting) onMore();
20
+ },
21
+ { threshold: 0.1 }
22
+ );
23
+ observer.observe(sentinelRef.current);
24
+ return () => observer.disconnect();
25
+ }, [onMore]);
26
+ return (
27
+ <tr ref={sentinelRef} className="usx-table__sentinel" aria-hidden="true">
28
+ <td />
29
+ </tr>
30
+ );
31
+ }
32
+
33
+ // ─── Helpers ─────────────────────────────────────────────────────────────────
34
+
35
+ function getDataLabel(col: TableColumn): string | undefined {
36
+ if (typeof col.header === 'string') return col.header;
37
+ return col.stackLabel;
38
+ }
39
+
40
+ // Parent/group columns exist only in the header; body cells render for leaves only.
41
+ function getLeafCols(cols: TableColumn[]): TableColumn[] {
42
+ return cols.reduce<TableColumn[]>((acc, col) => {
43
+ if (col.hidden) return acc;
44
+ if (col.columns?.length) return acc.concat(getLeafCols(col.columns));
45
+ return acc.concat(col);
46
+ }, []);
47
+ }
48
+
49
+ // ─── Single data row ─────────────────────────────────────────────────────────
50
+
51
+ function DataRow({ row, rowIndex }: { row: TableRowData; rowIndex: number }) {
52
+ const {
53
+ columns,
54
+ primaryKey,
55
+ selectionMode,
56
+ selectionPosition,
57
+ isSelected,
58
+ handleSelect,
59
+ disabled: disabledKeys,
60
+ responsive,
61
+ rowDetails,
62
+ toggleRow,
63
+ isRowExpanded,
64
+ } = useTableContext();
65
+
66
+ const selectionUidPrefix = useId();
67
+ const key = row[primaryKey] as RowKey;
68
+ const selected = isSelected(key);
69
+ const isDisabled = Array.isArray(disabledKeys) && disabledKeys.includes(key);
70
+ const visibleCols = getLeafCols(columns);
71
+ const hasRowDetails = !!rowDetails;
72
+ const isExpanded = isRowExpanded(key);
73
+
74
+ const renderDetail = typeof rowDetails === 'function' ? rowDetails : rowDetails?.render || null;
75
+ const expandLabel = rowDetails && typeof rowDetails === 'object' ? rowDetails.expandLabel : undefined;
76
+
77
+ const totalCols = visibleCols.length + (selectionMode ? 1 : 0) + (hasRowDetails ? 1 : 0);
78
+
79
+ function handleToggleDetail(e: React.MouseEvent) {
80
+ e.stopPropagation();
81
+ toggleRow(key);
82
+ }
83
+
84
+ const isRadio = selectionMode === 'radio';
85
+ const selectionInputId = `${selectionUidPrefix}-select`;
86
+
87
+ // Real USWDS checkbox visuals are drawn on the <label> (::before), so use the
88
+ // Checkbox component for identical themed markup. It is internally
89
+ // uncontrolled (defaultChecked), so key it on the selected state to force a
90
+ // remount whenever selection changes programmatically (e.g. "select all").
91
+ const selectionCell = (
92
+ <td key="__selection__" className="usx-table__cell usx-table__cell--selection">
93
+ {isRadio ? (
94
+ <div className="usa-radio usx-table__radio">
95
+ <input
96
+ type="radio"
97
+ id={selectionInputId}
98
+ className="usa-radio__input"
99
+ checked={selected}
100
+ disabled={isDisabled}
101
+ aria-label={`Select row ${rowIndex + 1}`}
102
+ onChange={() => handleSelect(key)}
103
+ onClick={(e) => e.stopPropagation()}
104
+ />
105
+ <label className="usa-radio__label" htmlFor={selectionInputId} />
106
+ </div>
107
+ ) : (
108
+ <Checkbox
109
+ key={selected ? 'checked' : 'unchecked'}
110
+ id={selectionInputId}
111
+ checked={selected}
112
+ disabled={isDisabled}
113
+ ariaLabel={`Select row ${rowIndex + 1}`}
114
+ onChange={() => handleSelect(key)}
115
+ onClick={(e) => e.stopPropagation()}
116
+ className="usx-table__checkbox"
117
+ />
118
+ )}
119
+ </td>
120
+ );
121
+
122
+ const detailToggleCell = hasRowDetails ? (
123
+ <td key="__detail-toggle__" className="usx-table__cell usx-table__cell--detail-toggle" onClick={handleToggleDetail}>
124
+ <button
125
+ type="button"
126
+ className={classnames(
127
+ 'usa-button usa-button--unstyled',
128
+ 'usx-table__detail-toggle',
129
+ 'width-full',
130
+ isExpanded && 'usx-table__detail-toggle--expanded'
131
+ )}
132
+ aria-expanded={isExpanded}
133
+ aria-label={
134
+ expandLabel
135
+ ? typeof expandLabel === 'function'
136
+ ? expandLabel(row)
137
+ : expandLabel
138
+ : `${isExpanded ? 'Collapse' : 'Expand'} row details`
139
+ }
140
+ >
141
+ <Icon name={isExpanded ? 'expand_less' : 'expand_more'} aria-hidden="true" />
142
+ </button>
143
+ </td>
144
+ ) : null;
145
+
146
+ const dataCells = visibleCols.map((col) => {
147
+ const Tag = col.primary ? 'th' : 'td';
148
+ const cellClasses = classnames('usx-table__cell', col.align && `usx-table__cell--align-${col.align}`, col.className);
149
+ const dataLabel = responsive === 'stack' || responsive === 'stack-header' ? getDataLabel(col) : undefined;
150
+ const content = col.render ? col.render(row, rowIndex) : (row[col.key] as React.ReactNode);
151
+
152
+ return (
153
+ <Tag
154
+ key={col.key}
155
+ className={cellClasses}
156
+ scope={col.primary ? 'row' : undefined}
157
+ data-label={dataLabel}
158
+ style={col.width ? { width: col.width } : undefined}
159
+ >
160
+ {content ?? '--'}
161
+ </Tag>
162
+ );
163
+ });
164
+
165
+ const cells: React.ReactNode[] = [];
166
+ if (detailToggleCell) cells.push(detailToggleCell);
167
+ if (selectionMode && selectionPosition === 'left') cells.push(selectionCell);
168
+ cells.push(...dataCells);
169
+ if (selectionMode && selectionPosition === 'right') cells.push(selectionCell);
170
+
171
+ return (
172
+ <>
173
+ <TableRow rowData={row} selected={selected} disabled={isDisabled}>
174
+ {cells}
175
+ </TableRow>
176
+
177
+ {hasRowDetails && isExpanded && renderDetail && (
178
+ <tr className="usx-table__detail-row">
179
+ <td className="usx-table__detail-cell" colSpan={totalCols}>
180
+ {renderDetail(row)}
181
+ </td>
182
+ </tr>
183
+ )}
184
+ </>
185
+ );
186
+ }
187
+
188
+ // ─── TableBody ───────────────────────────────────────────────────────────────
189
+
190
+ export type TableBodyProps = React.HTMLAttributes<HTMLTableSectionElement>;
191
+
192
+ /**
193
+ * Renders `<tbody>`. Compound mode: pass children directly. Data-driven mode:
194
+ * renders rows from the table's data, respecting groups.
195
+ */
196
+ export default function TableBody({ className = '', children, ...props }: TableBodyProps) {
197
+ const { data, primaryKey, groupBy, groups, placeholder, totalCols, onMore, loading } = useTableContext();
198
+ const bodyClass = classnames('usx-table__body', className);
199
+
200
+ if (children) {
201
+ return (
202
+ <tbody className={bodyClass} {...props}>
203
+ {children}
204
+ </tbody>
205
+ );
206
+ }
207
+
208
+ const placeholderRow =
209
+ data.length === 0 && placeholder ? (
210
+ <tr className="usx-table__placeholder-row">
211
+ <td className="usx-table__placeholder-cell" colSpan={totalCols}>
212
+ {placeholder}
213
+ </td>
214
+ </tr>
215
+ ) : null;
216
+
217
+ const sentinel = onMore ? <OnMoreSentinel onMore={onMore} /> : null;
218
+
219
+ const loadingRow = loading ? (
220
+ <tr className="usx-table__loading-row" aria-live="polite">
221
+ <td className="usx-table__loading-cell" colSpan={totalCols}>
222
+ <Spinner size={3} label="Loading more rows…" />
223
+ </td>
224
+ </tr>
225
+ ) : null;
226
+
227
+ const renderRows = (rows: TableRowData[]) =>
228
+ rows.map((row, rowIndex) => <DataRow key={(row[primaryKey] as RowKey) ?? rowIndex} row={row} rowIndex={rowIndex} />);
229
+
230
+ if (!groupBy) {
231
+ return (
232
+ <tbody className={bodyClass} {...props}>
233
+ {placeholderRow}
234
+ {renderRows(data)}
235
+ {loadingRow}
236
+ {sentinel}
237
+ </tbody>
238
+ );
239
+ }
240
+
241
+ return (
242
+ <tbody className={bodyClass} {...props}>
243
+ {placeholderRow}
244
+ {(groups || []).map(({ key, rows }) => (
245
+ <TableGroup key={key} groupKey={key} label={key}>
246
+ {renderRows(rows)}
247
+ </TableGroup>
248
+ ))}
249
+ {loadingRow}
250
+ {sentinel}
251
+ </tbody>
252
+ );
253
+ }
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import classnames from 'classnames';
3
+ import type { Align } from './types';
4
+
5
+ export interface TableCellProps extends React.HTMLAttributes<HTMLTableCellElement> {
6
+ as?: 'td' | 'th';
7
+ align?: Align;
8
+ headerAlign?: Align;
9
+ colSpan?: number;
10
+ rowSpan?: number;
11
+ scope?: string;
12
+ /** data-label for stacked/responsive layouts. */
13
+ dataLabel?: string;
14
+ }
15
+
16
+ /** Renders a `<td>` or `<th>`; used by the compound API and data-driven rendering. */
17
+ export default function TableCell({
18
+ as: Tag = 'td',
19
+ align,
20
+ headerAlign,
21
+ colSpan,
22
+ rowSpan,
23
+ scope,
24
+ dataLabel,
25
+ className = '',
26
+ children,
27
+ ...props
28
+ }: TableCellProps) {
29
+ const resolvedAlign = Tag === 'th' ? headerAlign || align : align;
30
+ const classes = classnames('usx-table__cell', resolvedAlign && `usx-table__cell--align-${resolvedAlign}`, className);
31
+
32
+ return (
33
+ <Tag className={classes} colSpan={colSpan} rowSpan={rowSpan} scope={scope} data-label={dataLabel} {...props}>
34
+ {children}
35
+ </Tag>
36
+ );
37
+ }
@@ -0,0 +1,87 @@
1
+ import { createContext, useContext } from 'react';
2
+ import type { MouseEvent, KeyboardEvent, ReactNode } from 'react';
3
+ import type {
4
+ GroupBy,
5
+ Responsive,
6
+ RowDetails,
7
+ RowKey,
8
+ SelectionMode,
9
+ SortState,
10
+ TableColumn,
11
+ TableGroupEntry,
12
+ TableRowData,
13
+ } from './types';
14
+
15
+ export interface TableContextValue {
16
+ id: string;
17
+ columns: TableColumn[];
18
+ data: TableRowData[];
19
+ primaryKey: string;
20
+ sortState: SortState;
21
+ handleSort: (key: string) => void;
22
+ selectionMode: SelectionMode;
23
+ selectionPosition: 'left' | 'right';
24
+ selectedKeys: Set<RowKey>;
25
+ handleSelect: (key: RowKey) => void;
26
+ handleSelectAll: () => void;
27
+ isSelected: (key: RowKey) => boolean;
28
+ isAllSelected: boolean;
29
+ isIndeterminate: boolean;
30
+ allowSelectAll: boolean;
31
+ disabled: RowKey[];
32
+ onClickRow: ((row: TableRowData, e: MouseEvent | KeyboardEvent) => void) | null;
33
+ groupBy: GroupBy;
34
+ groups: TableGroupEntry[] | null;
35
+ expandedGroups: Set<string>;
36
+ toggleGroup: (key: string) => void;
37
+ isGroupExpanded: (key: string) => boolean;
38
+ expandedRows: Set<RowKey>;
39
+ toggleRow: (key: RowKey) => void;
40
+ isRowExpanded: (key: RowKey) => boolean;
41
+ rowDetails: RowDetails;
42
+ responsive: Responsive;
43
+ stickyFirstColumn: boolean;
44
+ totalCols: number;
45
+ placeholder: ReactNode;
46
+ onMore: (() => void) | null;
47
+ loading: boolean;
48
+ }
49
+
50
+ export const TableContext = createContext<TableContextValue>({
51
+ id: '',
52
+ columns: [],
53
+ data: [],
54
+ primaryKey: 'id',
55
+ sortState: { key: null, direction: null },
56
+ handleSort: () => {},
57
+ selectionMode: null,
58
+ selectionPosition: 'left',
59
+ selectedKeys: new Set(),
60
+ handleSelect: () => {},
61
+ handleSelectAll: () => {},
62
+ isSelected: () => false,
63
+ isAllSelected: false,
64
+ isIndeterminate: false,
65
+ allowSelectAll: true,
66
+ disabled: [],
67
+ onClickRow: null,
68
+ groupBy: null,
69
+ groups: null,
70
+ expandedGroups: new Set(),
71
+ toggleGroup: () => {},
72
+ isGroupExpanded: () => true,
73
+ expandedRows: new Set(),
74
+ toggleRow: () => {},
75
+ isRowExpanded: () => false,
76
+ rowDetails: null,
77
+ responsive: false,
78
+ stickyFirstColumn: false,
79
+ totalCols: 0,
80
+ placeholder: null,
81
+ onMore: null,
82
+ loading: false,
83
+ });
84
+
85
+ export function useTableContext() {
86
+ return useContext(TableContext);
87
+ }