@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solexllc/usx-react",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "React component library for USX.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,9 +25,9 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@solexllc/usx": "0.10.0",
29
- "@solexllc/usx-theme": "0.10.0",
30
- "@solexllc/usx-uswds-fixes": "0.1.14",
28
+ "@solexllc/usx": "0.12.0",
29
+ "@solexllc/usx-theme": "0.11.1",
30
+ "@solexllc/usx-uswds-fixes": "0.1.16",
31
31
  "classnames": "^2.5.1",
32
32
  "prop-types": "^15.8.1"
33
33
  },
@@ -15,6 +15,7 @@ export interface AccordionItemProps {
15
15
  }
16
16
 
17
17
  export interface AccordionProps extends React.HTMLAttributes<HTMLDivElement> {
18
+ extraAttributes?: Record<string, unknown>;
18
19
  bordered?: boolean;
19
20
  items?: AccordionItemProps[];
20
21
  multiselectable?: boolean;
@@ -74,6 +75,7 @@ export function Accordion({
74
75
  className = '',
75
76
  headingClassName = '',
76
77
  contentClassName = '',
78
+ extraAttributes,
77
79
  ...props
78
80
  }: AccordionProps) {
79
81
  const accordionClasses = classnames(
@@ -91,6 +93,7 @@ export function Accordion({
91
93
  className={accordionClasses}
92
94
  data-allow-multiple={multiselectable ? true : undefined}
93
95
  {...props}
96
+ {...extraAttributes}
94
97
  >
95
98
  {items.map((item) => (
96
99
  <AccordionItem
@@ -105,4 +108,4 @@ export function Accordion({
105
108
  );
106
109
  }
107
110
 
108
- export default Accordion;
111
+ export default Accordion;
@@ -1,6 +1,6 @@
1
1
  <div
2
2
  id="{{ id }}"
3
- class="usa-accordion usx-accordion {% if bordered %}usa-accordion--bordered{% endif %}{% if iconPosition == 'start' %} usa-accordion--icon-start{% elif iconPosition == 'end' %} usa-accordion--icon-end{% endif %}{% if className %} {{ className }}{% endif %}"
3
+ class="usa-accordion usx-accordion {% if bordered %}usa-accordion--bordered{% endif %}{% if iconPosition == 'start' %} usa-accordion--icon-start{% elif iconPosition == 'end' %} usa-accordion--icon-end{% 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 %}
4
4
  {% if multiselectable %}
5
5
  data-allow-multiple="true"
6
6
  {% endif %}
@@ -23,6 +23,7 @@
23
23
  ]
24
24
  },
25
25
  "props": {
26
+ "extraAttributes": { "type": "object", "description": "Additional attributes on the USWDS enhancement target." },
26
27
  "id": {
27
28
  "type": "string",
28
29
  "description": "Base ID for the accordion. Items without their own id get this base plus the item's index."
@@ -4,6 +4,7 @@ import ClassNames from 'classnames';
4
4
  import { getAssetUrl as assetUrl } from '../../assets';
5
5
 
6
6
  export interface BannerProps extends React.HTMLAttributes<HTMLElement> {
7
+ extraAttributes?: Record<string, unknown>;
7
8
  id?: string;
8
9
  ariaLabel?: string;
9
10
  flagSrc?: string;
@@ -36,6 +37,7 @@ export default function Banner({
36
37
  </>
37
38
  ),
38
39
  className = '',
40
+ extraAttributes,
39
41
  ...props
40
42
  }: BannerProps) {
41
43
  const classes = ClassNames(
@@ -44,7 +46,7 @@ export default function Banner({
44
46
  className
45
47
  );
46
48
  return (
47
- <section id={id} className={classes} aria-label={ariaLabel} {...props}>
49
+ <section id={id} className={classes} aria-label={ariaLabel} {...props} {...extraAttributes}>
48
50
  <div id={`${id}-accordion`} className="usa-accordion">
49
51
  <header className="usa-banner__header">
50
52
  <div className="usa-banner__inner">
@@ -3,7 +3,7 @@
3
3
  {% with effective_tld=tld|default:'.gov' %}
4
4
  <section
5
5
  id="{{ id|default:'gov-banner' }}"
6
- class="usa-banner usx-banner {{ className }}"
6
+ class="usa-banner usx-banner {{ className }}" {% if extraAttributes %}{% for attr, value in extraAttributes.items %} {{ attr }}="{% if value is True %}true{% elif value is False %}false{% else %}{{ value }}{% endif %}"{% endfor %}{% endif %}
7
7
  aria-label="{{ ariaLabel|default:'Official government website' }}"
8
8
  >
9
9
  <div id="{{ id|default:'gov-banner' }}-accordion" class="usa-accordion">
@@ -6,6 +6,7 @@
6
6
  "id": "gov-banner-default"
7
7
  },
8
8
  "props": {
9
+ "extraAttributes": { "type": "object", "description": "Additional attributes on the USWDS enhancement target." },
9
10
  "staticBaseUrl": {
10
11
  "type": "string",
11
12
  "description": "Optional asset base for this component. A non-empty value overrides window.usxBaseUrl in React or STATIC_URL in Django; otherwise the global base or / is used. Asset filenames remain separate."
@@ -37,46 +37,6 @@
37
37
  </div>
38
38
  </div>
39
39
 
40
- <h3 class="site-preview-heading">Unenhanced</h3>
41
- <div
42
- class="usx-carousel"
43
- role="region"
44
- aria-roledescription="carousel"
45
- aria-label="Carousel without JS enhancement"
46
- data-enhanced="true"
47
- >
48
- <div class="usx-carousel__viewport">
49
- <div class="usx-carousel__track" aria-live="polite" tabindex="0">
50
- <div
51
- class="usx-carousel__slide"
52
- role="group"
53
- aria-roledescription="slide"
54
- aria-label="1 of 3"
55
- >
56
- <div class="width-full height-card bg-primary-dark text-white padding-8">Slide 1</div>
57
- </div>
58
-
59
- <div
60
- class="usx-carousel__slide"
61
- role="group"
62
- aria-roledescription="slide"
63
- aria-label="2 of 3"
64
- >
65
- <div class="width-full height-card bg-primary-light text-black padding-8">Slide 2</div>
66
- </div>
67
-
68
- <div
69
- class="usx-carousel__slide"
70
- role="group"
71
- aria-roledescription="slide"
72
- aria-label="3 of 3"
73
- >
74
- <div class="width-full height-card bg-secondary-dark text-white padding-8">Slide 3</div>
75
- </div>
76
- </div>
77
- </div>
78
- </div>
79
-
80
40
  <h3 class="site-preview-heading">Without Dots</h3>
81
41
  <div
82
42
  class="usx-carousel"
@@ -35,44 +35,6 @@
35
35
  </div>
36
36
  </div>
37
37
 
38
- <h3 class="site-preview-heading">Unenhanced</h3>
39
- <div
40
- class="usx-carousel"
41
- role="region"
42
- aria-roledescription="carousel"
43
- aria-label="Carousel without JS enhancement"
44
- data-enhanced="true"
45
- >
46
- <div class="usx-carousel__viewport">
47
- <div class="usx-carousel__track" aria-live="polite" tabindex="0">
48
- <div
49
- class="usx-carousel__slide"
50
- role="group"
51
- aria-roledescription="slide"
52
- aria-label="1 of 3"
53
- >
54
- <div class="width-full height-card bg-primary-dark text-white padding-8">Slide 1</div>
55
- </div>
56
- <div
57
- class="usx-carousel__slide"
58
- role="group"
59
- aria-roledescription="slide"
60
- aria-label="2 of 3"
61
- >
62
- <div class="width-full height-card bg-primary-light text-black padding-8">Slide 2</div>
63
- </div>
64
- <div
65
- class="usx-carousel__slide"
66
- role="group"
67
- aria-roledescription="slide"
68
- aria-label="3 of 3"
69
- >
70
- <div class="width-full height-card bg-secondary-dark text-white padding-8">Slide 3</div>
71
- </div>
72
- </div>
73
- </div>
74
- </div>
75
-
76
38
  <h3 class="site-preview-heading">Without Dots</h3>
77
39
  <div
78
40
  class="usx-carousel"
@@ -4,6 +4,7 @@ import Input from '../input/Input';
4
4
  import TextArea from '../text-area/TextArea';
5
5
 
6
6
  export interface CharacterCountProps {
7
+ extraAttributes?: Record<string, unknown>;
7
8
  id?: string;
8
9
  label?: React.ReactNode;
9
10
  max: number;
@@ -38,6 +39,7 @@ export default function CharacterCount({
38
39
  placeholder = '',
39
40
  textArea = false,
40
41
  className = '',
42
+ extraAttributes,
41
43
  ...props
42
44
  }: CharacterCountProps) {
43
45
  const fieldId = id || `character-count-${Math.random().toString(36).substr(2, 9)}`;
@@ -62,6 +64,7 @@ export default function CharacterCount({
62
64
  className: 'usa-character-count__field',
63
65
  'aria-describedby': [infoId, hintId, errorId].filter(Boolean).join(' '),
64
66
  ...props,
67
+ ...extraAttributes,
65
68
  };
66
69
 
67
70
  return (
@@ -400,3 +400,46 @@ Despite the text area providing more space, this default value is already way to
400
400
  You can enter up to 50 characters
401
401
  </span>
402
402
  </div>
403
+
404
+ <h3 class="site-preview-heading">Value</h3>
405
+ <div class="usa-character-count usx-character-count">
406
+ <div class="usa-form-group usx-form-group">
407
+ <label class="usa-label usx-label" for="django-cc-value"> Current value </label>
408
+
409
+ <input
410
+ class="usa-input usx-input usa-character-count__field"
411
+ id="django-cc-value"
412
+ placeholder=""
413
+ value="Current text"
414
+ maxlength="25"
415
+ aria-describedby="django-cc-value-info"
416
+ />
417
+ </div>
418
+
419
+ <span id="django-cc-value-info" class="usa-character-count__message">
420
+ You can enter up to 25 characters
421
+ </span>
422
+ </div>
423
+
424
+ <h3 class="site-preview-heading">Text Area Value</h3>
425
+ <div class="usa-character-count usx-character-count">
426
+ <div class="usa-form-group usx-form-group">
427
+ <label class="usa-label usx-label" for="django-cc-text-area-value">
428
+ Current text area value
429
+ </label>
430
+
431
+ <textarea
432
+ class="usa-textarea usx-textarea usa-character-count__field"
433
+ id="django-cc-text-area-value"
434
+ placeholder=""
435
+ maxlength="50"
436
+ aria-describedby="django-cc-text-area-value-info"
437
+ >
438
+ Current text</textarea
439
+ >
440
+ </div>
441
+
442
+ <span id="django-cc-text-area-value-info" class="usa-character-count__message">
443
+ You can enter up to 50 characters
444
+ </span>
445
+ </div>
@@ -7,9 +7,9 @@
7
7
  {% with id|default:"character-count" as field_id %}
8
8
  <div class="usa-character-count usx-character-count{% if className %} {{ className }}{% endif %}">
9
9
  {% if textArea %}
10
- {% text_area id=field_id formGroup=True label=label hint=hint error=error success=success disabled=disabled required=required screenReaderOnlyLabel=screenReaderOnlyLabel placeholder=placeholder defaultValue=defaultValue maxlength=max describedBy=field_id|add:"-info" className="usa-character-count__field" %}{% endtext_area %}
10
+ {% text_area id=field_id formGroup=True label=label hint=hint error=error success=success disabled=disabled required=required screenReaderOnlyLabel=screenReaderOnlyLabel placeholder=placeholder value=value defaultValue=defaultValue maxlength=max describedBy=field_id|add:"-info" className="usa-character-count__field" extraAttributes=extraAttributes %}{% endtext_area %}
11
11
  {% else %}
12
- {% input id=field_id formGroup=True label=label hint=hint error=error success=success disabled=disabled required=required screenReaderOnlyLabel=screenReaderOnlyLabel placeholder=placeholder value=defaultValue maxlength=max describedBy=field_id|add:"-info" className="usa-character-count__field" %}{% endinput %}
12
+ {% input id=field_id formGroup=True label=label hint=hint error=error success=success disabled=disabled required=required screenReaderOnlyLabel=screenReaderOnlyLabel placeholder=placeholder value=value defaultValue=defaultValue maxlength=max describedBy=field_id|add:"-info" className="usa-character-count__field" extraAttributes=extraAttributes %}{% endinput %}
13
13
  {% endif %}
14
14
  <span id="{{ field_id }}-info" class="usa-character-count__message">
15
15
  You can enter up to {{ max }} characters
@@ -344,3 +344,40 @@ Despite the text area providing more space, this default value is already way to
344
344
  >You can enter up to 50 characters</span
345
345
  >
346
346
  </div>
347
+
348
+ <h3 class="site-preview-heading">Value</h3>
349
+ <div class="usa-character-count usx-character-count">
350
+ <div class="usa-form-group usx-form-group">
351
+ <label class="usa-label usx-label" for="react-cc-value">Current value</label
352
+ ><input
353
+ id="react-cc-value"
354
+ class="usa-input usx-input usa-character-count__field"
355
+ placeholder=""
356
+ aria-describedby="react-cc-value-info"
357
+ maxlength="25"
358
+ value="Current text"
359
+ />
360
+ </div>
361
+ <span id="react-cc-value-info" class="usa-character-count__message"
362
+ >You can enter up to 25 characters</span
363
+ >
364
+ </div>
365
+
366
+ <h3 class="site-preview-heading">Text Area Value</h3>
367
+ <div class="usa-character-count usx-character-count">
368
+ <div class="usa-form-group usx-form-group">
369
+ <label class="usa-label usx-label" for="react-cc-text-area-value">Current text area value</label
370
+ ><textarea
371
+ id="react-cc-text-area-value"
372
+ class="usa-textarea usx-textarea usa-character-count__field"
373
+ placeholder=""
374
+ aria-describedby="react-cc-text-area-value-info"
375
+ maxlength="50"
376
+ >
377
+ Current text</textarea
378
+ >
379
+ </div>
380
+ <span id="react-cc-text-area-value-info" class="usa-character-count__message"
381
+ >You can enter up to 50 characters</span
382
+ >
383
+ </div>
@@ -8,6 +8,10 @@
8
8
  "max": 25
9
9
  },
10
10
  "props": {
11
+ "extraAttributes": {
12
+ "type": "object",
13
+ "description": "Additional attributes on the USWDS enhancement target."
14
+ },
11
15
  "id": {
12
16
  "type": "string",
13
17
  "default": null,
@@ -69,6 +73,11 @@
69
73
  "default": "",
70
74
  "description": "Initial value of the field."
71
75
  },
76
+ "value": {
77
+ "type": "string",
78
+ "default": null,
79
+ "description": "Current field value. Takes precedence over defaultValue."
80
+ },
72
81
  "textArea": {
73
82
  "type": "boolean",
74
83
  "default": false,
@@ -11,6 +11,7 @@ export interface CheckboxProps extends React.InputHTMLAttributes<HTMLInputElemen
11
11
  label?: string;
12
12
  ariaLabel?: string;
13
13
  checked?: boolean;
14
+ defaultChecked?: boolean;
14
15
  disabled?: boolean;
15
16
  description?: string;
16
17
  tile?: boolean;
@@ -18,6 +19,7 @@ export interface CheckboxProps extends React.InputHTMLAttributes<HTMLInputElemen
18
19
  error?: string;
19
20
  success?: string;
20
21
  className?: string;
22
+ labelClassName?: string;
21
23
  onChange?: React.ChangeEventHandler<HTMLInputElement>;
22
24
  required?: boolean;
23
25
  formGroup?: boolean;
@@ -29,14 +31,16 @@ export default function Checkbox({
29
31
  value,
30
32
  label = '',
31
33
  ariaLabel = '',
32
- checked = false,
34
+ checked,
35
+ defaultChecked,
33
36
  disabled = false,
34
- description = null,
37
+ description = '',
35
38
  tile = false,
36
39
  small = false,
37
40
  error,
38
41
  success,
39
42
  className = '',
43
+ labelClassName = '',
40
44
  onChange,
41
45
  required = false,
42
46
  formGroup = true,
@@ -52,10 +56,7 @@ export default function Checkbox({
52
56
  className
53
57
  );
54
58
 
55
- const inputClasses = ClassNames(
56
- 'usa-checkbox__input',
57
- { 'usa-checkbox__input--tile': tile }
58
- );
59
+ const inputClasses = ClassNames('usa-checkbox__input', { 'usa-checkbox__input--tile': tile });
59
60
 
60
61
  const content = (
61
62
  <>
@@ -67,18 +68,21 @@ export default function Checkbox({
67
68
  name={name}
68
69
  value={value}
69
70
  aria-label={ariaLabel || undefined}
70
- defaultChecked={checked}
71
+ {...(checked !== undefined && onChange
72
+ ? { checked }
73
+ : { defaultChecked: checked ?? defaultChecked })}
71
74
  disabled={disabled}
72
75
  required={required}
73
76
  {...(onChange ? { onChange } : {})}
74
77
  />
75
- <Label className="usa-checkbox__label" classOverride={true} htmlFor={id} required={required}>
78
+ <Label
79
+ className={ClassNames('usa-checkbox__label', labelClassName)}
80
+ classOverride={true}
81
+ htmlFor={id}
82
+ required={required}
83
+ >
76
84
  {label}
77
- {description && (
78
- <span className="usa-checkbox__label-description">
79
- {description}
80
- </span>
81
- )}
85
+ {description && <span className="usa-checkbox__label-description">{description}</span>}
82
86
  </Label>
83
87
  </div>
84
88
  {hasError ? (
@@ -371,3 +371,21 @@
371
371
  <span class="usa-error-message usx-error-message" role="alert"
372
372
  >You've done something wrong, although we don't necessarily know what.</span
373
373
  >
374
+
375
+ <h3 class="site-preview-heading">Default Checked</h3>
376
+ <div class="usa-form-group usx-form-group">
377
+ <div class="usa-checkbox usx-checkbox">
378
+ <input
379
+ class="usa-checkbox__input"
380
+ id="django-example-checkbox-21"
381
+ type="checkbox"
382
+ name="example-21"
383
+ value="example-value-21"
384
+ checked
385
+ />
386
+
387
+ <label class="usa-checkbox__label" for="django-example-checkbox-21">
388
+ Example Checkbox 21
389
+ </label>
390
+ </div>
391
+ </div>
@@ -1,11 +1,12 @@
1
1
  {# Django template for Checkbox #}
2
2
  {% load usx_components %}
3
3
  {% with formGroup|default_if_none:True as wrap_group %}
4
+ {% with extraLabelClass=labelClassName|default:'' %}
4
5
  {% if wrap_group %}
5
6
  {% form_group error=error %}
6
7
  <div class="usa-checkbox usx-checkbox{% if small %} usx-checkbox--small{% endif %}{% if className %} {{ className }}{% endif %}">
7
- <input class="usa-checkbox__input{% if tile %} usa-checkbox__input--tile{% endif %}" id="{{ id }}" type="checkbox" name="{{ name }}" value="{{ value }}"{% if checked %} checked{% endif %}{% if disabled %} disabled{% endif %}{% if required %} required{% endif %}{% if onChange %} onchange="{{ onChange }}"{% endif %}>
8
- {% label htmlFor=id className="usa-checkbox__label" classOverride=True required=required %}{{ label }}
8
+ <input class="usa-checkbox__input{% if tile %} usa-checkbox__input--tile{% endif %}" id="{{ id }}" type="checkbox"{% if name %} name="{{ name }}"{% endif %} value="{{ value }}"{% if ariaLabel %} aria-label="{{ ariaLabel }}"{% endif %}{% if checked is not None and checked or checked is None and defaultChecked %} checked{% endif %}{% if disabled %} disabled{% endif %}{% if required %} required{% endif %}{% if onChange %} onchange="{{ onChange }}"{% endif %}>
9
+ {% label htmlFor=id className='usa-checkbox__label '|add:extraLabelClass classOverride=True required=required %}{{ label }}
9
10
  {% if description %}
10
11
  <span class="usa-checkbox__label-description">{{ description }}</span>
11
12
  {% endif %}
@@ -19,8 +20,8 @@
19
20
  {% endform_group %}
20
21
  {% else %}
21
22
  <div class="usa-checkbox usx-checkbox{% if small %} usx-checkbox--small{% endif %}{% if className %} {{ className }}{% endif %}">
22
- <input class="usa-checkbox__input{% if tile %} usa-checkbox__input--tile{% endif %}" id="{{ id }}" type="checkbox" name="{{ name }}" value="{{ value }}"{% if checked %} checked{% endif %}{% if disabled %} disabled{% endif %}{% if required %} required{% endif %}{% if onChange %} onchange="{{ onChange }}"{% endif %}>
23
- {% label htmlFor=id className="usa-checkbox__label" classOverride=True required=required %}{{ label }}
23
+ <input class="usa-checkbox__input{% if tile %} usa-checkbox__input--tile{% endif %}" id="{{ id }}" type="checkbox"{% if name %} name="{{ name }}"{% endif %} value="{{ value }}"{% if ariaLabel %} aria-label="{{ ariaLabel }}"{% endif %}{% if checked is not None and checked or checked is None and defaultChecked %} checked{% endif %}{% if disabled %} disabled{% endif %}{% if required %} required{% endif %}{% if onChange %} onchange="{{ onChange }}"{% endif %}>
24
+ {% label htmlFor=id className='usa-checkbox__label '|add:extraLabelClass classOverride=True required=required %}{{ label }}
24
25
  {% if description %}
25
26
  <span class="usa-checkbox__label-description">{{ description }}</span>
26
27
  {% endif %}
@@ -33,3 +34,4 @@
33
34
  {% endif %}
34
35
  {% endif %}
35
36
  {% endwith %}
37
+ {% endwith %}
@@ -311,3 +311,17 @@
311
311
  >Great! You have successfully seen this message.</span
312
312
  >
313
313
  </div>
314
+
315
+ <h3 class="site-preview-heading">Default Checked</h3>
316
+ <div class="usa-form-group usx-form-group">
317
+ <div class="usa-checkbox usx-checkbox">
318
+ <input
319
+ class="usa-checkbox__input"
320
+ id="react-example-checkbox-21"
321
+ type="checkbox"
322
+ name="example-21"
323
+ checked=""
324
+ value="example-value-21"
325
+ /><label class="usa-checkbox__label" for="react-example-checkbox-21">Example Checkbox 21</label>
326
+ </div>
327
+ </div>
@@ -27,9 +27,18 @@
27
27
  },
28
28
  "checked": {
29
29
  "type": "boolean",
30
- "default": false,
30
+ "default": null,
31
31
  "description": "Whether the checkbox is checked"
32
32
  },
33
+ "defaultChecked": {
34
+ "type": "boolean",
35
+ "default": null,
36
+ "description": "Initial checked state when checked is not supplied."
37
+ },
38
+ "ariaLabel": {
39
+ "type": "string",
40
+ "description": "Accessible name when a visible label is unsuitable."
41
+ },
33
42
  "disabled": {
34
43
  "type": "boolean",
35
44
  "default": false,
@@ -370,3 +370,57 @@
370
370
  </div>
371
371
  </fieldset>
372
372
  </div>
373
+
374
+ <h3 class="site-preview-heading">With Initial Checks</h3>
375
+ <div class="usa-form-group usx-form-group">
376
+ <fieldset
377
+ id="django-historical-figures-initial-checks"
378
+ class="usa-fieldset usx-fieldset usa-checkbox-group usx-checkbox-group"
379
+ >
380
+ <legend class="usa-legend usx-legend">Initial and current checks</legend>
381
+
382
+ <div class="usa-checkbox usx-checkbox">
383
+ <input
384
+ class="usa-checkbox__input"
385
+ id="django-historical-figures-initial-checks-0"
386
+ type="checkbox"
387
+ name="historical-figures-initial-checks"
388
+ value="sojourner-truth"
389
+ checked
390
+ />
391
+
392
+ <label class="usa-checkbox__label" for="django-historical-figures-initial-checks-0">
393
+ Sojourner Truth
394
+ </label>
395
+ </div>
396
+
397
+ <div class="usa-checkbox usx-checkbox">
398
+ <input
399
+ class="usa-checkbox__input"
400
+ id="django-historical-figures-initial-checks-1"
401
+ type="checkbox"
402
+ name="historical-figures-initial-checks"
403
+ value="frederick-douglass"
404
+ checked
405
+ />
406
+
407
+ <label class="usa-checkbox__label" for="django-historical-figures-initial-checks-1">
408
+ Frederick Douglass
409
+ </label>
410
+ </div>
411
+
412
+ <div class="usa-checkbox usx-checkbox">
413
+ <input
414
+ class="usa-checkbox__input"
415
+ id="django-historical-figures-initial-checks-2"
416
+ type="checkbox"
417
+ name="historical-figures-initial-checks"
418
+ value="booker-t-washington"
419
+ />
420
+
421
+ <label class="usa-checkbox__label" for="django-historical-figures-initial-checks-2">
422
+ Booker T. Washington
423
+ </label>
424
+ </div>
425
+ </fieldset>
426
+ </div>
@@ -298,3 +298,48 @@
298
298
  </div>
299
299
  </fieldset>
300
300
  </div>
301
+
302
+ <h3 class="site-preview-heading">With Initial Checks</h3>
303
+ <div class="usa-form-group usx-form-group">
304
+ <fieldset
305
+ class="usa-fieldset usx-fieldset usa-checkbox-group usx-checkbox-group"
306
+ id="react-historical-figures-initial-checks"
307
+ >
308
+ <legend class="usa-legend usx-legend">Initial and current checks</legend>
309
+ <div class="usa-checkbox usx-checkbox">
310
+ <input
311
+ class="usa-checkbox__input"
312
+ id="react-historical-figures-initial-checks-0"
313
+ type="checkbox"
314
+ name="historical-figures-initial-checks"
315
+ checked=""
316
+ value="sojourner-truth"
317
+ /><label class="usa-checkbox__label" for="react-historical-figures-initial-checks-0"
318
+ >Sojourner Truth</label
319
+ >
320
+ </div>
321
+ <div class="usa-checkbox usx-checkbox">
322
+ <input
323
+ class="usa-checkbox__input"
324
+ id="react-historical-figures-initial-checks-1"
325
+ type="checkbox"
326
+ name="historical-figures-initial-checks"
327
+ checked=""
328
+ value="frederick-douglass"
329
+ /><label class="usa-checkbox__label" for="react-historical-figures-initial-checks-1"
330
+ >Frederick Douglass</label
331
+ >
332
+ </div>
333
+ <div class="usa-checkbox usx-checkbox">
334
+ <input
335
+ class="usa-checkbox__input"
336
+ id="react-historical-figures-initial-checks-2"
337
+ type="checkbox"
338
+ name="historical-figures-initial-checks"
339
+ value="booker-t-washington"
340
+ /><label class="usa-checkbox__label" for="react-historical-figures-initial-checks-2"
341
+ >Booker T. Washington</label
342
+ >
343
+ </div>
344
+ </fieldset>
345
+ </div>