@solexllc/usx-react 0.1.4 → 0.1.6
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/dist/index.cjs +92 -1264
- package/dist/index.js +94 -1266
- package/package.json +4 -4
- package/src/components/accordion/Accordion.tsx +105 -0
- package/src/components/accordion/accordion.django.html +1 -1
- package/src/components/accordion/config.json +6 -1
- package/src/components/banner/Banner.tsx +35 -27
- package/src/components/banner/banner.django.html +1 -1
- package/src/components/banner/config.json +4 -0
- package/src/components/date-picker/{DatePicker.jsx → DatePicker.tsx} +12 -17
- package/src/components/date-range-picker/{DateRangePicker.jsx → DateRangePicker.tsx} +21 -21
- package/src/components/fieldset/Fieldset.tsx +1 -1
- package/src/components/file-input/{FileInput.jsx → FileInput.tsx} +31 -34
- package/src/components/file-list/{FileList.jsx → FileList.tsx} +24 -24
- package/src/components/header/{HeaderBranding.jsx → HeaderBranding.tsx} +0 -1
- package/src/components/hero/Hero.tsx +49 -7
- package/src/components/hero/config.json +45 -0
- package/src/components/hero/hero.django.html +16 -5
- package/src/components/hero/hero.html +19 -0
- package/src/components/in-page-nav/{InPageNav.jsx → InPageNav.tsx} +14 -18
- package/src/components/language-selector/{LanguageSelector.jsx → LanguageSelector.tsx} +40 -69
- package/src/components/legend/Legend.tsx +1 -1
- package/src/components/memorable-date/{MemorableDate.jsx → MemorableDate.tsx} +27 -27
- package/src/components/page/{Page.jsx → Page.tsx} +7 -11
- package/src/components/range-slider/{RangeSlider.jsx → RangeSlider.tsx} +13 -21
- package/src/components/select/Select.tsx +2 -2
- package/src/components/time-picker/{TimePicker.jsx → TimePicker.tsx} +14 -19
- package/src/index.js +11 -11
- package/src/components/accordion/Accordion.jsx +0 -170
|
@@ -8,6 +8,12 @@ export interface HeroButtonProps {
|
|
|
8
8
|
onClick?: React.MouseEventHandler<HTMLAnchorElement | HTMLButtonElement>;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export interface HeroSecondaryContent {
|
|
12
|
+
title?: string;
|
|
13
|
+
paragraph?: string;
|
|
14
|
+
link?: { href: string; text: string } | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
export interface HeroProps extends React.HTMLAttributes<HTMLElement> {
|
|
12
18
|
title?: string;
|
|
13
19
|
callout?: string;
|
|
@@ -15,7 +21,14 @@ export interface HeroProps extends React.HTMLAttributes<HTMLElement> {
|
|
|
15
21
|
button?: HeroButtonProps | null;
|
|
16
22
|
searchProps?: SearchProps | null;
|
|
17
23
|
backgroundImage?: string;
|
|
24
|
+
backgroundPosition?: React.CSSProperties['backgroundPosition'];
|
|
25
|
+
contentPosition?: 'left' | 'center' | 'right';
|
|
26
|
+
boxed?: boolean;
|
|
27
|
+
calloutMaxWidth?: string;
|
|
28
|
+
headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
|
|
29
|
+
secondaryContent?: HeroSecondaryContent | null;
|
|
18
30
|
overlay?: boolean;
|
|
31
|
+
overlayOpacity?: number;
|
|
19
32
|
ariaLabel?: string;
|
|
20
33
|
className?: string;
|
|
21
34
|
}
|
|
@@ -27,29 +40,47 @@ export default function Hero({
|
|
|
27
40
|
button = null,
|
|
28
41
|
searchProps = null,
|
|
29
42
|
backgroundImage = '',
|
|
43
|
+
backgroundPosition,
|
|
44
|
+
contentPosition = 'left',
|
|
45
|
+
boxed = true,
|
|
46
|
+
calloutMaxWidth,
|
|
47
|
+
headingLevel = 'h1',
|
|
48
|
+
secondaryContent = null,
|
|
30
49
|
overlay = true,
|
|
50
|
+
overlayOpacity,
|
|
31
51
|
ariaLabel = 'Introduction',
|
|
32
52
|
className = '',
|
|
53
|
+
style,
|
|
33
54
|
...props
|
|
34
55
|
}: HeroProps) {
|
|
56
|
+
const Heading = headingLevel;
|
|
57
|
+
const secondaryHeadings = { h1: 'h2', h2: 'h3', h3: 'h4', h4: 'h5', h5: 'h6' } as const;
|
|
58
|
+
const SecondaryHeading = secondaryHeadings[headingLevel];
|
|
35
59
|
const classes = [
|
|
36
60
|
'usx-hero',
|
|
37
61
|
overlay && 'usx-hero--has-overlay',
|
|
62
|
+
overlayOpacity !== undefined && 'usx-hero--custom-overlay',
|
|
63
|
+
contentPosition !== 'left' && `usx-hero--content-${contentPosition}`,
|
|
64
|
+
!boxed && 'usx-hero--unboxed',
|
|
65
|
+
secondaryContent && 'usx-hero--split',
|
|
38
66
|
className,
|
|
39
67
|
].filter(Boolean).join(' ');
|
|
40
68
|
|
|
41
|
-
const
|
|
42
|
-
? { backgroundImage: `url('${backgroundImage}')` }
|
|
43
|
-
:
|
|
69
|
+
const heroStyle: React.CSSProperties & { '--hero-overlay-opacity'?: number } = {
|
|
70
|
+
...(backgroundImage ? { backgroundImage: `url('${backgroundImage}')` } : {}),
|
|
71
|
+
...(backgroundPosition ? { backgroundPosition } : {}),
|
|
72
|
+
...(overlayOpacity !== undefined ? { '--hero-overlay-opacity': Math.min(1, Math.max(0, overlayOpacity)) } : {}),
|
|
73
|
+
...style,
|
|
74
|
+
};
|
|
44
75
|
|
|
45
76
|
return (
|
|
46
|
-
<section className={classes} aria-label={ariaLabel} style={
|
|
77
|
+
<section className={classes} aria-label={ariaLabel} style={heroStyle} {...props}>
|
|
47
78
|
<div className="usx-hero__inner">
|
|
48
|
-
<div className="usx-hero__callout">
|
|
49
|
-
<
|
|
79
|
+
<div className="usx-hero__callout" style={calloutMaxWidth ? { maxWidth: calloutMaxWidth } : undefined}>
|
|
80
|
+
<Heading className="usx-hero__heading">
|
|
50
81
|
{callout && <span className="usx-hero__heading--alt">{callout}</span>}
|
|
51
82
|
{title}
|
|
52
|
-
</
|
|
83
|
+
</Heading>
|
|
53
84
|
{paragraph && <p className="usx-hero__paragraph">{paragraph}</p>}
|
|
54
85
|
{searchProps && <Search {...searchProps} />}
|
|
55
86
|
{!searchProps && button && (
|
|
@@ -58,6 +89,17 @@ export default function Hero({
|
|
|
58
89
|
</Button>
|
|
59
90
|
)}
|
|
60
91
|
</div>
|
|
92
|
+
{secondaryContent && (
|
|
93
|
+
<div className="usx-hero__secondary">
|
|
94
|
+
{secondaryContent.title && <SecondaryHeading className="usx-hero__secondary-heading">{secondaryContent.title}</SecondaryHeading>}
|
|
95
|
+
{secondaryContent.paragraph && <p className="usx-hero__paragraph">{secondaryContent.paragraph}</p>}
|
|
96
|
+
{secondaryContent.link && (
|
|
97
|
+
<a className="usx-hero__secondary-link" href={secondaryContent.link.href}>
|
|
98
|
+
{secondaryContent.link.text}
|
|
99
|
+
</a>
|
|
100
|
+
)}
|
|
101
|
+
</div>
|
|
102
|
+
)}
|
|
61
103
|
</div>
|
|
62
104
|
</section>
|
|
63
105
|
);
|
|
@@ -53,11 +53,56 @@
|
|
|
53
53
|
"type": "string",
|
|
54
54
|
"description": "URL of the background image applied via inline style"
|
|
55
55
|
},
|
|
56
|
+
"contentPosition": {
|
|
57
|
+
"type": "select",
|
|
58
|
+
"options": ["left", "center", "right"],
|
|
59
|
+
"default": "left",
|
|
60
|
+
"description": "Main content position. Secondary content sits opposite on desktop for left/right layouts, and below for centered or mobile layouts. Reading order always starts with the main content."
|
|
61
|
+
},
|
|
62
|
+
"calloutMaxWidth": {
|
|
63
|
+
"type": "string",
|
|
64
|
+
"description": "Optional CSS maximum width for the main callout, such as 28rem or 50%. Overrides the theme width for this Hero only; omit to keep the theme default. Remains constrained by the available container width. Does not change split-layout column proportions."
|
|
65
|
+
},
|
|
66
|
+
"boxed": {
|
|
67
|
+
"type": "boolean",
|
|
68
|
+
"default": true,
|
|
69
|
+
"description": "Show the padded callout background. Disable for unboxed content directly over the hero background; ensure sufficient text contrast. Independent of overlay."
|
|
70
|
+
},
|
|
71
|
+
"backgroundPosition": {
|
|
72
|
+
"type": "string",
|
|
73
|
+
"description": "CSS background position for the image focal point, such as center, right center, or 70% 40%. Defaults to the stylesheet setting."
|
|
74
|
+
},
|
|
75
|
+
"headingLevel": {
|
|
76
|
+
"type": "select",
|
|
77
|
+
"options": ["h1", "h2", "h3", "h4", "h5"],
|
|
78
|
+
"default": "h1",
|
|
79
|
+
"description": "Main heading element, independent of visual size. Secondary content uses the next heading level."
|
|
80
|
+
},
|
|
81
|
+
"secondaryContent": {
|
|
82
|
+
"type": "object",
|
|
83
|
+
"description": "Optional unboxed supporting content: title, paragraph, and link. Stacks after the main content on mobile; use overlay or a suitable background for readable contrast.",
|
|
84
|
+
"properties": {
|
|
85
|
+
"title": { "type": "string", "description": "Supporting heading" },
|
|
86
|
+
"paragraph": { "type": "string", "description": "Supporting description" },
|
|
87
|
+
"link": {
|
|
88
|
+
"type": "object",
|
|
89
|
+
"description": "Optional secondary text link",
|
|
90
|
+
"properties": {
|
|
91
|
+
"href": { "type": "string", "description": "Destination URL" },
|
|
92
|
+
"text": { "type": "string", "description": "Link text" }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
56
97
|
"overlay": {
|
|
57
98
|
"type": "boolean",
|
|
58
99
|
"default": true,
|
|
59
100
|
"description": "When true, adds a semi-transparent dark overlay over the background image to improve text legibility"
|
|
60
101
|
},
|
|
102
|
+
"overlayOpacity": {
|
|
103
|
+
"type": "number",
|
|
104
|
+
"description": "Optional black overlay opacity from 0 (transparent) to 1 (opaque), clamped to that range. Overrides the theme overlay color when set. Has no effect when overlay is false; omit to preserve the theme setting."
|
|
105
|
+
},
|
|
61
106
|
"ariaLabel": {
|
|
62
107
|
"type": "string",
|
|
63
108
|
"description": "Accessible label for the section element (defaults to 'Introduction')"
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{# Django template for Hero #}
|
|
2
2
|
{% load components %}
|
|
3
3
|
<section
|
|
4
|
-
class="usx-hero{% if overlay != False %} usx-hero--has-overlay{% endif %}{% if className %} {{ className }}{% endif %}"
|
|
4
|
+
class="usx-hero{% if overlay != False %} usx-hero--has-overlay{% endif %}{% if overlayOpacity or overlayOpacity == 0 %} usx-hero--custom-overlay{% endif %}{% if contentPosition == 'right' %} usx-hero--content-right{% elif contentPosition == 'center' %} usx-hero--content-center{% endif %}{% if boxed == False %} usx-hero--unboxed{% endif %}{% if secondaryContent %} usx-hero--split{% endif %}{% if className %} {{ className }}{% endif %}"
|
|
5
5
|
aria-label="{% if ariaLabel %}{{ ariaLabel }}{% else %}Introduction{% endif %}"
|
|
6
|
-
{% if backgroundImage %}style="background-image: url('{{ backgroundImage }}')"{% endif %}
|
|
6
|
+
{% if backgroundImage or backgroundPosition or overlayOpacity or overlayOpacity == 0 %}style="{% if backgroundImage %}background-image: url('{{ backgroundImage }}');{% endif %}{% if backgroundPosition %}background-position: {{ backgroundPosition }};{% endif %}{% if overlayOpacity or overlayOpacity == 0 %}--hero-overlay-opacity: {{ overlayOpacity }};{% endif %}"{% endif %}
|
|
7
7
|
>
|
|
8
8
|
<div class="usx-hero__inner">
|
|
9
|
-
<div class="usx-hero__callout">
|
|
10
|
-
<h1 class="usx-hero__heading">
|
|
9
|
+
<div class="usx-hero__callout"{% if calloutMaxWidth %} style="max-width: {{ calloutMaxWidth }};"{% endif %}>
|
|
10
|
+
{% if headingLevel == 'h2' %}<h2 class="usx-hero__heading">{% elif headingLevel == 'h3' %}<h3 class="usx-hero__heading">{% elif headingLevel == 'h4' %}<h4 class="usx-hero__heading">{% elif headingLevel == 'h5' %}<h5 class="usx-hero__heading">{% else %}<h1 class="usx-hero__heading">{% endif %}
|
|
11
11
|
{% if callout %}<span class="usx-hero__heading--alt">{{ callout }}</span>{% endif %}
|
|
12
12
|
{{ title }}
|
|
13
|
-
</h1>
|
|
13
|
+
{% if headingLevel == 'h2' %}</h2>{% elif headingLevel == 'h3' %}</h3>{% elif headingLevel == 'h4' %}</h4>{% elif headingLevel == 'h5' %}</h5>{% else %}</h1>{% endif %}
|
|
14
14
|
{% if paragraph %}<p class="usx-hero__paragraph">{{ paragraph }}</p>{% endif %}
|
|
15
15
|
{% if searchProps %}
|
|
16
16
|
{% search id=searchProps.id ariaLabel=searchProps.ariaLabel searchKey=searchProps.searchKey label=searchProps.label icon=searchProps.icon iconOnly=searchProps.iconOnly buttonVariant=searchProps.buttonVariant big=searchProps.big action=searchProps.action placeholder=searchProps.placeholder defaultValue=searchProps.defaultValue onSubmit=searchProps.onSubmit className=searchProps.className|default:'' %}{% endsearch %}
|
|
@@ -18,5 +18,16 @@
|
|
|
18
18
|
{% button variant="primary" href=button.href %}{{ button.text }}{% endbutton %}
|
|
19
19
|
{% endif %}
|
|
20
20
|
</div>
|
|
21
|
+
{% if secondaryContent %}
|
|
22
|
+
<div class="usx-hero__secondary">
|
|
23
|
+
{% if secondaryContent.title %}
|
|
24
|
+
{% if headingLevel == 'h2' %}<h3 class="usx-hero__secondary-heading">{% elif headingLevel == 'h3' %}<h4 class="usx-hero__secondary-heading">{% elif headingLevel == 'h4' %}<h5 class="usx-hero__secondary-heading">{% elif headingLevel == 'h5' %}<h6 class="usx-hero__secondary-heading">{% else %}<h2 class="usx-hero__secondary-heading">{% endif %}
|
|
25
|
+
{{ secondaryContent.title }}
|
|
26
|
+
{% if headingLevel == 'h2' %}</h3>{% elif headingLevel == 'h3' %}</h4>{% elif headingLevel == 'h4' %}</h5>{% elif headingLevel == 'h5' %}</h6>{% else %}</h2>{% endif %}
|
|
27
|
+
{% endif %}
|
|
28
|
+
{% if secondaryContent.paragraph %}<p class="usx-hero__paragraph">{{ secondaryContent.paragraph }}</p>{% endif %}
|
|
29
|
+
{% if secondaryContent.link %}<a class="usx-hero__secondary-link" href="{{ secondaryContent.link.href }}">{{ secondaryContent.link.text }}</a>{% endif %}
|
|
30
|
+
</div>
|
|
31
|
+
{% endif %}
|
|
21
32
|
</div>
|
|
22
33
|
</section>
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
<h3 class="site-preview-heading">Right-side content with supporting information</h3>
|
|
2
|
+
<section class="usx-hero usx-hero--has-overlay usx-hero--custom-overlay usx-hero--content-right usx-hero--unboxed usx-hero--split" aria-label="Public services" style="background-image: url('https://designsystem.digital.gov/img/introducing-uswds-2-0/built-to-grow--alt.jpg'); background-position: left center; --hero-overlay-opacity: 0.8;">
|
|
3
|
+
<div class="usx-hero__inner">
|
|
4
|
+
<div class="usx-hero__callout">
|
|
5
|
+
<h1 class="usx-hero__heading">
|
|
6
|
+
<span class="usx-hero__heading--alt">Your community</span>
|
|
7
|
+
Public services
|
|
8
|
+
</h1>
|
|
9
|
+
<p class="usx-hero__paragraph">Find the services and information you need, all in one place.</p>
|
|
10
|
+
<a class="usa-button usx-button usa-button--primary" href="#services">Explore services</a>
|
|
11
|
+
</div>
|
|
12
|
+
<div class="usx-hero__secondary">
|
|
13
|
+
<h2 class="usx-hero__secondary-heading">Need a hand?</h2>
|
|
14
|
+
<p class="usx-hero__paragraph">Our team can help you find the right service or answer questions about your application.</p>
|
|
15
|
+
<a class="usx-hero__secondary-link" href="#contact">Contact our team</a>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
</section>
|
|
19
|
+
|
|
1
20
|
<h3 class="site-preview-heading">With search</h3>
|
|
2
21
|
<section class="usx-hero usx-hero--has-overlay" aria-label="Introduction" style="background-image: url('https://designsystem.digital.gov/img/introducing-uswds-2-0/built-to-grow--alt.jpg')">
|
|
3
22
|
<div class="usx-hero__inner">
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
|
|
5
|
+
export interface InPageNavProps extends React.HTMLAttributes<HTMLElement> {
|
|
6
|
+
headingElements?: string;
|
|
7
|
+
mainContentSelector?: string | null;
|
|
8
|
+
titleHeadingLevel?: string;
|
|
9
|
+
titleText?: string;
|
|
10
|
+
scrollOffset?: string | number;
|
|
11
|
+
rootMargin?: string;
|
|
12
|
+
threshold?: string | number;
|
|
13
|
+
minimumHeadingCount?: string | number;
|
|
14
|
+
contentClassName?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
5
17
|
// USWDS's own JS (usa-in-page-navigation) builds the <nav>/<ul> list into
|
|
6
18
|
// the empty <aside> below by reading headings out of the element matched by
|
|
7
19
|
// data-main-content-selector — it does not render anything itself. Call ONLY
|
|
@@ -23,7 +35,7 @@ export default function InPageNav({
|
|
|
23
35
|
className = '',
|
|
24
36
|
contentClassName = '',
|
|
25
37
|
...props
|
|
26
|
-
}) {
|
|
38
|
+
}: InPageNavProps) {
|
|
27
39
|
const contentId = `${id}-content`;
|
|
28
40
|
// Real USWDS points data-main-content-selector at a real <main> landmark,
|
|
29
41
|
// but that only works for a single instance per page — Storybook (and any
|
|
@@ -58,19 +70,3 @@ export default function InPageNav({
|
|
|
58
70
|
</div>
|
|
59
71
|
);
|
|
60
72
|
}
|
|
61
|
-
|
|
62
|
-
InPageNav.propTypes = {
|
|
63
|
-
id: PropTypes.string,
|
|
64
|
-
headingElements: PropTypes.string,
|
|
65
|
-
mainContentSelector: PropTypes.string,
|
|
66
|
-
titleHeadingLevel: PropTypes.string,
|
|
67
|
-
titleText: PropTypes.string,
|
|
68
|
-
scrollOffset: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
69
|
-
rootMargin: PropTypes.string,
|
|
70
|
-
threshold: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
71
|
-
minimumHeadingCount: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
72
|
-
content: PropTypes.string,
|
|
73
|
-
children: PropTypes.node,
|
|
74
|
-
className: PropTypes.string,
|
|
75
|
-
contentClassName: PropTypes.string,
|
|
76
|
-
};
|
|
@@ -1,7 +1,36 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
|
|
5
|
+
export interface LanguageOption {
|
|
6
|
+
code?: string;
|
|
7
|
+
label?: React.ReactNode;
|
|
8
|
+
description?: string;
|
|
9
|
+
href?: string;
|
|
10
|
+
current?: boolean;
|
|
11
|
+
plain?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface LanguageSelectorProps {
|
|
15
|
+
languages?: LanguageOption[];
|
|
16
|
+
variant?: 'two' | 'menu' | null;
|
|
17
|
+
unstyled?: boolean;
|
|
18
|
+
small?: boolean;
|
|
19
|
+
label?: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
navAriaLabel?: string;
|
|
22
|
+
className?: string;
|
|
23
|
+
onSelect?: ((language: LanguageOption, event: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement>) => void) | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface TwoLanguageSelectorProps extends Pick<LanguageSelectorProps, 'onSelect' | 'className' | 'navAriaLabel'> {
|
|
27
|
+
target: LanguageOption;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface MenuLanguageSelectorProps extends Omit<LanguageSelectorProps, 'variant' | 'languages'> {
|
|
31
|
+
languages: LanguageOption[];
|
|
32
|
+
}
|
|
33
|
+
|
|
5
34
|
/**
|
|
6
35
|
* Renders a single language link/submenu-item's accessible label.
|
|
7
36
|
* Real USWDS wraps the native-language name in <strong> and appends an
|
|
@@ -9,35 +38,29 @@ import classnames from 'classnames';
|
|
|
9
38
|
* whole thing carries `lang`/`xml:lang` so assistive tech announces it in
|
|
10
39
|
* the correct language (WCAG H58).
|
|
11
40
|
*/
|
|
12
|
-
function LanguageLabel({ code, label, description }) {
|
|
41
|
+
function LanguageLabel({ code, label, description }: Pick<LanguageOption, 'code' | 'label' | 'description'>) {
|
|
13
42
|
if (!code) {
|
|
14
43
|
return <>{label}</>;
|
|
15
44
|
}
|
|
16
45
|
|
|
17
46
|
return (
|
|
18
|
-
<span lang
|
|
47
|
+
<span {...{ lang: code, xmlLang: code }}>
|
|
19
48
|
<strong>{label}</strong>
|
|
20
49
|
{description ? ` (${description})` : null}
|
|
21
50
|
</span>
|
|
22
51
|
);
|
|
23
52
|
}
|
|
24
53
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function TwoLanguageSelector({ target, onSelect, className, navAriaLabel }) {
|
|
32
|
-
const handleClick = (e) => {
|
|
33
|
-
if (onSelect) onSelect(target, e);
|
|
34
|
-
if (!target.href) e.preventDefault();
|
|
54
|
+
function TwoLanguageSelector({ target, onSelect, className, navAriaLabel }: TwoLanguageSelectorProps) {
|
|
55
|
+
const handleClick = (event: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement>) => {
|
|
56
|
+
if (onSelect) onSelect(target, event);
|
|
57
|
+
if (!target.href) event.preventDefault();
|
|
35
58
|
};
|
|
36
59
|
|
|
37
60
|
const Tag = target.href ? 'a' : 'button';
|
|
38
61
|
const tagProps = target.href
|
|
39
62
|
? { href: target.href }
|
|
40
|
-
: { type: 'button' };
|
|
63
|
+
: { type: 'button' as const };
|
|
41
64
|
|
|
42
65
|
return (
|
|
43
66
|
<nav aria-label={navAriaLabel} className={className}>
|
|
@@ -50,17 +73,6 @@ function TwoLanguageSelector({ target, onSelect, className, navAriaLabel }) {
|
|
|
50
73
|
);
|
|
51
74
|
}
|
|
52
75
|
|
|
53
|
-
TwoLanguageSelector.propTypes = {
|
|
54
|
-
target: PropTypes.shape({
|
|
55
|
-
code: PropTypes.string,
|
|
56
|
-
label: PropTypes.node,
|
|
57
|
-
href: PropTypes.string,
|
|
58
|
-
}).isRequired,
|
|
59
|
-
onSelect: PropTypes.func,
|
|
60
|
-
className: PropTypes.string,
|
|
61
|
-
navAriaLabel: PropTypes.string,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
76
|
function MenuLanguageSelector({
|
|
65
77
|
languages,
|
|
66
78
|
unstyled,
|
|
@@ -70,7 +82,7 @@ function MenuLanguageSelector({
|
|
|
70
82
|
onSelect,
|
|
71
83
|
className,
|
|
72
84
|
navAriaLabel,
|
|
73
|
-
}) {
|
|
85
|
+
}: MenuLanguageSelectorProps) {
|
|
74
86
|
// Open/close (aria-expanded, hidden, outside-click, Escape, focusout) is
|
|
75
87
|
// driven by USWDS's own JS, initialized via a decorator in the story/host
|
|
76
88
|
// app — this component only renders the static USWDS markup.
|
|
@@ -101,7 +113,7 @@ function MenuLanguageSelector({
|
|
|
101
113
|
</button>
|
|
102
114
|
<ul id={id} className="usa-language__submenu" hidden>
|
|
103
115
|
{languages.map((lang, idx) => (
|
|
104
|
-
<li className="usa-language__submenu-item" key={lang.code || lang.label || idx}>
|
|
116
|
+
<li className="usa-language__submenu-item" key={lang.code || (typeof lang.label === 'string' || typeof lang.label === 'number' ? lang.label : undefined) || idx}>
|
|
105
117
|
<a
|
|
106
118
|
href={lang.href || 'javascript:void(0);'}
|
|
107
119
|
aria-current={lang.current ? 'true' : undefined}
|
|
@@ -126,26 +138,6 @@ function MenuLanguageSelector({
|
|
|
126
138
|
);
|
|
127
139
|
}
|
|
128
140
|
|
|
129
|
-
MenuLanguageSelector.propTypes = {
|
|
130
|
-
languages: PropTypes.arrayOf(
|
|
131
|
-
PropTypes.shape({
|
|
132
|
-
code: PropTypes.string,
|
|
133
|
-
label: PropTypes.node,
|
|
134
|
-
description: PropTypes.string,
|
|
135
|
-
href: PropTypes.string,
|
|
136
|
-
current: PropTypes.bool,
|
|
137
|
-
plain: PropTypes.bool,
|
|
138
|
-
})
|
|
139
|
-
).isRequired,
|
|
140
|
-
unstyled: PropTypes.bool,
|
|
141
|
-
small: PropTypes.bool,
|
|
142
|
-
label: PropTypes.string,
|
|
143
|
-
id: PropTypes.string,
|
|
144
|
-
onSelect: PropTypes.func,
|
|
145
|
-
className: PropTypes.string,
|
|
146
|
-
navAriaLabel: PropTypes.string,
|
|
147
|
-
};
|
|
148
|
-
|
|
149
141
|
/**
|
|
150
142
|
* LanguageSelector — USWDS `usa-language-selector` with the USX treatment.
|
|
151
143
|
*
|
|
@@ -166,7 +158,7 @@ export default function LanguageSelector({
|
|
|
166
158
|
className = '',
|
|
167
159
|
onSelect = null,
|
|
168
160
|
...props
|
|
169
|
-
}) {
|
|
161
|
+
}: LanguageSelectorProps) {
|
|
170
162
|
const resolvedVariant = variant || (languages.length > 2 ? 'menu' : 'two');
|
|
171
163
|
const classes = classnames('usx-language-selector', className);
|
|
172
164
|
|
|
@@ -201,24 +193,3 @@ export default function LanguageSelector({
|
|
|
201
193
|
/>
|
|
202
194
|
);
|
|
203
195
|
}
|
|
204
|
-
|
|
205
|
-
LanguageSelector.propTypes = {
|
|
206
|
-
languages: PropTypes.arrayOf(
|
|
207
|
-
PropTypes.shape({
|
|
208
|
-
code: PropTypes.string,
|
|
209
|
-
label: PropTypes.node,
|
|
210
|
-
description: PropTypes.string,
|
|
211
|
-
href: PropTypes.string,
|
|
212
|
-
current: PropTypes.bool,
|
|
213
|
-
plain: PropTypes.bool,
|
|
214
|
-
})
|
|
215
|
-
),
|
|
216
|
-
variant: PropTypes.oneOf(['two', 'menu']),
|
|
217
|
-
unstyled: PropTypes.bool,
|
|
218
|
-
small: PropTypes.bool,
|
|
219
|
-
label: PropTypes.string,
|
|
220
|
-
id: PropTypes.string,
|
|
221
|
-
navAriaLabel: PropTypes.string,
|
|
222
|
-
className: PropTypes.string,
|
|
223
|
-
onSelect: PropTypes.func,
|
|
224
|
-
};
|
|
@@ -3,7 +3,7 @@ import ClassNames from 'classnames';
|
|
|
3
3
|
import Required from '../required/Required';
|
|
4
4
|
|
|
5
5
|
export interface LegendProps extends HTMLAttributes<HTMLLegendElement> {
|
|
6
|
-
text?:
|
|
6
|
+
text?: ReactNode;
|
|
7
7
|
required?: boolean;
|
|
8
8
|
large?: boolean;
|
|
9
9
|
children?: ReactNode;
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import Fieldset from '../fieldset/Fieldset';
|
|
4
4
|
import FormGroup from '../form-group/FormGroup';
|
|
5
5
|
import Hint from '../hint/Hint';
|
|
6
6
|
import Select from '../select/Select';
|
|
7
7
|
import Input from '../input/Input';
|
|
8
8
|
|
|
9
|
+
export interface MemorableDateProps {
|
|
10
|
+
id?: string;
|
|
11
|
+
legend?: React.ReactNode;
|
|
12
|
+
groupHint?: React.ReactNode;
|
|
13
|
+
monthLabel?: React.ReactNode;
|
|
14
|
+
dayLabel?: React.ReactNode;
|
|
15
|
+
yearLabel?: React.ReactNode;
|
|
16
|
+
monthHint?: React.ReactNode;
|
|
17
|
+
dayHint?: React.ReactNode;
|
|
18
|
+
yearHint?: React.ReactNode;
|
|
19
|
+
monthName?: string;
|
|
20
|
+
dayName?: string;
|
|
21
|
+
yearName?: string;
|
|
22
|
+
defaultMonth?: string;
|
|
23
|
+
defaultDay?: string;
|
|
24
|
+
defaultYear?: string;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
ariaDisabled?: boolean;
|
|
27
|
+
required?: boolean;
|
|
28
|
+
error?: string | null;
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
9
32
|
const MONTH_OPTIONS = [
|
|
10
33
|
{ value: '1', label: 'January' },
|
|
11
34
|
{ value: '2', label: 'February' },
|
|
@@ -42,7 +65,7 @@ export default function MemorableDate({
|
|
|
42
65
|
required = false,
|
|
43
66
|
error = null,
|
|
44
67
|
className = '',
|
|
45
|
-
}) {
|
|
68
|
+
}: MemorableDateProps) {
|
|
46
69
|
const monthId = `${id}-month`;
|
|
47
70
|
const dayId = `${id}-day`;
|
|
48
71
|
const yearId = `${id}-year`;
|
|
@@ -53,10 +76,10 @@ export default function MemorableDate({
|
|
|
53
76
|
const errorId = error ? `${id}-error` : undefined;
|
|
54
77
|
const hasError = !!error;
|
|
55
78
|
|
|
56
|
-
const describedBy = (hintId) => [hintId, errorId].filter(Boolean).join(' ') || undefined;
|
|
79
|
+
const describedBy = (hintId: string) => [hintId, errorId].filter(Boolean).join(' ') || undefined;
|
|
57
80
|
|
|
58
81
|
// Native disabled and aria-disabled are mutually exclusive, matching real USWDS's variants.
|
|
59
|
-
const stateProps = disabled
|
|
82
|
+
const stateProps: Pick<React.InputHTMLAttributes<HTMLInputElement>, 'disabled' | 'aria-disabled'> = disabled
|
|
60
83
|
? { disabled: true }
|
|
61
84
|
: ariaDisabled
|
|
62
85
|
? { 'aria-disabled': 'true' }
|
|
@@ -142,26 +165,3 @@ export default function MemorableDate({
|
|
|
142
165
|
</FormGroup>
|
|
143
166
|
);
|
|
144
167
|
}
|
|
145
|
-
|
|
146
|
-
MemorableDate.propTypes = {
|
|
147
|
-
id: PropTypes.string,
|
|
148
|
-
legend: PropTypes.node,
|
|
149
|
-
groupHint: PropTypes.node,
|
|
150
|
-
monthLabel: PropTypes.node,
|
|
151
|
-
dayLabel: PropTypes.node,
|
|
152
|
-
yearLabel: PropTypes.node,
|
|
153
|
-
monthHint: PropTypes.node,
|
|
154
|
-
dayHint: PropTypes.node,
|
|
155
|
-
yearHint: PropTypes.node,
|
|
156
|
-
monthName: PropTypes.string,
|
|
157
|
-
dayName: PropTypes.string,
|
|
158
|
-
yearName: PropTypes.string,
|
|
159
|
-
defaultMonth: PropTypes.string,
|
|
160
|
-
defaultDay: PropTypes.string,
|
|
161
|
-
defaultYear: PropTypes.string,
|
|
162
|
-
disabled: PropTypes.bool,
|
|
163
|
-
ariaDisabled: PropTypes.bool,
|
|
164
|
-
required: PropTypes.bool,
|
|
165
|
-
error: PropTypes.string,
|
|
166
|
-
className: PropTypes.string,
|
|
167
|
-
};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
export interface PageProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title' | 'content'> {
|
|
4
|
+
title?: React.ReactNode;
|
|
5
|
+
eyebrow?: React.ReactNode;
|
|
6
|
+
content?: React.ReactNode;
|
|
7
|
+
}
|
|
3
8
|
|
|
4
9
|
export default function Page({
|
|
5
10
|
id = undefined,
|
|
@@ -9,7 +14,7 @@ export default function Page({
|
|
|
9
14
|
content = null,
|
|
10
15
|
className = '',
|
|
11
16
|
...props
|
|
12
|
-
}) {
|
|
17
|
+
}: PageProps) {
|
|
13
18
|
const classes = ['usx-page', className].filter(Boolean).join(' ');
|
|
14
19
|
const pageContent = children || content;
|
|
15
20
|
|
|
@@ -23,12 +28,3 @@ export default function Page({
|
|
|
23
28
|
</main>
|
|
24
29
|
);
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
Page.propTypes = {
|
|
28
|
-
id: PropTypes.string,
|
|
29
|
-
title: PropTypes.string,
|
|
30
|
-
eyebrow: PropTypes.node,
|
|
31
|
-
children: PropTypes.node,
|
|
32
|
-
content: PropTypes.node,
|
|
33
|
-
className: PropTypes.string,
|
|
34
|
-
};
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import Label from '../label/Label';
|
|
4
4
|
import FormGroup from '../form-group/FormGroup';
|
|
5
5
|
import Hint from '../hint/Hint';
|
|
6
6
|
import ErrorMessage from '../error-message/ErrorMessage';
|
|
7
7
|
|
|
8
|
+
export interface RangeSliderProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue'> {
|
|
9
|
+
label?: React.ReactNode;
|
|
10
|
+
hint?: React.ReactNode;
|
|
11
|
+
error?: React.ReactNode;
|
|
12
|
+
value?: number | string;
|
|
13
|
+
defaultValue?: number | string;
|
|
14
|
+
textUnit?: string | null;
|
|
15
|
+
textPreposition?: string | null;
|
|
16
|
+
formGroup?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
8
19
|
// Enhanced by @uswds/uswds/js/usa-range at runtime (call ONLY range.init() in
|
|
9
20
|
// the consuming app, never .on()/.off() — see Combobox.tsx for why) — that
|
|
10
21
|
// script builds the value display span and keeps the aria-valuetext
|
|
@@ -27,7 +38,7 @@ export default function RangeSlider({
|
|
|
27
38
|
formGroup = true,
|
|
28
39
|
className = '',
|
|
29
40
|
...props
|
|
30
|
-
}) {
|
|
41
|
+
}: RangeSliderProps) {
|
|
31
42
|
const hintId = hint ? `${id}-hint` : undefined;
|
|
32
43
|
const errorId = error ? `${id}-error` : undefined;
|
|
33
44
|
const describedBy = [hintId, errorId].filter(Boolean).join(' ') || undefined;
|
|
@@ -63,22 +74,3 @@ export default function RangeSlider({
|
|
|
63
74
|
|
|
64
75
|
return formGroup ? <FormGroup error={!!error}>{content}</FormGroup> : content;
|
|
65
76
|
}
|
|
66
|
-
|
|
67
|
-
RangeSlider.propTypes = {
|
|
68
|
-
id: PropTypes.string,
|
|
69
|
-
name: PropTypes.string,
|
|
70
|
-
label: PropTypes.node,
|
|
71
|
-
hint: PropTypes.node,
|
|
72
|
-
error: PropTypes.node,
|
|
73
|
-
disabled: PropTypes.bool,
|
|
74
|
-
required: PropTypes.bool,
|
|
75
|
-
min: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
76
|
-
max: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
77
|
-
step: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
78
|
-
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
79
|
-
defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
80
|
-
textUnit: PropTypes.string,
|
|
81
|
-
textPreposition: PropTypes.string,
|
|
82
|
-
formGroup: PropTypes.bool,
|
|
83
|
-
className: PropTypes.string,
|
|
84
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// import React from 'react';
|
|
2
|
-
import { SelectHTMLAttributes } from 'react';
|
|
2
|
+
import { ReactNode, SelectHTMLAttributes } from 'react';
|
|
3
3
|
import ClassNames from 'classnames';
|
|
4
4
|
import Label from '../label/Label';
|
|
5
5
|
import Hint from '../hint/Hint';
|
|
@@ -12,7 +12,7 @@ export interface SelectOption {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export interface SelectProps extends Omit<SelectHTMLAttributes<HTMLSelectElement>, 'size'> {
|
|
15
|
-
label:
|
|
15
|
+
label: ReactNode;
|
|
16
16
|
id?: string;
|
|
17
17
|
name?: string;
|
|
18
18
|
options?: SelectOption[];
|