@govuk-react/primitives 0.0.0-stage → 0.2.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 +271 -2
- package/dist/accordion-element.d.ts +17 -0
- package/dist/accordion-element.js +9 -0
- package/dist/accordion-element.js.map +1 -0
- package/dist/accordion.d.ts +2 -0
- package/dist/accordion.js +34 -0
- package/dist/accordion.js.map +1 -0
- package/dist/auto-focus-element.d.ts +3 -0
- package/dist/auto-focus-element.js +10 -0
- package/dist/auto-focus-element.js.map +1 -0
- package/dist/auto-focus.d.ts +2 -0
- package/dist/auto-focus.js +15 -0
- package/dist/auto-focus.js.map +1 -0
- package/dist/autocomplete-element.d.ts +30 -0
- package/dist/autocomplete-element.js +12 -0
- package/dist/autocomplete-element.js.map +1 -0
- package/dist/autocomplete.d.ts +4 -0
- package/dist/autocomplete.js +25 -0
- package/dist/autocomplete.js.map +1 -0
- package/dist/button-element.d.ts +2 -0
- package/dist/button-element.js +3 -0
- package/dist/button-element.js.map +1 -0
- package/dist/button.d.ts +2 -0
- package/dist/button.js +12 -0
- package/dist/button.js.map +1 -0
- package/dist/character-count-element.d.ts +10 -0
- package/dist/character-count-element.js +10 -0
- package/dist/character-count-element.js.map +1 -0
- package/dist/character-count.d.ts +3 -0
- package/dist/character-count.js +26 -0
- package/dist/character-count.js.map +1 -0
- package/dist/choices-element.d.ts +8 -0
- package/dist/choices-element.js +9 -0
- package/dist/choices-element.js.map +1 -0
- package/dist/choices.d.ts +2 -0
- package/dist/choices.js +16 -0
- package/dist/choices.js.map +1 -0
- package/dist/chunk-2IHAQAYF.js +23 -0
- package/dist/chunk-2IHAQAYF.js.map +1 -0
- package/dist/chunk-2ZJVSNC2.js +31 -0
- package/dist/chunk-2ZJVSNC2.js.map +1 -0
- package/dist/chunk-47NMY4SS.js +108 -0
- package/dist/chunk-47NMY4SS.js.map +1 -0
- package/dist/chunk-4XAR4FFG.js +83 -0
- package/dist/chunk-4XAR4FFG.js.map +1 -0
- package/dist/chunk-5HWRMQK2.js +91 -0
- package/dist/chunk-5HWRMQK2.js.map +1 -0
- package/dist/chunk-6ZFU4VYW.js +41 -0
- package/dist/chunk-6ZFU4VYW.js.map +1 -0
- package/dist/chunk-B2I4J5NL.js +264 -0
- package/dist/chunk-B2I4J5NL.js.map +1 -0
- package/dist/chunk-DPERPCUH.js +188 -0
- package/dist/chunk-DPERPCUH.js.map +1 -0
- package/dist/chunk-ECYGKE4D.js +168 -0
- package/dist/chunk-ECYGKE4D.js.map +1 -0
- package/dist/chunk-ESBMTI25.js +11 -0
- package/dist/chunk-ESBMTI25.js.map +1 -0
- package/dist/chunk-ET7DCQM7.js +133 -0
- package/dist/chunk-ET7DCQM7.js.map +1 -0
- package/dist/chunk-F5XFC4QJ.js +177 -0
- package/dist/chunk-F5XFC4QJ.js.map +1 -0
- package/dist/chunk-GVGBDSDN.js +78 -0
- package/dist/chunk-GVGBDSDN.js.map +1 -0
- package/dist/chunk-IZQ2C4BC.js +351 -0
- package/dist/chunk-IZQ2C4BC.js.map +1 -0
- package/dist/chunk-L7E6GN2D.js +87 -0
- package/dist/chunk-L7E6GN2D.js.map +1 -0
- package/dist/chunk-LWIA644X.js +34 -0
- package/dist/chunk-LWIA644X.js.map +1 -0
- package/dist/chunk-NX4B3NKM.js +35 -0
- package/dist/chunk-NX4B3NKM.js.map +1 -0
- package/dist/chunk-PNWPGD7B.js +68 -0
- package/dist/chunk-PNWPGD7B.js.map +1 -0
- package/dist/chunk-QLQ6O7OW.js +111 -0
- package/dist/chunk-QLQ6O7OW.js.map +1 -0
- package/dist/chunk-RDUPELOK.js +55 -0
- package/dist/chunk-RDUPELOK.js.map +1 -0
- package/dist/chunk-RPMHI67T.js +104 -0
- package/dist/chunk-RPMHI67T.js.map +1 -0
- package/dist/chunk-TE4RUYVK.js +97 -0
- package/dist/chunk-TE4RUYVK.js.map +1 -0
- package/dist/chunk-TJVBFRIE.js +60 -0
- package/dist/chunk-TJVBFRIE.js.map +1 -0
- package/dist/chunk-U5OKNKYC.js +510 -0
- package/dist/chunk-U5OKNKYC.js.map +1 -0
- package/dist/chunk-UXJO4AJP.js +290 -0
- package/dist/chunk-UXJO4AJP.js.map +1 -0
- package/dist/chunk-VNXXENCU.js +39 -0
- package/dist/chunk-VNXXENCU.js.map +1 -0
- package/dist/chunk-XGK73UCD.js +62 -0
- package/dist/chunk-XGK73UCD.js.map +1 -0
- package/dist/chunk-XJYLFTYE.js +157 -0
- package/dist/chunk-XJYLFTYE.js.map +1 -0
- package/dist/chunk-YCESNTXQ.js +241 -0
- package/dist/chunk-YCESNTXQ.js.map +1 -0
- package/dist/chunk-ZTJLVNR4.js +62 -0
- package/dist/chunk-ZTJLVNR4.js.map +1 -0
- package/dist/disclosure-element.d.ts +17 -0
- package/dist/disclosure-element.js +9 -0
- package/dist/disclosure-element.js.map +1 -0
- package/dist/disclosure.d.ts +2 -0
- package/dist/disclosure.js +16 -0
- package/dist/disclosure.js.map +1 -0
- package/dist/exit-this-page-element.d.ts +22 -0
- package/dist/exit-this-page-element.js +13 -0
- package/dist/exit-this-page-element.js.map +1 -0
- package/dist/exit-this-page.d.ts +3 -0
- package/dist/exit-this-page.js +25 -0
- package/dist/exit-this-page.js.map +1 -0
- package/dist/file-upload-element.d.ts +27 -0
- package/dist/file-upload-element.js +14 -0
- package/dist/file-upload-element.js.map +1 -0
- package/dist/file-upload.d.ts +3 -0
- package/dist/file-upload.js +25 -0
- package/dist/file-upload.js.map +1 -0
- package/dist/focus-links-element.d.ts +3 -0
- package/dist/focus-links-element.js +10 -0
- package/dist/focus-links-element.js.map +1 -0
- package/dist/focus-links.d.ts +2 -0
- package/dist/focus-links.js +12 -0
- package/dist/focus-links.js.map +1 -0
- package/dist/index--FxJgSOS.d.ts +108 -0
- package/dist/index-BR3MAGF8.d.ts +299 -0
- package/dist/index-Bul0NJh_.d.ts +310 -0
- package/dist/index-CikOyFud.d.ts +54 -0
- package/dist/index-D4Gzyvfu.d.ts +321 -0
- package/dist/index-D7lMYMUR.d.ts +373 -0
- package/dist/index-D8N5vxTL.d.ts +90 -0
- package/dist/index-DMWpkC_d.d.ts +105 -0
- package/dist/index-DN7fGMc3.d.ts +20 -0
- package/dist/index-DPXR1Yua.d.ts +69 -0
- package/dist/index-WuGvkTxu.d.ts +323 -0
- package/dist/index-qF0jIQCW.d.ts +354 -0
- package/dist/index-sEHnx4-M.d.ts +334 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/inline/accordion-element.js +1 -0
- package/dist/inline/auto-focus-element.js +1 -0
- package/dist/inline/autocomplete-element.js +2 -0
- package/dist/inline/button-element.js +1 -0
- package/dist/inline/character-count-element.js +1 -0
- package/dist/inline/choices-element.js +1 -0
- package/dist/inline/disclosure-element.js +1 -0
- package/dist/inline/exit-this-page-element.js +1 -0
- package/dist/inline/file-upload-element.js +1 -0
- package/dist/inline/focus-links-element.js +1 -0
- package/dist/inline/modal-element.js +1 -0
- package/dist/inline/password-input-element.js +1 -0
- package/dist/inline/tabs-element.js +1 -0
- package/dist/inline-script.d.ts +29 -0
- package/dist/inline-script.js +63 -0
- package/dist/inline-script.js.map +1 -0
- package/dist/modal-element.d.ts +12 -0
- package/dist/modal-element.js +11 -0
- package/dist/modal-element.js.map +1 -0
- package/dist/modal.d.ts +2 -0
- package/dist/modal.js +20 -0
- package/dist/modal.js.map +1 -0
- package/dist/password-input-element.d.ts +3 -0
- package/dist/password-input-element.js +9 -0
- package/dist/password-input-element.js.map +1 -0
- package/dist/password-input.d.ts +2 -0
- package/dist/password-input.js +18 -0
- package/dist/password-input.js.map +1 -0
- package/dist/tabs-element.d.ts +22 -0
- package/dist/tabs-element.js +9 -0
- package/dist/tabs-element.js.map +1 -0
- package/dist/tabs.d.ts +2 -0
- package/dist/tabs.js +28 -0
- package/dist/tabs.js.map +1 -0
- package/dist/translation-BnpO2mN2.d.ts +4 -0
- package/licences/accessible-autocomplete.txt +20 -0
- package/package.json +42 -4
package/README.md
CHANGED
|
@@ -1,3 +1,272 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @govuk-react/primitives
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Headless behaviour for design system components, as light-DOM custom elements with unstyled React parts over them. It ships no styles and no GOV.UK markup, so any library can use it. govuk-react's components are the reference implementation, built with govuk-frontend-react's markup.
|
|
4
|
+
|
|
5
|
+
Each primitive:
|
|
6
|
+
|
|
7
|
+
- works without JavaScript, through a fallback you choose
|
|
8
|
+
- upgrades to the full WAI-ARIA pattern when its custom element is defined, with or without React
|
|
9
|
+
- adds React state (`value`, `defaultValue`, `onValueChange`) once hydrated
|
|
10
|
+
- takes `asChild` on every part, so you render your own elements
|
|
11
|
+
|
|
12
|
+
## Inline scripts
|
|
13
|
+
|
|
14
|
+
Each element is also built as a small, self-contained classic script, with no imports and no React, at `@govuk-react/primitives/inline/<name>-element.js`, such as `inline/tabs-element.js`. Inline the ones your page uses, so the markup is interactive as soon as it loads, before React has downloaded and hydrated. React's parts then pick up from the elements, including anything the user did before hydration. Each element is defined only once, whichever runs first: the inline script or React's bundle.
|
|
15
|
+
|
|
16
|
+
To render them from React on the server, `inline-script` has each script as a string, and an `InlineScript` component:
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { InlineScript, tabs } from '@govuk-react/primitives/inline-script';
|
|
20
|
+
|
|
21
|
+
<head>
|
|
22
|
+
<InlineScript script={tabs} nonce={nonce} />
|
|
23
|
+
</head>;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The scripts are `accordion`, `autocomplete`, `autoFocus`, `button`, `characterCount`, `choices`, `disclosure`, `exitThisPage`, `fileUpload`, `focusLinks`, `modal`, `passwordInput` and `tabs`. `InlineScript` isn't a client component, so the scripts stay out of client bundles. A script React adds in the browser doesn't run, and isn't needed, since React's parts define their elements.
|
|
27
|
+
|
|
28
|
+
## Accordion
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import * as Accordion from '@govuk-react/primitives/accordion';
|
|
32
|
+
|
|
33
|
+
<Accordion.Root defaultValue={['web']}>
|
|
34
|
+
<Accordion.Controls>
|
|
35
|
+
<Accordion.ShowAll>
|
|
36
|
+
<Accordion.ShowAllText />
|
|
37
|
+
</Accordion.ShowAll>
|
|
38
|
+
</Accordion.Controls>
|
|
39
|
+
<Accordion.Section value="web">
|
|
40
|
+
<h2>
|
|
41
|
+
<Accordion.Fallback>Writing well for the web</Accordion.Fallback>
|
|
42
|
+
<Accordion.Trigger>
|
|
43
|
+
<Accordion.Label>Writing well for the web</Accordion.Label> <Accordion.ToggleText />
|
|
44
|
+
</Accordion.Trigger>
|
|
45
|
+
</h2>
|
|
46
|
+
<Accordion.Content id="web-content">…</Accordion.Content>
|
|
47
|
+
</Accordion.Section>
|
|
48
|
+
</Accordion.Root>;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Without JavaScript every section is shown under its `Fallback` heading. Each section also renders a hidden `Trigger` with the same heading, which the element shows on upgrade while hiding the fallback. Nothing is moved, so React can keep rendering the markup. Closed content gets `hidden="until-found"`, so find in page opens it. `Label`s name the trigger, followed by "Show this section" or "Hide this section".
|
|
52
|
+
|
|
53
|
+
`ShowAll` opens every section, or closes them all when every one is open. `value` and `onValueChange` control the open sections once hydrated, and a section opened before hydration is reported rather than undone. As in govuk-frontend, open sections are remembered for the session by content id, unless `rememberExpanded` is `false`. In an island without a `Root`, pass `defaultExpanded` to `Section`.
|
|
54
|
+
|
|
55
|
+
## Tabs
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import * as Tabs from '@govuk-react/primitives/tabs';
|
|
59
|
+
|
|
60
|
+
<Tabs.Root defaultValue="past-day">
|
|
61
|
+
<Tabs.List>
|
|
62
|
+
<Tabs.Trigger value="past-day">Past day</Tabs.Trigger>
|
|
63
|
+
<Tabs.Trigger value="past-week">Past week</Tabs.Trigger>
|
|
64
|
+
</Tabs.List>
|
|
65
|
+
<Tabs.Content value="past-day">…</Tabs.Content>
|
|
66
|
+
<Tabs.Content value="past-week">…</Tabs.Content>
|
|
67
|
+
</Tabs.Root>;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Each panel holds a hidden radio, and the radio group is the source of truth, as in the reference. Choosing a tab checks its radio, and the radio's native change updates the tabs and calls `onValueChange`.
|
|
71
|
+
|
|
72
|
+
The root sets how the tabs work without JavaScript, and its parts match it:
|
|
73
|
+
|
|
74
|
+
- `Root`, with `Trigger` and `Content`: each tab links to its panel, and every panel shows.
|
|
75
|
+
- `RadiosRoot`, with `RadioTrigger` and `RadioContent`: each tab is a label for a hidden radio in its panel, so tabs switch with no JavaScript when clicked. It needs `defaultValue` or `value`. Without JavaScript the labels can't be reached by keyboard, as in the reference. Pass `name` when tabs render in separate React roots, such as islands. `RadiosRoot` adds the fallback's CSS inline; under a strict CSP, add `radiosFallbackCss` to a stylesheet instead.
|
|
76
|
+
|
|
77
|
+
They are separate components rather than a prop, because a prop can change after the first render, and the markup each needs can't.
|
|
78
|
+
|
|
79
|
+
When controlled with `value`, a user's choice calls `onValueChange` and the tab changes only when `value` does. `preHydration` sets what happens to a tab the user picked before React hydrated: `"ignore"` (the default) keeps `value`, `"report"` calls `onValueChange` with it. When uncontrolled, the pick is always reported.
|
|
80
|
+
|
|
81
|
+
`orientation` (`"horizontal"` or `"vertical"`) sets the axis of the arrow keys.
|
|
82
|
+
|
|
83
|
+
`media` limits the tab behaviour to a media query. Below it, `Root`'s tabs are a list of links to panels, and `RadiosRoot`'s keep switching through their radios. With `Root`, the URL hash follows the selected tab, as in govuk-frontend.
|
|
84
|
+
|
|
85
|
+
In an island without a root, pass `name` and `defaultSelected` to the triggers and panels. `upgradedClass`, `activeItemClass` and `hiddenContentClass` add classes for styles that key off classes rather than `data-state`, `aria-selected` and `hidden`.
|
|
86
|
+
|
|
87
|
+
Without React, use the `<govuk-react-tabs>` element from `@govuk-react/primitives/tabs-element` with the same markup, including a hidden radio as the first child of each panel. Listen for its `govuk-react-tabs:change` event. See [the element's source](src/tabs/element.ts) for its attributes.
|
|
88
|
+
|
|
89
|
+
It follows the Tabs reference in [react-design-system-apis](https://github.com/penx/react-design-system-apis). Browser tests in `packages/primitives-e2e` cover it without JavaScript, upgraded without React, hydrated, before hydration, controlled, nested, in islands and rendered only on the client.
|
|
90
|
+
|
|
91
|
+
## Disclosure
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import * as Disclosure from '@govuk-react/primitives/disclosure';
|
|
95
|
+
|
|
96
|
+
<nav aria-label="Menu">
|
|
97
|
+
<Disclosure.Root media="(min-width: 40.0625em)">
|
|
98
|
+
<Disclosure.Toggle>Menu</Disclosure.Toggle>
|
|
99
|
+
<Disclosure.Content asChild>
|
|
100
|
+
<ul id="navigation">…</ul>
|
|
101
|
+
</Disclosure.Content>
|
|
102
|
+
</Disclosure.Root>
|
|
103
|
+
</nav>;
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
A button that shows and hides some content, such as a navigation menu on small screens. Without JavaScript the content is shown and the button hidden. While `media` matches, the content is always shown and the button hidden.
|
|
107
|
+
|
|
108
|
+
`open` and `onOpenChange` control it once hydrated, such as to close a menu after navigating. A user's click before hydration is reported through `onOpenChange` rather than undone. `defaultOpen` starts it open.
|
|
109
|
+
|
|
110
|
+
## Modal
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import * as Modal from '@govuk-react/primitives/modal';
|
|
114
|
+
|
|
115
|
+
<Modal.Root>
|
|
116
|
+
<Modal.Trigger>Delete account</Modal.Trigger>
|
|
117
|
+
<Modal.Content>
|
|
118
|
+
<Modal.Title>Are you sure?</Modal.Title>
|
|
119
|
+
<Modal.Close>Cancel</Modal.Close>
|
|
120
|
+
</Modal.Content>
|
|
121
|
+
</Modal.Root>;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`Content` is a native `dialog`, and `Trigger` and `Close` are buttons with invoker commands (`command="show-modal"` and `command="close"`, with `commandfor` naming the dialog). Where the browser supports them (Chrome and Edge 135, Firefox 144, Safari 26.2), the dialog opens as a true modal without JavaScript: the page behind is inert, focus moves into the dialog and Escape closes it. In older browsers, the `<govuk-react-modal>` element runs the commands once its script loads.
|
|
125
|
+
|
|
126
|
+
`Title` names the dialog, so always include one, or pass `aria-label` to `Content`. Pass `closedby="any"` to `Content` to also close it when the user clicks outside it.
|
|
127
|
+
|
|
128
|
+
`open` and `onOpenChange` control the dialog once hydrated. In an island without a `Root`, pass `dialogId` to `Trigger` and `Close`, and `id` and `aria-labelledby` to `Content`.
|
|
129
|
+
|
|
130
|
+
## Character count
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import * as CharacterCount from '@govuk-react/primitives/character-count';
|
|
134
|
+
|
|
135
|
+
<CharacterCount.Root maxLength={200}>
|
|
136
|
+
<label htmlFor="more-detail">Can you provide more detail?</label>
|
|
137
|
+
<CharacterCount.Input id="more-detail" aria-describedby="more-detail-info" maxLength={200} />
|
|
138
|
+
<CharacterCount.Description id="more-detail-info">You can enter up to 200 characters</CharacterCount.Description>
|
|
139
|
+
<CharacterCount.Status />
|
|
140
|
+
<CharacterCount.ScreenReaderStatus className="visually-hidden" />
|
|
141
|
+
</CharacterCount.Root>;
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Without JavaScript the `Description` is shown and both statuses are hidden. On upgrade the element visually hides the description, removes the field's `maxlength` so users can see by how much they're over, and shows `Status`, which updates as the user types. As in govuk-frontend, `ScreenReaderStatus` updates once the user pauses, rather than on every key, and is hidden from screen readers below `threshold`.
|
|
145
|
+
|
|
146
|
+
`countType` is "length" (the default, as `maxlength` counts), "characters" (as users see them, such as an emoji as one) or "words". The messages are English by default, and take a message for each plural form. The statuses get `data-state` ("under", "at" or "over") for styling, or pass class names such as `overLimitClass`. The field's value is the state, so a value React sets is counted too.
|
|
147
|
+
|
|
148
|
+
## Autocomplete
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
import * as Autocomplete from '@govuk-react/primitives/autocomplete';
|
|
152
|
+
|
|
153
|
+
<label htmlFor="country">Country</label>
|
|
154
|
+
<Autocomplete.Root onQueryChange={fetchCountries} onConfirm={setCountry}>
|
|
155
|
+
<Autocomplete.Input id="country" name="country" />
|
|
156
|
+
<Autocomplete.Listbox>
|
|
157
|
+
{countries.map((country) => (
|
|
158
|
+
<Autocomplete.Option key={country} value={country}>
|
|
159
|
+
{country}
|
|
160
|
+
</Autocomplete.Option>
|
|
161
|
+
))}
|
|
162
|
+
<Autocomplete.NoResults />
|
|
163
|
+
</Autocomplete.Listbox>
|
|
164
|
+
<Autocomplete.Status />
|
|
165
|
+
<Autocomplete.AssistiveHint />
|
|
166
|
+
</Autocomplete.Root>;
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
A port of GOV.UK's [accessible-autocomplete](https://github.com/alphagov/accessible-autocomplete) that enhances your own input. Without JavaScript the input is a plain input. On upgrade it's a combobox with accessible-autocomplete's behaviour: options that match the query show in the `Listbox`, Up and Down move focus through them, Enter, Space or a click confirms one, and Escape closes the menu. `Status` tells screen readers how many options there are once the user pauses, and `AssistiveHint` describes the input while the query is empty.
|
|
170
|
+
|
|
171
|
+
The input's value is the query, and the options are whatever you render, so there is nothing else to control. `onQueryChange` is called when options are due, such as to fetch them, including for a query typed before hydration. `filter` sets which options match the query: "contains" (the default), "starts-with", or "none" for options that already match, such as results from a server. Leave out `NoResults` to show nothing when no option matches.
|
|
172
|
+
|
|
173
|
+
`minLength` is the length the query needs before options show. `onConfirm` is called when the user confirms an option. With `submitOnConfirm`, confirming an option submits the form, and Enter submits it while no option is highlighted. As in accessible-autocomplete, focus leaving a highlighted option confirms it, unless `confirmOnBlur` is `false`. The status messages are English by default, and take a message for each plural form.
|
|
174
|
+
|
|
175
|
+
Not ported from accessible-autocomplete: `showAllValues` and its dropdown arrow, `enhanceSelectElement`, `autoselect` and its inline hint, `displayMenu` (style the `Listbox` instead) and the iOS position workaround.
|
|
176
|
+
|
|
177
|
+
accessible-autocomplete is Copyright (c) 2017 Crown Copyright (Government Digital Service), under the [MIT licence](licences/accessible-autocomplete.txt).
|
|
178
|
+
|
|
179
|
+
## File upload
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import * as FileUpload from '@govuk-react/primitives/file-upload';
|
|
183
|
+
|
|
184
|
+
<label id="photo-label" htmlFor="photo">Upload a photo</label>
|
|
185
|
+
<FileUpload.Root>
|
|
186
|
+
<FileUpload.DropZone>
|
|
187
|
+
<FileUpload.Button>
|
|
188
|
+
<FileUpload.Status />
|
|
189
|
+
<FileUpload.Separator className="visually-hidden" />
|
|
190
|
+
Choose file or drop file
|
|
191
|
+
</FileUpload.Button>
|
|
192
|
+
<FileUpload.Input id="photo" name="photo" />
|
|
193
|
+
</FileUpload.DropZone>
|
|
194
|
+
<FileUpload.Announcements className="visually-hidden" />
|
|
195
|
+
</FileUpload.Root>;
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Without JavaScript the native file input is shown and the `Button` is hidden. On upgrade the element hides the input and shows the button, which opens the file picker, takes files dropped on it, and says in `Status` which files are chosen. As in govuk-frontend, the button takes the input's `id` (the input's gets `-input` added), so the input's label names it, along with its `aria-describedby` and `disabled`. Give the label an id: without one the element adds it, which React warns about when it hydrates. `Announcements` tells screen readers when files are dragged into and out of the `DropZone`.
|
|
199
|
+
|
|
200
|
+
The input's files are the state, so there is nothing to control. Dropped files fire bubbling `input` and `change` events, so React's `onChange` hears them. The text is English by default, and `multipleFilesChosen` takes a message for each plural form. The button gets `data-empty` and `data-dragging`, and the drop zone `data-disabled`, for styling, or pass class names such as `emptyClass`.
|
|
201
|
+
|
|
202
|
+
## Choices
|
|
203
|
+
|
|
204
|
+
```tsx
|
|
205
|
+
import * as Choices from '@govuk-react/primitives/choices';
|
|
206
|
+
|
|
207
|
+
<Choices.Root>
|
|
208
|
+
<Choices.Input type="radio" id="email" name="contact" value="email" controls="email-reveal" />
|
|
209
|
+
<label htmlFor="email">Email</label>
|
|
210
|
+
<Choices.Conditional id="email-reveal">…</Choices.Conditional>
|
|
211
|
+
</Choices.Root>;
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
For a group of radios or checkboxes. Without JavaScript every `Conditional` is shown. On upgrade, each one shows only while the choice that `controls` it is checked, and that choice gets `aria-controls` and `aria-expanded`. A checkbox with `exclusive`, such as "None of these", unchecks the other checkboxes with its name when checked, and is unchecked when one of them is. They're unchecked with `click()`, so `change` events fire and controlled React inputs hear about it. Control the inputs as usual, with `checked` and `onChange`.
|
|
215
|
+
|
|
216
|
+
## AutoFocus
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
import * as AutoFocus from '@govuk-react/primitives/auto-focus';
|
|
220
|
+
|
|
221
|
+
<AutoFocus.Root>
|
|
222
|
+
<AutoFocus.Target role="alert">There is a problem</AutoFocus.Target>
|
|
223
|
+
</AutoFocus.Root>;
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Moves focus to `Target` when it appears, such as an error summary after a form is submitted. The server renders the target with `tabindex="-1"` and `autofocus`, so the browser focuses it when the page loads, even without JavaScript. As in govuk-frontend, the target loses its `tabindex` once focus moves on. Pass `disabled` to both parts to leave focus alone.
|
|
227
|
+
|
|
228
|
+
## FocusLinks
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
import * as FocusLinks from '@govuk-react/primitives/focus-links';
|
|
232
|
+
|
|
233
|
+
<FocusLinks.Root focusedClass="focused">
|
|
234
|
+
<a href="#main-content">Skip to main content</a>
|
|
235
|
+
</FocusLinks.Root>;
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Makes links inside it, to a part of the same page, move focus there. A link to a form field focuses the field and scrolls its label into view, or its fieldset's legend, as govuk-frontend's error summary does. A link to anything else focuses it with `tabindex="-1"` and `focusedClass` until focus moves on, as govuk-frontend's skip link does. Without JavaScript the browser follows the link as usual.
|
|
239
|
+
|
|
240
|
+
## Button
|
|
241
|
+
|
|
242
|
+
```tsx
|
|
243
|
+
import * as Button from '@govuk-react/primitives/button';
|
|
244
|
+
|
|
245
|
+
<Button.Root preventDoubleClick>Save and continue</Button.Root>;
|
|
246
|
+
|
|
247
|
+
<Button.Root asChild>
|
|
248
|
+
<a href="/start" role="button">
|
|
249
|
+
Start now
|
|
250
|
+
</a>
|
|
251
|
+
</Button.Root>;
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
With `preventDoubleClick`, a second click within a second of the first is ignored, so a form isn't submitted twice. The click is stopped before React hears it, so `onClick` doesn't run twice either. Space activates a link with `role="button"`, as it does a button. Unlike the other primitives there's no wrapper element, which would change a button group's layout: importing the module adds one click and one keydown listener to the document, for any element marked by `Root`. Without React, import `@govuk-react/primitives/button-element` and mark buttons with `data-button`.
|
|
255
|
+
|
|
256
|
+
## ExitThisPage
|
|
257
|
+
|
|
258
|
+
```tsx
|
|
259
|
+
import * as ExitThisPage from '@govuk-react/primitives/exit-this-page';
|
|
260
|
+
|
|
261
|
+
<ExitThisPage.SkipLink href="https://www.bbc.co.uk/weather">Exit this page</ExitThisPage.SkipLink>;
|
|
262
|
+
|
|
263
|
+
<ExitThisPage.Root hideContentClass="hide-content" overlayClass="overlay">
|
|
264
|
+
<ExitThisPage.Button href="https://www.bbc.co.uk/weather">
|
|
265
|
+
Exit this page
|
|
266
|
+
<ExitThisPage.Indicator />
|
|
267
|
+
</ExitThisPage.Button>
|
|
268
|
+
<ExitThisPage.Status className="visually-hidden" />
|
|
269
|
+
</ExitThisPage.Root>;
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Lets users leave the page quickly. Without JavaScript the button is a plain link. Once upgraded, the button, a `SkipLink`, or pressing Shift 3 times within 5 seconds hides the page behind an overlay that says it's loading, and goes to the button's `href`. `Indicator` shows the presses, and `Status` tells screen readers how many more are needed. Only the page's first `Root` listens for Shift and skip links. Before leaving, the element fires a cancelable `govuk-react-exit-this-page:exit` event, so a test can stay on the page.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface HTMLElementEventMap {
|
|
3
|
+
'govuk-react-accordion:change': CustomEvent<{
|
|
4
|
+
value: string[];
|
|
5
|
+
}>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
declare const tagName = "govuk-react-accordion";
|
|
9
|
+
interface AccordionElement extends HTMLElement {
|
|
10
|
+
/** The open sections' values, once upgraded. */
|
|
11
|
+
readonly openValues: string[] | undefined;
|
|
12
|
+
/** The open sections after the user's last change before `value` was first set, such as before React hydrated. */
|
|
13
|
+
readonly pickedValue: string[] | undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { tagName };
|
|
17
|
+
export type { AccordionElement };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import 'react';
|
|
2
|
+
export { C as Content, a as ContentProps, b as Controls, c as ControlsProps, F as Fallback, d as FallbackProps, I as Icon, e as IconProps, L as Label, f as LabelProps, R as Root, g as RootProps, S as Section, h as SectionProps, j as ShowAll, k as ShowAllProps, l as ShowAllText, m as ShowAllTextProps, T as ToggleText, n as ToggleTextProps, o as Trigger, p as TriggerProps, q as accordionCss } from './index-DMWpkC_d.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use client";
|
|
3
|
+
import {
|
|
4
|
+
Content,
|
|
5
|
+
Controls,
|
|
6
|
+
Fallback,
|
|
7
|
+
Icon,
|
|
8
|
+
Label,
|
|
9
|
+
Root,
|
|
10
|
+
Section,
|
|
11
|
+
ShowAll,
|
|
12
|
+
ShowAllText,
|
|
13
|
+
ToggleText,
|
|
14
|
+
Trigger,
|
|
15
|
+
accordionCss
|
|
16
|
+
} from "./chunk-DPERPCUH.js";
|
|
17
|
+
import "./chunk-B2I4J5NL.js";
|
|
18
|
+
import "./chunk-NX4B3NKM.js";
|
|
19
|
+
import "./chunk-ESBMTI25.js";
|
|
20
|
+
export {
|
|
21
|
+
Content,
|
|
22
|
+
Controls,
|
|
23
|
+
Fallback,
|
|
24
|
+
Icon,
|
|
25
|
+
Label,
|
|
26
|
+
Root,
|
|
27
|
+
Section,
|
|
28
|
+
ShowAll,
|
|
29
|
+
ShowAllText,
|
|
30
|
+
ToggleText,
|
|
31
|
+
Trigger,
|
|
32
|
+
accordionCss
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=accordion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use client";
|
|
3
|
+
import {
|
|
4
|
+
Root,
|
|
5
|
+
Target
|
|
6
|
+
} from "./chunk-6ZFU4VYW.js";
|
|
7
|
+
import "./chunk-XGK73UCD.js";
|
|
8
|
+
import "./chunk-LWIA644X.js";
|
|
9
|
+
import "./chunk-NX4B3NKM.js";
|
|
10
|
+
import "./chunk-ESBMTI25.js";
|
|
11
|
+
export {
|
|
12
|
+
Root,
|
|
13
|
+
Target
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=auto-focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*! Based on accessible-autocomplete, Copyright (c) 2017 Crown Copyright (Government Digital Service), MIT licence: licences/accessible-autocomplete.txt */
|
|
2
|
+
declare const tagName = "govuk-react-autocomplete";
|
|
3
|
+
type Filter = 'contains' | 'starts-with' | 'none';
|
|
4
|
+
interface AutocompleteElement extends HTMLElement {
|
|
5
|
+
/** The query, once upgraded. */
|
|
6
|
+
readonly query: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
interface HTMLElementEventMap {
|
|
10
|
+
'govuk-react-autocomplete:query': CustomEvent<{
|
|
11
|
+
query: string;
|
|
12
|
+
}>;
|
|
13
|
+
'govuk-react-autocomplete:confirm': CustomEvent<{
|
|
14
|
+
value: string;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** accessible-autocomplete's English text. */
|
|
19
|
+
declare const defaults: {
|
|
20
|
+
'status-query-too-short': string;
|
|
21
|
+
'status-no-results': string;
|
|
22
|
+
'status-selected-option': string;
|
|
23
|
+
'status-results': {
|
|
24
|
+
one: string;
|
|
25
|
+
other: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { defaults, tagName };
|
|
30
|
+
export type { AutocompleteElement, Filter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import 'react';
|
|
2
|
+
export { T as Translation } from './translation-BnpO2mN2.js';
|
|
3
|
+
export { Filter } from './autocomplete-element.js';
|
|
4
|
+
export { A as AssistiveHint, a as AssistiveHintProps, I as Input, b as InputProps, L as Listbox, c as ListboxProps, N as NoResults, d as NoResultsProps, O as Option, e as OptionProps, R as Root, f as RootProps, S as Status, g as StatusProps } from './index-D7lMYMUR.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use client";
|
|
3
|
+
import {
|
|
4
|
+
AssistiveHint,
|
|
5
|
+
Input,
|
|
6
|
+
Listbox,
|
|
7
|
+
NoResults,
|
|
8
|
+
Option,
|
|
9
|
+
Root,
|
|
10
|
+
Status
|
|
11
|
+
} from "./chunk-XJYLFTYE.js";
|
|
12
|
+
import "./chunk-U5OKNKYC.js";
|
|
13
|
+
import "./chunk-RDUPELOK.js";
|
|
14
|
+
import "./chunk-NX4B3NKM.js";
|
|
15
|
+
import "./chunk-ESBMTI25.js";
|
|
16
|
+
export {
|
|
17
|
+
AssistiveHint,
|
|
18
|
+
Input,
|
|
19
|
+
Listbox,
|
|
20
|
+
NoResults,
|
|
21
|
+
Option,
|
|
22
|
+
Root,
|
|
23
|
+
Status
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=autocomplete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/button.d.ts
ADDED
package/dist/button.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const tagName = "govuk-react-character-count";
|
|
2
|
+
interface CharacterCountElement extends HTMLElement {
|
|
3
|
+
/** The count, once upgraded. */
|
|
4
|
+
readonly count: number | undefined;
|
|
5
|
+
/** Counts the field again and updates the visible count, such as after setting its value. */
|
|
6
|
+
update(): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { tagName };
|
|
10
|
+
export type { CharacterCountElement };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import 'react';
|
|
2
|
+
export { C as CountType, D as Description, a as DescriptionProps, I as Input, b as InputProps, R as Root, c as RootProps, S as ScreenReaderStatus, d as ScreenReaderStatusProps, e as Status, f as StatusProps, g as countMessage, h as countOf } from './index-D8N5vxTL.js';
|
|
3
|
+
export { T as Translation } from './translation-BnpO2mN2.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use client";
|
|
3
|
+
import {
|
|
4
|
+
Description,
|
|
5
|
+
Input,
|
|
6
|
+
Root,
|
|
7
|
+
ScreenReaderStatus,
|
|
8
|
+
Status
|
|
9
|
+
} from "./chunk-QLQ6O7OW.js";
|
|
10
|
+
import {
|
|
11
|
+
countMessage,
|
|
12
|
+
countOf
|
|
13
|
+
} from "./chunk-UXJO4AJP.js";
|
|
14
|
+
import "./chunk-RDUPELOK.js";
|
|
15
|
+
import "./chunk-NX4B3NKM.js";
|
|
16
|
+
import "./chunk-ESBMTI25.js";
|
|
17
|
+
export {
|
|
18
|
+
Description,
|
|
19
|
+
Input,
|
|
20
|
+
Root,
|
|
21
|
+
ScreenReaderStatus,
|
|
22
|
+
Status,
|
|
23
|
+
countMessage,
|
|
24
|
+
countOf
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=character-count.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/choices.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use client";
|
|
3
|
+
import {
|
|
4
|
+
Conditional,
|
|
5
|
+
Input,
|
|
6
|
+
Root
|
|
7
|
+
} from "./chunk-TJVBFRIE.js";
|
|
8
|
+
import "./chunk-ET7DCQM7.js";
|
|
9
|
+
import "./chunk-NX4B3NKM.js";
|
|
10
|
+
import "./chunk-ESBMTI25.js";
|
|
11
|
+
export {
|
|
12
|
+
Conditional,
|
|
13
|
+
Input,
|
|
14
|
+
Root
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=choices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
tagName
|
|
4
|
+
} from "./chunk-PNWPGD7B.js";
|
|
5
|
+
import {
|
|
6
|
+
__export
|
|
7
|
+
} from "./chunk-ESBMTI25.js";
|
|
8
|
+
|
|
9
|
+
// src/focus-links/index.tsx
|
|
10
|
+
var focus_links_exports = {};
|
|
11
|
+
__export(focus_links_exports, {
|
|
12
|
+
Root: () => Root
|
|
13
|
+
});
|
|
14
|
+
import * as React from "react";
|
|
15
|
+
function Root({ focusedClass, ...props }) {
|
|
16
|
+
return React.createElement(tagName, { ...props, "focused-class": focusedClass });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
Root,
|
|
21
|
+
focus_links_exports
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=chunk-2IHAQAYF.js.map
|