@solexllc/usx-react 0.4.0 → 0.6.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 (105) hide show
  1. package/README.md +99 -0
  2. package/dist/index.cjs +576 -442
  3. package/dist/index.js +576 -442
  4. package/package.json +5 -5
  5. package/src/components/attribution/config.json +5 -5
  6. package/src/components/banner/config.json +2 -2
  7. package/src/components/breadcrumb/Breadcrumb.tsx +5 -6
  8. package/src/components/breadcrumb/config.json +11 -1
  9. package/src/components/button/button.html +2 -2
  10. package/src/components/button-group/button-group.django.html +1 -1
  11. package/src/components/calendar-date/calendar-date.django.html +3 -3
  12. package/src/components/callout/Callout.tsx +53 -0
  13. package/src/components/callout/callout.django.html +5 -0
  14. package/src/components/callout/callout.html +76 -0
  15. package/src/components/callout/config.json +74 -0
  16. package/src/components/card/Card.tsx +18 -34
  17. package/src/components/card/card.django.html +12 -10
  18. package/src/components/card/config.json +15 -40
  19. package/src/components/card-group/card-group.django.html +1 -1
  20. package/src/components/carousel/Carousel.tsx +3 -2
  21. package/src/components/carousel/carousel.django.html +13 -2
  22. package/src/components/carousel/config.json +2 -2
  23. package/src/components/character-count/config.json +2 -2
  24. package/src/components/checkbox-group/CheckboxGroup.tsx +10 -20
  25. package/src/components/checkbox-group/checkbox-group.django.html +10 -4
  26. package/src/components/checkbox-group/config.json +10 -5
  27. package/src/components/clickable/clickable.html +21 -39
  28. package/src/components/clickable/config.json +2 -2
  29. package/src/components/collection/Collection.tsx +5 -5
  30. package/src/components/collection/collection.django.html +2 -4
  31. package/src/components/collection/config.json +7 -6
  32. package/src/components/combobox/config.json +4 -4
  33. package/src/components/container/Container.tsx +108 -0
  34. package/src/components/container/_layout-classes.django.html +12 -0
  35. package/src/components/container/config.json +288 -0
  36. package/src/components/container/container.django.html +13 -0
  37. package/src/components/container/container.html +125 -0
  38. package/src/components/date-picker/config.json +4 -4
  39. package/src/components/date-range-picker/config.json +7 -7
  40. package/src/components/error-message/config.json +2 -2
  41. package/src/components/eyebrow/Eyebrow.tsx +2 -1
  42. package/src/components/eyebrow/config.json +2 -2
  43. package/src/components/fieldset/config.json +5 -5
  44. package/src/components/file-input/FileInput.tsx +3 -2
  45. package/src/components/file-input/config.json +5 -5
  46. package/src/components/file-list/FileList.tsx +2 -1
  47. package/src/components/file-list/config.json +2 -2
  48. package/src/components/footer/Footer.tsx +5 -5
  49. package/src/components/form-group/config.json +2 -2
  50. package/src/components/hero/Hero.tsx +8 -14
  51. package/src/components/hero/config.json +36 -27
  52. package/src/components/hero/hero.django.html +2 -2
  53. package/src/components/hint/config.json +2 -2
  54. package/src/components/in-page-nav/config.json +11 -1
  55. package/src/components/indicator/config.json +2 -2
  56. package/src/components/input/config.json +2 -2
  57. package/src/components/label/config.json +2 -2
  58. package/src/components/language-selector/config.json +2 -2
  59. package/src/components/layout/Layout.tsx +1 -1
  60. package/src/components/legend/config.json +3 -3
  61. package/src/components/link/config.json +2 -2
  62. package/src/components/memorable-date/config.json +9 -9
  63. package/src/components/misc-banner/MiscBanner.tsx +2 -1
  64. package/src/components/misc-banner/config.json +2 -2
  65. package/src/components/modal/config.json +2 -2
  66. package/src/components/page/Page.tsx +2 -1
  67. package/src/components/page/config.json +7 -7
  68. package/src/components/page/page.django.html +1 -1
  69. package/src/components/pagination/Pagination.tsx +2 -1
  70. package/src/components/pagination/container/PaginationContainer.tsx +2 -1
  71. package/src/components/prose/config.json +5 -1
  72. package/src/components/quote/Quote.tsx +58 -0
  73. package/src/components/quote/config.json +51 -0
  74. package/src/components/quote/quote.django.html +15 -0
  75. package/src/components/quote/quote.html +66 -0
  76. package/src/components/radio-buttons/config.json +3 -3
  77. package/src/components/range-slider/RangeSlider.tsx +2 -1
  78. package/src/components/range-slider/config.json +4 -4
  79. package/src/components/required/config.json +2 -2
  80. package/src/components/section/Section.tsx +6 -2
  81. package/src/components/section/config.json +19 -6
  82. package/src/components/section/section.django.html +9 -2
  83. package/src/components/select/config.json +2 -2
  84. package/src/components/site-alert/SiteAlert.tsx +5 -6
  85. package/src/components/skipnav/config.json +2 -2
  86. package/src/components/summary-box/config.json +3 -3
  87. package/src/components/swap/Swap.tsx +4 -3
  88. package/src/components/swap/config.json +4 -4
  89. package/src/components/switch/config.json +2 -2
  90. package/src/components/table/config.json +13 -3
  91. package/src/components/tag/config.json +2 -2
  92. package/src/components/tag-group/config.json +2 -2
  93. package/src/components/text-area/config.json +2 -2
  94. package/src/components/time-picker/config.json +4 -4
  95. package/src/components/toggle/Toggle.tsx +69 -40
  96. package/src/components/toggle/config.json +42 -10
  97. package/src/components/toggle/toggle.django.html +25 -17
  98. package/src/components/toggle/toggle.html +319 -85
  99. package/src/components/tooltip/config.json +2 -2
  100. package/src/components/villain/Villain.tsx +2 -1
  101. package/src/index.js +3 -1
  102. package/src/components/block/Block.tsx +0 -78
  103. package/src/components/block/block.django.html +0 -26
  104. package/src/components/block/block.html +0 -162
  105. package/src/components/block/config.json +0 -88
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "time-picker",
3
3
  "template": "time-picker/time-picker.django.html",
4
- "version": 1,
4
+ "version": 2,
5
5
  "default": {
6
6
  "id": "appointment-time",
7
7
  "name": "appointment-time",
@@ -19,16 +19,16 @@
19
19
  "description": "name attribute for the input. Defaults to id."
20
20
  },
21
21
  "label": {
22
- "type": "string",
22
+ "type": "slot",
23
23
  "description": "Label text for the field."
24
24
  },
25
25
  "hint": {
26
- "type": "string",
26
+ "type": "slot",
27
27
  "default": "Select a time from the dropdown. Type into the input to filter options.",
28
28
  "description": "Hint text displayed below the label."
29
29
  },
30
30
  "error": {
31
- "type": "string",
31
+ "type": "slot",
32
32
  "description": "Error message. Renders aria-describedby and error styling."
33
33
  },
34
34
  "disabled": {
@@ -1,4 +1,5 @@
1
- import React, { useRef } from 'react';
1
+ import React, { useId } from 'react';
2
+ import ClassNames from 'classnames';
2
3
  import Icon from '../icon/Icon';
3
4
 
4
5
  export interface ToggleOption {
@@ -8,73 +9,101 @@ export interface ToggleOption {
8
9
  disabled?: boolean;
9
10
  }
10
11
 
11
- export interface ToggleProps extends React.HTMLAttributes<HTMLUListElement> {
12
+ export interface ToggleProps extends Omit<React.HTMLAttributes<HTMLUListElement>, 'onChange'> {
13
+ className?: string;
14
+ id?: string;
12
15
  options?: (ToggleOption | string | number)[];
13
16
  value?: string | number;
14
17
  defaultValue?: string | number;
15
18
  onChange?: (value: string | number) => void;
16
19
  name?: string;
17
- id?: string;
20
+ ariaLabel?: string;
18
21
  variant?: 'text' | 'icon';
19
22
  disabled?: boolean;
20
- className?: string;
23
+ required?: boolean;
21
24
  }
22
25
 
23
- const Toggle: React.FC<ToggleProps> = ({
26
+ export default function Toggle({
24
27
  options = [],
25
28
  value,
26
29
  defaultValue,
27
30
  onChange,
28
31
  name,
29
32
  id,
33
+ ariaLabel,
30
34
  variant = 'text',
31
35
  disabled = false,
32
- className = '',
36
+ required = false,
37
+ className,
38
+ 'aria-label': nativeAriaLabel,
39
+ 'aria-labelledby': labelledBy,
33
40
  ...props
34
- }) => {
35
- const idRef = useRef(id || name || `toggle-${Math.random().toString(36).substr(2, 8)}`);
36
- const generatedName = idRef.current;
37
- const classes = [
38
- 'usa-button-group',
39
- 'usx-button-group',
40
- 'usa-button-group--segmented',
41
- 'usx-toggle',
42
- variant === 'icon' ? 'usx-toggle--icon' : '',
43
- className
44
- ].filter(Boolean).join(' ');
41
+ }: ToggleProps) {
42
+ const instanceId = useId();
43
+ const groupId = id || `toggle-${instanceId}`;
44
+ const groupName = name || groupId;
45
+ const controlled = value !== undefined;
45
46
  return (
46
- <ul className={classes} role="radiogroup" aria-disabled={disabled} {...props}>
47
- {options.map((opt, i) => {
48
- const optValue = typeof opt === 'object' ? opt.value ?? opt : opt;
49
- const optLabel = typeof opt === 'object' ? opt.label ?? opt : opt;
50
- const optIcon = typeof opt === 'object' ? opt.icon : undefined;
51
- const optDisabled = typeof opt === 'object' ? !!opt.disabled : false;
52
- const inputId = `${generatedName}-${i}`;
47
+ <ul
48
+ {...props}
49
+ id={groupId}
50
+ className={ClassNames(
51
+ 'usx-toggle',
52
+ 'usa-button-group',
53
+ variant === 'icon' && 'usx-toggle--icon',
54
+ className
55
+ )}
56
+ role="radiogroup"
57
+ aria-labelledby={labelledBy}
58
+ aria-label={
59
+ labelledBy ? undefined : ariaLabel || nativeAriaLabel || name || 'Choose an option'
60
+ }
61
+ aria-disabled={disabled || undefined}
62
+ aria-required={required || undefined}
63
+ >
64
+ {options.map((option, index) => {
65
+ const opt = typeof option === 'object' ? option : { value: option, label: option };
66
+ const optionValue =
67
+ opt.value ??
68
+ (typeof opt.label === 'string' || typeof opt.label === 'number' ? opt.label : index);
69
+ const optionLabel = opt.label ?? String(optionValue);
70
+ const inputId = `${groupId}-option-${index}`;
71
+ const iconOnly = variant === 'icon' && Boolean(opt.icon);
53
72
  return (
54
- <li key={inputId} className={`usa-button-group__item usx-toggle__item${optDisabled ? ' usx-toggle__item--disabled' : ''}`}>
73
+ <li key={inputId} className="usa-button-group__item" role="presentation">
55
74
  <input
56
75
  className="usx-toggle__input"
57
76
  type="radio"
58
77
  id={inputId}
59
- name={name || generatedName}
60
- value={optValue}
61
- checked={value === optValue ? true : undefined}
62
- defaultChecked={defaultValue === optValue ? true : undefined}
63
- disabled={disabled ? true : optDisabled ? true : undefined}
64
- onChange={onChange ? () => onChange(optValue as string | number) : undefined}
78
+ name={groupName}
79
+ value={optionValue}
80
+ {...(controlled
81
+ ? { checked: value === optionValue }
82
+ : { defaultChecked: defaultValue === optionValue })}
83
+ disabled={disabled || opt.disabled}
84
+ required={required}
85
+ onChange={(event) => {
86
+ if (event.target.checked) onChange?.(optionValue);
87
+ }}
65
88
  />
66
- <label htmlFor={inputId} className="usa-button usx-button usa-button--outline">
67
- {variant === 'icon' && optIcon ? (
68
- <Icon name={optIcon} className="usx-toggle__label" ariaHidden />
69
- ) : (
70
- <span className="usx-toggle__label">{optLabel}</span>
71
- )}
89
+ <label
90
+ htmlFor={inputId}
91
+ className="usa-button usx-button usa-button--primary usx-toggle__button"
92
+ aria-disabled={disabled || opt.disabled || undefined}
93
+ title={
94
+ iconOnly && (typeof optionLabel === 'string' || typeof optionLabel === 'number')
95
+ ? String(optionLabel)
96
+ : undefined
97
+ }
98
+ >
99
+ {opt.icon && <Icon name={opt.icon} className="usx-toggle__icon" aria-hidden="true" />}
100
+ <span className={iconOnly ? 'usa-sr-only' : undefined}>
101
+ {optionLabel}
102
+ </span>
72
103
  </label>
73
104
  </li>
74
105
  );
75
106
  })}
76
107
  </ul>
77
108
  );
78
- };
79
-
80
- export default Toggle;
109
+ }
@@ -1,28 +1,35 @@
1
1
  {
2
2
  "name": "toggle",
3
3
  "template": "toggle/toggle.django.html",
4
- "version": 1,
4
+ "version": 2,
5
5
  "required": [
6
6
  "options"
7
7
  ],
8
8
  "props": {
9
9
  "id": {
10
10
  "type": "string",
11
- "description": "ID for the control (used as prefix for option IDs)"
11
+ "description": "ID for the control (used as prefix for option IDs). Supply a unique ID in Django."
12
12
  },
13
13
  "options": {
14
14
  "type": "array",
15
- "description": "Array of option objects: {value,label,icon?,disabled?}",
15
+ "description": "Options as strings, numbers, or objects with value, label, icon, and disabled. Django requires option objects with value and label. Use distinct values and a label for every icon option.",
16
16
  "items": {
17
- "type": "object",
17
+ "type": [
18
+ "object",
19
+ "string",
20
+ "number"
21
+ ],
18
22
  "description": "Toggle option.",
19
23
  "properties": {
20
24
  "value": {
21
- "type": "string",
25
+ "type": [
26
+ "string",
27
+ "number"
28
+ ],
22
29
  "description": "Option value."
23
30
  },
24
31
  "label": {
25
- "type": "string",
32
+ "type": "slot",
26
33
  "description": "Option display label."
27
34
  },
28
35
  "icon": {
@@ -37,11 +44,17 @@
37
44
  }
38
45
  },
39
46
  "value": {
40
- "type": "string",
47
+ "type": [
48
+ "string",
49
+ "number"
50
+ ],
41
51
  "description": "Controlled selected value"
42
52
  },
43
53
  "defaultValue": {
44
- "type": "string",
54
+ "type": [
55
+ "string",
56
+ "number"
57
+ ],
45
58
  "description": "Uncontrolled initial value"
46
59
  },
47
60
  "name": {
@@ -54,7 +67,8 @@
54
67
  "text",
55
68
  "icon"
56
69
  ],
57
- "description": "Visual variant"
70
+ "description": "Visual variant",
71
+ "default": "text"
58
72
  },
59
73
  "disabled": {
60
74
  "type": "boolean",
@@ -63,7 +77,25 @@
63
77
  },
64
78
  "className": {
65
79
  "type": "string",
66
- "description": "Additional classes"
80
+ "description": "Additional classes for the toggle list"
81
+ },
82
+ "ariaLabel": {
83
+ "type": "string",
84
+ "description": "Accessible name for the radio group. Defaults to name when omitted."
85
+ },
86
+ "required": {
87
+ "type": "boolean",
88
+ "default": false,
89
+ "description": "Require a choice for native form submission."
90
+ },
91
+ "onChange": {
92
+ "type": "function",
93
+ "description": "React callback receiving the selected string or number.",
94
+ "renderers": {
95
+ "django": {
96
+ "supported": false
97
+ }
98
+ }
67
99
  }
68
100
  }
69
101
  }
@@ -1,19 +1,27 @@
1
- {# Django template for Toggle using USWDS segmented button group #}
2
1
  {% load components %}
3
-
4
- <ul class="usa-button-group usx-button-group usa-button-group--segmented usx-toggle{% if variant == 'icon' %} usx-toggle--icon{% endif %}{% if className %} {{ className }}{% endif %}" role="radiogroup"{% if name %} aria-label="{{ name }}"{% endif %}>
5
- {% for option in options %}
6
- {% with optValue=option.value|default:option optLabel=option.label|default:option optDisabled=option.disabled|default:False %}
7
- <li class="usa-button-group__item usx-toggle__item{% if optDisabled %} usx-toggle__item--disabled{% endif %}">
8
- <input class="usx-toggle__input" type="radio" id="{{ id }}-{{ forloop.counter }}" name="{{ name|default:id }}" value="{{ optValue }}" {% if optValue == value or optValue == defaultValue %}checked{% endif %}{% if disabled or optDisabled %} disabled{% endif %}>
9
- <label for="{{ id }}-{{ forloop.counter }}" class="usa-button usx-button usa-button--outline">
10
- {% if variant == 'icon' and option.icon %}
11
- {% icon name=option.icon className="usx-toggle__label" %}{% endicon %}
12
- {% else %}
13
- <span class="usx-toggle__label">{{ optLabel }}</span>
14
- {% endif %}
15
- </label>
16
- </li>
17
- {% endwith %}
18
- {% endfor %}
2
+ {% spaceless %}
3
+ <ul id="{{ id }}" class="usx-toggle usa-button-group{% if variant == 'icon' %} usx-toggle--icon{% endif %}{% if className %} {{ className }}{% endif %}" role="radiogroup" aria-label="{% firstof ariaLabel name 'Choose an option' %}"{% if disabled %} aria-disabled="true"{% endif %}{% if required %} aria-required="true"{% endif %}>
4
+ {% for option in options %}
5
+ {% with optionSuffix=option.value|stringformat:"s" %}
6
+ {% with optionId=id|add:"-"|add:optionSuffix %}
7
+ <li class="usa-button-group__item" role="presentation">
8
+ <input
9
+ class="usx-toggle__input"
10
+ id="{{ optionId }}"
11
+ type="radio"
12
+ name="{% firstof name id "toggle-group" %}"
13
+ value="{{ option.value }}"
14
+ {% if value != None %}{% if value == option.value %}checked="checked"{% endif %}{% elif defaultValue == option.value or option.checked %}checked="checked"{% endif %}
15
+ {% if disabled or option.disabled %}disabled="disabled"{% endif %}
16
+ {% if required %}required="required"{% endif %}
17
+ >
18
+ <label for="{{ optionId }}" class="usa-button usx-button usa-button--primary usx-toggle__button"{% if disabled or option.disabled %} aria-disabled="true"{% endif %}{% if variant == 'icon' and option.icon %} title="{{ option.label|striptags }}"{% endif %}>
19
+ {% if option.icon %}{% icon name=option.icon className="usx-toggle__icon" %}{% endicon %}{% endif %}
20
+ <span{% if variant == 'icon' and option.icon %} class="usa-sr-only"{% endif %}>{{ option.label|safe }}</span>
21
+ </label>
22
+ </li>
23
+ {% endwith %}
24
+ {% endwith %}
25
+ {% endfor %}
19
26
  </ul>
27
+ {% endspaceless %}