@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.
- package/README.md +99 -0
- package/dist/index.cjs +576 -442
- package/dist/index.js +576 -442
- package/package.json +5 -5
- package/src/components/attribution/config.json +5 -5
- package/src/components/banner/config.json +2 -2
- package/src/components/breadcrumb/Breadcrumb.tsx +5 -6
- package/src/components/breadcrumb/config.json +11 -1
- package/src/components/button/button.html +2 -2
- package/src/components/button-group/button-group.django.html +1 -1
- package/src/components/calendar-date/calendar-date.django.html +3 -3
- package/src/components/callout/Callout.tsx +53 -0
- package/src/components/callout/callout.django.html +5 -0
- package/src/components/callout/callout.html +76 -0
- package/src/components/callout/config.json +74 -0
- package/src/components/card/Card.tsx +18 -34
- package/src/components/card/card.django.html +12 -10
- package/src/components/card/config.json +15 -40
- package/src/components/card-group/card-group.django.html +1 -1
- package/src/components/carousel/Carousel.tsx +3 -2
- package/src/components/carousel/carousel.django.html +13 -2
- package/src/components/carousel/config.json +2 -2
- package/src/components/character-count/config.json +2 -2
- package/src/components/checkbox-group/CheckboxGroup.tsx +10 -20
- package/src/components/checkbox-group/checkbox-group.django.html +10 -4
- package/src/components/checkbox-group/config.json +10 -5
- package/src/components/clickable/clickable.html +21 -39
- package/src/components/clickable/config.json +2 -2
- package/src/components/collection/Collection.tsx +5 -5
- package/src/components/collection/collection.django.html +2 -4
- package/src/components/collection/config.json +7 -6
- package/src/components/combobox/config.json +4 -4
- package/src/components/container/Container.tsx +108 -0
- package/src/components/container/_layout-classes.django.html +12 -0
- package/src/components/container/config.json +288 -0
- package/src/components/container/container.django.html +13 -0
- package/src/components/container/container.html +125 -0
- package/src/components/date-picker/config.json +4 -4
- package/src/components/date-range-picker/config.json +7 -7
- package/src/components/error-message/config.json +2 -2
- package/src/components/eyebrow/Eyebrow.tsx +2 -1
- package/src/components/eyebrow/config.json +2 -2
- package/src/components/fieldset/config.json +5 -5
- package/src/components/file-input/FileInput.tsx +3 -2
- package/src/components/file-input/config.json +5 -5
- package/src/components/file-list/FileList.tsx +2 -1
- package/src/components/file-list/config.json +2 -2
- package/src/components/footer/Footer.tsx +5 -5
- package/src/components/form-group/config.json +2 -2
- package/src/components/hero/Hero.tsx +8 -14
- package/src/components/hero/config.json +36 -27
- package/src/components/hero/hero.django.html +2 -2
- package/src/components/hint/config.json +2 -2
- package/src/components/in-page-nav/config.json +11 -1
- package/src/components/indicator/config.json +2 -2
- package/src/components/input/config.json +2 -2
- package/src/components/label/config.json +2 -2
- package/src/components/language-selector/config.json +2 -2
- package/src/components/layout/Layout.tsx +1 -1
- package/src/components/legend/config.json +3 -3
- package/src/components/link/config.json +2 -2
- package/src/components/memorable-date/config.json +9 -9
- package/src/components/misc-banner/MiscBanner.tsx +2 -1
- package/src/components/misc-banner/config.json +2 -2
- package/src/components/modal/config.json +2 -2
- package/src/components/page/Page.tsx +2 -1
- package/src/components/page/config.json +7 -7
- package/src/components/page/page.django.html +1 -1
- package/src/components/pagination/Pagination.tsx +2 -1
- package/src/components/pagination/container/PaginationContainer.tsx +2 -1
- package/src/components/prose/config.json +5 -1
- package/src/components/quote/Quote.tsx +58 -0
- package/src/components/quote/config.json +51 -0
- package/src/components/quote/quote.django.html +15 -0
- package/src/components/quote/quote.html +66 -0
- package/src/components/radio-buttons/config.json +3 -3
- package/src/components/range-slider/RangeSlider.tsx +2 -1
- package/src/components/range-slider/config.json +4 -4
- package/src/components/required/config.json +2 -2
- package/src/components/section/Section.tsx +6 -2
- package/src/components/section/config.json +19 -6
- package/src/components/section/section.django.html +9 -2
- package/src/components/select/config.json +2 -2
- package/src/components/site-alert/SiteAlert.tsx +5 -6
- package/src/components/skipnav/config.json +2 -2
- package/src/components/summary-box/config.json +3 -3
- package/src/components/swap/Swap.tsx +4 -3
- package/src/components/swap/config.json +4 -4
- package/src/components/switch/config.json +2 -2
- package/src/components/table/config.json +13 -3
- package/src/components/tag/config.json +2 -2
- package/src/components/tag-group/config.json +2 -2
- package/src/components/text-area/config.json +2 -2
- package/src/components/time-picker/config.json +4 -4
- package/src/components/toggle/Toggle.tsx +69 -40
- package/src/components/toggle/config.json +42 -10
- package/src/components/toggle/toggle.django.html +25 -17
- package/src/components/toggle/toggle.html +319 -85
- package/src/components/tooltip/config.json +2 -2
- package/src/components/villain/Villain.tsx +2 -1
- package/src/index.js +3 -1
- package/src/components/block/Block.tsx +0 -78
- package/src/components/block/block.django.html +0 -26
- package/src/components/block/block.html +0 -162
- 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":
|
|
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": "
|
|
22
|
+
"type": "slot",
|
|
23
23
|
"description": "Label text for the field."
|
|
24
24
|
},
|
|
25
25
|
"hint": {
|
|
26
|
-
"type": "
|
|
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": "
|
|
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, {
|
|
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
|
-
|
|
20
|
+
ariaLabel?: string;
|
|
18
21
|
variant?: 'text' | 'icon';
|
|
19
22
|
disabled?: boolean;
|
|
20
|
-
|
|
23
|
+
required?: boolean;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
|
|
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
|
-
|
|
36
|
+
required = false,
|
|
37
|
+
className,
|
|
38
|
+
'aria-label': nativeAriaLabel,
|
|
39
|
+
'aria-labelledby': labelledBy,
|
|
33
40
|
...props
|
|
34
|
-
})
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
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
|
|
47
|
-
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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=
|
|
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={
|
|
60
|
-
value={
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
67
|
-
{
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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":
|
|
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": "
|
|
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":
|
|
17
|
+
"type": [
|
|
18
|
+
"object",
|
|
19
|
+
"string",
|
|
20
|
+
"number"
|
|
21
|
+
],
|
|
18
22
|
"description": "Toggle option.",
|
|
19
23
|
"properties": {
|
|
20
24
|
"value": {
|
|
21
|
-
"type":
|
|
25
|
+
"type": [
|
|
26
|
+
"string",
|
|
27
|
+
"number"
|
|
28
|
+
],
|
|
22
29
|
"description": "Option value."
|
|
23
30
|
},
|
|
24
31
|
"label": {
|
|
25
|
-
"type": "
|
|
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":
|
|
47
|
+
"type": [
|
|
48
|
+
"string",
|
|
49
|
+
"number"
|
|
50
|
+
],
|
|
41
51
|
"description": "Controlled selected value"
|
|
42
52
|
},
|
|
43
53
|
"defaultValue": {
|
|
44
|
-
"type":
|
|
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="
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 %}
|