@solexllc/usx-react 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/README.md +16 -0
  2. package/dist/index.cjs +3231 -3270
  3. package/dist/index.js +3232 -3271
  4. package/package.json +4 -4
  5. package/src/components/accordion/Accordion.tsx +4 -1
  6. package/src/components/accordion/accordion.django.html +1 -1
  7. package/src/components/accordion/config.json +1 -0
  8. package/src/components/banner/Banner.tsx +3 -1
  9. package/src/components/banner/banner.django.html +1 -1
  10. package/src/components/banner/config.json +1 -0
  11. package/src/components/carousel/carousel.django-snapshot.html +0 -40
  12. package/src/components/carousel/carousel.react-snapshot.html +0 -38
  13. package/src/components/character-count/CharacterCount.tsx +3 -0
  14. package/src/components/character-count/character-count.django-snapshot.html +43 -0
  15. package/src/components/character-count/character-count.django.html +2 -2
  16. package/src/components/character-count/character-count.react-snapshot.html +37 -0
  17. package/src/components/character-count/config.json +9 -0
  18. package/src/components/checkbox/Checkbox.tsx +17 -13
  19. package/src/components/checkbox/checkbox.django-snapshot.html +18 -0
  20. package/src/components/checkbox/checkbox.django.html +6 -4
  21. package/src/components/checkbox/checkbox.react-snapshot.html +14 -0
  22. package/src/components/checkbox/config.json +10 -1
  23. package/src/components/checkbox-group/checkbox-group.django-snapshot.html +54 -0
  24. package/src/components/checkbox-group/checkbox-group.react-snapshot.html +45 -0
  25. package/src/components/combobox/Combobox.tsx +6 -1
  26. package/src/components/combobox/combobox.django-snapshot.html +141 -0
  27. package/src/components/combobox/combobox.django.html +2 -2
  28. package/src/components/combobox/combobox.react-snapshot.html +76 -0
  29. package/src/components/combobox/config.json +9 -0
  30. package/src/components/data-table/DataTable.tsx +180 -0
  31. package/src/components/data-table/README.md +42 -0
  32. package/src/components/data-table/TableBody.tsx +123 -0
  33. package/src/components/{table → data-table}/TableCell.tsx +6 -3
  34. package/src/components/data-table/TableContext.tsx +49 -0
  35. package/src/components/{table → data-table}/TableFoot.tsx +8 -7
  36. package/src/components/data-table/TableGroup.tsx +62 -0
  37. package/src/components/data-table/TableHead.tsx +126 -0
  38. package/src/components/data-table/TableRow.tsx +24 -0
  39. package/src/components/data-table/cells.ts +49 -0
  40. package/src/components/data-table/columns.ts +15 -0
  41. package/src/components/data-table/config.json +379 -0
  42. package/src/components/data-table/data-table.django-snapshot.html +13560 -0
  43. package/src/components/data-table/data-table.django.html +13 -0
  44. package/src/components/data-table/data-table.html +34 -0
  45. package/src/components/data-table/data-table.react-snapshot.html +12033 -0
  46. package/src/components/{table → data-table}/table-body.django.html +12 -12
  47. package/src/components/{table → data-table}/table-foot.django.html +6 -6
  48. package/src/components/data-table/table-group.django.html +24 -0
  49. package/src/components/data-table/table-head.django.html +21 -0
  50. package/src/components/data-table/table-row.django.html +57 -0
  51. package/src/components/{table → data-table}/types.ts +48 -5
  52. package/src/components/date-picker/DatePicker.tsx +6 -1
  53. package/src/components/date-picker/config.json +9 -0
  54. package/src/components/date-picker/date-picker.django-snapshot.html +23 -0
  55. package/src/components/date-picker/date-picker.django.html +4 -4
  56. package/src/components/date-picker/date-picker.react-snapshot.html +19 -0
  57. package/src/components/date-range-picker/DateRangePicker.tsx +11 -2
  58. package/src/components/date-range-picker/config.json +14 -0
  59. package/src/components/date-range-picker/date-range-picker.django-snapshot.html +47 -0
  60. package/src/components/date-range-picker/date-range-picker.django.html +5 -5
  61. package/src/components/date-range-picker/date-range-picker.react-snapshot.html +38 -0
  62. package/src/components/drawer/Drawer.tsx +3 -1
  63. package/src/components/drawer/config.json +4 -0
  64. package/src/components/drawer/drawer.django.html +1 -1
  65. package/src/components/file-input/FileInput.tsx +7 -2
  66. package/src/components/file-input/_contents.django.html +2 -1
  67. package/src/components/file-input/config.json +4 -0
  68. package/src/components/header/Header.tsx +15 -9
  69. package/src/components/header/config.json +1 -0
  70. package/src/components/header/header.django-snapshot.html +24 -0
  71. package/src/components/header/header.django.html +8 -4
  72. package/src/components/header/header.html +20 -0
  73. package/src/components/header/header.react-snapshot.html +20 -0
  74. package/src/components/in-page-nav/InPageNav.tsx +3 -0
  75. package/src/components/in-page-nav/config.json +1 -0
  76. package/src/components/in-page-nav/in-page-nav.django.html +1 -1
  77. package/src/components/input/Input.tsx +3 -0
  78. package/src/components/input/config.json +10 -0
  79. package/src/components/input/input.django-snapshot.html +24 -0
  80. package/src/components/input/input.django.html +4 -4
  81. package/src/components/input/input.react-snapshot.html +22 -0
  82. package/src/components/language-selector/LanguageSelector.tsx +10 -5
  83. package/src/components/language-selector/config.json +1 -0
  84. package/src/components/language-selector/language-selector.django.html +2 -2
  85. package/src/components/layout/Layout.tsx +3 -1
  86. package/src/components/layout/config.json +4 -0
  87. package/src/components/layout/layout.django.html +1 -1
  88. package/src/components/memorable-date/MemorableDate.tsx +18 -3
  89. package/src/components/memorable-date/config.json +15 -0
  90. package/src/components/memorable-date/memorable-date.django-snapshot.html +82 -0
  91. package/src/components/memorable-date/memorable-date.django.html +14 -14
  92. package/src/components/memorable-date/memorable-date.react-snapshot.html +70 -0
  93. package/src/components/modal/Modal.tsx +3 -0
  94. package/src/components/modal/config.json +1 -0
  95. package/src/components/modal/modal.django.html +1 -1
  96. package/src/components/pagination/Pagination.tsx +7 -1
  97. package/src/components/pagination/config.json +8 -0
  98. package/src/components/pagination/navigation/PaginationNavigation.tsx +10 -0
  99. package/src/components/pagination/step-options/PaginationStepOptions.tsx +3 -0
  100. package/src/components/popover/Popover.tsx +3 -0
  101. package/src/components/popover/config.json +4 -0
  102. package/src/components/popover/popover.django-snapshot.html +30 -0
  103. package/src/components/popover/popover.django.html +1 -0
  104. package/src/components/radio-buttons/RadioButtons.tsx +41 -27
  105. package/src/components/radio-buttons/config.json +19 -1
  106. package/src/components/radio-buttons/radio-buttons.django-snapshot.html +93 -60
  107. package/src/components/radio-buttons/radio-buttons.django.html +16 -28
  108. package/src/components/radio-buttons/radio-buttons.react-snapshot.html +53 -0
  109. package/src/components/range-slider/RangeSlider.tsx +4 -2
  110. package/src/components/range-slider/config.json +1 -0
  111. package/src/components/range-slider/range-slider.django-snapshot.html +17 -0
  112. package/src/components/range-slider/range-slider.django.html +4 -4
  113. package/src/components/range-slider/range-slider.react-snapshot.html +16 -0
  114. package/src/components/search/Search.tsx +6 -1
  115. package/src/components/search/config.json +5 -0
  116. package/src/components/search/search.django-snapshot.html +683 -563
  117. package/src/components/search/search.django.html +1 -1
  118. package/src/components/search/search.react-snapshot.html +25 -0
  119. package/src/components/select/Select.tsx +3 -1
  120. package/src/components/select/config.json +5 -0
  121. package/src/components/select/select.django-snapshot.html +15 -0
  122. package/src/components/select/select.django.html +2 -2
  123. package/src/components/select/select.react-snapshot.html +11 -0
  124. package/src/components/switch/Switch.tsx +13 -70
  125. package/src/components/switch/config.json +60 -23
  126. package/src/components/switch/switch.django-snapshot.html +507 -56
  127. package/src/components/switch/switch.django.html +23 -26
  128. package/src/components/switch/switch.html +425 -33
  129. package/src/components/switch/switch.react-snapshot.html +447 -58
  130. package/src/components/table/Table.tsx +66 -334
  131. package/src/components/table/config.json +22 -339
  132. package/src/components/table/table.django-snapshot.html +712 -1482
  133. package/src/components/table/table.django.html +14 -59
  134. package/src/components/table/table.html +7 -2364
  135. package/src/components/table/table.react-snapshot.html +711 -2085
  136. package/src/components/text-area/TextArea.tsx +3 -1
  137. package/src/components/text-area/config.json +5 -0
  138. package/src/components/text-area/text-area.django-snapshot.html +18 -0
  139. package/src/components/text-area/text-area.django.html +4 -4
  140. package/src/components/text-area/text-area.react-snapshot.html +16 -0
  141. package/src/components/theme-picker/ThemePicker.tsx +3 -1
  142. package/src/components/theme-picker/config.json +14 -1
  143. package/src/components/theme-picker/theme-picker.django-snapshot.html +64 -0
  144. package/src/components/theme-picker/theme-picker.django.html +2 -2
  145. package/src/components/theme-picker/theme-picker.react-snapshot.html +52 -0
  146. package/src/components/time-picker/TimePicker.tsx +6 -1
  147. package/src/components/time-picker/config.json +9 -0
  148. package/src/components/time-picker/time-picker.django-snapshot.html +26 -0
  149. package/src/components/time-picker/time-picker.django.html +4 -4
  150. package/src/components/time-picker/time-picker.react-snapshot.html +22 -0
  151. package/src/index.js +1 -0
  152. package/src/components/table/TableBody.tsx +0 -256
  153. package/src/components/table/TableContext.tsx +0 -87
  154. package/src/components/table/TableGroup.tsx +0 -69
  155. package/src/components/table/TableHead.tsx +0 -139
  156. package/src/components/table/TableRow.tsx +0 -56
  157. package/src/components/table/hooks/useRowDetails.ts +0 -34
  158. package/src/components/table/hooks/useTableGroups.ts +0 -61
  159. package/src/components/table/hooks/useTableSelect.ts +0 -82
  160. package/src/components/table/hooks/useTableSort.ts +0 -60
  161. package/src/components/table/table-group.django.html +0 -40
  162. package/src/components/table/table-head.django.html +0 -85
  163. package/src/components/table/table-row.django.html +0 -98
  164. package/src/components/table/table_helper.py +0 -298
  165. /package/src/components/{table → data-table}/table-detail-row.django.html +0 -0
@@ -11,6 +11,7 @@ export interface ComboboxOption {
11
11
  }
12
12
 
13
13
  export interface ComboboxProps extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>, 'onSelect' | 'defaultValue'> {
14
+ extraAttributes?: Record<string, unknown>;
14
15
  id: string;
15
16
  name: string;
16
17
  label: React.ReactNode;
@@ -19,6 +20,7 @@ export interface ComboboxProps extends Omit<React.SelectHTMLAttributes<HTMLSelec
19
20
  hint?: React.ReactNode;
20
21
  placeholder?: string;
21
22
  defaultValue?: string | null;
23
+ value?: string;
22
24
  error?: React.ReactNode;
23
25
  options?: ComboboxOption[];
24
26
  onSearch?: (value: string) => void;
@@ -44,12 +46,14 @@ export default function Combobox({
44
46
  hint = null,
45
47
  placeholder,
46
48
  defaultValue = null,
49
+ value,
47
50
  error = null,
48
51
  options = [],
49
52
  onSearch,
50
53
  onSelect,
51
54
  formGroup = true,
52
55
  className = '',
56
+ extraAttributes,
53
57
  ...props
54
58
  }: ComboboxProps) {
55
59
  const labelId = `${id}-label`;
@@ -81,6 +85,7 @@ export default function Combobox({
81
85
  {error && <ErrorMessage id={errorId}>{error}</ErrorMessage>}
82
86
 
83
87
  <div
88
+ {...extraAttributes}
84
89
  className={
85
90
  classNames(
86
91
  'usa-combo-box',
@@ -90,7 +95,7 @@ export default function Combobox({
90
95
  )
91
96
  }
92
97
  {...(placeholder ? { 'data-placeholder': placeholder } : {})}
93
- {...(defaultValue ? { 'data-default-value': defaultValue } : {})}
98
+ {...((value ?? defaultValue) ? { 'data-default-value': value ?? defaultValue } : {})}
94
99
  {...(onSearch ? { onInput: handleInput } : {})}
95
100
  >
96
101
  <select
@@ -1300,3 +1300,144 @@
1300
1300
  </select>
1301
1301
  </div>
1302
1302
  </div>
1303
+
1304
+ <h3 class="site-preview-heading">With Value</h3>
1305
+ <div class="usa-form-group usx-form-group">
1306
+ <label id="django-fruit-value-label" class="usa-label usx-label" for="django-fruit-value">
1307
+ Current fruit
1308
+ </label>
1309
+
1310
+ <div class="usa-combo-box usx-combo-box" data-default-value="peach">
1311
+ <select id="django-fruit-value" class="usa-select usx-select" name="fruit-value">
1312
+ <option value="">Select a fruit</option>
1313
+
1314
+ <option value="apple">Apple</option>
1315
+
1316
+ <option value="apricot">Apricot</option>
1317
+
1318
+ <option value="avocado">Avocado</option>
1319
+
1320
+ <option value="banana">Banana</option>
1321
+
1322
+ <option value="blackberry">Blackberry</option>
1323
+
1324
+ <option value="blood orange">Blood orange</option>
1325
+
1326
+ <option value="blueberry">Blueberry</option>
1327
+
1328
+ <option value="boysenberry">Boysenberry</option>
1329
+
1330
+ <option value="breadfruit">Breadfruit</option>
1331
+
1332
+ <option value="buddhas hand citron">Buddha&#x27;s hand citron</option>
1333
+
1334
+ <option value="cantaloupe">Cantaloupe</option>
1335
+
1336
+ <option value="clementine">Clementine</option>
1337
+
1338
+ <option value="crab apple">Crab apple</option>
1339
+
1340
+ <option value="currant">Currant</option>
1341
+
1342
+ <option value="cherry">Cherry</option>
1343
+
1344
+ <option value="custard apple">Custard apple</option>
1345
+
1346
+ <option value="coconut">Coconut</option>
1347
+
1348
+ <option value="cranberry">Cranberry</option>
1349
+
1350
+ <option value="date">Date</option>
1351
+
1352
+ <option value="dragonfruit">Dragonfruit</option>
1353
+
1354
+ <option value="durian">Durian</option>
1355
+
1356
+ <option value="elderberry">Elderberry</option>
1357
+
1358
+ <option value="fig">Fig</option>
1359
+
1360
+ <option value="gooseberry">Gooseberry</option>
1361
+
1362
+ <option value="grape">Grape</option>
1363
+
1364
+ <option value="grapefruit">Grapefruit</option>
1365
+
1366
+ <option value="guava">Guava</option>
1367
+
1368
+ <option value="honeydew melon">Honeydew melon</option>
1369
+
1370
+ <option value="jackfruit">Jackfruit</option>
1371
+
1372
+ <option value="kiwifruit">Kiwifruit</option>
1373
+
1374
+ <option value="kumquat">Kumquat</option>
1375
+
1376
+ <option value="lemon">Lemon</option>
1377
+
1378
+ <option value="lime">Lime</option>
1379
+
1380
+ <option value="lychee">Lychee</option>
1381
+
1382
+ <option value="mandarine">Mandarine</option>
1383
+
1384
+ <option value="mango">Mango</option>
1385
+
1386
+ <option value="mangosteen">Mangosteen</option>
1387
+
1388
+ <option value="marionberry">Marionberry</option>
1389
+
1390
+ <option value="nectarine">Nectarine</option>
1391
+
1392
+ <option value="orange">Orange</option>
1393
+
1394
+ <option value="papaya">Papaya</option>
1395
+
1396
+ <option value="passionfruit">Passionfruit</option>
1397
+
1398
+ <option value="peach">Peach</option>
1399
+
1400
+ <option value="pear">Pear</option>
1401
+
1402
+ <option value="persimmon">Persimmon</option>
1403
+
1404
+ <option value="plantain">Plantain</option>
1405
+
1406
+ <option value="plum">Plum</option>
1407
+
1408
+ <option value="pineapple">Pineapple</option>
1409
+
1410
+ <option value="pluot">Pluot</option>
1411
+
1412
+ <option value="pomegranate">Pomegranate</option>
1413
+
1414
+ <option value="pomelo">Pomelo</option>
1415
+
1416
+ <option value="quince">Quince</option>
1417
+
1418
+ <option value="raspberry">Raspberry</option>
1419
+
1420
+ <option value="rambutan">Rambutan</option>
1421
+
1422
+ <option value="soursop">Soursop</option>
1423
+
1424
+ <option value="starfruit">Starfruit</option>
1425
+
1426
+ <option value="strawberry">Strawberry</option>
1427
+
1428
+ <option value="tamarind">Tamarind</option>
1429
+
1430
+ <option value="tangelo">Tangelo</option>
1431
+
1432
+ <option value="tangerine">Tangerine</option>
1433
+
1434
+ <option value="ugli fruit">Ugli fruit</option>
1435
+
1436
+ <option value="watermelon">Watermelon</option>
1437
+
1438
+ <option value="white currant">White currant</option>
1439
+
1440
+ <option value="yuzu">Yuzu</option>
1441
+ </select>
1442
+ </div>
1443
+ </div>
@@ -13,7 +13,7 @@
13
13
  {% error_message id=id|add:"-error" %}{{ error }}{% enderror_message %}
14
14
  {% endif %}
15
15
 
16
- <div class="usa-combo-box usx-combo-box{% if error %} usx-combo-box--error{% endif %}{% if className %} {{ className }}{% endif %}"{% if placeholder %} data-placeholder="{{ placeholder }}"{% endif %}{% if defaultValue %} data-default-value="{{ defaultValue }}"{% endif %}>
16
+ <div class="usa-combo-box usx-combo-box{% if error %} usx-combo-box--error{% endif %}{% if className %} {{ className }}{% endif %}" {% if extraAttributes %}{% for attr, value in extraAttributes.items %} {{ attr }}="{% if value is True %}true{% elif value is False %}false{% else %}{{ value }}{% endif %}"{% endfor %}{% endif %}{% if placeholder %} data-placeholder="{{ placeholder }}"{% endif %}{% if value is not None and value or value is None and defaultValue %} data-default-value="{% if value is not None %}{{ value }}{% else %}{{ defaultValue }}{% endif %}"{% endif %}>
17
17
  <select
18
18
  id="{{ id }}"
19
19
  class="usa-select usx-select"
@@ -40,7 +40,7 @@
40
40
  {% error_message id=id|add:"-error" %}{{ error }}{% enderror_message %}
41
41
  {% endif %}
42
42
 
43
- <div class="usa-combo-box usx-combo-box{% if error %} usx-combo-box--error{% endif %}{% if className %} {{ className }}{% endif %}"{% if placeholder %} data-placeholder="{{ placeholder }}"{% endif %}{% if defaultValue %} data-default-value="{{ defaultValue }}"{% endif %}>
43
+ <div class="usa-combo-box usx-combo-box{% if error %} usx-combo-box--error{% endif %}{% if className %} {{ className }}{% endif %}" {% if extraAttributes %}{% for attr, value in extraAttributes.items %} {{ attr }}="{% if value is True %}true{% elif value is False %}false{% else %}{{ value }}{% endif %}"{% endfor %}{% endif %}{% if placeholder %} data-placeholder="{{ placeholder }}"{% endif %}{% if value is not None and value or value is None and defaultValue %} data-default-value="{% if value is not None %}{{ value }}{% else %}{{ defaultValue }}{% endif %}"{% endif %}>
44
44
  <select
45
45
  id="{{ id }}"
46
46
  class="usa-select usx-select"
@@ -712,3 +712,79 @@
712
712
  </select>
713
713
  </div>
714
714
  </div>
715
+
716
+ <h3 class="site-preview-heading">With Value</h3>
717
+ <div class="usa-form-group usx-form-group">
718
+ <label id="react-fruit-value-label" class="usa-label usx-label" for="react-fruit-value"
719
+ >Current fruit</label
720
+ >
721
+ <div class="usa-combo-box usx-combo-box" data-default-value="peach">
722
+ <select class="usa-select usx-select" id="react-fruit-value" name="fruit-value">
723
+ <option value="">Select a fruit</option>
724
+ <option value="apple">Apple</option>
725
+ <option value="apricot">Apricot</option>
726
+ <option value="avocado">Avocado</option>
727
+ <option value="banana">Banana</option>
728
+ <option value="blackberry">Blackberry</option>
729
+ <option value="blood orange">Blood orange</option>
730
+ <option value="blueberry">Blueberry</option>
731
+ <option value="boysenberry">Boysenberry</option>
732
+ <option value="breadfruit">Breadfruit</option>
733
+ <option value="buddhas hand citron">Buddha&#x27;s hand citron</option>
734
+ <option value="cantaloupe">Cantaloupe</option>
735
+ <option value="clementine">Clementine</option>
736
+ <option value="crab apple">Crab apple</option>
737
+ <option value="currant">Currant</option>
738
+ <option value="cherry">Cherry</option>
739
+ <option value="custard apple">Custard apple</option>
740
+ <option value="coconut">Coconut</option>
741
+ <option value="cranberry">Cranberry</option>
742
+ <option value="date">Date</option>
743
+ <option value="dragonfruit">Dragonfruit</option>
744
+ <option value="durian">Durian</option>
745
+ <option value="elderberry">Elderberry</option>
746
+ <option value="fig">Fig</option>
747
+ <option value="gooseberry">Gooseberry</option>
748
+ <option value="grape">Grape</option>
749
+ <option value="grapefruit">Grapefruit</option>
750
+ <option value="guava">Guava</option>
751
+ <option value="honeydew melon">Honeydew melon</option>
752
+ <option value="jackfruit">Jackfruit</option>
753
+ <option value="kiwifruit">Kiwifruit</option>
754
+ <option value="kumquat">Kumquat</option>
755
+ <option value="lemon">Lemon</option>
756
+ <option value="lime">Lime</option>
757
+ <option value="lychee">Lychee</option>
758
+ <option value="mandarine">Mandarine</option>
759
+ <option value="mango">Mango</option>
760
+ <option value="mangosteen">Mangosteen</option>
761
+ <option value="marionberry">Marionberry</option>
762
+ <option value="nectarine">Nectarine</option>
763
+ <option value="orange">Orange</option>
764
+ <option value="papaya">Papaya</option>
765
+ <option value="passionfruit">Passionfruit</option>
766
+ <option value="peach">Peach</option>
767
+ <option value="pear">Pear</option>
768
+ <option value="persimmon">Persimmon</option>
769
+ <option value="plantain">Plantain</option>
770
+ <option value="plum">Plum</option>
771
+ <option value="pineapple">Pineapple</option>
772
+ <option value="pluot">Pluot</option>
773
+ <option value="pomegranate">Pomegranate</option>
774
+ <option value="pomelo">Pomelo</option>
775
+ <option value="quince">Quince</option>
776
+ <option value="raspberry">Raspberry</option>
777
+ <option value="rambutan">Rambutan</option>
778
+ <option value="soursop">Soursop</option>
779
+ <option value="starfruit">Starfruit</option>
780
+ <option value="strawberry">Strawberry</option>
781
+ <option value="tamarind">Tamarind</option>
782
+ <option value="tangelo">Tangelo</option>
783
+ <option value="tangerine">Tangerine</option>
784
+ <option value="ugli fruit">Ugli fruit</option>
785
+ <option value="watermelon">Watermelon</option>
786
+ <option value="white currant">White currant</option>
787
+ <option value="yuzu">Yuzu</option>
788
+ </select>
789
+ </div>
790
+ </div>
@@ -270,6 +270,10 @@
270
270
  ]
271
271
  },
272
272
  "props": {
273
+ "extraAttributes": {
274
+ "type": "object",
275
+ "description": "Additional attributes on the USWDS enhancement target."
276
+ },
273
277
  "id": {
274
278
  "type": "string",
275
279
  "description": "id attribute for the select"
@@ -304,6 +308,11 @@
304
308
  "type": "string",
305
309
  "description": "Default selected value"
306
310
  },
311
+ "value": {
312
+ "type": "string",
313
+ "default": null,
314
+ "description": "Option used to initialize the USWDS combo box, taking precedence over defaultValue."
315
+ },
307
316
  "error": {
308
317
  "type": "slot",
309
318
  "description": "Error message (renders aria-describedby and error class)"
@@ -0,0 +1,180 @@
1
+ import React, { useId } from 'react';
2
+ import classnames from 'classnames';
3
+ import { TableContext } from './TableContext';
4
+ import type { TableContextValue } from './TableContext';
5
+ import TableHead from './TableHead';
6
+ import TableBody from './TableBody';
7
+ import TableFoot from './TableFoot';
8
+ import TableRow from './TableRow';
9
+ import TableCell from './TableCell';
10
+ import TableGroup from './TableGroup';
11
+ import { leafColumns } from './columns';
12
+ import Input from '../input/Input';
13
+ import Pagination from '../pagination/Pagination';
14
+ import type {
15
+ GroupBy, PaginateConfig, Responsive, RowDetails, RowKey, SelectionMode,
16
+ SortState, TableColumn, TableRowData, VerticalAlign,
17
+ } from './types';
18
+
19
+ export type {
20
+ Align, Aggregate, CellOptions, GroupBy, GroupColumn, GroupByConfig,
21
+ PaginateConfig, Responsive, RowOptions, RowDetails, RowDetailsConfig,
22
+ RowKey, SelectionMode, SortDirection, SortState, TableColumn, TableRowData,
23
+ VerticalAlign,
24
+ } from './types';
25
+
26
+ function Caption({ className = '', children, ...rest }: React.HTMLAttributes<HTMLTableCaptionElement>) {
27
+ return <caption className={classnames('usx-data-table__caption', className)} {...rest}>{children}</caption>;
28
+ }
29
+
30
+ // DataTable renders the complete initial DOM. @solexllc/usx/js/data-table owns every interaction.
31
+ export interface TableProps extends Omit<React.TableHTMLAttributes<HTMLTableElement>, 'children' | 'placeholder' | 'onSelect'> {
32
+ columns?: TableColumn[];
33
+ data?: TableRowData[];
34
+ primaryKey?: string;
35
+ striped?: boolean;
36
+ borderless?: boolean;
37
+ compact?: boolean;
38
+ scrollable?: boolean;
39
+ height?: string;
40
+ responsive?: Responsive;
41
+ stickyHeader?: boolean;
42
+ stickyFirstColumn?: boolean;
43
+ caption?: React.ReactNode;
44
+ searchable?: boolean;
45
+ searchPlaceholder?: string;
46
+ sortable?: boolean;
47
+ /** Initial sort state. Subsequent changes are emitted as usx:data-table:sort events. */
48
+ sort?: SortState | null;
49
+ selectionMode?: SelectionMode;
50
+ selectionPosition?: 'left' | 'right';
51
+ selectionVerticalAlign?: VerticalAlign;
52
+ /** Initially selected keys. */
53
+ select?: RowKey[] | null;
54
+ allowSelectAll?: boolean;
55
+ disabled?: RowKey[];
56
+ /** Emit usx:data-table:row-activate for clicks and Enter/Space on rows. */
57
+ clickableRows?: boolean;
58
+ groupBy?: GroupBy;
59
+ rowDetails?: RowDetails;
60
+ showFooter?: boolean;
61
+ paginate?: boolean | PaginateConfig;
62
+ /** Emit usx:data-table:more when the sentinel enters the viewport. */
63
+ infinite?: boolean;
64
+ loading?: boolean;
65
+ placeholder?: React.ReactNode;
66
+ children?: React.ReactNode;
67
+ extraAttributes?: Record<string, unknown>;
68
+ }
69
+
70
+ /** Data-driven table with a compound markup escape hatch. */
71
+ function DataTable({
72
+ id: idProp,
73
+ columns = [],
74
+ data = [],
75
+ primaryKey = 'id',
76
+ striped = false,
77
+ borderless = false,
78
+ compact = false,
79
+ scrollable = false,
80
+ height,
81
+ responsive = false,
82
+ stickyHeader = false,
83
+ stickyFirstColumn = false,
84
+ caption,
85
+ searchable = false,
86
+ searchPlaceholder = 'Search table',
87
+ sortable: sortableAll = false,
88
+ sort: initialSort,
89
+ selectionMode = null,
90
+ selectionPosition = 'left',
91
+ selectionVerticalAlign = 'middle',
92
+ select: initialSelection,
93
+ allowSelectAll = true,
94
+ disabled = [],
95
+ clickableRows = false,
96
+ groupBy,
97
+ rowDetails,
98
+ showFooter = false,
99
+ paginate,
100
+ infinite = false,
101
+ loading = false,
102
+ placeholder = 'No rows to display',
103
+ className = '',
104
+ children,
105
+ extraAttributes,
106
+ ...props
107
+ }: TableProps) {
108
+ const generatedId = useId();
109
+ const id = idProp ?? `usx-data-table-${generatedId}`;
110
+ const resolveColumns = (items: TableColumn[]): TableColumn[] => items.map((column) => ({
111
+ ...column,
112
+ ...(column.columns?.length
113
+ ? { columns: resolveColumns(column.columns) }
114
+ : sortableAll ? { sortable: column.sortable !== false } : {}),
115
+ }));
116
+ const resolvedColumns = sortableAll ? resolveColumns(columns) : columns;
117
+ const groupConfig = typeof groupBy === 'object' && groupBy !== null ? groupBy : null;
118
+ const groupKey = typeof groupBy === 'string' ? groupBy : groupConfig?.property;
119
+ const groups = groupKey ? [...data.reduce((map, row) => {
120
+ const key = String(row[groupKey] ?? '__ungrouped__');
121
+ if (!map.has(key)) map.set(key, []);
122
+ map.get(key)!.push(row);
123
+ return map;
124
+ }, new Map<string, TableRowData[]>())].map(([key, rows]) => ({ key, rows })) : null;
125
+ const expandedGroups = new Set<string>(groupConfig?.expand
126
+ ? groupConfig.expand.map(String)
127
+ : groupConfig?.defaultExpanded === false ? [] : groups?.map(({ key }) => key) || []);
128
+ const detailConfig = rowDetails && typeof rowDetails === 'object' ? rowDetails : null;
129
+ const pageConfig: PaginateConfig = paginate === true ? {} : paginate || {};
130
+ const pageSize = pageConfig.pageSize || 10;
131
+ const totalCols = leafColumns(resolvedColumns).length + Number(!!selectionMode) + Number(!!rowDetails);
132
+ const contextValue: TableContextValue = {
133
+ id, columns: resolvedColumns, data, primaryKey,
134
+ selectionMode, selectionPosition, selectionVerticalAlign,
135
+ selectedKeys: new Set(initialSelection || []), allowSelectAll, disabled, clickableRows,
136
+ groupBy, groupColumns: groupConfig?.columns || [],
137
+ groupHeaders: groupConfig?.headers || groupConfig?.columns || [],
138
+ groupValues: groupConfig?.values || {},
139
+ groups, expandedGroups, expandedRows: new Set(detailConfig?.expand || []),
140
+ rowDetails, responsive, totalCols, placeholder, infinite, loading,
141
+ };
142
+ const tableClasses = classnames(
143
+ 'usa-table', 'usx-data-table',
144
+ striped && 'usx-data-table--striped', borderless && 'usx-data-table--borderless',
145
+ compact && 'usx-data-table--compact', stickyHeader && 'usx-data-table--sticky-header',
146
+ responsive === 'stack' && 'usx-data-table--stacked',
147
+ responsive === 'stack-header' && 'usx-data-table--stacked-header',
148
+ stickyFirstColumn && 'usx-data-table--sticky-first-col', className,
149
+ );
150
+ const table = <table id={id} className={tableClasses} {...props}>
151
+ {caption && <Caption>{caption}</Caption>}
152
+ {children || <><TableHead /><TableBody />{showFooter && <TableFoot />}</>}
153
+ </table>;
154
+
155
+ return <TableContext.Provider value={contextValue}>
156
+ <div className="usx-data-table-shell" data-usx-data-table
157
+ data-searchable={searchable || undefined} data-paginate={!!paginate || undefined}
158
+ data-page-size={paginate ? pageSize : undefined}
159
+ data-initial-sort-key={initialSort?.direction ? initialSort.key || undefined : undefined}
160
+ data-initial-sort-direction={initialSort?.direction || undefined}
161
+ data-total-count={pageConfig.totalCount} data-infinite={infinite || undefined}
162
+ {...extraAttributes}>
163
+ {searchable && <div className="usx-data-table__toolbar">
164
+ <Input id={`${id}-search`} label="Search" formGroup={false} placeholder={searchPlaceholder} />
165
+ </div>}
166
+ {scrollable || height ? <div className="usx-data-table-container--scrollable" tabIndex={0}
167
+ style={height ? { maxHeight: height, overflow: 'auto' } : undefined}>{table}</div> : table}
168
+ {!!paginate && <Pagination className="usx-data-table__pagination" currentPage={1} pageSize={pageSize}
169
+ totalItems={pageConfig.totalCount ?? data.length}
170
+ pageSizeOptions={pageConfig.pageSizeOptions ?? [pageSize, 10, 25, 50].filter((value, index, list) => list.indexOf(value) === index)}
171
+ showStepOptions={pageConfig.showStepOptions !== false} showSummary={pageConfig.showSummary !== false}
172
+ stepOptionsId={`${id}-page-size`} ariaLabel={`${typeof caption === 'string' ? caption : 'Data table'} pages`} />}
173
+ </div>
174
+ </TableContext.Provider>;
175
+ }
176
+
177
+ export default Object.assign(DataTable, {
178
+ Head: TableHead, Body: TableBody, Foot: TableFoot,
179
+ Row: TableRow, Cell: TableCell, Group: TableGroup, Caption,
180
+ });
@@ -0,0 +1,42 @@
1
+ # DataTable
2
+
3
+ `DataTable` is the USX table for interactive data sets. It uses the USWDS `usa-table` base class for table layout, borders, spacing, and caption styling, with `usx-data-table` classes for its richer behavior and USX theme colors. Load the USWDS table stylesheet separately; `@solexllc/usx` does not bundle it. `Table` remains the small USWDS table component.
4
+
5
+ Set `responsive="stack"` or `responsive="stack-header"` to use the USWDS-style stacked layout below the `mobile-lg` breakpoint (480px). Both modes hide the column header and show each cell's column label above its value. `stack-header` instead shades the first data cell in each row as its heading and omits that cell's repeated label. Set a column's `stackLabel` to customize its mobile label, including when its header is rendered as an element.
6
+
7
+ Both tables share sorted-column theme tokens. `table-sorted-header-bg` defaults to USWDS's `#97d4ea`, `table-sorted-column-bg` to `#e1f3f8`, and `table-sorted-stripe-bg` to `#c3ebfa`. Their text colors can be set independently with `table-sorted-header-text`, `table-sorted-column-text`, and `table-sorted-stripe-text`. Ordinary striped rows use `table-stripe-text`, which follows `text-ink` by default. `table-border` also follows `text-ink` by default, so inverted sorted-header text does not recolor the grid; it can be overridden separately. `table-sorted-icon-color` and `table-unsorted-icon-color` control the arrow artwork. Set these tokens in a USX theme or override their `--usx-*` custom properties at runtime.
8
+
9
+ ## React
10
+
11
+ ```tsx
12
+ <DataTable
13
+ caption="State admissions"
14
+ columns={[
15
+ { key: 'name', header: 'State', primary: true, sortable: true },
16
+ { key: 'order', header: 'Order admitted', sortable: true },
17
+ { key: 'region', header: 'Region' },
18
+ ]}
19
+ data={states}
20
+ searchable
21
+ paginate={{ pageSize: 25, pageSizeOptions: [10, 25, 50] }}
22
+ />
23
+ ```
24
+
25
+ The React and Django components render the complete table markup before JavaScript runs. DataTable interactions do not use React state or USWDS's table JavaScript. Load `@solexllc/usx/js/start` once or call `dataTable.init(root)` from `@solexllc/usx/js/data-table` after mounting a table. `start` observes inserted DataTables; an explicit `init(root)` call is useful when your app controls the mount lifecycle. The same initializer provides search, sorting, pagination, selection, grouped rows, and row details in React, Django, and static HTML. Initial values can be set with `sort`, `select`, `groupBy.expand`, and `rowDetails.expand`; `sort` is applied on initialization. Listen on the `.usx-data-table-shell` for `usx:data-table:sort`, `:select`, `:search`, `:page-change`, `:group-toggle`, `:detail-toggle`, `:row-activate`, and `:more` events. `searchValue(row)` supplies searchable text for a computed cell; `filterable: false` excludes a column from search. `sortValue(row)` supplies a comparable value for custom sorting. Set `clickableRows` to make rows keyboard and pointer activatable.
26
+
27
+ Rows can set `cellProps` by column key, with `rowSpan`, `colSpan`, `backgroundColor`, and `color`. A row can set `rowProps.backgroundColor` and `rowProps.color`; columns can set `backgroundColor`, `color`, `headerBackgroundColor`, and `headerColor`. You can also apply USX `bg-*` and `text-*` utility classes through `rowProps.className`, column `className` or `headerClassName`, and `cellProps[key].className`. Row classes color the whole row, including its cells. Cell classes take precedence over column classes of the same color family, followed by row classes. Utility colors use `!important`, so they also override inline colors. Spans are clamped to the visible leaf columns and the current group or page. Covered cells are omitted automatically.
28
+
29
+ Set `align: 'center'` on a column to center text, buttons, avatars, or other compact content horizontally while retaining cell padding and top alignment. Add `verticalAlign: 'middle'` to center it vertically too. `cellProps[columnKey]` can override either setting for a particular row. In compound mode, use `<DataTable.Cell align="center" verticalAlign="middle">`. Selection checkboxes and radios are centered both ways by default; set `selectionVerticalAlign="top"` to keep them at the padded top of tall rows. Their labels remain accessible through input names while the visible controls use a fixed hit area.
30
+
31
+ For grouped rows with multiple cells, pass `groupBy={{ property, columns, values }}`. `columns` defines the group-row cells; the first contains the disclosure button, and the others can show totals. Set `groupBy.headers` to show a separate top header band with broader labels, so it need not repeat the group-row labels. The spans in each set must add up to the number of visible data columns. `groupBy.rowClassName` applies classes, including `bg-*` and `text-*`, across the whole group row. `values` maps each group key to values by group column key; each value can also be `{ value, backgroundColor, color }`. Regular table `columns` can be nested for additional header levels. `GroupedRows` shows regional case totals; `GroupedMatrix` shows grant outcomes by agency and program.
32
+
33
+ ## Django and static HTML
34
+
35
+ ```django
36
+ {% load usx_components %}
37
+ {% data_table caption="State admissions" columns=columns data=rows searchable=True paginate=page_options %}{% enddata_table %}
38
+ ```
39
+
40
+ Load `@solexllc/usx/js/start` on the page, or call `dataTable.init(root)` from `@solexllc/usx/js/data-table` after inserting markup. It is safe to call `init` more than once on an already enhanced table. If rows change inside the same table shell, call `dataTable.off(root)` and then `dataTable.init(root)` after the update so the enhancer reads the new rows. `data-table.html` shows the static markup contract. Django accepts `rowDetailField` for detail content and built-in aggregate names for footer values. React render callbacks produce cell and detail markup during rendering; they do not provide interaction behavior.
41
+
42
+ The HTML story shows the static reference. React and Django snapshot boards have matching play checks.