@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,68 @@
1
+ import React from 'react';
2
+ import classnames from 'classnames';
3
+ import { useTableContext } from './TableContext';
4
+ import type { Aggregate, TableRowData } from './types';
5
+
6
+ function aggregate(data: TableRowData[], key: string, type: Aggregate): React.ReactNode {
7
+ const vals = data.map((row) => Number(row[key])).filter((v) => !isNaN(v));
8
+ if (!vals.length) return '--';
9
+ switch (type) {
10
+ case 'sum':
11
+ return vals.reduce((a, b) => a + b, 0);
12
+ case 'avg':
13
+ return (vals.reduce((a, b) => a + b, 0) / vals.length).toFixed(2);
14
+ case 'min':
15
+ return Math.min(...vals);
16
+ case 'max':
17
+ return Math.max(...vals);
18
+ case 'count':
19
+ return vals.length;
20
+ default:
21
+ return '--';
22
+ }
23
+ }
24
+
25
+ export type TableFootProps = React.HTMLAttributes<HTMLTableSectionElement>;
26
+
27
+ /**
28
+ * Renders `<tfoot>`. Compound mode: pass children. Data-driven mode: renders a
29
+ * single footer row from `column.footer` values or `column.aggregate`.
30
+ */
31
+ export default function TableFoot({ className = '', children, ...props }: TableFootProps) {
32
+ const { columns, data, selectionMode, rowDetails } = useTableContext();
33
+
34
+ if (children) {
35
+ return (
36
+ <tfoot className={classnames('usx-table__foot', className)} {...props}>
37
+ {children}
38
+ </tfoot>
39
+ );
40
+ }
41
+
42
+ const visibleCols = columns.filter((c) => !c.hidden);
43
+ const hasFooter = visibleCols.some((c) => c.footer !== undefined || c.aggregate);
44
+ if (!hasFooter) return null;
45
+
46
+ return (
47
+ <tfoot className={classnames('usx-table__foot', className)} {...props}>
48
+ <tr className="usx-table__foot-row">
49
+ {!!rowDetails && <td className="usx-table__cell" />}
50
+ {!!selectionMode && <td className="usx-table__cell usx-table__cell--selection" />}
51
+
52
+ {visibleCols.map((col) => {
53
+ let content: React.ReactNode = '--';
54
+ if (col.footer !== undefined) {
55
+ content = typeof col.footer === 'function' ? col.footer(data) : col.footer;
56
+ } else if (col.aggregate) {
57
+ content = aggregate(data, col.key, col.aggregate);
58
+ }
59
+ return (
60
+ <td key={col.key} className={classnames('usx-table__cell', col.align && `usx-table__cell--align-${col.align}`)}>
61
+ {content}
62
+ </td>
63
+ );
64
+ })}
65
+ </tr>
66
+ </tfoot>
67
+ );
68
+ }
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+ import classnames from 'classnames';
3
+ import { useTableContext } from './TableContext';
4
+
5
+ // `onToggle` exists on HTMLAttributes as a DOM event; the group API redefines it.
6
+ export interface TableGroupProps extends Omit<React.HTMLAttributes<HTMLTableRowElement>, 'onToggle'> {
7
+ /** Display label for the group header. */
8
+ label: React.ReactNode;
9
+ /** Unique key identifying this group (used for context-managed expand state). */
10
+ groupKey: string;
11
+ /** Controlled expanded state; omit to use the table's own group state. */
12
+ expanded?: boolean;
13
+ /** Controlled toggle handler. */
14
+ onToggle?: (groupKey: string) => void;
15
+ /** colSpan for the group header cell. Defaults to totalCols from context. */
16
+ colSpan?: number;
17
+ }
18
+
19
+ /** Expandable group subheader row inside `<tbody>`. */
20
+ export default function TableGroup({
21
+ label,
22
+ groupKey,
23
+ expanded: expandedProp,
24
+ onToggle: onToggleProp,
25
+ colSpan,
26
+ className = '',
27
+ children,
28
+ ...props
29
+ }: TableGroupProps) {
30
+ const { toggleGroup, isGroupExpanded, totalCols } = useTableContext();
31
+
32
+ const isExpanded = expandedProp !== undefined ? expandedProp : isGroupExpanded(groupKey);
33
+
34
+ const handleToggle = (e: React.SyntheticEvent) => {
35
+ e.stopPropagation();
36
+ if (onToggleProp) onToggleProp(groupKey);
37
+ else toggleGroup(groupKey);
38
+ };
39
+
40
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
41
+ if (e.key === 'Enter' || e.key === ' ') {
42
+ e.preventDefault();
43
+ handleToggle(e);
44
+ }
45
+ };
46
+
47
+ return (
48
+ <>
49
+ <tr className={classnames('usx-table__group-row', className)} {...props}>
50
+ <td colSpan={colSpan || totalCols || 1} className="usx-table__group-cell">
51
+ <div className="usx-accordion usa-accordion">
52
+ <h4 className="usa-accordion__heading">
53
+ <button
54
+ type="button"
55
+ className="usa-accordion__button usx-table__group-toggle"
56
+ aria-expanded={isExpanded}
57
+ onClick={handleToggle}
58
+ onKeyDown={handleKeyDown}
59
+ >
60
+ {label}
61
+ </button>
62
+ </h4>
63
+ </div>
64
+ </td>
65
+ </tr>
66
+ {isExpanded && children}
67
+ </>
68
+ );
69
+ }
@@ -0,0 +1,139 @@
1
+ import React from 'react';
2
+ import classnames from 'classnames';
3
+ import { useTableContext } from './TableContext';
4
+ import Icon from '../icon/Icon';
5
+ import Checkbox from '../checkbox/Checkbox';
6
+ import type { SortDirection, TableColumn } from './types';
7
+
8
+ // ─── Multi-level header helpers ──────────────────────────────────────────────
9
+
10
+ function getDepth(columns: TableColumn[]): number {
11
+ let max = 1;
12
+ for (const col of columns) {
13
+ if (col.columns?.length) max = Math.max(max, 1 + getDepth(col.columns));
14
+ }
15
+ return max;
16
+ }
17
+
18
+ function getLeafCount(col: TableColumn): number {
19
+ if (!col.columns?.length) return 1;
20
+ return col.columns.reduce((sum, c) => sum + getLeafCount(c), 0);
21
+ }
22
+
23
+ interface HeaderCell {
24
+ col: TableColumn;
25
+ rowSpan: number;
26
+ colSpan: number;
27
+ }
28
+
29
+ // One array of cells per header level; leaf columns span down to the last level.
30
+ function buildHeaderRows(columns: TableColumn[], totalDepth: number): HeaderCell[][] {
31
+ const rows: HeaderCell[][] = Array.from({ length: totalDepth }, () => []);
32
+ function traverse(cols: TableColumn[], level: number) {
33
+ for (const col of cols) {
34
+ const isLeaf = !col.columns?.length;
35
+ rows[level].push({ col, rowSpan: isLeaf ? totalDepth - level : 1, colSpan: isLeaf ? 1 : getLeafCount(col) });
36
+ if (!isLeaf) traverse(col.columns!, level + 1);
37
+ }
38
+ }
39
+ traverse(columns, 0);
40
+ return rows;
41
+ }
42
+
43
+ function SortIcon({ direction }: { direction: SortDirection }) {
44
+ const name = direction === 'asc' ? 'arrow_upward' : direction === 'desc' ? 'arrow_downward' : 'sort_arrow';
45
+ return <Icon name={name} aria-hidden="true" />;
46
+ }
47
+
48
+ export type TableHeadProps = React.HTMLAttributes<HTMLTableSectionElement>;
49
+
50
+ /**
51
+ * Renders `<thead>`. Compound mode: wrap your own `<tr>`/`<th>` children.
52
+ * Data-driven mode: pass no children; renders from the table's columns.
53
+ */
54
+ export default function TableHead({ className = '', children, ...props }: TableHeadProps) {
55
+ const { id, columns, sortState, handleSort, selectionMode, selectionPosition, handleSelectAll, allowSelectAll, rowDetails } =
56
+ useTableContext();
57
+
58
+ if (children) {
59
+ return (
60
+ <thead className={classnames('usx-table__head', className)} {...props}>
61
+ {children}
62
+ </thead>
63
+ );
64
+ }
65
+
66
+ const visibleCols = columns.filter((c) => !c.hidden);
67
+ const totalDepth = getDepth(visibleCols);
68
+ const headerRows = buildHeaderRows(visibleCols, totalDepth);
69
+ const hasRowDetails = !!rowDetails;
70
+ const hasSelection = !!selectionMode;
71
+
72
+ const selectAllCell = (
73
+ <th scope="col" rowSpan={totalDepth} className="usx-table__cell usx-table__cell--selection">
74
+ {selectionMode === 'checkbox' && allowSelectAll && (
75
+ <Checkbox id={`${id}-select-all`} onChange={handleSelectAll} ariaLabel="Select all rows" className="usx-table__checkbox" />
76
+ )}
77
+ </th>
78
+ );
79
+
80
+ return (
81
+ <thead className={classnames('usx-table__head', className)} {...props}>
82
+ {/* Sort announcement region for screen readers */}
83
+ <tr hidden aria-hidden="true">
84
+ <td>
85
+ <span className="usa-sr-only usa-table__announcement-region" aria-live="polite" id={`${id}-sort-announcement`} />
86
+ </td>
87
+ </tr>
88
+
89
+ {headerRows.map((row, rowIndex) => (
90
+ <tr key={rowIndex} className="usx-table__head-row">
91
+ {hasRowDetails && rowIndex === 0 && (
92
+ <th scope="col" rowSpan={totalDepth} className="usx-table__cell usx-table__cell--detail-toggle" aria-label="Row details" />
93
+ )}
94
+ {hasSelection && selectionPosition === 'left' && rowIndex === 0 && selectAllCell}
95
+
96
+ {row.map(({ col, rowSpan, colSpan }) => {
97
+ const isSortable = col.sortable === true;
98
+ const sortDir = sortState.key === col.key ? sortState.direction : null;
99
+ const cellClasses = classnames(
100
+ 'usx-table__cell',
101
+ col.headerAlign && `usx-table__cell--align-${col.headerAlign}`,
102
+ !col.headerAlign && col.align && `usx-table__cell--align-${col.align}`,
103
+ col.headerClassName
104
+ );
105
+ const ariaSort = !isSortable ? undefined : sortDir === 'asc' ? 'ascending' : sortDir === 'desc' ? 'descending' : undefined;
106
+
107
+ return (
108
+ <th
109
+ key={col.key}
110
+ scope="col"
111
+ className={cellClasses}
112
+ rowSpan={rowSpan > 1 ? rowSpan : undefined}
113
+ colSpan={colSpan > 1 ? colSpan : undefined}
114
+ style={col.width ? { width: col.width } : undefined}
115
+ aria-sort={ariaSort}
116
+ data-sortable={isSortable || undefined}
117
+ >
118
+ {isSortable ? (
119
+ <button
120
+ type="button"
121
+ className={classnames('usx-table__sort-button', sortDir && 'usx-table__sort-button--active')}
122
+ onClick={() => handleSort(col.key)}
123
+ >
124
+ {col.header}
125
+ <SortIcon direction={sortDir} />
126
+ </button>
127
+ ) : (
128
+ col.header
129
+ )}
130
+ </th>
131
+ );
132
+ })}
133
+
134
+ {hasSelection && selectionPosition === 'right' && rowIndex === 0 && selectAllCell}
135
+ </tr>
136
+ ))}
137
+ </thead>
138
+ );
139
+ }
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import classnames from 'classnames';
3
+ import { useTableContext } from './TableContext';
4
+ import type { TableRowData } from './types';
5
+
6
+ export interface TableRowProps extends Omit<React.HTMLAttributes<HTMLTableRowElement>, 'onClick'> {
7
+ /** The data object for this row (passed to the table-level onClickRow). */
8
+ rowData?: TableRowData | null;
9
+ selected?: boolean;
10
+ disabled?: boolean;
11
+ onClick?: (e: React.MouseEvent<HTMLTableRowElement> | React.KeyboardEvent<HTMLTableRowElement>) => void;
12
+ }
13
+
14
+ /** Renders a `<tr>`; created internally in data-driven mode, or directly by compound consumers. */
15
+ export default function TableRow({
16
+ rowData = null,
17
+ selected = false,
18
+ disabled = false,
19
+ className = '',
20
+ onClick,
21
+ children,
22
+ ...props
23
+ }: TableRowProps) {
24
+ const { onClickRow } = useTableContext();
25
+
26
+ const isClickable = !!(onClick || onClickRow);
27
+ const classes = classnames(
28
+ 'usx-table__row',
29
+ selected && 'usx-table__row--selected',
30
+ disabled && 'usx-table__row--disabled',
31
+ isClickable && !disabled && 'usx-table__row--clickable',
32
+ className
33
+ );
34
+
35
+ function handleClick(e: React.MouseEvent<HTMLTableRowElement> | React.KeyboardEvent<HTMLTableRowElement>) {
36
+ if (disabled) return;
37
+ onClick?.(e);
38
+ if (onClickRow && rowData) onClickRow(rowData, e);
39
+ }
40
+
41
+ function handleKeyDown(e: React.KeyboardEvent<HTMLTableRowElement>) {
42
+ if (disabled) return;
43
+ if (e.key === 'Enter' || e.key === ' ') {
44
+ e.preventDefault();
45
+ handleClick(e);
46
+ }
47
+ }
48
+
49
+ const interactiveProps = isClickable && !disabled ? { tabIndex: 0, onClick: handleClick, onKeyDown: handleKeyDown } : {};
50
+
51
+ return (
52
+ <tr className={classes} {...interactiveProps} {...props}>
53
+ {children}
54
+ </tr>
55
+ );
56
+ }
@@ -0,0 +1,297 @@
1
+ {
2
+ "name": "table",
3
+ "template": "table/table.django.html",
4
+ "version": 1,
5
+ "required": [
6
+ "columns",
7
+ "data"
8
+ ],
9
+ "default": {},
10
+ "props": {
11
+ "id": {
12
+ "type": "string",
13
+ "description": "ID for the <table> element. Required for accessibility when using sticky headers or scrollable tables."
14
+ },
15
+ "columns": {
16
+ "type": "array",
17
+ "description": "Column definitions. Each item: { key, header, render, align, sortable, width, pin, primary, hidden, aggregate, footer, className, headerClassName }.",
18
+ "items": {
19
+ "type": "object",
20
+ "description": "Column definition.",
21
+ "properties": {
22
+ "key": {
23
+ "type": "string",
24
+ "description": "Row data property to read."
25
+ },
26
+ "header": {
27
+ "type": "string",
28
+ "description": "Column header text."
29
+ },
30
+ "render": {
31
+ "type": "function",
32
+ "description": "Custom cell renderer: (value, row) => node."
33
+ },
34
+ "align": {
35
+ "type": "select",
36
+ "options": [
37
+ "left",
38
+ "center",
39
+ "right"
40
+ ],
41
+ "description": "Cell text alignment."
42
+ },
43
+ "sortable": {
44
+ "type": "boolean",
45
+ "description": "Allow sorting by this column."
46
+ },
47
+ "width": {
48
+ "type": "string",
49
+ "description": "CSS width for the column."
50
+ },
51
+ "pin": {
52
+ "type": "select",
53
+ "options": [
54
+ "left",
55
+ "right"
56
+ ],
57
+ "description": "Pin the column on horizontal scroll."
58
+ },
59
+ "primary": {
60
+ "type": "boolean",
61
+ "description": "Marks the primary column shown in stacked/responsive mode."
62
+ },
63
+ "hidden": {
64
+ "type": "boolean",
65
+ "description": "Hide the column."
66
+ },
67
+ "aggregate": {
68
+ "type": "function",
69
+ "description": "Footer aggregate function: (data) => value."
70
+ },
71
+ "footer": {
72
+ "type": "string",
73
+ "description": "Static footer cell content."
74
+ },
75
+ "className": {
76
+ "type": "string",
77
+ "description": "Additional cell classes."
78
+ },
79
+ "headerClassName": {
80
+ "type": "string",
81
+ "description": "Additional header cell classes."
82
+ }
83
+ }
84
+ }
85
+ },
86
+ "data": {
87
+ "type": "array",
88
+ "description": "Array of row data objects."
89
+ },
90
+ "primaryKey": {
91
+ "type": "string",
92
+ "default": "id",
93
+ "description": "Property name used as the unique row identifier."
94
+ },
95
+ "caption": {
96
+ "type": "string",
97
+ "description": "Table caption rendered as <caption>."
98
+ },
99
+ "striped": {
100
+ "type": "boolean",
101
+ "default": false,
102
+ "description": "Apply alternating row shading (usa-table--striped)."
103
+ },
104
+ "borderless": {
105
+ "type": "boolean",
106
+ "default": false,
107
+ "description": "Remove cell borders (usa-table--borderless)."
108
+ },
109
+ "compact": {
110
+ "type": "boolean",
111
+ "default": false,
112
+ "description": "Reduce cell padding (usa-table--compact)."
113
+ },
114
+ "scrollable": {
115
+ "type": "boolean",
116
+ "default": false,
117
+ "description": "Wrap the table in a horizontally-scrollable container."
118
+ },
119
+ "height": {
120
+ "type": "string",
121
+ "description": "CSS max-height for vertical scrolling (e.g. '400px')."
122
+ },
123
+ "responsive": {
124
+ "type": "select",
125
+ "options": [
126
+ "false",
127
+ "stack",
128
+ "stack-header"
129
+ ],
130
+ "default": "false",
131
+ "description": "Responsive mode: 'stack' or 'stack-header' for mobile stacking behaviour."
132
+ },
133
+ "stickyHeader": {
134
+ "type": "boolean",
135
+ "default": false,
136
+ "description": "Keep the header row visible while scrolling (usa-table--sticky-header)."
137
+ },
138
+ "stickyFirstColumn": {
139
+ "type": "boolean",
140
+ "default": false,
141
+ "description": "Sticky-pin the first column on horizontal scroll."
142
+ },
143
+ "sortable": {
144
+ "type": "boolean",
145
+ "default": false,
146
+ "description": "Enable sorting on all columns (individual columns can opt out via column.sortable: false)."
147
+ },
148
+ "sort": {
149
+ "type": "object",
150
+ "description": "Controlled sort state: { key: string, direction: 'asc' | 'desc' | null }."
151
+ },
152
+ "onSort": {
153
+ "type": "function",
154
+ "description": "Callback fired when a column header is clicked: ({ key, direction }) => void."
155
+ },
156
+ "selectionMode": {
157
+ "type": "select",
158
+ "options": [
159
+ "null",
160
+ "checkbox",
161
+ "radio"
162
+ ],
163
+ "default": "null",
164
+ "description": "Row selection mode. 'checkbox' enables multi-select; 'radio' enables single-select."
165
+ },
166
+ "selectionPosition": {
167
+ "type": "select",
168
+ "options": [
169
+ "left",
170
+ "right"
171
+ ],
172
+ "default": "left",
173
+ "description": "Position of the selection column."
174
+ },
175
+ "select": {
176
+ "type": "array",
177
+ "description": "Controlled array of selected primary key values."
178
+ },
179
+ "onSelect": {
180
+ "type": "function",
181
+ "description": "Callback fired when selection changes: (selectedKeys[]) => void."
182
+ },
183
+ "allowSelectAll": {
184
+ "type": "boolean",
185
+ "default": true,
186
+ "description": "Show 'select all' checkbox in header (checkbox mode only)."
187
+ },
188
+ "disabled": {
189
+ "type": "array",
190
+ "description": "Array of primary key values for rows that should be non-interactive."
191
+ },
192
+ "onClickRow": {
193
+ "type": "function",
194
+ "description": "Callback fired when a row is clicked: (rowData, event) => void."
195
+ },
196
+ "groupBy": {
197
+ "type": "object",
198
+ "description": "Group rows by a property. String shorthand or object: { property, expand, onExpand, defaultExpanded }."
199
+ },
200
+ "rowDetails": {
201
+ "type": "object",
202
+ "description": "Enable expandable row detail panels. Function: (row) => ReactNode. Object: { render, expand, onExpand, expandLabel }."
203
+ },
204
+ "showFooter": {
205
+ "type": "boolean",
206
+ "default": false,
207
+ "description": "Render a <tfoot> row using column.footer or column.aggregate values."
208
+ },
209
+ "paginate": {
210
+ "type": "object",
211
+ "description": "Enable pagination. true for client-side; object { pageSize, totalCount, onPageChange } for server-side."
212
+ },
213
+ "onMore": {
214
+ "type": "function",
215
+ "description": "Infinite scroll callback, called when the last row becomes visible."
216
+ },
217
+ "loading": {
218
+ "type": "boolean",
219
+ "default": false,
220
+ "description": "Show a loading state overlay. Does not affect interactivity."
221
+ },
222
+ "placeholder": {
223
+ "type": "string",
224
+ "description": "Content shown when the data array is empty."
225
+ },
226
+ "className": {
227
+ "type": "string",
228
+ "default": "",
229
+ "description": "Additional CSS classes applied to the <table> element."
230
+ },
231
+ "header_rows": {
232
+ "type": "array",
233
+ "default": null,
234
+ "description": "Django only. Pre-computed header row structure from table_helper.build_header_rows(columns). Required for rendering; compute in the view and pass as context."
235
+ },
236
+ "leaf_columns": {
237
+ "type": "array",
238
+ "default": null,
239
+ "description": "Django only. Flat list of leaf (non-parent) columns from table_helper.get_leaf_cols(columns). Required for body and footer rendering."
240
+ },
241
+ "total_cols": {
242
+ "type": "number",
243
+ "default": null,
244
+ "description": "Django only. Total column count including aux columns (selection, detail). From table_helper.total_col_count()."
245
+ },
246
+ "total_depth": {
247
+ "type": "number",
248
+ "default": 1,
249
+ "description": "Django only. Number of header levels; len(header_rows). Required for rowspan calculations."
250
+ },
251
+ "groups": {
252
+ "type": "array",
253
+ "default": null,
254
+ "description": "Django only. Pre-grouped data from table_helper.group_data(data, field). Required when groupBy is set."
255
+ },
256
+ "defaultExpanded": {
257
+ "type": "boolean",
258
+ "default": true,
259
+ "description": "Django only. Whether grouped rows start expanded. Defaults to true. Pass false to render all groups collapsed."
260
+ },
261
+ "footerValues": {
262
+ "type": "object",
263
+ "default": null,
264
+ "description": "Django only. Pre-computed footer values dict from table_helper.compute_footer(columns, data). Required when showFooter is True."
265
+ },
266
+ "expandedRows": {
267
+ "type": "array",
268
+ "default": [],
269
+ "description": "Django only. List of primary-key values whose detail rows are open on initial render. Mirrors the React rowDetails.expand controlled prop."
270
+ },
271
+ "rowDetailTemplate": {
272
+ "type": "string",
273
+ "default": null,
274
+ "description": "Django only. Path to a Django partial template rendered as row-detail content (replaces React rowDetails.render)."
275
+ },
276
+ "rowDetailField": {
277
+ "type": "string",
278
+ "default": null,
279
+ "description": "Django only. Key in each row dict whose value is used as inline row-detail content (simpler alternative to rowDetailTemplate)."
280
+ },
281
+ "rowUrlField": {
282
+ "type": "string",
283
+ "default": null,
284
+ "description": "Django only. Key in each row dict holding the navigation URL for clickable rows (replaces React onClickRow). The block-link CSS pattern is used; no JS required."
285
+ },
286
+ "paginateUrlPrefix": {
287
+ "type": "string",
288
+ "default": "?page=",
289
+ "description": "Django only. URL prefix for pagination page links, forwarded to the pagination sub-template."
290
+ },
291
+ "pagination": {
292
+ "type": "object",
293
+ "default": null,
294
+ "description": "Django only. Pagination state dict from table_helper.paginate_table(): {current_page, total_pages, total, page_size}. Required when paginate is True."
295
+ }
296
+ }
297
+ }
@@ -0,0 +1,34 @@
1
+ import { useState, useCallback, useMemo } from 'react';
2
+ import type { RowDetails, RowKey } from '../types';
3
+
4
+ export interface UseRowDetailsOptions {
5
+ rowDetails: RowDetails;
6
+ }
7
+
8
+ export function useRowDetails({ rowDetails }: UseRowDetailsOptions) {
9
+ const config = rowDetails && typeof rowDetails === 'object' ? rowDetails : null;
10
+ const expandProp = config?.expand;
11
+ const onExpandProp = config?.onExpand;
12
+ const isControlled = expandProp !== undefined && expandProp !== null;
13
+
14
+ const [internalExpanded, setInternalExpanded] = useState<Set<RowKey>>(() => new Set(expandProp || []));
15
+ const expandedRows = useMemo(
16
+ () => (isControlled ? new Set<RowKey>(expandProp || []) : internalExpanded),
17
+ [isControlled, expandProp, internalExpanded]
18
+ );
19
+
20
+ const toggleRow = useCallback(
21
+ (key: RowKey) => {
22
+ const next = new Set(expandedRows);
23
+ if (next.has(key)) next.delete(key);
24
+ else next.add(key);
25
+ if (!isControlled) setInternalExpanded(next);
26
+ onExpandProp?.([...next]);
27
+ },
28
+ [expandedRows, isControlled, onExpandProp]
29
+ );
30
+
31
+ const isRowExpanded = useCallback((key: RowKey) => expandedRows.has(key), [expandedRows]);
32
+
33
+ return { expandedRows, toggleRow, isRowExpanded };
34
+ }