@govuk-react/primitives 0.2.0 → 0.2.1
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/{accordion-element.d.ts → accordion/element.d.ts} +2 -5
- package/dist/accordion/element.js +302 -0
- package/dist/accordion/element.js.map +1 -0
- package/dist/accordion/index.d.ts +74 -0
- package/dist/accordion/index.js +138 -0
- package/dist/accordion/index.js.map +1 -0
- package/dist/auto-focus/element.d.ts +1 -0
- package/dist/auto-focus/element.js +75 -0
- package/dist/auto-focus/element.js.map +1 -0
- package/dist/{index-Bul0NJh_.d.ts → auto-focus/index.d.ts} +27 -40
- package/dist/auto-focus/index.js +29 -0
- package/dist/{chunk-6ZFU4VYW.js.map → auto-focus/index.js.map} +1 -1
- package/dist/{autocomplete-element.d.ts → autocomplete/element.d.ts} +4 -7
- package/dist/autocomplete/element.js +597 -0
- package/dist/autocomplete/element.js.map +1 -0
- package/dist/{index-D7lMYMUR.d.ts → autocomplete/index.d.ts} +34 -57
- package/dist/autocomplete/index.js +108 -0
- package/dist/autocomplete/index.js.map +1 -0
- package/dist/button/element.d.ts +1 -0
- package/dist/button/element.js +59 -0
- package/dist/button/element.js.map +1 -0
- package/dist/button/index.d.ts +10 -0
- package/dist/button/index.js +9 -0
- package/dist/button/index.js.map +1 -0
- package/dist/{character-count-element.d.ts → character-count/element.d.ts} +2 -5
- package/dist/character-count/element.js +287 -0
- package/dist/character-count/element.js.map +1 -0
- package/dist/character-count/index.d.ts +57 -0
- package/dist/character-count/index.js +79 -0
- package/dist/character-count/index.js.map +1 -0
- package/dist/character-count/messages.d.ts +20 -0
- package/dist/character-count/messages.js +54 -0
- package/dist/character-count/messages.js.map +1 -0
- package/dist/choices/element.d.ts +5 -0
- package/dist/choices/element.js +202 -0
- package/dist/choices/element.js.map +1 -0
- package/dist/{index-WuGvkTxu.d.ts → choices/index.d.ts} +30 -44
- package/dist/choices/index.js +37 -0
- package/dist/choices/index.js.map +1 -0
- package/dist/{disclosure-element.d.ts → disclosure/element.d.ts} +2 -5
- package/dist/disclosure/element.js +123 -0
- package/dist/disclosure/element.js.map +1 -0
- package/dist/{index-D4Gzyvfu.d.ts → disclosure/index.d.ts} +40 -54
- package/dist/disclosure/index.js +66 -0
- package/dist/disclosure/index.js.map +1 -0
- package/dist/exit-this-page/element.d.ts +19 -0
- package/dist/exit-this-page/element.js +201 -0
- package/dist/exit-this-page/element.js.map +1 -0
- package/dist/{index-qF0jIQCW.d.ts → exit-this-page/index.d.ts} +36 -60
- package/dist/exit-this-page/index.js +54 -0
- package/dist/exit-this-page/index.js.map +1 -0
- package/dist/{file-upload-element.d.ts → file-upload/element.d.ts} +5 -9
- package/dist/file-upload/element.js +270 -0
- package/dist/file-upload/element.js.map +1 -0
- package/dist/file-upload/index.d.ts +46 -0
- package/dist/file-upload/index.js +65 -0
- package/dist/file-upload/index.js.map +1 -0
- package/dist/focus-links/element.d.ts +1 -0
- package/dist/focus-links/element.js +90 -0
- package/dist/focus-links/element.js.map +1 -0
- package/dist/{index-BR3MAGF8.d.ts → focus-links/index.d.ts} +24 -35
- package/dist/focus-links/index.js +7 -0
- package/dist/focus-links/index.js.map +1 -0
- package/dist/index.d.ts +13 -17
- package/dist/index.js +13 -72
- package/dist/index.js.map +1 -1
- package/dist/inline/accordion-element.js +1 -1
- package/dist/inline/auto-focus-element.js +1 -1
- package/dist/inline/autocomplete-element.js +1 -1
- package/dist/inline/character-count-element.js +1 -1
- package/dist/inline/choices-element.js +1 -1
- package/dist/inline/disclosure-element.js +1 -1
- package/dist/inline/exit-this-page-element.js +1 -1
- package/dist/inline/file-upload-element.js +1 -1
- package/dist/inline/focus-links-element.js +1 -1
- package/dist/inline/modal-element.js +1 -1
- package/dist/inline/password-input-element.js +1 -1
- package/dist/inline/tabs-element.js +1 -1
- package/dist/inline-script/index.d.ts +26 -0
- package/dist/inline-script/index.js +31 -0
- package/dist/inline-script/index.js.map +1 -0
- package/dist/{modal-element.d.ts → modal/element.d.ts} +2 -4
- package/dist/modal/element.js +114 -0
- package/dist/modal/element.js.map +1 -0
- package/dist/modal/index.d.ts +36 -0
- package/dist/modal/index.js +109 -0
- package/dist/modal/index.js.map +1 -0
- package/dist/password-input/element.d.ts +1 -0
- package/dist/password-input/element.js +134 -0
- package/dist/password-input/element.js.map +1 -0
- package/dist/{index-sEHnx4-M.d.ts → password-input/index.d.ts} +32 -48
- package/dist/password-input/index.js +35 -0
- package/dist/password-input/index.js.map +1 -0
- package/dist/{tabs-element.d.ts → tabs/element.d.ts} +2 -5
- package/dist/tabs/element.js +416 -0
- package/dist/tabs/element.js.map +1 -0
- package/dist/tabs/index.d.ts +83 -0
- package/dist/tabs/index.js +138 -0
- package/dist/tabs/index.js.map +1 -0
- package/dist/utils/dom.d.ts +9 -0
- package/dist/utils/dom.js +27 -0
- package/dist/utils/dom.js.map +1 -0
- package/dist/utils/on-property-set.d.ts +9 -0
- package/dist/utils/on-property-set.js +38 -0
- package/dist/utils/on-property-set.js.map +1 -0
- package/dist/utils/set-focus.d.ts +11 -0
- package/dist/utils/set-focus.js +38 -0
- package/dist/utils/set-focus.js.map +1 -0
- package/dist/utils/set-up-when-ready.d.ts +6 -0
- package/dist/utils/set-up-when-ready.js +16 -0
- package/dist/utils/set-up-when-ready.js.map +1 -0
- package/dist/utils/slot.d.ts +13 -0
- package/dist/utils/slot.js +40 -0
- package/dist/utils/slot.js.map +1 -0
- package/dist/utils/translation.d.ts +13 -0
- package/dist/utils/translation.js +57 -0
- package/dist/utils/translation.js.map +1 -0
- package/package.json +11 -4
- package/dist/accordion-element.js +0 -9
- package/dist/accordion-element.js.map +0 -1
- package/dist/accordion.d.ts +0 -2
- package/dist/accordion.js +0 -34
- package/dist/accordion.js.map +0 -1
- package/dist/auto-focus-element.d.ts +0 -3
- package/dist/auto-focus-element.js +0 -10
- package/dist/auto-focus-element.js.map +0 -1
- package/dist/auto-focus.d.ts +0 -2
- package/dist/auto-focus.js +0 -15
- package/dist/auto-focus.js.map +0 -1
- package/dist/autocomplete-element.js +0 -12
- package/dist/autocomplete-element.js.map +0 -1
- package/dist/autocomplete.d.ts +0 -4
- package/dist/autocomplete.js +0 -25
- package/dist/autocomplete.js.map +0 -1
- package/dist/button-element.d.ts +0 -2
- package/dist/button-element.js +0 -3
- package/dist/button-element.js.map +0 -1
- package/dist/button.d.ts +0 -2
- package/dist/button.js +0 -12
- package/dist/button.js.map +0 -1
- package/dist/character-count-element.js +0 -10
- package/dist/character-count-element.js.map +0 -1
- package/dist/character-count.d.ts +0 -3
- package/dist/character-count.js +0 -26
- package/dist/character-count.js.map +0 -1
- package/dist/choices-element.d.ts +0 -8
- package/dist/choices-element.js +0 -9
- package/dist/choices-element.js.map +0 -1
- package/dist/choices.d.ts +0 -2
- package/dist/choices.js +0 -16
- package/dist/choices.js.map +0 -1
- package/dist/chunk-2IHAQAYF.js +0 -23
- package/dist/chunk-2IHAQAYF.js.map +0 -1
- package/dist/chunk-2ZJVSNC2.js +0 -31
- package/dist/chunk-2ZJVSNC2.js.map +0 -1
- package/dist/chunk-47NMY4SS.js +0 -108
- package/dist/chunk-47NMY4SS.js.map +0 -1
- package/dist/chunk-4XAR4FFG.js +0 -83
- package/dist/chunk-4XAR4FFG.js.map +0 -1
- package/dist/chunk-5HWRMQK2.js +0 -91
- package/dist/chunk-5HWRMQK2.js.map +0 -1
- package/dist/chunk-6ZFU4VYW.js +0 -41
- package/dist/chunk-B2I4J5NL.js +0 -264
- package/dist/chunk-B2I4J5NL.js.map +0 -1
- package/dist/chunk-DPERPCUH.js +0 -188
- package/dist/chunk-DPERPCUH.js.map +0 -1
- package/dist/chunk-ECYGKE4D.js +0 -168
- package/dist/chunk-ECYGKE4D.js.map +0 -1
- package/dist/chunk-ESBMTI25.js +0 -11
- package/dist/chunk-ESBMTI25.js.map +0 -1
- package/dist/chunk-ET7DCQM7.js +0 -133
- package/dist/chunk-ET7DCQM7.js.map +0 -1
- package/dist/chunk-F5XFC4QJ.js +0 -177
- package/dist/chunk-F5XFC4QJ.js.map +0 -1
- package/dist/chunk-GVGBDSDN.js +0 -78
- package/dist/chunk-GVGBDSDN.js.map +0 -1
- package/dist/chunk-IZQ2C4BC.js +0 -351
- package/dist/chunk-IZQ2C4BC.js.map +0 -1
- package/dist/chunk-L7E6GN2D.js +0 -87
- package/dist/chunk-L7E6GN2D.js.map +0 -1
- package/dist/chunk-LWIA644X.js +0 -34
- package/dist/chunk-LWIA644X.js.map +0 -1
- package/dist/chunk-NX4B3NKM.js +0 -35
- package/dist/chunk-NX4B3NKM.js.map +0 -1
- package/dist/chunk-PNWPGD7B.js +0 -68
- package/dist/chunk-PNWPGD7B.js.map +0 -1
- package/dist/chunk-QLQ6O7OW.js +0 -111
- package/dist/chunk-QLQ6O7OW.js.map +0 -1
- package/dist/chunk-RDUPELOK.js +0 -55
- package/dist/chunk-RDUPELOK.js.map +0 -1
- package/dist/chunk-RPMHI67T.js +0 -104
- package/dist/chunk-RPMHI67T.js.map +0 -1
- package/dist/chunk-TE4RUYVK.js +0 -97
- package/dist/chunk-TE4RUYVK.js.map +0 -1
- package/dist/chunk-TJVBFRIE.js +0 -60
- package/dist/chunk-TJVBFRIE.js.map +0 -1
- package/dist/chunk-U5OKNKYC.js +0 -510
- package/dist/chunk-U5OKNKYC.js.map +0 -1
- package/dist/chunk-UXJO4AJP.js +0 -290
- package/dist/chunk-UXJO4AJP.js.map +0 -1
- package/dist/chunk-VNXXENCU.js +0 -39
- package/dist/chunk-VNXXENCU.js.map +0 -1
- package/dist/chunk-XGK73UCD.js +0 -62
- package/dist/chunk-XGK73UCD.js.map +0 -1
- package/dist/chunk-XJYLFTYE.js +0 -157
- package/dist/chunk-XJYLFTYE.js.map +0 -1
- package/dist/chunk-YCESNTXQ.js +0 -241
- package/dist/chunk-YCESNTXQ.js.map +0 -1
- package/dist/chunk-ZTJLVNR4.js +0 -62
- package/dist/chunk-ZTJLVNR4.js.map +0 -1
- package/dist/disclosure-element.js +0 -9
- package/dist/disclosure-element.js.map +0 -1
- package/dist/disclosure.d.ts +0 -2
- package/dist/disclosure.js +0 -16
- package/dist/disclosure.js.map +0 -1
- package/dist/exit-this-page-element.d.ts +0 -22
- package/dist/exit-this-page-element.js +0 -13
- package/dist/exit-this-page-element.js.map +0 -1
- package/dist/exit-this-page.d.ts +0 -3
- package/dist/exit-this-page.js +0 -25
- package/dist/exit-this-page.js.map +0 -1
- package/dist/file-upload-element.js +0 -14
- package/dist/file-upload-element.js.map +0 -1
- package/dist/file-upload.d.ts +0 -3
- package/dist/file-upload.js +0 -25
- package/dist/file-upload.js.map +0 -1
- package/dist/focus-links-element.d.ts +0 -3
- package/dist/focus-links-element.js +0 -10
- package/dist/focus-links-element.js.map +0 -1
- package/dist/focus-links.d.ts +0 -2
- package/dist/focus-links.js +0 -12
- package/dist/focus-links.js.map +0 -1
- package/dist/index--FxJgSOS.d.ts +0 -108
- package/dist/index-CikOyFud.d.ts +0 -54
- package/dist/index-D8N5vxTL.d.ts +0 -90
- package/dist/index-DMWpkC_d.d.ts +0 -105
- package/dist/index-DN7fGMc3.d.ts +0 -20
- package/dist/index-DPXR1Yua.d.ts +0 -69
- package/dist/inline-script.d.ts +0 -29
- package/dist/inline-script.js +0 -63
- package/dist/inline-script.js.map +0 -1
- package/dist/modal-element.js +0 -11
- package/dist/modal-element.js.map +0 -1
- package/dist/modal.d.ts +0 -2
- package/dist/modal.js +0 -20
- package/dist/modal.js.map +0 -1
- package/dist/password-input-element.d.ts +0 -3
- package/dist/password-input-element.js +0 -9
- package/dist/password-input-element.js.map +0 -1
- package/dist/password-input.d.ts +0 -2
- package/dist/password-input.js +0 -18
- package/dist/password-input.js.map +0 -1
- package/dist/tabs-element.js +0 -9
- package/dist/tabs-element.js.map +0 -1
- package/dist/tabs.d.ts +0 -2
- package/dist/tabs.js +0 -28
- package/dist/tabs.js.map +0 -1
- package/dist/translation-BnpO2mN2.d.ts +0 -4
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ComponentProps } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type RootProps = React.HTMLAttributes<HTMLElement> & {
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
export { defaultMessages, type ExitThisPageElement, type MessageName } from './element.js';
|
|
4
|
+
export type RootProps = React.HTMLAttributes<HTMLElement> & {
|
|
6
5
|
/** Announced once activated. Defaults to "Loading.". */
|
|
7
6
|
activatedText?: string;
|
|
8
7
|
/** Announced when the Shift presses time out. Defaults to "Exit this page expired.". */
|
|
@@ -20,7 +19,7 @@ type RootProps = React.HTMLAttributes<HTMLElement> & {
|
|
|
20
19
|
/** Classes for the overlay. Without them, inline styles cover the page. */
|
|
21
20
|
overlayClass?: string;
|
|
22
21
|
};
|
|
23
|
-
declare function Root({ activatedText, timedOutText, pressTwoMoreTimesText, pressOneMoreTimeText, indicatorVisibleClass, lightOnClass, hideContentClass, overlayClass, ...props }: RootProps): React.DOMElement<{
|
|
22
|
+
export declare function Root({ activatedText, timedOutText, pressTwoMoreTimesText, pressOneMoreTimeText, indicatorVisibleClass, lightOnClass, hideContentClass, overlayClass, ...props }: RootProps): React.DOMElement<{
|
|
24
23
|
activated: string;
|
|
25
24
|
'timed-out': string;
|
|
26
25
|
'press-two-more-times': string;
|
|
@@ -37,17 +36,17 @@ declare function Root({ activatedText, timedOutText, pressTwoMoreTimesText, pres
|
|
|
37
36
|
autoCapitalize?: "off" | "none" | "on" | "sentences" | "words" | "characters" | (string & {});
|
|
38
37
|
autoFocus?: boolean;
|
|
39
38
|
className?: string;
|
|
40
|
-
contentEditable?: (boolean | "
|
|
39
|
+
contentEditable?: (boolean | "false" | "true") | "inherit" | "plaintext-only";
|
|
41
40
|
contextMenu?: string;
|
|
42
41
|
dir?: string;
|
|
43
|
-
draggable?: boolean | "
|
|
42
|
+
draggable?: boolean | "false" | "true";
|
|
44
43
|
enterKeyHint?: "search" | "enter" | "done" | "go" | "next" | "previous" | "send";
|
|
45
44
|
hidden?: boolean;
|
|
46
45
|
id?: string;
|
|
47
46
|
lang?: string;
|
|
48
47
|
nonce?: string;
|
|
49
48
|
slot?: string;
|
|
50
|
-
spellCheck?: boolean | "
|
|
49
|
+
spellCheck?: boolean | "false" | "true";
|
|
51
50
|
style?: React.CSSProperties;
|
|
52
51
|
tabIndex?: number;
|
|
53
52
|
title?: string;
|
|
@@ -80,57 +79,57 @@ declare function Root({ activatedText, timedOutText, pressTwoMoreTimesText, pres
|
|
|
80
79
|
popoverTargetAction?: "toggle" | "show" | "hide";
|
|
81
80
|
popoverTarget?: string;
|
|
82
81
|
inert?: boolean;
|
|
83
|
-
inputMode?: "search" | "
|
|
82
|
+
inputMode?: "search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal";
|
|
84
83
|
is?: string;
|
|
85
84
|
exportparts?: string;
|
|
86
85
|
part?: string;
|
|
87
86
|
"aria-activedescendant"?: string;
|
|
88
|
-
"aria-atomic"?: boolean | "
|
|
87
|
+
"aria-atomic"?: boolean | "false" | "true";
|
|
89
88
|
"aria-autocomplete"?: "none" | "list" | "inline" | "both";
|
|
90
89
|
"aria-braillelabel"?: string;
|
|
91
90
|
"aria-brailleroledescription"?: string;
|
|
92
|
-
"aria-busy"?: boolean | "
|
|
93
|
-
"aria-checked"?: boolean | "
|
|
91
|
+
"aria-busy"?: boolean | "false" | "true";
|
|
92
|
+
"aria-checked"?: boolean | "false" | "true" | "mixed";
|
|
94
93
|
"aria-colcount"?: number;
|
|
95
94
|
"aria-colindex"?: number;
|
|
96
95
|
"aria-colindextext"?: string;
|
|
97
96
|
"aria-colspan"?: number;
|
|
98
97
|
"aria-controls"?: string;
|
|
99
|
-
"aria-current"?: boolean | "time" | "
|
|
98
|
+
"aria-current"?: boolean | "time" | "false" | "true" | "page" | "step" | "location" | "date";
|
|
100
99
|
"aria-describedby"?: string;
|
|
101
100
|
"aria-description"?: string;
|
|
102
101
|
"aria-details"?: string;
|
|
103
|
-
"aria-disabled"?: boolean | "
|
|
104
|
-
"aria-dropeffect"?: "link" | "
|
|
102
|
+
"aria-disabled"?: boolean | "false" | "true";
|
|
103
|
+
"aria-dropeffect"?: "link" | "copy" | "none" | "execute" | "move" | "popup";
|
|
105
104
|
"aria-errormessage"?: string;
|
|
106
|
-
"aria-expanded"?: boolean | "
|
|
105
|
+
"aria-expanded"?: boolean | "false" | "true";
|
|
107
106
|
"aria-flowto"?: string;
|
|
108
|
-
"aria-grabbed"?: boolean | "
|
|
109
|
-
"aria-haspopup"?: boolean | "dialog" | "menu" | "
|
|
110
|
-
"aria-hidden"?: boolean | "
|
|
111
|
-
"aria-invalid"?: boolean | "
|
|
107
|
+
"aria-grabbed"?: boolean | "false" | "true";
|
|
108
|
+
"aria-haspopup"?: boolean | "dialog" | "menu" | "false" | "true" | "grid" | "listbox" | "tree";
|
|
109
|
+
"aria-hidden"?: boolean | "false" | "true";
|
|
110
|
+
"aria-invalid"?: boolean | "false" | "true" | "grammar" | "spelling";
|
|
112
111
|
"aria-keyshortcuts"?: string;
|
|
113
112
|
"aria-label"?: string;
|
|
114
113
|
"aria-labelledby"?: string;
|
|
115
114
|
"aria-level"?: number;
|
|
116
115
|
"aria-live"?: "off" | "assertive" | "polite";
|
|
117
|
-
"aria-modal"?: boolean | "
|
|
118
|
-
"aria-multiline"?: boolean | "
|
|
119
|
-
"aria-multiselectable"?: boolean | "
|
|
116
|
+
"aria-modal"?: boolean | "false" | "true";
|
|
117
|
+
"aria-multiline"?: boolean | "false" | "true";
|
|
118
|
+
"aria-multiselectable"?: boolean | "false" | "true";
|
|
120
119
|
"aria-orientation"?: "horizontal" | "vertical";
|
|
121
120
|
"aria-owns"?: string;
|
|
122
121
|
"aria-placeholder"?: string;
|
|
123
122
|
"aria-posinset"?: number;
|
|
124
|
-
"aria-pressed"?: boolean | "
|
|
125
|
-
"aria-readonly"?: boolean | "
|
|
123
|
+
"aria-pressed"?: boolean | "false" | "true" | "mixed";
|
|
124
|
+
"aria-readonly"?: boolean | "false" | "true";
|
|
126
125
|
"aria-relevant"?: "text" | "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals";
|
|
127
|
-
"aria-required"?: boolean | "
|
|
126
|
+
"aria-required"?: boolean | "false" | "true";
|
|
128
127
|
"aria-roledescription"?: string;
|
|
129
128
|
"aria-rowcount"?: number;
|
|
130
129
|
"aria-rowindex"?: number;
|
|
131
130
|
"aria-rowindextext"?: string;
|
|
132
131
|
"aria-rowspan"?: number;
|
|
133
|
-
"aria-selected"?: boolean | "
|
|
132
|
+
"aria-selected"?: boolean | "false" | "true";
|
|
134
133
|
"aria-setsize"?: number;
|
|
135
134
|
"aria-sort"?: "none" | "ascending" | "descending" | "other";
|
|
136
135
|
"aria-valuemax"?: number;
|
|
@@ -314,41 +313,18 @@ type PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E>
|
|
|
314
313
|
/** Render the only child instead, with this part's props merged onto it. */
|
|
315
314
|
asChild?: boolean;
|
|
316
315
|
};
|
|
317
|
-
type ButtonProps = PartProps<'a'>;
|
|
316
|
+
export type ButtonProps = PartProps<'a'>;
|
|
318
317
|
/** The link to a safe page, which the element follows once it has hidden the page. */
|
|
319
|
-
declare function Button({ asChild, ...props }: ButtonProps): React.JSX.Element;
|
|
320
|
-
type SkipLinkProps = PartProps<'a'>;
|
|
318
|
+
export declare function Button({ asChild, ...props }: ButtonProps): React.JSX.Element;
|
|
319
|
+
export type SkipLinkProps = PartProps<'a'>;
|
|
321
320
|
/** A link anywhere on the page, such as in the skip links, that exits too. */
|
|
322
|
-
declare function SkipLink({ asChild, ...props }: SkipLinkProps): React.JSX.Element;
|
|
323
|
-
type IndicatorProps = PartProps<'div'>;
|
|
321
|
+
export declare function SkipLink({ asChild, ...props }: SkipLinkProps): React.JSX.Element;
|
|
322
|
+
export type IndicatorProps = PartProps<'div'>;
|
|
324
323
|
/** Shows how many times Shift has been pressed. Has three Lights unless given children. */
|
|
325
|
-
declare function Indicator({ asChild, children, ...props }: IndicatorProps): React.JSX.Element;
|
|
326
|
-
type LightProps = PartProps<'div'>;
|
|
324
|
+
export declare function Indicator({ asChild, children, ...props }: IndicatorProps): React.JSX.Element;
|
|
325
|
+
export type LightProps = PartProps<'div'>;
|
|
327
326
|
/** One press of Shift. */
|
|
328
|
-
declare function Light({ asChild, ...props }: LightProps): React.JSX.Element;
|
|
329
|
-
type StatusProps = PartProps<'span'>;
|
|
327
|
+
export declare function Light({ asChild, ...props }: LightProps): React.JSX.Element;
|
|
328
|
+
export type StatusProps = PartProps<'span'>;
|
|
330
329
|
/** Tells screen readers how many more presses are needed. Make it visually hidden. */
|
|
331
|
-
declare function Status({ asChild, children, ...props }: StatusProps): React.JSX.Element;
|
|
332
|
-
|
|
333
|
-
declare const index_Button: typeof Button;
|
|
334
|
-
type index_ButtonProps = ButtonProps;
|
|
335
|
-
declare const index_ExitThisPageElement: typeof ExitThisPageElement;
|
|
336
|
-
declare const index_Indicator: typeof Indicator;
|
|
337
|
-
type index_IndicatorProps = IndicatorProps;
|
|
338
|
-
declare const index_Light: typeof Light;
|
|
339
|
-
type index_LightProps = LightProps;
|
|
340
|
-
declare const index_MessageName: typeof MessageName;
|
|
341
|
-
declare const index_Root: typeof Root;
|
|
342
|
-
type index_RootProps = RootProps;
|
|
343
|
-
declare const index_SkipLink: typeof SkipLink;
|
|
344
|
-
type index_SkipLinkProps = SkipLinkProps;
|
|
345
|
-
declare const index_Status: typeof Status;
|
|
346
|
-
type index_StatusProps = StatusProps;
|
|
347
|
-
declare const index_defaultMessages: typeof defaultMessages;
|
|
348
|
-
declare namespace index {
|
|
349
|
-
export { index_Button as Button, index_ExitThisPageElement as ExitThisPageElement, index_Indicator as Indicator, index_Light as Light, index_MessageName as MessageName, index_Root as Root, index_SkipLink as SkipLink, index_Status as Status, index_defaultMessages as defaultMessages };
|
|
350
|
-
export type { index_ButtonProps as ButtonProps, index_IndicatorProps as IndicatorProps, index_LightProps as LightProps, index_RootProps as RootProps, index_SkipLinkProps as SkipLinkProps, index_StatusProps as StatusProps };
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
export { Button as B, Indicator as I, Light as L, Root as R, SkipLink as S, Status as f, index as i };
|
|
354
|
-
export type { ButtonProps as a, IndicatorProps as b, LightProps as c, RootProps as d, SkipLinkProps as e, StatusProps as g };
|
|
330
|
+
export declare function Status({ asChild, children, ...props }: StatusProps): React.JSX.Element;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Slot } from '../utils/slot.js';
|
|
4
|
+
import { tagName } from './element.js';
|
|
5
|
+
export { defaultMessages } from './element.js';
|
|
6
|
+
export function Root({ activatedText, timedOutText, pressTwoMoreTimesText, pressOneMoreTimeText, indicatorVisibleClass, lightOnClass, hideContentClass, overlayClass, ...props }) {
|
|
7
|
+
return React.createElement(tagName, {
|
|
8
|
+
...props,
|
|
9
|
+
activated: activatedText,
|
|
10
|
+
'timed-out': timedOutText,
|
|
11
|
+
'press-two-more-times': pressTwoMoreTimesText,
|
|
12
|
+
'press-one-more-time': pressOneMoreTimeText,
|
|
13
|
+
'indicator-visible-class': indicatorVisibleClass,
|
|
14
|
+
'light-on-class': lightOnClass,
|
|
15
|
+
'hide-content-class': hideContentClass,
|
|
16
|
+
'overlay-class': overlayClass,
|
|
17
|
+
// The element owns `data-upgraded`.
|
|
18
|
+
suppressHydrationWarning: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** The link to a safe page, which the element follows once it has hidden the page. */
|
|
22
|
+
export function Button({ asChild, ...props }) {
|
|
23
|
+
const Element = asChild ? Slot : 'a';
|
|
24
|
+
return React.createElement(Element, { "data-exit-this-page-button": "", ...props });
|
|
25
|
+
}
|
|
26
|
+
/** A link anywhere on the page, such as in the skip links, that exits too. */
|
|
27
|
+
export function SkipLink({ asChild, ...props }) {
|
|
28
|
+
const Element = asChild ? Slot : 'a';
|
|
29
|
+
return React.createElement(Element, { "data-exit-this-page-skiplink": "", ...props });
|
|
30
|
+
}
|
|
31
|
+
/** Shows how many times Shift has been pressed. Has three Lights unless given children. */
|
|
32
|
+
export function Indicator({ asChild, children, ...props }) {
|
|
33
|
+
const Element = asChild ? Slot : 'div';
|
|
34
|
+
return (
|
|
35
|
+
// The element owns `data-visible` and its classes.
|
|
36
|
+
React.createElement(Element, { "data-exit-this-page-indicator": "", "aria-hidden": "true", suppressHydrationWarning: true, ...props }, children !== null && children !== void 0 ? children : (React.createElement(React.Fragment, null,
|
|
37
|
+
React.createElement(Light, null),
|
|
38
|
+
React.createElement(Light, null),
|
|
39
|
+
React.createElement(Light, null)))));
|
|
40
|
+
}
|
|
41
|
+
/** One press of Shift. */
|
|
42
|
+
export function Light({ asChild, ...props }) {
|
|
43
|
+
const Element = asChild ? Slot : 'div';
|
|
44
|
+
// The element owns `data-on` and its classes.
|
|
45
|
+
return React.createElement(Element, { "data-exit-this-page-light": "", suppressHydrationWarning: true, ...props });
|
|
46
|
+
}
|
|
47
|
+
/** Tells screen readers how many more presses are needed. Make it visually hidden. */
|
|
48
|
+
export function Status({ asChild, children, ...props }) {
|
|
49
|
+
const Element = asChild ? Slot : 'span';
|
|
50
|
+
// The element owns its text. A string child, even an empty one, is hydrated as text, so text the
|
|
51
|
+
// element set before hydration is kept rather than being a mismatch.
|
|
52
|
+
return (React.createElement(Element, { "data-exit-this-page-status": "", role: "status", suppressHydrationWarning: true, ...props }, children !== null && children !== void 0 ? children : ''));
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exit-this-page/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,e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;IACnD,oBAAC,OAAO,qCAA+B,EAAE,iBAAa,MAAM,EAAC,wBAAwB,WAAK,KAAK,IAC5F,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,CACX;QACE,oBAAC,KAAK,OAAG;QACT,oBAAC,KAAK,OAAG;QACT,oBAAC,KAAK,OAAG,CACR,CACJ,CACO,CACX,CAAC;AACJ,CAAC;AAID,0BAA0B;AAC1B,MAAM,UAAU,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,EAAc;IACrD,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IACvC,8CAA8C;IAC9C,OAAO,oBAAC,OAAO,iCAA2B,EAAE,EAAC,wBAAwB,WAAK,KAAK,GAAI,CAAC;AACtF,CAAC;AAID,sFAAsF;AACtF,MAAM,UAAU,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAe;IACjE,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACxC,iGAAiG;IACjG,qEAAqE;IACrE,OAAO,CACL,oBAAC,OAAO,kCAA4B,EAAE,EAAC,IAAI,EAAC,QAAQ,EAAC,wBAAwB,WAAK,KAAK,IACpF,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CACP,CACX,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { ComponentProps } from 'react';\nimport { Slot } from '../utils/slot.js';\nimport { tagName } from './element.js';\n\nexport { defaultMessages, type ExitThisPageElement, type MessageName } from './element.js';\n\n/*\n * Headless exit this page: unstyled parts over the <govuk-react-exit-this-page> element\n * (./element.ts). The button, a SkipLink, or pressing Shift 3 times hides the page and goes to\n * the button's `href`. Every part except Root takes `asChild`.\n *\n * Without JavaScript the button is a plain link. To stay on the page, such as in a test, listen for\n * `govuk-react-exit-this-page:exit` and cancel it.\n */\n\nexport type RootProps = React.HTMLAttributes<HTMLElement> & {\n /** Announced once activated. Defaults to \"Loading.\". */\n activatedText?: string;\n /** Announced when the Shift presses time out. Defaults to \"Exit this page expired.\". */\n timedOutText?: string;\n /** Announced after one press of Shift. Defaults to \"Shift, press 2 more times to exit.\". */\n pressTwoMoreTimesText?: string;\n /** Announced after two presses of Shift. Defaults to \"Shift, press 1 more time to exit.\". */\n pressOneMoreTimeText?: string;\n /** Classes for the indicator while counting presses. */\n indicatorVisibleClass?: string;\n /** Classes for each light of the indicator once pressed. */\n lightOnClass?: string;\n /** Classes for `body` that hide the page behind the overlay. */\n hideContentClass?: string;\n /** Classes for the overlay. Without them, inline styles cover the page. */\n overlayClass?: string;\n};\n\nexport function Root({\n activatedText,\n timedOutText,\n pressTwoMoreTimesText,\n pressOneMoreTimeText,\n indicatorVisibleClass,\n lightOnClass,\n hideContentClass,\n overlayClass,\n ...props\n}: RootProps) {\n return React.createElement(tagName, {\n ...props,\n activated: activatedText,\n 'timed-out': timedOutText,\n 'press-two-more-times': pressTwoMoreTimesText,\n 'press-one-more-time': pressOneMoreTimeText,\n 'indicator-visible-class': indicatorVisibleClass,\n 'light-on-class': lightOnClass,\n 'hide-content-class': hideContentClass,\n 'overlay-class': overlayClass,\n // The element owns `data-upgraded`.\n suppressHydrationWarning: true,\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 ButtonProps = PartProps<'a'>;\n\n/** The link to a safe page, which the element follows once it has hidden the page. */\nexport function Button({ asChild, ...props }: ButtonProps) {\n const Element = asChild ? Slot : 'a';\n return <Element data-exit-this-page-button=\"\" {...props} />;\n}\n\nexport type SkipLinkProps = PartProps<'a'>;\n\n/** A link anywhere on the page, such as in the skip links, that exits too. */\nexport function SkipLink({ asChild, ...props }: SkipLinkProps) {\n const Element = asChild ? Slot : 'a';\n return <Element data-exit-this-page-skiplink=\"\" {...props} />;\n}\n\nexport type IndicatorProps = PartProps<'div'>;\n\n/** Shows how many times Shift has been pressed. Has three Lights unless given children. */\nexport function Indicator({ asChild, children, ...props }: IndicatorProps) {\n const Element = asChild ? Slot : 'div';\n return (\n // The element owns `data-visible` and its classes.\n <Element data-exit-this-page-indicator=\"\" aria-hidden=\"true\" suppressHydrationWarning {...props}>\n {children ?? (\n <>\n <Light />\n <Light />\n <Light />\n </>\n )}\n </Element>\n );\n}\n\nexport type LightProps = PartProps<'div'>;\n\n/** One press of Shift. */\nexport function Light({ asChild, ...props }: LightProps) {\n const Element = asChild ? Slot : 'div';\n // The element owns `data-on` and its classes.\n return <Element data-exit-this-page-light=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type StatusProps = PartProps<'span'>;\n\n/** Tells screen readers how many more presses are needed. Make it visually hidden. */\nexport function Status({ asChild, children, ...props }: StatusProps) {\n const Element = asChild ? Slot : 'span';\n // The element owns its text. A string child, even an empty one, is hydrated as text, so text the\n // element set before hydration is kept rather than being a mismatch.\n return (\n <Element data-exit-this-page-status=\"\" role=\"status\" suppressHydrationWarning {...props}>\n {children ?? ''}\n </Element>\n );\n}\n"]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Translation } from '
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface FileUploadElement extends HTMLElement {
|
|
1
|
+
import { type Translation } from '../utils/translation.js';
|
|
2
|
+
export declare const tagName = "govuk-react-file-upload";
|
|
3
|
+
export interface FileUploadElement extends HTMLElement {
|
|
5
4
|
/** Updates the button from the input's files, such as after setting them. */
|
|
6
5
|
update(): void;
|
|
7
6
|
}
|
|
8
7
|
/** govuk-frontend's English text. */
|
|
9
|
-
declare const defaults: {
|
|
8
|
+
export declare const defaults: {
|
|
10
9
|
'no-file-chosen': string;
|
|
11
10
|
'multiple-files-chosen': {
|
|
12
11
|
one: string;
|
|
@@ -16,12 +15,9 @@ declare const defaults: {
|
|
|
16
15
|
'left-drop-zone': string;
|
|
17
16
|
};
|
|
18
17
|
/** What the status says for the files chosen. */
|
|
19
|
-
declare function statusText(files: ArrayLike<{
|
|
18
|
+
export declare function statusText(files: ArrayLike<{
|
|
20
19
|
name: string;
|
|
21
20
|
}>, messages: {
|
|
22
21
|
'no-file-chosen'?: Translation;
|
|
23
22
|
'multiple-files-chosen'?: Translation;
|
|
24
23
|
}, locale?: string): string;
|
|
25
|
-
|
|
26
|
-
export { defaults, statusText, tagName };
|
|
27
|
-
export type { FileUploadElement };
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* <govuk-react-file-upload>: a headless, light-DOM custom element that turns a file input into a
|
|
3
|
+
* button and drop zone, with or without React, as govuk-frontend's improved file upload does.
|
|
4
|
+
*
|
|
5
|
+
* The input's files are the state. Without JavaScript the native file input shows and the button
|
|
6
|
+
* stays hidden. On upgrade the element hides the input and shows the button, which opens the file
|
|
7
|
+
* picker, says which files are chosen, and takes files dropped on it. The rendered markup is never
|
|
8
|
+
* moved, so React can keep rendering it.
|
|
9
|
+
*
|
|
10
|
+
* As in govuk-frontend, the button takes the input's `id`, so its label names the button, and the
|
|
11
|
+
* input's id gets `-input` added. The button also takes the input's `aria-describedby` and
|
|
12
|
+
* `disabled`, and its accessible name is the label, the separator and its own text.
|
|
13
|
+
*
|
|
14
|
+
* Markup inside the element:
|
|
15
|
+
* - `input[type="file"]`: the field, with an `id` and a `label`. Hidden on upgrade.
|
|
16
|
+
* - `button[data-file-upload-button]`: rendered `hidden`, with `type="button"`.
|
|
17
|
+
* - `[data-file-upload-status]`: which files are chosen.
|
|
18
|
+
* - `[data-file-upload-separator]` (optional): between the label and the button's text in its
|
|
19
|
+
* accessible name, such as a visually hidden comma.
|
|
20
|
+
* - `[data-file-upload-drop-zone]` (optional): the area that shows dragging. The element itself
|
|
21
|
+
* without one.
|
|
22
|
+
* - `[data-file-upload-announcements]` (optional): a visually hidden live region for entering and
|
|
23
|
+
* leaving the drop zone.
|
|
24
|
+
*
|
|
25
|
+
* The button gets `data-empty` while no file is chosen and `data-dragging` while files are dragged
|
|
26
|
+
* over the drop zone, and the drop zone gets `data-disabled`.
|
|
27
|
+
*
|
|
28
|
+
* Attributes:
|
|
29
|
+
* - `no-file-chosen`, `multiple-files-chosen`, `entered-drop-zone`, `left-drop-zone`: the text,
|
|
30
|
+
* English by default, with `%{count}` for the number of files. Add a plural form to the name,
|
|
31
|
+
* such as `multiple-files-chosen-one`, for a message for each form.
|
|
32
|
+
* - `empty-class`, `dragging-class`: classes for the button while empty and while dragging.
|
|
33
|
+
* - `disabled-class`: classes for the drop zone while the input is disabled.
|
|
34
|
+
*/
|
|
35
|
+
import { translate, translationAttributeNames, translationFromAttributes, } from '../utils/translation.js';
|
|
36
|
+
import { classesOf, setText, setAttribute } from '../utils/dom.js';
|
|
37
|
+
export const tagName = 'govuk-react-file-upload';
|
|
38
|
+
/** govuk-frontend's English text. */
|
|
39
|
+
export const defaults = {
|
|
40
|
+
'no-file-chosen': 'No file chosen',
|
|
41
|
+
'multiple-files-chosen': { one: '%{count} file chosen', other: '%{count} files chosen' },
|
|
42
|
+
'entered-drop-zone': 'Entered drop zone',
|
|
43
|
+
'left-drop-zone': 'Left drop zone',
|
|
44
|
+
};
|
|
45
|
+
/** What the status says for the files chosen. */
|
|
46
|
+
export function statusText(files, messages, locale) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (files.length === 0)
|
|
49
|
+
return translate((_a = messages['no-file-chosen']) !== null && _a !== void 0 ? _a : defaults['no-file-chosen'], 0, locale);
|
|
50
|
+
if (files.length === 1)
|
|
51
|
+
return files[0].name;
|
|
52
|
+
return translate((_b = messages['multiple-files-chosen']) !== null && _b !== void 0 ? _b : defaults['multiple-files-chosen'], files.length, locale);
|
|
53
|
+
}
|
|
54
|
+
const countFiles = (items) => Array.from(items).filter((item) => item.kind === 'file').length;
|
|
55
|
+
if (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {
|
|
56
|
+
class GovukReactFileUpload extends HTMLElement {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(...arguments);
|
|
59
|
+
/** The input's id before upgrade, which the button takes. */
|
|
60
|
+
this.fieldId = '';
|
|
61
|
+
this.dragging = false;
|
|
62
|
+
this.enteredAnotherElement = false;
|
|
63
|
+
this.onChange = () => this.update();
|
|
64
|
+
this.onReset = () => window.setTimeout(() => this.update());
|
|
65
|
+
this.onClick = () => { var _a; return (_a = this.input) === null || _a === void 0 ? void 0 : _a.click(); };
|
|
66
|
+
this.onDragOver = (event) => event.preventDefault();
|
|
67
|
+
this.onDrop = (event) => {
|
|
68
|
+
var _a;
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
const { input } = this;
|
|
71
|
+
const files = (_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.files;
|
|
72
|
+
if (!input || !files || !this.matchesCapacity(files.length))
|
|
73
|
+
return;
|
|
74
|
+
input.files = files;
|
|
75
|
+
// Bubbles, unlike govuk-frontend's, so React's `onChange` hears dropped files too.
|
|
76
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
77
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
78
|
+
this.setDragging(false);
|
|
79
|
+
};
|
|
80
|
+
this.onDocumentDragEnter = (event) => {
|
|
81
|
+
this.enteredAnotherElement = true;
|
|
82
|
+
if (!this.button || this.button.disabled || !(event.target instanceof Node))
|
|
83
|
+
return;
|
|
84
|
+
if (this.dropZone.contains(event.target)) {
|
|
85
|
+
if (event.dataTransfer && this.canDrop(event.dataTransfer) && !this.dragging) {
|
|
86
|
+
this.setDragging(true);
|
|
87
|
+
this.announce('entered-drop-zone');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (this.dragging) {
|
|
91
|
+
this.setDragging(false);
|
|
92
|
+
this.announce('left-drop-zone');
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// Leaving the window, or dragging back out of it, fires `dragleave` with no `dragenter`.
|
|
96
|
+
this.onDocumentDragLeave = () => {
|
|
97
|
+
var _a;
|
|
98
|
+
if (!this.enteredAnotherElement && this.dragging && !((_a = this.button) === null || _a === void 0 ? void 0 : _a.disabled)) {
|
|
99
|
+
this.setDragging(false);
|
|
100
|
+
this.announce('left-drop-zone');
|
|
101
|
+
}
|
|
102
|
+
this.enteredAnotherElement = false;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
static get observedAttributes() {
|
|
106
|
+
return [
|
|
107
|
+
'empty-class',
|
|
108
|
+
'dragging-class',
|
|
109
|
+
'disabled-class',
|
|
110
|
+
...Object.keys(defaults).flatMap(translationAttributeNames),
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
connectedCallback() {
|
|
114
|
+
// The parts may be parsed or rendered later, and React can rewrite the input's attributes.
|
|
115
|
+
this.observer = new MutationObserver(() => this.setup());
|
|
116
|
+
this.observer.observe(this, {
|
|
117
|
+
childList: true,
|
|
118
|
+
subtree: true,
|
|
119
|
+
attributes: true,
|
|
120
|
+
attributeFilter: ['class', 'disabled', 'id', 'aria-describedby'],
|
|
121
|
+
});
|
|
122
|
+
document.addEventListener('dragenter', this.onDocumentDragEnter);
|
|
123
|
+
document.addEventListener('dragleave', this.onDocumentDragLeave);
|
|
124
|
+
this.setup();
|
|
125
|
+
}
|
|
126
|
+
disconnectedCallback() {
|
|
127
|
+
var _a;
|
|
128
|
+
(_a = this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
129
|
+
document.removeEventListener('dragenter', this.onDocumentDragEnter);
|
|
130
|
+
document.removeEventListener('dragleave', this.onDocumentDragLeave);
|
|
131
|
+
this.unbind();
|
|
132
|
+
}
|
|
133
|
+
attributeChangedCallback() {
|
|
134
|
+
// Wait for every attribute: React sets them one by one before connecting the element.
|
|
135
|
+
if (this.isConnected)
|
|
136
|
+
this.update();
|
|
137
|
+
}
|
|
138
|
+
own(selector) {
|
|
139
|
+
return Array.from(this.querySelectorAll(selector)).find((element) => element.closest(tagName) === this);
|
|
140
|
+
}
|
|
141
|
+
get dropZone() {
|
|
142
|
+
var _a;
|
|
143
|
+
return (_a = this.own('[data-file-upload-drop-zone]')) !== null && _a !== void 0 ? _a : this;
|
|
144
|
+
}
|
|
145
|
+
get locale() {
|
|
146
|
+
var _a;
|
|
147
|
+
return ((_a = this.closest('[lang]')) === null || _a === void 0 ? void 0 : _a.getAttribute('lang')) || 'en';
|
|
148
|
+
}
|
|
149
|
+
message(name) {
|
|
150
|
+
var _a;
|
|
151
|
+
return (_a = translationFromAttributes(this, name)) !== null && _a !== void 0 ? _a : defaults[name];
|
|
152
|
+
}
|
|
153
|
+
setup() {
|
|
154
|
+
var _a;
|
|
155
|
+
const input = this.own('input[type="file"]');
|
|
156
|
+
const button = this.own('button[data-file-upload-button]');
|
|
157
|
+
if (!input || !button)
|
|
158
|
+
return;
|
|
159
|
+
// A new input, or a new id from React, rather than the one the element gave it.
|
|
160
|
+
if (input.id !== `${this.fieldId}-input`)
|
|
161
|
+
this.fieldId = input.id;
|
|
162
|
+
if (!this.fieldId)
|
|
163
|
+
return;
|
|
164
|
+
if (input !== this.input || button !== this.button) {
|
|
165
|
+
this.unbind();
|
|
166
|
+
this.input = input;
|
|
167
|
+
this.button = button;
|
|
168
|
+
this.form = input.form;
|
|
169
|
+
input.addEventListener('change', this.onChange);
|
|
170
|
+
(_a = this.form) === null || _a === void 0 ? void 0 : _a.addEventListener('reset', this.onReset);
|
|
171
|
+
button.addEventListener('click', this.onClick);
|
|
172
|
+
button.addEventListener('dragover', this.onDragOver);
|
|
173
|
+
button.addEventListener('drop', this.onDrop);
|
|
174
|
+
}
|
|
175
|
+
this.upgrade(input, button);
|
|
176
|
+
this.update();
|
|
177
|
+
}
|
|
178
|
+
unbind() {
|
|
179
|
+
var _a, _b, _c, _d, _e;
|
|
180
|
+
(_a = this.input) === null || _a === void 0 ? void 0 : _a.removeEventListener('change', this.onChange);
|
|
181
|
+
(_b = this.form) === null || _b === void 0 ? void 0 : _b.removeEventListener('reset', this.onReset);
|
|
182
|
+
(_c = this.button) === null || _c === void 0 ? void 0 : _c.removeEventListener('click', this.onClick);
|
|
183
|
+
(_d = this.button) === null || _d === void 0 ? void 0 : _d.removeEventListener('dragover', this.onDragOver);
|
|
184
|
+
(_e = this.button) === null || _e === void 0 ? void 0 : _e.removeEventListener('drop', this.onDrop);
|
|
185
|
+
this.input = undefined;
|
|
186
|
+
this.button = undefined;
|
|
187
|
+
this.form = undefined;
|
|
188
|
+
}
|
|
189
|
+
/** Moves the id to the button, names it, and swaps it for the input, as govuk-frontend does. */
|
|
190
|
+
upgrade(input, button) {
|
|
191
|
+
const id = this.fieldId;
|
|
192
|
+
const root = this.getRootNode();
|
|
193
|
+
const label = root instanceof Document || root instanceof ShadowRoot
|
|
194
|
+
? root.querySelector(`label[for="${CSS.escape(id)}"]`)
|
|
195
|
+
: null;
|
|
196
|
+
if (label && !label.id)
|
|
197
|
+
label.id = `${id}-label`;
|
|
198
|
+
setAttribute(input, 'id', `${id}-input`);
|
|
199
|
+
setAttribute(button, 'id', id);
|
|
200
|
+
const separator = button.querySelector('[data-file-upload-separator]');
|
|
201
|
+
if (separator)
|
|
202
|
+
setAttribute(separator, 'id', `${id}-comma`);
|
|
203
|
+
if (label) {
|
|
204
|
+
setAttribute(button, 'aria-labelledby', [label.id, separator === null || separator === void 0 ? void 0 : separator.id, id].filter(Boolean).join(' '));
|
|
205
|
+
}
|
|
206
|
+
setAttribute(button, 'aria-describedby', input.getAttribute('aria-describedby'));
|
|
207
|
+
setAttribute(input, 'hidden', 'hidden');
|
|
208
|
+
if (button.hidden)
|
|
209
|
+
button.hidden = false;
|
|
210
|
+
this.dataset.upgraded = '';
|
|
211
|
+
}
|
|
212
|
+
update() {
|
|
213
|
+
const { input, button } = this;
|
|
214
|
+
if (!input || !button)
|
|
215
|
+
return;
|
|
216
|
+
const { files } = input;
|
|
217
|
+
const empty = !(files === null || files === void 0 ? void 0 : files.length);
|
|
218
|
+
const status = button.querySelector('[data-file-upload-status]');
|
|
219
|
+
if (status) {
|
|
220
|
+
setText(status, statusText(files !== null && files !== void 0 ? files : [], {
|
|
221
|
+
'no-file-chosen': this.message('no-file-chosen'),
|
|
222
|
+
'multiple-files-chosen': this.message('multiple-files-chosen'),
|
|
223
|
+
}, this.locale));
|
|
224
|
+
}
|
|
225
|
+
// `toggle` with force leaves a class that's already there alone, so the observer isn't woken.
|
|
226
|
+
setAttribute(button, 'data-empty', empty ? '' : null);
|
|
227
|
+
classesOf(this.getAttribute('empty-class')).forEach((name) => button.classList.toggle(name, empty));
|
|
228
|
+
if (button.disabled !== input.disabled)
|
|
229
|
+
button.disabled = input.disabled;
|
|
230
|
+
const zone = this.dropZone;
|
|
231
|
+
setAttribute(zone, 'data-disabled', input.disabled ? '' : null);
|
|
232
|
+
classesOf(this.getAttribute('disabled-class')).forEach((name) => zone.classList.toggle(name, input.disabled));
|
|
233
|
+
if (input.disabled)
|
|
234
|
+
this.setDragging(false);
|
|
235
|
+
else
|
|
236
|
+
this.renderDragging();
|
|
237
|
+
}
|
|
238
|
+
setDragging(dragging) {
|
|
239
|
+
this.dragging = dragging;
|
|
240
|
+
this.renderDragging();
|
|
241
|
+
}
|
|
242
|
+
renderDragging() {
|
|
243
|
+
const { button, dragging } = this;
|
|
244
|
+
if (!button)
|
|
245
|
+
return;
|
|
246
|
+
setAttribute(button, 'data-dragging', dragging ? '' : null);
|
|
247
|
+
classesOf(this.getAttribute('dragging-class')).forEach((name) => button.classList.toggle(name, dragging));
|
|
248
|
+
}
|
|
249
|
+
announce(name) {
|
|
250
|
+
const announcements = this.own('[data-file-upload-announcements]');
|
|
251
|
+
// Replaces the text node every time, so screen readers hear the same message again.
|
|
252
|
+
if (announcements)
|
|
253
|
+
announcements.textContent = translate(this.message(name), 0, this.locale);
|
|
254
|
+
}
|
|
255
|
+
canDrop(dataTransfer) {
|
|
256
|
+
if (dataTransfer.items.length)
|
|
257
|
+
return this.matchesCapacity(countFiles(dataTransfer.items));
|
|
258
|
+
if (dataTransfer.types.length)
|
|
259
|
+
return dataTransfer.types.includes('Files');
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
matchesCapacity(count) {
|
|
263
|
+
var _a;
|
|
264
|
+
return ((_a = this.input) === null || _a === void 0 ? void 0 : _a.multiple) ? count > 0 : count === 1;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (!customElements.get(tagName))
|
|
268
|
+
customElements.define(tagName, GovukReactFileUpload);
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/file-upload/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EACL,SAAS,EACT,yBAAyB,EACzB,yBAAyB,GAE1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEnE,MAAM,CAAC,MAAM,OAAO,GAAG,yBAAyB,CAAC;AAOjD,qCAAqC;AACrC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,gBAAgB,EAAE,gBAAgB;IAClC,uBAAuB,EAAE,EAAE,GAAG,EAAE,sBAAsB,EAAE,KAAK,EAAE,uBAAuB,EAAE;IACxF,mBAAmB,EAAE,mBAAmB;IACxC,gBAAgB,EAAE,gBAAgB;CACG,CAAC;AAExC,iDAAiD;AACjD,MAAM,UAAU,UAAU,CACxB,KAAkC,EAClC,QAAmF,EACnF,MAAe;;IAEf,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC,MAAA,QAAQ,CAAC,gBAAgB,CAAC,mCAAI,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;IAC9G,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,CAAC,CAA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;gBAAE,aAAa,CAAC,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/F,CAAC;QAEO,OAAO,CAAC,YAA0B;YACxC,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YAC3F,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM;gBAAE,OAAO,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC3E,OAAO,IAAI,CAAC;QACd,CAAC;QAEO,eAAe,CAAC,KAAa;;YACnC,OAAO,CAAA,MAAA,IAAI,CAAC,KAAK,0CAAE,QAAQ,EAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;QACxD,CAAC;KACF;IAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;AACzF,CAAC","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.js';\nimport { classesOf, setText, setAttribute } from '../utils/dom.js';\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 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"]}
|