@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
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
translate,
|
|
4
|
+
translationAttributeNames,
|
|
5
|
+
translationFromAttributes
|
|
6
|
+
} from "./chunk-RDUPELOK.js";
|
|
7
|
+
|
|
8
|
+
// src/file-upload/element.ts
|
|
9
|
+
var tagName = "govuk-react-file-upload";
|
|
10
|
+
var defaults = {
|
|
11
|
+
"no-file-chosen": "No file chosen",
|
|
12
|
+
"multiple-files-chosen": { one: "%{count} file chosen", other: "%{count} files chosen" },
|
|
13
|
+
"entered-drop-zone": "Entered drop zone",
|
|
14
|
+
"left-drop-zone": "Left drop zone"
|
|
15
|
+
};
|
|
16
|
+
function statusText(files, messages, locale) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
if (files.length === 0) return translate((_a = messages["no-file-chosen"]) != null ? _a : defaults["no-file-chosen"], 0, locale);
|
|
19
|
+
if (files.length === 1) return files[0].name;
|
|
20
|
+
return translate((_b = messages["multiple-files-chosen"]) != null ? _b : defaults["multiple-files-chosen"], files.length, locale);
|
|
21
|
+
}
|
|
22
|
+
var classesOf = (attribute) => {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = attribute == null ? void 0 : attribute.split(/\s+/).filter(Boolean)) != null ? _a : [];
|
|
25
|
+
};
|
|
26
|
+
var setText = (element, text) => {
|
|
27
|
+
if (element.textContent === text) return;
|
|
28
|
+
const { firstChild } = element;
|
|
29
|
+
if (firstChild instanceof Text && element.childNodes.length === 1) firstChild.nodeValue = text;
|
|
30
|
+
else element.textContent = text;
|
|
31
|
+
};
|
|
32
|
+
var setAttribute = (element, name, value) => {
|
|
33
|
+
if (value === null) element.removeAttribute(name);
|
|
34
|
+
else if (element.getAttribute(name) !== value) element.setAttribute(name, value);
|
|
35
|
+
};
|
|
36
|
+
var countFiles = (items) => Array.from(items).filter((item) => item.kind === "file").length;
|
|
37
|
+
if (typeof HTMLElement !== "undefined" && typeof customElements !== "undefined") {
|
|
38
|
+
class GovukReactFileUpload extends HTMLElement {
|
|
39
|
+
constructor() {
|
|
40
|
+
super(...arguments);
|
|
41
|
+
/** The input's id before upgrade, which the button takes. */
|
|
42
|
+
this.fieldId = "";
|
|
43
|
+
this.dragging = false;
|
|
44
|
+
this.enteredAnotherElement = false;
|
|
45
|
+
this.onChange = () => this.update();
|
|
46
|
+
this.onReset = () => window.setTimeout(() => this.update());
|
|
47
|
+
this.onClick = () => {
|
|
48
|
+
var _a;
|
|
49
|
+
return (_a = this.input) == null ? void 0 : _a.click();
|
|
50
|
+
};
|
|
51
|
+
this.onDragOver = (event) => event.preventDefault();
|
|
52
|
+
this.onDrop = (event) => {
|
|
53
|
+
var _a;
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
const { input } = this;
|
|
56
|
+
const files = (_a = event.dataTransfer) == null ? void 0 : _a.files;
|
|
57
|
+
if (!input || !files || !this.matchesCapacity(files.length)) return;
|
|
58
|
+
input.files = files;
|
|
59
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
60
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
61
|
+
this.setDragging(false);
|
|
62
|
+
};
|
|
63
|
+
this.onDocumentDragEnter = (event) => {
|
|
64
|
+
this.enteredAnotherElement = true;
|
|
65
|
+
if (!this.button || this.button.disabled || !(event.target instanceof Node)) return;
|
|
66
|
+
if (this.dropZone.contains(event.target)) {
|
|
67
|
+
if (event.dataTransfer && this.canDrop(event.dataTransfer) && !this.dragging) {
|
|
68
|
+
this.setDragging(true);
|
|
69
|
+
this.announce("entered-drop-zone");
|
|
70
|
+
}
|
|
71
|
+
} else if (this.dragging) {
|
|
72
|
+
this.setDragging(false);
|
|
73
|
+
this.announce("left-drop-zone");
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// Leaving the window, or dragging back out of it, fires `dragleave` with no `dragenter`.
|
|
77
|
+
this.onDocumentDragLeave = () => {
|
|
78
|
+
var _a;
|
|
79
|
+
if (!this.enteredAnotherElement && this.dragging && !((_a = this.button) == null ? void 0 : _a.disabled)) {
|
|
80
|
+
this.setDragging(false);
|
|
81
|
+
this.announce("left-drop-zone");
|
|
82
|
+
}
|
|
83
|
+
this.enteredAnotherElement = false;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
static get observedAttributes() {
|
|
87
|
+
return [
|
|
88
|
+
"empty-class",
|
|
89
|
+
"dragging-class",
|
|
90
|
+
"disabled-class",
|
|
91
|
+
...Object.keys(defaults).flatMap(translationAttributeNames)
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
connectedCallback() {
|
|
95
|
+
this.observer = new MutationObserver(() => this.setup());
|
|
96
|
+
this.observer.observe(this, {
|
|
97
|
+
childList: true,
|
|
98
|
+
subtree: true,
|
|
99
|
+
attributes: true,
|
|
100
|
+
attributeFilter: ["class", "disabled", "id", "aria-describedby"]
|
|
101
|
+
});
|
|
102
|
+
document.addEventListener("dragenter", this.onDocumentDragEnter);
|
|
103
|
+
document.addEventListener("dragleave", this.onDocumentDragLeave);
|
|
104
|
+
this.setup();
|
|
105
|
+
}
|
|
106
|
+
disconnectedCallback() {
|
|
107
|
+
var _a;
|
|
108
|
+
(_a = this.observer) == null ? void 0 : _a.disconnect();
|
|
109
|
+
document.removeEventListener("dragenter", this.onDocumentDragEnter);
|
|
110
|
+
document.removeEventListener("dragleave", this.onDocumentDragLeave);
|
|
111
|
+
this.unbind();
|
|
112
|
+
}
|
|
113
|
+
attributeChangedCallback() {
|
|
114
|
+
if (this.isConnected) this.update();
|
|
115
|
+
}
|
|
116
|
+
own(selector) {
|
|
117
|
+
return Array.from(this.querySelectorAll(selector)).find((element) => element.closest(tagName) === this);
|
|
118
|
+
}
|
|
119
|
+
get dropZone() {
|
|
120
|
+
var _a;
|
|
121
|
+
return (_a = this.own("[data-file-upload-drop-zone]")) != null ? _a : this;
|
|
122
|
+
}
|
|
123
|
+
get locale() {
|
|
124
|
+
var _a;
|
|
125
|
+
return ((_a = this.closest("[lang]")) == null ? void 0 : _a.getAttribute("lang")) || "en";
|
|
126
|
+
}
|
|
127
|
+
message(name) {
|
|
128
|
+
var _a;
|
|
129
|
+
return (_a = translationFromAttributes(this, name)) != null ? _a : defaults[name];
|
|
130
|
+
}
|
|
131
|
+
setup() {
|
|
132
|
+
var _a;
|
|
133
|
+
const input = this.own('input[type="file"]');
|
|
134
|
+
const button = this.own("button[data-file-upload-button]");
|
|
135
|
+
if (!input || !button) return;
|
|
136
|
+
if (input.id !== `${this.fieldId}-input`) this.fieldId = input.id;
|
|
137
|
+
if (!this.fieldId) return;
|
|
138
|
+
if (input !== this.input || button !== this.button) {
|
|
139
|
+
this.unbind();
|
|
140
|
+
this.input = input;
|
|
141
|
+
this.button = button;
|
|
142
|
+
this.form = input.form;
|
|
143
|
+
input.addEventListener("change", this.onChange);
|
|
144
|
+
(_a = this.form) == null ? void 0 : _a.addEventListener("reset", this.onReset);
|
|
145
|
+
button.addEventListener("click", this.onClick);
|
|
146
|
+
button.addEventListener("dragover", this.onDragOver);
|
|
147
|
+
button.addEventListener("drop", this.onDrop);
|
|
148
|
+
}
|
|
149
|
+
this.upgrade(input, button);
|
|
150
|
+
this.update();
|
|
151
|
+
}
|
|
152
|
+
unbind() {
|
|
153
|
+
var _a, _b, _c, _d, _e;
|
|
154
|
+
(_a = this.input) == null ? void 0 : _a.removeEventListener("change", this.onChange);
|
|
155
|
+
(_b = this.form) == null ? void 0 : _b.removeEventListener("reset", this.onReset);
|
|
156
|
+
(_c = this.button) == null ? void 0 : _c.removeEventListener("click", this.onClick);
|
|
157
|
+
(_d = this.button) == null ? void 0 : _d.removeEventListener("dragover", this.onDragOver);
|
|
158
|
+
(_e = this.button) == null ? void 0 : _e.removeEventListener("drop", this.onDrop);
|
|
159
|
+
this.input = void 0;
|
|
160
|
+
this.button = void 0;
|
|
161
|
+
this.form = void 0;
|
|
162
|
+
}
|
|
163
|
+
/** Moves the id to the button, names it, and swaps it for the input, as govuk-frontend does. */
|
|
164
|
+
upgrade(input, button) {
|
|
165
|
+
const id = this.fieldId;
|
|
166
|
+
const root = this.getRootNode();
|
|
167
|
+
const label = root instanceof Document || root instanceof ShadowRoot ? root.querySelector(`label[for="${CSS.escape(id)}"]`) : null;
|
|
168
|
+
if (label && !label.id) label.id = `${id}-label`;
|
|
169
|
+
setAttribute(input, "id", `${id}-input`);
|
|
170
|
+
setAttribute(button, "id", id);
|
|
171
|
+
const separator = button.querySelector("[data-file-upload-separator]");
|
|
172
|
+
if (separator) setAttribute(separator, "id", `${id}-comma`);
|
|
173
|
+
if (label) {
|
|
174
|
+
setAttribute(button, "aria-labelledby", [label.id, separator == null ? void 0 : separator.id, id].filter(Boolean).join(" "));
|
|
175
|
+
}
|
|
176
|
+
setAttribute(button, "aria-describedby", input.getAttribute("aria-describedby"));
|
|
177
|
+
setAttribute(input, "hidden", "hidden");
|
|
178
|
+
if (button.hidden) button.hidden = false;
|
|
179
|
+
this.dataset.upgraded = "";
|
|
180
|
+
}
|
|
181
|
+
update() {
|
|
182
|
+
const { input, button } = this;
|
|
183
|
+
if (!input || !button) return;
|
|
184
|
+
const { files } = input;
|
|
185
|
+
const empty = !(files == null ? void 0 : files.length);
|
|
186
|
+
const status = button.querySelector("[data-file-upload-status]");
|
|
187
|
+
if (status) {
|
|
188
|
+
setText(
|
|
189
|
+
status,
|
|
190
|
+
statusText(
|
|
191
|
+
files != null ? files : [],
|
|
192
|
+
{
|
|
193
|
+
"no-file-chosen": this.message("no-file-chosen"),
|
|
194
|
+
"multiple-files-chosen": this.message("multiple-files-chosen")
|
|
195
|
+
},
|
|
196
|
+
this.locale
|
|
197
|
+
)
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
setAttribute(button, "data-empty", empty ? "" : null);
|
|
201
|
+
classesOf(this.getAttribute("empty-class")).forEach((name) => button.classList.toggle(name, empty));
|
|
202
|
+
if (button.disabled !== input.disabled) button.disabled = input.disabled;
|
|
203
|
+
const zone = this.dropZone;
|
|
204
|
+
setAttribute(zone, "data-disabled", input.disabled ? "" : null);
|
|
205
|
+
classesOf(this.getAttribute("disabled-class")).forEach((name) => zone.classList.toggle(name, input.disabled));
|
|
206
|
+
if (input.disabled) this.setDragging(false);
|
|
207
|
+
else this.renderDragging();
|
|
208
|
+
}
|
|
209
|
+
setDragging(dragging) {
|
|
210
|
+
this.dragging = dragging;
|
|
211
|
+
this.renderDragging();
|
|
212
|
+
}
|
|
213
|
+
renderDragging() {
|
|
214
|
+
const { button, dragging } = this;
|
|
215
|
+
if (!button) return;
|
|
216
|
+
setAttribute(button, "data-dragging", dragging ? "" : null);
|
|
217
|
+
classesOf(this.getAttribute("dragging-class")).forEach((name) => button.classList.toggle(name, dragging));
|
|
218
|
+
}
|
|
219
|
+
announce(name) {
|
|
220
|
+
const announcements = this.own("[data-file-upload-announcements]");
|
|
221
|
+
if (announcements) announcements.textContent = translate(this.message(name), 0, this.locale);
|
|
222
|
+
}
|
|
223
|
+
canDrop(dataTransfer) {
|
|
224
|
+
if (dataTransfer.items.length) return this.matchesCapacity(countFiles(dataTransfer.items));
|
|
225
|
+
if (dataTransfer.types.length) return dataTransfer.types.includes("Files");
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
matchesCapacity(count) {
|
|
229
|
+
var _a;
|
|
230
|
+
return ((_a = this.input) == null ? void 0 : _a.multiple) ? count > 0 : count === 1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (!customElements.get(tagName)) customElements.define(tagName, GovukReactFileUpload);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export {
|
|
237
|
+
tagName,
|
|
238
|
+
defaults,
|
|
239
|
+
statusText
|
|
240
|
+
};
|
|
241
|
+
//# sourceMappingURL=chunk-YCESNTXQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/file-upload/element.ts"],"sourcesContent":["/*\n * <govuk-react-file-upload>: a headless, light-DOM custom element that turns a file input into a\n * button and drop zone, with or without React, as govuk-frontend's improved file upload does.\n *\n * The input's files are the state. Without JavaScript the native file input shows and the button\n * stays hidden. On upgrade the element hides the input and shows the button, which opens the file\n * picker, says which files are chosen, and takes files dropped on it. The rendered markup is never\n * moved, so React can keep rendering it.\n *\n * As in govuk-frontend, the button takes the input's `id`, so its label names the button, and the\n * input's id gets `-input` added. The button also takes the input's `aria-describedby` and\n * `disabled`, and its accessible name is the label, the separator and its own text.\n *\n * Markup inside the element:\n * - `input[type=\"file\"]`: the field, with an `id` and a `label`. Hidden on upgrade.\n * - `button[data-file-upload-button]`: rendered `hidden`, with `type=\"button\"`.\n * - `[data-file-upload-status]`: which files are chosen.\n * - `[data-file-upload-separator]` (optional): between the label and the button's text in its\n * accessible name, such as a visually hidden comma.\n * - `[data-file-upload-drop-zone]` (optional): the area that shows dragging. The element itself\n * without one.\n * - `[data-file-upload-announcements]` (optional): a visually hidden live region for entering and\n * leaving the drop zone.\n *\n * The button gets `data-empty` while no file is chosen and `data-dragging` while files are dragged\n * over the drop zone, and the drop zone gets `data-disabled`.\n *\n * Attributes:\n * - `no-file-chosen`, `multiple-files-chosen`, `entered-drop-zone`, `left-drop-zone`: the text,\n * English by default, with `%{count}` for the number of files. Add a plural form to the name,\n * such as `multiple-files-chosen-one`, for a message for each form.\n * - `empty-class`, `dragging-class`: classes for the button while empty and while dragging.\n * - `disabled-class`: classes for the drop zone while the input is disabled.\n */\n\nimport {\n translate,\n translationAttributeNames,\n translationFromAttributes,\n type Translation,\n} from '../utils/translation';\n\nexport const tagName = 'govuk-react-file-upload';\n\nexport interface FileUploadElement extends HTMLElement {\n /** Updates the button from the input's files, such as after setting them. */\n update(): void;\n}\n\n/** govuk-frontend's English text. */\nexport const defaults = {\n 'no-file-chosen': 'No file chosen',\n 'multiple-files-chosen': { one: '%{count} file chosen', other: '%{count} files chosen' },\n 'entered-drop-zone': 'Entered drop zone',\n 'left-drop-zone': 'Left drop zone',\n} satisfies Record<string, Translation>;\n\n/** What the status says for the files chosen. */\nexport function statusText(\n files: ArrayLike<{ name: string }>,\n messages: { 'no-file-chosen'?: Translation; 'multiple-files-chosen'?: Translation },\n locale?: string\n) {\n if (files.length === 0) return translate(messages['no-file-chosen'] ?? defaults['no-file-chosen'], 0, locale);\n if (files.length === 1) return files[0].name;\n return translate(messages['multiple-files-chosen'] ?? defaults['multiple-files-chosen'], files.length, locale);\n}\n\nconst classesOf = (attribute: string | null) => attribute?.split(/\\s+/).filter(Boolean) ?? [];\n\n// Keeps the text node React rendered, so React can still update it.\nconst setText = (element: Element, text: string) => {\n if (element.textContent === text) return;\n const { firstChild } = element;\n if (firstChild instanceof Text && element.childNodes.length === 1) firstChild.nodeValue = text;\n else element.textContent = text;\n};\n\nconst setAttribute = (element: Element, name: string, value: string | null) => {\n if (value === null) element.removeAttribute(name);\n else if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n};\n\nconst countFiles = (items: DataTransferItemList) => Array.from(items).filter((item) => item.kind === 'file').length;\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactFileUpload extends HTMLElement implements FileUploadElement {\n static get observedAttributes() {\n return [\n 'empty-class',\n 'dragging-class',\n 'disabled-class',\n ...Object.keys(defaults).flatMap(translationAttributeNames),\n ];\n }\n\n private input?: HTMLInputElement;\n\n private button?: HTMLButtonElement;\n\n private form?: HTMLFormElement | null;\n\n /** The input's id before upgrade, which the button takes. */\n private fieldId = '';\n\n private dragging = false;\n\n private enteredAnotherElement = false;\n\n private observer?: MutationObserver;\n\n private readonly onChange = () => this.update();\n\n private readonly onReset = () => window.setTimeout(() => this.update());\n\n private readonly onClick = () => this.input?.click();\n\n private readonly onDragOver = (event: DragEvent) => event.preventDefault();\n\n private readonly onDrop = (event: DragEvent) => {\n event.preventDefault();\n const { input } = this;\n const files = event.dataTransfer?.files;\n if (!input || !files || !this.matchesCapacity(files.length)) return;\n input.files = files;\n // Bubbles, unlike govuk-frontend's, so React's `onChange` hears dropped files too.\n input.dispatchEvent(new Event('input', { bubbles: true }));\n input.dispatchEvent(new Event('change', { bubbles: true }));\n this.setDragging(false);\n };\n\n private readonly onDocumentDragEnter = (event: DragEvent) => {\n this.enteredAnotherElement = true;\n if (!this.button || this.button.disabled || !(event.target instanceof Node)) return;\n if (this.dropZone.contains(event.target)) {\n if (event.dataTransfer && this.canDrop(event.dataTransfer) && !this.dragging) {\n this.setDragging(true);\n this.announce('entered-drop-zone');\n }\n } else if (this.dragging) {\n this.setDragging(false);\n this.announce('left-drop-zone');\n }\n };\n\n // Leaving the window, or dragging back out of it, fires `dragleave` with no `dragenter`.\n private readonly onDocumentDragLeave = () => {\n if (!this.enteredAnotherElement && this.dragging && !this.button?.disabled) {\n this.setDragging(false);\n this.announce('left-drop-zone');\n }\n this.enteredAnotherElement = false;\n };\n\n connectedCallback() {\n // The parts may be parsed or rendered later, and React can rewrite the input's attributes.\n this.observer = new MutationObserver(() => this.setup());\n this.observer.observe(this, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['class', 'disabled', 'id', 'aria-describedby'],\n });\n document.addEventListener('dragenter', this.onDocumentDragEnter);\n document.addEventListener('dragleave', this.onDocumentDragLeave);\n this.setup();\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n document.removeEventListener('dragenter', this.onDocumentDragEnter);\n document.removeEventListener('dragleave', this.onDocumentDragLeave);\n this.unbind();\n }\n\n attributeChangedCallback() {\n // Wait for every attribute: React sets them one by one before connecting the element.\n if (this.isConnected) this.update();\n }\n\n private own<E extends Element>(selector: string) {\n return Array.from(this.querySelectorAll<E>(selector)).find((element) => element.closest(tagName) === this);\n }\n\n private get dropZone(): HTMLElement {\n return this.own<HTMLElement>('[data-file-upload-drop-zone]') ?? this;\n }\n\n private get locale() {\n return this.closest('[lang]')?.getAttribute('lang') || 'en';\n }\n\n private message(name: keyof typeof defaults) {\n return translationFromAttributes(this, name) ?? defaults[name];\n }\n\n private setup() {\n const input = this.own<HTMLInputElement>('input[type=\"file\"]');\n const button = this.own<HTMLButtonElement>('button[data-file-upload-button]');\n if (!input || !button) return;\n // A new input, or a new id from React, rather than the one the element gave it.\n if (input.id !== `${this.fieldId}-input`) this.fieldId = input.id;\n if (!this.fieldId) return;\n if (input !== this.input || button !== this.button) {\n this.unbind();\n this.input = input;\n this.button = button;\n this.form = input.form;\n input.addEventListener('change', this.onChange);\n this.form?.addEventListener('reset', this.onReset);\n button.addEventListener('click', this.onClick);\n button.addEventListener('dragover', this.onDragOver);\n button.addEventListener('drop', this.onDrop);\n }\n this.upgrade(input, button);\n this.update();\n }\n\n private unbind() {\n this.input?.removeEventListener('change', this.onChange);\n this.form?.removeEventListener('reset', this.onReset);\n this.button?.removeEventListener('click', this.onClick);\n this.button?.removeEventListener('dragover', this.onDragOver);\n this.button?.removeEventListener('drop', this.onDrop);\n this.input = undefined;\n this.button = undefined;\n this.form = undefined;\n }\n\n /** Moves the id to the button, names it, and swaps it for the input, as govuk-frontend does. */\n private upgrade(input: HTMLInputElement, button: HTMLButtonElement) {\n const id = this.fieldId;\n const root = this.getRootNode();\n const label =\n root instanceof Document || root instanceof ShadowRoot\n ? root.querySelector(`label[for=\"${CSS.escape(id)}\"]`)\n : null;\n if (label && !label.id) label.id = `${id}-label`;\n setAttribute(input, 'id', `${id}-input`);\n setAttribute(button, 'id', id);\n const separator = button.querySelector('[data-file-upload-separator]');\n if (separator) setAttribute(separator, 'id', `${id}-comma`);\n if (label) {\n setAttribute(button, 'aria-labelledby', [label.id, separator?.id, id].filter(Boolean).join(' '));\n }\n setAttribute(button, 'aria-describedby', input.getAttribute('aria-describedby'));\n setAttribute(input, 'hidden', 'hidden');\n if (button.hidden) button.hidden = false;\n this.dataset.upgraded = '';\n }\n\n update() {\n const { input, button } = this;\n if (!input || !button) return;\n const { files } = input;\n const empty = !files?.length;\n const status = button.querySelector('[data-file-upload-status]');\n if (status) {\n setText(\n status,\n statusText(\n files ?? [],\n {\n 'no-file-chosen': this.message('no-file-chosen'),\n 'multiple-files-chosen': this.message('multiple-files-chosen'),\n },\n this.locale\n )\n );\n }\n // `toggle` with force leaves a class that's already there alone, so the observer isn't woken.\n setAttribute(button, 'data-empty', empty ? '' : null);\n classesOf(this.getAttribute('empty-class')).forEach((name) => button.classList.toggle(name, empty));\n if (button.disabled !== input.disabled) button.disabled = input.disabled;\n const zone = this.dropZone;\n setAttribute(zone, 'data-disabled', input.disabled ? '' : null);\n classesOf(this.getAttribute('disabled-class')).forEach((name) => zone.classList.toggle(name, input.disabled));\n if (input.disabled) this.setDragging(false);\n else this.renderDragging();\n }\n\n private setDragging(dragging: boolean) {\n this.dragging = dragging;\n this.renderDragging();\n }\n\n private renderDragging() {\n const { button, dragging } = this;\n if (!button) return;\n setAttribute(button, 'data-dragging', dragging ? '' : null);\n classesOf(this.getAttribute('dragging-class')).forEach((name) => button.classList.toggle(name, dragging));\n }\n\n private announce(name: 'entered-drop-zone' | 'left-drop-zone') {\n const announcements = this.own('[data-file-upload-announcements]');\n // Replaces the text node every time, so screen readers hear the same message again.\n if (announcements) announcements.textContent = translate(this.message(name), 0, this.locale);\n }\n\n private canDrop(dataTransfer: DataTransfer) {\n if (dataTransfer.items.length) return this.matchesCapacity(countFiles(dataTransfer.items));\n if (dataTransfer.types.length) return dataTransfer.types.includes('Files');\n return true;\n }\n\n private matchesCapacity(count: number) {\n return this.input?.multiple ? count > 0 : count === 1;\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactFileUpload);\n}\n"],"mappings":";;;;;;;;AA0CO,IAAM,UAAU;AAQhB,IAAM,WAAW;AAAA,EACtB,kBAAkB;AAAA,EAClB,yBAAyB,EAAE,KAAK,wBAAwB,OAAO,wBAAwB;AAAA,EACvF,qBAAqB;AAAA,EACrB,kBAAkB;AACpB;AAGO,SAAS,WACd,OACA,UACA,QACA;AA9DF;AA+DE,MAAI,MAAM,WAAW,EAAG,QAAO,WAAU,cAAS,gBAAgB,MAAzB,YAA8B,SAAS,gBAAgB,GAAG,GAAG,MAAM;AAC5G,MAAI,MAAM,WAAW,EAA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AAC,EAAE,QAAQ,CAAC,SAAS,OAAO,UAAU,OAAO,MAAM,QAAQ,CAAC;AAAA,IAC1G;AAAA,IAEQ,SAAS,MAA8C;AAC7D,YAAM,gBAAgB,KAAK,IAAI,kCAAkC;AAEjE,UAAI,cAAe,eAAc,cAAc,UAAU,KAAK,QAAQ,IAAI,GAAG,GAAG,KAAK,MAAM;AAAA,IAC7F;AAAA,IAEQ,QAAQ,cAA4B;AAC1C,UAAI,aAAa,MAAM,OAAQ,QAAO,KAAK,gBAAgB,WAAW,aAAa,KAAK,CAAC;AACzF,UAAI,aAAa,MAAM,OAAQ,QAAO,aAAa,MAAM,SAAS,OAAO;AACzE,aAAO;AAAA,IACT;AAAA,IAEQ,gBAAgB,OAAe;AAjT3C;AAkTM,eAAO,UAAK,UAAL,mBAAY,YAAW,QAAQ,IAAI,UAAU;AAAA,IACtD;AAAA,EACF;AAEA,MAAI,CAAC,eAAe,IAAI,OAAO,EAAG,gBAAe,OAAO,SAAS,oBAAoB;AACvF;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
tagName
|
|
4
|
+
} from "./chunk-TE4RUYVK.js";
|
|
5
|
+
import {
|
|
6
|
+
Slot
|
|
7
|
+
} from "./chunk-NX4B3NKM.js";
|
|
8
|
+
import {
|
|
9
|
+
__export
|
|
10
|
+
} from "./chunk-ESBMTI25.js";
|
|
11
|
+
|
|
12
|
+
// src/password-input/index.tsx
|
|
13
|
+
var password_input_exports = {};
|
|
14
|
+
__export(password_input_exports, {
|
|
15
|
+
Input: () => Input,
|
|
16
|
+
Root: () => Root,
|
|
17
|
+
Status: () => Status,
|
|
18
|
+
Toggle: () => Toggle
|
|
19
|
+
});
|
|
20
|
+
import * as React from "react";
|
|
21
|
+
function Root({
|
|
22
|
+
showText,
|
|
23
|
+
hideText,
|
|
24
|
+
showLabel,
|
|
25
|
+
hideLabel,
|
|
26
|
+
shownAnnouncement,
|
|
27
|
+
hiddenAnnouncement,
|
|
28
|
+
...props
|
|
29
|
+
}) {
|
|
30
|
+
return React.createElement(tagName, {
|
|
31
|
+
...props,
|
|
32
|
+
"show-text": showText,
|
|
33
|
+
"hide-text": hideText,
|
|
34
|
+
"show-label": showLabel,
|
|
35
|
+
"hide-label": hideLabel,
|
|
36
|
+
"shown-announcement": shownAnnouncement,
|
|
37
|
+
"hidden-announcement": hiddenAnnouncement
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function Input({ asChild, ...props }) {
|
|
41
|
+
if (asChild) return /* @__PURE__ */ React.createElement(Slot, { "data-password-input": "", suppressHydrationWarning: true, ...props });
|
|
42
|
+
return /* @__PURE__ */ React.createElement("input", { type: "password", "data-password-input": "", suppressHydrationWarning: true, ...props });
|
|
43
|
+
}
|
|
44
|
+
function Toggle({ asChild, children = "Show", ...props }) {
|
|
45
|
+
const shared = { "data-password-toggle": "", hidden: true, suppressHydrationWarning: true };
|
|
46
|
+
if (asChild)
|
|
47
|
+
return /* @__PURE__ */ React.createElement(Slot, { ...shared, ...props }, children);
|
|
48
|
+
return /* @__PURE__ */ React.createElement("button", { type: "button", "aria-label": "Show password", ...shared, ...props }, children);
|
|
49
|
+
}
|
|
50
|
+
function Status({ asChild, ...props }) {
|
|
51
|
+
const Element = asChild ? Slot : "div";
|
|
52
|
+
return /* @__PURE__ */ React.createElement(Element, { "data-password-status": "", "aria-live": "polite", suppressHydrationWarning: true, ...props });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
Root,
|
|
57
|
+
Input,
|
|
58
|
+
Toggle,
|
|
59
|
+
Status,
|
|
60
|
+
password_input_exports
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=chunk-ZTJLVNR4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/password-input/index.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { ComponentProps } from 'react';\nimport { Slot } from '../utils/slot';\nimport { tagName } from './element';\n\n/*\n * Headless password input: unstyled parts over the <govuk-react-password-input> element\n * (./element.ts), which adds the show and hide button on upgrade. Every part except Root takes\n * `asChild`.\n *\n * The input's `type` is the state, owned by the element, so there is no React state to control.\n */\n\nexport type RootProps = React.HTMLAttributes<HTMLElement> & {\n /** The button's text when the password is hidden. Defaults to \"Show\". */\n showText?: string;\n /** The button's text when the password is visible. Defaults to \"Hide\". */\n hideText?: string;\n /** The button's accessible name when the password is hidden. Defaults to \"Show password\". */\n showLabel?: string;\n /** The button's accessible name when the password is visible. Defaults to \"Hide password\". */\n hideLabel?: string;\n /** Announced when the password becomes visible. Defaults to \"Your password is visible\". */\n shownAnnouncement?: string;\n /** Announced when the password is hidden. Defaults to \"Your password is hidden\". */\n hiddenAnnouncement?: string;\n};\n\nexport function Root({\n showText,\n hideText,\n showLabel,\n hideLabel,\n shownAnnouncement,\n hiddenAnnouncement,\n ...props\n}: RootProps) {\n return React.createElement(tagName, {\n ...props,\n 'show-text': showText,\n 'hide-text': hideText,\n 'show-label': showLabel,\n 'hide-label': hideLabel,\n 'shown-announcement': shownAnnouncement,\n 'hidden-announcement': hiddenAnnouncement,\n });\n}\n\ntype PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {\n /** Render the only child instead, with this part's props merged onto it. */\n asChild?: boolean;\n};\n\nexport type InputProps = PartProps<'input'>;\n\n/** The password field. Its `type` starts as \"password\" and the element switches it. */\nexport function Input({ asChild, ...props }: InputProps) {\n if (asChild) return <Slot data-password-input=\"\" suppressHydrationWarning {...props} />;\n // The element sets `type` after upgrade, so it can differ from the server's.\n return <input type=\"password\" data-password-input=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type ToggleProps = PartProps<'button'>;\n\n/** The show and hide button. Hidden until the element upgrades, which then sets its text and label. */\nexport function Toggle({ asChild, children = 'Show', ...props }: ToggleProps) {\n const shared = { 'data-password-toggle': '', hidden: true, suppressHydrationWarning: true };\n if (asChild)\n return (\n <Slot {...shared} {...props}>\n {children}\n </Slot>\n );\n return (\n <button type=\"button\" aria-label=\"Show password\" {...shared} {...props}>\n {children}\n </button>\n );\n}\n\nexport type StatusProps = PartProps<'div'>;\n\n/** A live region for the announcements. Make it visually hidden. */\nexport function Status({ asChild, ...props }: StatusProps) {\n const Element = asChild ? Slot : 'div';\n return <Element data-password-status=\"\" aria-live=\"polite\" suppressHydrationWarning {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAY,WAAW;AA4BhB,SAAS,KAAK;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAc;AACZ,SAAa,oBAAc,SAAS;AAAA,IAClC,GAAG;AAAA,IACH,aAAa;AAAA,IACb,aAAa;AAAA,IACb,cAAc;AAAA,IACd,cAAc;AAAA,IACd,sBAAsB;AAAA,IACtB,uBAAuB;AAAA,EACzB,CAAC;AACH;AAUO,SAAS,MAAM,EAAE,SAAS,GAAG,MAAM,GAAe;AACvD,MAAI,QAAS,QAAO,oCAAC,QAAK,uBAAoB,IAAG,0BAAwB,MAAE,GAAG,OAAO;AAErF,SAAO,oCAAC,WAAM,MAAK,YAAW,uBAAoB,IAAG,0BAAwB,MAAE,GAAG,OAAO;AAC3F;AAKO,SAAS,OAAO,EAAE,SAAS,WAAW,QAAQ,GAAG,MAAM,GAAgB;AAC5E,QAAM,SAAS,EAAE,wBAAwB,IAAI,QAAQ,MAAM,0BAA0B,KAAK;AAC1F,MAAI;AACF,WACE,oCAAC,QAAM,GAAG,QAAS,GAAG,SACnB,QACH;AAEJ,SACE,oCAAC,YAAO,MAAK,UAAS,cAAW,iBAAiB,GAAG,QAAS,GAAG,SAC9D,QACH;AAEJ;AAKO,SAAS,OAAO,EAAE,SAAS,GAAG,MAAM,GAAgB;AACzD,QAAM,UAAU,UAAU,OAAO;AACjC,SAAO,oCAAC,WAAQ,wBAAqB,IAAG,aAAU,UAAS,0BAAwB,MAAE,GAAG,OAAO;AACjG;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface HTMLElementEventMap {
|
|
3
|
+
'govuk-react-disclosure:change': CustomEvent<{
|
|
4
|
+
open: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
declare const tagName = "govuk-react-disclosure";
|
|
9
|
+
interface DisclosureElement extends HTMLElement {
|
|
10
|
+
/** Whether the content is open, once upgraded, even while `media` shows it anyway. */
|
|
11
|
+
readonly expanded: boolean | undefined;
|
|
12
|
+
/** The user's last choice before `open` was first set, such as before React hydrated. */
|
|
13
|
+
readonly pickedOpen: boolean | undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { tagName };
|
|
17
|
+
export type { DisclosureElement };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use client";
|
|
3
|
+
import {
|
|
4
|
+
Content,
|
|
5
|
+
Root,
|
|
6
|
+
Toggle
|
|
7
|
+
} from "./chunk-GVGBDSDN.js";
|
|
8
|
+
import "./chunk-RPMHI67T.js";
|
|
9
|
+
import "./chunk-NX4B3NKM.js";
|
|
10
|
+
import "./chunk-ESBMTI25.js";
|
|
11
|
+
export {
|
|
12
|
+
Content,
|
|
13
|
+
Root,
|
|
14
|
+
Toggle
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=disclosure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const tagName = "govuk-react-exit-this-page";
|
|
2
|
+
declare const messageNames: readonly ["activated", "timed-out", "press-two-more-times", "press-one-more-time"];
|
|
3
|
+
type MessageName = (typeof messageNames)[number];
|
|
4
|
+
/** govuk-frontend's English messages. */
|
|
5
|
+
declare const defaultMessages: Record<MessageName, string>;
|
|
6
|
+
interface ExitThisPageElement extends HTMLElement {
|
|
7
|
+
/** Hides the page and goes to the button's `href`, unless the exit event is cancelled. */
|
|
8
|
+
exit(): void;
|
|
9
|
+
}
|
|
10
|
+
declare global {
|
|
11
|
+
interface HTMLElementTagNameMap {
|
|
12
|
+
'govuk-react-exit-this-page': ExitThisPageElement;
|
|
13
|
+
}
|
|
14
|
+
interface HTMLElementEventMap {
|
|
15
|
+
'govuk-react-exit-this-page:exit': CustomEvent<{
|
|
16
|
+
href: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { defaultMessages, messageNames, tagName };
|
|
22
|
+
export type { ExitThisPageElement, MessageName };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import 'react';
|
|
2
|
+
export { ExitThisPageElement, MessageName, defaultMessages } from './exit-this-page-element.js';
|
|
3
|
+
export { B as Button, a as ButtonProps, I as Indicator, b as IndicatorProps, L as Light, c as LightProps, R as Root, d as RootProps, S as SkipLink, e as SkipLinkProps, f as Status, g as StatusProps } from './index-qF0jIQCW.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use client";
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Indicator,
|
|
6
|
+
Light,
|
|
7
|
+
Root,
|
|
8
|
+
SkipLink,
|
|
9
|
+
Status
|
|
10
|
+
} from "./chunk-4XAR4FFG.js";
|
|
11
|
+
import {
|
|
12
|
+
defaultMessages
|
|
13
|
+
} from "./chunk-ECYGKE4D.js";
|
|
14
|
+
import "./chunk-NX4B3NKM.js";
|
|
15
|
+
import "./chunk-ESBMTI25.js";
|
|
16
|
+
export {
|
|
17
|
+
Button,
|
|
18
|
+
Indicator,
|
|
19
|
+
Light,
|
|
20
|
+
Root,
|
|
21
|
+
SkipLink,
|
|
22
|
+
Status,
|
|
23
|
+
defaultMessages
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=exit-this-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Translation } from './autocomplete.js';
|
|
2
|
+
|
|
3
|
+
declare const tagName = "govuk-react-file-upload";
|
|
4
|
+
interface FileUploadElement extends HTMLElement {
|
|
5
|
+
/** Updates the button from the input's files, such as after setting them. */
|
|
6
|
+
update(): void;
|
|
7
|
+
}
|
|
8
|
+
/** govuk-frontend's English text. */
|
|
9
|
+
declare const defaults: {
|
|
10
|
+
'no-file-chosen': string;
|
|
11
|
+
'multiple-files-chosen': {
|
|
12
|
+
one: string;
|
|
13
|
+
other: string;
|
|
14
|
+
};
|
|
15
|
+
'entered-drop-zone': string;
|
|
16
|
+
'left-drop-zone': string;
|
|
17
|
+
};
|
|
18
|
+
/** What the status says for the files chosen. */
|
|
19
|
+
declare function statusText(files: ArrayLike<{
|
|
20
|
+
name: string;
|
|
21
|
+
}>, messages: {
|
|
22
|
+
'no-file-chosen'?: Translation;
|
|
23
|
+
'multiple-files-chosen'?: Translation;
|
|
24
|
+
}, locale?: string): string;
|
|
25
|
+
|
|
26
|
+
export { defaults, statusText, tagName };
|
|
27
|
+
export type { FileUploadElement };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
defaults,
|
|
4
|
+
statusText,
|
|
5
|
+
tagName
|
|
6
|
+
} from "./chunk-YCESNTXQ.js";
|
|
7
|
+
import "./chunk-RDUPELOK.js";
|
|
8
|
+
import "./chunk-ESBMTI25.js";
|
|
9
|
+
export {
|
|
10
|
+
defaults,
|
|
11
|
+
statusText,
|
|
12
|
+
tagName
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=file-upload-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import 'react';
|
|
2
|
+
export { T as Translation } from './translation-BnpO2mN2.js';
|
|
3
|
+
export { A as Announcements, a as AnnouncementsProps, B as Button, b as ButtonProps, D as DropZone, c as DropZoneProps, I as Input, d as InputProps, R as Root, e as RootProps, S as Separator, f as SeparatorProps, g as Status, h as StatusProps } from './index-DPXR1Yua.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use client";
|
|
3
|
+
import {
|
|
4
|
+
Announcements,
|
|
5
|
+
Button,
|
|
6
|
+
DropZone,
|
|
7
|
+
Input,
|
|
8
|
+
Root,
|
|
9
|
+
Separator,
|
|
10
|
+
Status
|
|
11
|
+
} from "./chunk-5HWRMQK2.js";
|
|
12
|
+
import "./chunk-YCESNTXQ.js";
|
|
13
|
+
import "./chunk-RDUPELOK.js";
|
|
14
|
+
import "./chunk-NX4B3NKM.js";
|
|
15
|
+
import "./chunk-ESBMTI25.js";
|
|
16
|
+
export {
|
|
17
|
+
Announcements,
|
|
18
|
+
Button,
|
|
19
|
+
DropZone,
|
|
20
|
+
Input,
|
|
21
|
+
Root,
|
|
22
|
+
Separator,
|
|
23
|
+
Status
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=file-upload.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 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|