@govuk-react/primitives 0.0.0-stage → 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/README.md +271 -2
- package/dist/accordion/element.d.ts +14 -0
- 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/auto-focus/index.d.ts +297 -0
- package/dist/auto-focus/index.js +29 -0
- package/dist/auto-focus/index.js.map +1 -0
- package/dist/autocomplete/element.d.ts +27 -0
- package/dist/autocomplete/element.js +597 -0
- package/dist/autocomplete/element.js.map +1 -0
- package/dist/autocomplete/index.d.ts +350 -0
- 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 +7 -0
- 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/choices/index.d.ts +309 -0
- package/dist/choices/index.js +37 -0
- package/dist/choices/index.js.map +1 -0
- package/dist/disclosure/element.d.ts +14 -0
- package/dist/disclosure/element.js +123 -0
- package/dist/disclosure/element.js.map +1 -0
- package/dist/disclosure/index.d.ts +307 -0
- 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/exit-this-page/index.d.ts +330 -0
- 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 +23 -0
- 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/focus-links/index.d.ts +288 -0
- package/dist/focus-links/index.js +7 -0
- package/dist/focus-links/index.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +14 -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/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 +10 -0
- 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/password-input/index.d.ts +318 -0
- package/dist/password-input/index.js +35 -0
- package/dist/password-input/index.js.map +1 -0
- package/dist/tabs/element.d.ts +19 -0
- 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/licences/accessible-autocomplete.txt +20 -0
- package/package.json +49 -4
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* <govuk-react-password-input>: a headless, light-DOM custom element that adds a show and hide
|
|
3
|
+
* button to a password field, with or without React.
|
|
4
|
+
*
|
|
5
|
+
* The input's `type` is the state, kept when React sets it again. Without JavaScript the field
|
|
6
|
+
* stays a password field and the button stays hidden. On upgrade the element shows the button, which switches the input between
|
|
7
|
+
* "password" and "text", updates its own text and label, and announces the change.
|
|
8
|
+
*
|
|
9
|
+
* Markup inside the element:
|
|
10
|
+
* - `[data-password-input]`: an `input` of type "password".
|
|
11
|
+
* - `[data-password-toggle]`: a `button` of type "button", rendered `hidden`.
|
|
12
|
+
* - `[data-password-status]` (optional): a visually hidden live region for the announcements.
|
|
13
|
+
* Without one, the element adds one after the input.
|
|
14
|
+
*
|
|
15
|
+
* Attributes, for the text (English by default):
|
|
16
|
+
* - `show-text`, `hide-text`: the button's text.
|
|
17
|
+
* - `show-label`, `hide-label`: the button's accessible name.
|
|
18
|
+
* - `shown-announcement`, `hidden-announcement`: announced when the password is shown or hidden.
|
|
19
|
+
*
|
|
20
|
+
* As in govuk-frontend, the password is hidden again when its form is submitted, unless by a hidden
|
|
21
|
+
* submit button such as a form library's, and when the page is restored from the back-forward cache.
|
|
22
|
+
*/
|
|
23
|
+
import { onPropertySet } from '../utils/on-property-set.js';
|
|
24
|
+
import { setUpWhenReady } from '../utils/set-up-when-ready.js';
|
|
25
|
+
export const tagName = 'govuk-react-password-input';
|
|
26
|
+
const defaults = {
|
|
27
|
+
'show-text': 'Show',
|
|
28
|
+
'hide-text': 'Hide',
|
|
29
|
+
'show-label': 'Show password',
|
|
30
|
+
'hide-label': 'Hide password',
|
|
31
|
+
'shown-announcement': 'Your password is visible',
|
|
32
|
+
'hidden-announcement': 'Your password is hidden',
|
|
33
|
+
};
|
|
34
|
+
// The same visually hidden styles as govuk-frontend's, for a live region the element adds itself.
|
|
35
|
+
const visuallyHidden = 'position:absolute;width:1px;height:1px;margin:0;padding:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);border:0;white-space:nowrap';
|
|
36
|
+
if (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {
|
|
37
|
+
class GovukReactPasswordInput extends HTMLElement {
|
|
38
|
+
constructor() {
|
|
39
|
+
super(...arguments);
|
|
40
|
+
this.visible = false;
|
|
41
|
+
// React sets `type` again whenever it updates a controlled input.
|
|
42
|
+
this.onTypeSet = () => {
|
|
43
|
+
const type = this.visible ? 'text' : 'password';
|
|
44
|
+
if (this.input && this.input.type !== type)
|
|
45
|
+
this.input.type = type;
|
|
46
|
+
};
|
|
47
|
+
this.onToggle = (event) => {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
this.setVisible(!this.visible);
|
|
50
|
+
};
|
|
51
|
+
// A hidden submitter isn't the user submitting, but a script, such as Conform validating as the
|
|
52
|
+
// user types.
|
|
53
|
+
this.onSubmit = (event) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const submitter = event instanceof SubmitEvent ? event.submitter : null;
|
|
56
|
+
if (event.target === ((_a = this.input) === null || _a === void 0 ? void 0 : _a.form) && !(submitter instanceof HTMLElement && submitter.hidden)) {
|
|
57
|
+
this.setVisible(false);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
this.onPageShow = (event) => {
|
|
61
|
+
if (event.persisted)
|
|
62
|
+
this.setVisible(false);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
connectedCallback() {
|
|
66
|
+
this.observer = setUpWhenReady(this, () => this.setup());
|
|
67
|
+
}
|
|
68
|
+
disconnectedCallback() {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
(_a = this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
71
|
+
(_b = this.toggle) === null || _b === void 0 ? void 0 : _b.removeEventListener('click', this.onToggle);
|
|
72
|
+
document.removeEventListener('submit', this.onSubmit);
|
|
73
|
+
window.removeEventListener('pageshow', this.onPageShow);
|
|
74
|
+
(_c = this.stopWatchingType) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
75
|
+
this.input = undefined;
|
|
76
|
+
this.toggle = undefined;
|
|
77
|
+
}
|
|
78
|
+
text(name) {
|
|
79
|
+
var _a;
|
|
80
|
+
return (_a = this.getAttribute(name)) !== null && _a !== void 0 ? _a : defaults[name];
|
|
81
|
+
}
|
|
82
|
+
own(selector, type) {
|
|
83
|
+
const element = this.querySelector(selector);
|
|
84
|
+
return element instanceof type && element.closest(tagName) === this ? element : undefined;
|
|
85
|
+
}
|
|
86
|
+
setup() {
|
|
87
|
+
if (this.input)
|
|
88
|
+
return true;
|
|
89
|
+
const input = this.own('[data-password-input]', HTMLInputElement);
|
|
90
|
+
const toggle = this.own('[data-password-toggle]', HTMLButtonElement);
|
|
91
|
+
if (!input || !toggle)
|
|
92
|
+
return false;
|
|
93
|
+
this.input = input;
|
|
94
|
+
this.toggle = toggle;
|
|
95
|
+
this.status = this.own('[data-password-status]', HTMLElement);
|
|
96
|
+
if (!this.status) {
|
|
97
|
+
this.status = document.createElement('div');
|
|
98
|
+
this.status.dataset.passwordStatus = '';
|
|
99
|
+
this.status.setAttribute('aria-live', 'polite');
|
|
100
|
+
this.status.setAttribute('style', visuallyHidden);
|
|
101
|
+
input.insertAdjacentElement('afterend', this.status);
|
|
102
|
+
}
|
|
103
|
+
toggle.hidden = false;
|
|
104
|
+
toggle.addEventListener('click', this.onToggle);
|
|
105
|
+
document.addEventListener('submit', this.onSubmit);
|
|
106
|
+
window.addEventListener('pageshow', this.onPageShow);
|
|
107
|
+
// Start hidden, with the text set but nothing announced.
|
|
108
|
+
this.visible = false;
|
|
109
|
+
input.type = 'password';
|
|
110
|
+
this.stopWatchingType = onPropertySet(input, 'type', this.onTypeSet);
|
|
111
|
+
this.label(false);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
setVisible(visible) {
|
|
115
|
+
const { input } = this;
|
|
116
|
+
if (!input || visible === this.visible)
|
|
117
|
+
return;
|
|
118
|
+
this.visible = visible;
|
|
119
|
+
input.type = visible ? 'text' : 'password';
|
|
120
|
+
this.label(visible);
|
|
121
|
+
if (this.status)
|
|
122
|
+
this.status.textContent = this.text(visible ? 'shown-announcement' : 'hidden-announcement');
|
|
123
|
+
}
|
|
124
|
+
label(visible) {
|
|
125
|
+
if (!this.toggle)
|
|
126
|
+
return;
|
|
127
|
+
this.toggle.textContent = this.text(visible ? 'hide-text' : 'show-text');
|
|
128
|
+
this.toggle.setAttribute('aria-label', this.text(visible ? 'hide-label' : 'show-label'));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!customElements.get(tagName))
|
|
132
|
+
customElements.define(tagName, GovukReactPasswordInput);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,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AE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;QAC3F,CAAC;KACF;IAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["/*\n * <govuk-react-password-input>: a headless, light-DOM custom element that adds a show and hide\n * button to a password field, with or without React.\n *\n * The input's `type` is the state, kept when React sets it again. Without JavaScript the field\n * stays a password field and the button stays hidden. On upgrade the element shows the button, which switches the input between\n * \"password\" and \"text\", updates its own text and label, and announces the change.\n *\n * Markup inside the element:\n * - `[data-password-input]`: an `input` of type \"password\".\n * - `[data-password-toggle]`: a `button` of type \"button\", rendered `hidden`.\n * - `[data-password-status]` (optional): a visually hidden live region for the announcements.\n * Without one, the element adds one after the input.\n *\n * Attributes, for the text (English by default):\n * - `show-text`, `hide-text`: the button's text.\n * - `show-label`, `hide-label`: the button's accessible name.\n * - `shown-announcement`, `hidden-announcement`: announced when the password is shown or hidden.\n *\n * As in govuk-frontend, the password is hidden again when its form is submitted, unless by a hidden\n * submit button such as a form library's, and when the page is restored from the back-forward cache.\n */\n\nimport { onPropertySet } from '../utils/on-property-set.js';\nimport { setUpWhenReady } from '../utils/set-up-when-ready.js';\n\nexport const tagName = 'govuk-react-password-input';\n\nconst defaults = {\n 'show-text': 'Show',\n 'hide-text': 'Hide',\n 'show-label': 'Show password',\n 'hide-label': 'Hide password',\n 'shown-announcement': 'Your password is visible',\n 'hidden-announcement': 'Your password is hidden',\n};\n\n// The same visually hidden styles as govuk-frontend's, for a live region the element adds itself.\nconst visuallyHidden =\n 'position:absolute;width:1px;height:1px;margin:0;padding:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);border:0;white-space:nowrap';\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactPasswordInput extends HTMLElement {\n private input?: HTMLInputElement;\n\n private toggle?: HTMLButtonElement;\n\n private status?: HTMLElement;\n\n private observer?: MutationObserver;\n\n private visible = false;\n\n private stopWatchingType?: () => void;\n\n // React sets `type` again whenever it updates a controlled input.\n private readonly onTypeSet = () => {\n const type = this.visible ? 'text' : 'password';\n if (this.input && this.input.type !== type) this.input.type = type;\n };\n\n private readonly onToggle = (event: MouseEvent) => {\n event.preventDefault();\n this.setVisible(!this.visible);\n };\n\n // A hidden submitter isn't the user submitting, but a script, such as Conform validating as the\n // user types.\n private readonly onSubmit = (event: Event) => {\n const submitter = event instanceof SubmitEvent ? event.submitter : null;\n if (event.target === this.input?.form && !(submitter instanceof HTMLElement && submitter.hidden)) {\n this.setVisible(false);\n }\n };\n\n private readonly onPageShow = (event: PageTransitionEvent) => {\n if (event.persisted) this.setVisible(false);\n };\n\n connectedCallback() {\n this.observer = setUpWhenReady(this, () => this.setup());\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n this.toggle?.removeEventListener('click', this.onToggle);\n document.removeEventListener('submit', this.onSubmit);\n window.removeEventListener('pageshow', this.onPageShow);\n this.stopWatchingType?.();\n this.input = undefined;\n this.toggle = undefined;\n }\n\n private text(name: keyof typeof defaults) {\n return this.getAttribute(name) ?? defaults[name];\n }\n\n private own<E extends Element>(selector: string, type: new () => E): E | undefined {\n const element = this.querySelector(selector);\n return element instanceof type && element.closest(tagName) === this ? element : undefined;\n }\n\n private setup() {\n if (this.input) return true;\n const input = this.own('[data-password-input]', HTMLInputElement);\n const toggle = this.own('[data-password-toggle]', HTMLButtonElement);\n if (!input || !toggle) return false;\n this.input = input;\n this.toggle = toggle;\n this.status = this.own('[data-password-status]', HTMLElement);\n if (!this.status) {\n this.status = document.createElement('div');\n this.status.dataset.passwordStatus = '';\n this.status.setAttribute('aria-live', 'polite');\n this.status.setAttribute('style', visuallyHidden);\n input.insertAdjacentElement('afterend', this.status);\n }\n toggle.hidden = false;\n toggle.addEventListener('click', this.onToggle);\n document.addEventListener('submit', this.onSubmit);\n window.addEventListener('pageshow', this.onPageShow);\n // Start hidden, with the text set but nothing announced.\n this.visible = false;\n input.type = 'password';\n this.stopWatchingType = onPropertySet(input, 'type', this.onTypeSet);\n this.label(false);\n return true;\n }\n\n private setVisible(visible: boolean) {\n const { input } = this;\n if (!input || visible === this.visible) return;\n this.visible = visible;\n input.type = visible ? 'text' : 'password';\n this.label(visible);\n if (this.status) this.status.textContent = this.text(visible ? 'shown-announcement' : 'hidden-announcement');\n }\n\n private label(visible: boolean) {\n if (!this.toggle) return;\n this.toggle.textContent = this.text(visible ? 'hide-text' : 'show-text');\n this.toggle.setAttribute('aria-label', this.text(visible ? 'hide-label' : 'show-label'));\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactPasswordInput);\n}\n"]}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
export type RootProps = React.HTMLAttributes<HTMLElement> & {
|
|
4
|
+
/** The button's text when the password is hidden. Defaults to "Show". */
|
|
5
|
+
showText?: string;
|
|
6
|
+
/** The button's text when the password is visible. Defaults to "Hide". */
|
|
7
|
+
hideText?: string;
|
|
8
|
+
/** The button's accessible name when the password is hidden. Defaults to "Show password". */
|
|
9
|
+
showLabel?: string;
|
|
10
|
+
/** The button's accessible name when the password is visible. Defaults to "Hide password". */
|
|
11
|
+
hideLabel?: string;
|
|
12
|
+
/** Announced when the password becomes visible. Defaults to "Your password is visible". */
|
|
13
|
+
shownAnnouncement?: string;
|
|
14
|
+
/** Announced when the password is hidden. Defaults to "Your password is hidden". */
|
|
15
|
+
hiddenAnnouncement?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function Root({ showText, hideText, showLabel, hideLabel, shownAnnouncement, hiddenAnnouncement, ...props }: RootProps): React.DOMElement<{
|
|
18
|
+
'show-text': string;
|
|
19
|
+
'hide-text': string;
|
|
20
|
+
'show-label': string;
|
|
21
|
+
'hide-label': string;
|
|
22
|
+
'shown-announcement': string;
|
|
23
|
+
'hidden-announcement': string;
|
|
24
|
+
defaultChecked?: boolean;
|
|
25
|
+
defaultValue?: string | number | readonly string[];
|
|
26
|
+
suppressContentEditableWarning?: boolean;
|
|
27
|
+
suppressHydrationWarning?: boolean;
|
|
28
|
+
accessKey?: string;
|
|
29
|
+
autoCapitalize?: "off" | "none" | "on" | "sentences" | "words" | "characters" | (string & {});
|
|
30
|
+
autoFocus?: boolean;
|
|
31
|
+
className?: string;
|
|
32
|
+
contentEditable?: (boolean | "false" | "true") | "inherit" | "plaintext-only";
|
|
33
|
+
contextMenu?: string;
|
|
34
|
+
dir?: string;
|
|
35
|
+
draggable?: boolean | "false" | "true";
|
|
36
|
+
enterKeyHint?: "search" | "enter" | "done" | "go" | "next" | "previous" | "send";
|
|
37
|
+
hidden?: boolean;
|
|
38
|
+
id?: string;
|
|
39
|
+
lang?: string;
|
|
40
|
+
nonce?: string;
|
|
41
|
+
slot?: string;
|
|
42
|
+
spellCheck?: boolean | "false" | "true";
|
|
43
|
+
style?: React.CSSProperties;
|
|
44
|
+
tabIndex?: number;
|
|
45
|
+
title?: string;
|
|
46
|
+
translate?: "yes" | "no";
|
|
47
|
+
radioGroup?: string;
|
|
48
|
+
role?: React.AriaRole;
|
|
49
|
+
about?: string;
|
|
50
|
+
content?: string;
|
|
51
|
+
datatype?: string;
|
|
52
|
+
inlist?: any;
|
|
53
|
+
prefix?: string;
|
|
54
|
+
property?: string;
|
|
55
|
+
rel?: string;
|
|
56
|
+
resource?: string;
|
|
57
|
+
rev?: string;
|
|
58
|
+
typeof?: string;
|
|
59
|
+
vocab?: string;
|
|
60
|
+
autoCorrect?: string;
|
|
61
|
+
autoSave?: string;
|
|
62
|
+
color?: string;
|
|
63
|
+
itemProp?: string;
|
|
64
|
+
itemScope?: boolean;
|
|
65
|
+
itemType?: string;
|
|
66
|
+
itemID?: string;
|
|
67
|
+
itemRef?: string;
|
|
68
|
+
results?: number;
|
|
69
|
+
security?: string;
|
|
70
|
+
unselectable?: "off" | "on";
|
|
71
|
+
popover?: "" | "auto" | "manual" | "hint";
|
|
72
|
+
popoverTargetAction?: "toggle" | "show" | "hide";
|
|
73
|
+
popoverTarget?: string;
|
|
74
|
+
inert?: boolean;
|
|
75
|
+
inputMode?: "search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal";
|
|
76
|
+
is?: string;
|
|
77
|
+
exportparts?: string;
|
|
78
|
+
part?: string;
|
|
79
|
+
"aria-activedescendant"?: string;
|
|
80
|
+
"aria-atomic"?: boolean | "false" | "true";
|
|
81
|
+
"aria-autocomplete"?: "none" | "list" | "inline" | "both";
|
|
82
|
+
"aria-braillelabel"?: string;
|
|
83
|
+
"aria-brailleroledescription"?: string;
|
|
84
|
+
"aria-busy"?: boolean | "false" | "true";
|
|
85
|
+
"aria-checked"?: boolean | "false" | "true" | "mixed";
|
|
86
|
+
"aria-colcount"?: number;
|
|
87
|
+
"aria-colindex"?: number;
|
|
88
|
+
"aria-colindextext"?: string;
|
|
89
|
+
"aria-colspan"?: number;
|
|
90
|
+
"aria-controls"?: string;
|
|
91
|
+
"aria-current"?: boolean | "time" | "false" | "true" | "page" | "step" | "location" | "date";
|
|
92
|
+
"aria-describedby"?: string;
|
|
93
|
+
"aria-description"?: string;
|
|
94
|
+
"aria-details"?: string;
|
|
95
|
+
"aria-disabled"?: boolean | "false" | "true";
|
|
96
|
+
"aria-dropeffect"?: "link" | "copy" | "none" | "execute" | "move" | "popup";
|
|
97
|
+
"aria-errormessage"?: string;
|
|
98
|
+
"aria-expanded"?: boolean | "false" | "true";
|
|
99
|
+
"aria-flowto"?: string;
|
|
100
|
+
"aria-grabbed"?: boolean | "false" | "true";
|
|
101
|
+
"aria-haspopup"?: boolean | "dialog" | "menu" | "false" | "true" | "grid" | "listbox" | "tree";
|
|
102
|
+
"aria-hidden"?: boolean | "false" | "true";
|
|
103
|
+
"aria-invalid"?: boolean | "false" | "true" | "grammar" | "spelling";
|
|
104
|
+
"aria-keyshortcuts"?: string;
|
|
105
|
+
"aria-label"?: string;
|
|
106
|
+
"aria-labelledby"?: string;
|
|
107
|
+
"aria-level"?: number;
|
|
108
|
+
"aria-live"?: "off" | "assertive" | "polite";
|
|
109
|
+
"aria-modal"?: boolean | "false" | "true";
|
|
110
|
+
"aria-multiline"?: boolean | "false" | "true";
|
|
111
|
+
"aria-multiselectable"?: boolean | "false" | "true";
|
|
112
|
+
"aria-orientation"?: "horizontal" | "vertical";
|
|
113
|
+
"aria-owns"?: string;
|
|
114
|
+
"aria-placeholder"?: string;
|
|
115
|
+
"aria-posinset"?: number;
|
|
116
|
+
"aria-pressed"?: boolean | "false" | "true" | "mixed";
|
|
117
|
+
"aria-readonly"?: boolean | "false" | "true";
|
|
118
|
+
"aria-relevant"?: "text" | "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals";
|
|
119
|
+
"aria-required"?: boolean | "false" | "true";
|
|
120
|
+
"aria-roledescription"?: string;
|
|
121
|
+
"aria-rowcount"?: number;
|
|
122
|
+
"aria-rowindex"?: number;
|
|
123
|
+
"aria-rowindextext"?: string;
|
|
124
|
+
"aria-rowspan"?: number;
|
|
125
|
+
"aria-selected"?: boolean | "false" | "true";
|
|
126
|
+
"aria-setsize"?: number;
|
|
127
|
+
"aria-sort"?: "none" | "ascending" | "descending" | "other";
|
|
128
|
+
"aria-valuemax"?: number;
|
|
129
|
+
"aria-valuemin"?: number;
|
|
130
|
+
"aria-valuenow"?: number;
|
|
131
|
+
"aria-valuetext"?: string;
|
|
132
|
+
children?: React.ReactNode;
|
|
133
|
+
dangerouslySetInnerHTML?: {
|
|
134
|
+
__html: string | TrustedHTML;
|
|
135
|
+
};
|
|
136
|
+
onCopy?: React.ClipboardEventHandler<HTMLElement>;
|
|
137
|
+
onCopyCapture?: React.ClipboardEventHandler<HTMLElement>;
|
|
138
|
+
onCut?: React.ClipboardEventHandler<HTMLElement>;
|
|
139
|
+
onCutCapture?: React.ClipboardEventHandler<HTMLElement>;
|
|
140
|
+
onPaste?: React.ClipboardEventHandler<HTMLElement>;
|
|
141
|
+
onPasteCapture?: React.ClipboardEventHandler<HTMLElement>;
|
|
142
|
+
onCompositionEnd?: React.CompositionEventHandler<HTMLElement>;
|
|
143
|
+
onCompositionEndCapture?: React.CompositionEventHandler<HTMLElement>;
|
|
144
|
+
onCompositionStart?: React.CompositionEventHandler<HTMLElement>;
|
|
145
|
+
onCompositionStartCapture?: React.CompositionEventHandler<HTMLElement>;
|
|
146
|
+
onCompositionUpdate?: React.CompositionEventHandler<HTMLElement>;
|
|
147
|
+
onCompositionUpdateCapture?: React.CompositionEventHandler<HTMLElement>;
|
|
148
|
+
onFocus?: React.FocusEventHandler<HTMLElement>;
|
|
149
|
+
onFocusCapture?: React.FocusEventHandler<HTMLElement>;
|
|
150
|
+
onBlur?: React.FocusEventHandler<HTMLElement>;
|
|
151
|
+
onBlurCapture?: React.FocusEventHandler<HTMLElement>;
|
|
152
|
+
onChange?: React.ChangeEventHandler<HTMLElement, Element>;
|
|
153
|
+
onChangeCapture?: React.ChangeEventHandler<HTMLElement, Element>;
|
|
154
|
+
onBeforeInput?: React.InputEventHandler<HTMLElement>;
|
|
155
|
+
onBeforeInputCapture?: React.InputEventHandler<HTMLElement>;
|
|
156
|
+
onInput?: React.InputEventHandler<HTMLElement>;
|
|
157
|
+
onInputCapture?: React.InputEventHandler<HTMLElement>;
|
|
158
|
+
onReset?: React.ReactEventHandler<HTMLElement>;
|
|
159
|
+
onResetCapture?: React.ReactEventHandler<HTMLElement>;
|
|
160
|
+
onSubmit?: React.SubmitEventHandler<HTMLElement>;
|
|
161
|
+
onSubmitCapture?: React.SubmitEventHandler<HTMLElement>;
|
|
162
|
+
onInvalid?: React.ReactEventHandler<HTMLElement>;
|
|
163
|
+
onInvalidCapture?: React.ReactEventHandler<HTMLElement>;
|
|
164
|
+
onLoad?: React.ReactEventHandler<HTMLElement>;
|
|
165
|
+
onLoadCapture?: React.ReactEventHandler<HTMLElement>;
|
|
166
|
+
onError?: React.ReactEventHandler<HTMLElement>;
|
|
167
|
+
onErrorCapture?: React.ReactEventHandler<HTMLElement>;
|
|
168
|
+
onKeyDown?: React.KeyboardEventHandler<HTMLElement>;
|
|
169
|
+
onKeyDownCapture?: React.KeyboardEventHandler<HTMLElement>;
|
|
170
|
+
onKeyPress?: React.KeyboardEventHandler<HTMLElement>;
|
|
171
|
+
onKeyPressCapture?: React.KeyboardEventHandler<HTMLElement>;
|
|
172
|
+
onKeyUp?: React.KeyboardEventHandler<HTMLElement>;
|
|
173
|
+
onKeyUpCapture?: React.KeyboardEventHandler<HTMLElement>;
|
|
174
|
+
onAbort?: React.ReactEventHandler<HTMLElement>;
|
|
175
|
+
onAbortCapture?: React.ReactEventHandler<HTMLElement>;
|
|
176
|
+
onCanPlay?: React.ReactEventHandler<HTMLElement>;
|
|
177
|
+
onCanPlayCapture?: React.ReactEventHandler<HTMLElement>;
|
|
178
|
+
onCanPlayThrough?: React.ReactEventHandler<HTMLElement>;
|
|
179
|
+
onCanPlayThroughCapture?: React.ReactEventHandler<HTMLElement>;
|
|
180
|
+
onDurationChange?: React.ReactEventHandler<HTMLElement>;
|
|
181
|
+
onDurationChangeCapture?: React.ReactEventHandler<HTMLElement>;
|
|
182
|
+
onEmptied?: React.ReactEventHandler<HTMLElement>;
|
|
183
|
+
onEmptiedCapture?: React.ReactEventHandler<HTMLElement>;
|
|
184
|
+
onEncrypted?: React.ReactEventHandler<HTMLElement>;
|
|
185
|
+
onEncryptedCapture?: React.ReactEventHandler<HTMLElement>;
|
|
186
|
+
onEnded?: React.ReactEventHandler<HTMLElement>;
|
|
187
|
+
onEndedCapture?: React.ReactEventHandler<HTMLElement>;
|
|
188
|
+
onLoadedData?: React.ReactEventHandler<HTMLElement>;
|
|
189
|
+
onLoadedDataCapture?: React.ReactEventHandler<HTMLElement>;
|
|
190
|
+
onLoadedMetadata?: React.ReactEventHandler<HTMLElement>;
|
|
191
|
+
onLoadedMetadataCapture?: React.ReactEventHandler<HTMLElement>;
|
|
192
|
+
onLoadStart?: React.ReactEventHandler<HTMLElement>;
|
|
193
|
+
onLoadStartCapture?: React.ReactEventHandler<HTMLElement>;
|
|
194
|
+
onPause?: React.ReactEventHandler<HTMLElement>;
|
|
195
|
+
onPauseCapture?: React.ReactEventHandler<HTMLElement>;
|
|
196
|
+
onPlay?: React.ReactEventHandler<HTMLElement>;
|
|
197
|
+
onPlayCapture?: React.ReactEventHandler<HTMLElement>;
|
|
198
|
+
onPlaying?: React.ReactEventHandler<HTMLElement>;
|
|
199
|
+
onPlayingCapture?: React.ReactEventHandler<HTMLElement>;
|
|
200
|
+
onProgress?: React.ReactEventHandler<HTMLElement>;
|
|
201
|
+
onProgressCapture?: React.ReactEventHandler<HTMLElement>;
|
|
202
|
+
onRateChange?: React.ReactEventHandler<HTMLElement>;
|
|
203
|
+
onRateChangeCapture?: React.ReactEventHandler<HTMLElement>;
|
|
204
|
+
onSeeked?: React.ReactEventHandler<HTMLElement>;
|
|
205
|
+
onSeekedCapture?: React.ReactEventHandler<HTMLElement>;
|
|
206
|
+
onSeeking?: React.ReactEventHandler<HTMLElement>;
|
|
207
|
+
onSeekingCapture?: React.ReactEventHandler<HTMLElement>;
|
|
208
|
+
onStalled?: React.ReactEventHandler<HTMLElement>;
|
|
209
|
+
onStalledCapture?: React.ReactEventHandler<HTMLElement>;
|
|
210
|
+
onSuspend?: React.ReactEventHandler<HTMLElement>;
|
|
211
|
+
onSuspendCapture?: React.ReactEventHandler<HTMLElement>;
|
|
212
|
+
onTimeUpdate?: React.ReactEventHandler<HTMLElement>;
|
|
213
|
+
onTimeUpdateCapture?: React.ReactEventHandler<HTMLElement>;
|
|
214
|
+
onVolumeChange?: React.ReactEventHandler<HTMLElement>;
|
|
215
|
+
onVolumeChangeCapture?: React.ReactEventHandler<HTMLElement>;
|
|
216
|
+
onWaiting?: React.ReactEventHandler<HTMLElement>;
|
|
217
|
+
onWaitingCapture?: React.ReactEventHandler<HTMLElement>;
|
|
218
|
+
onAuxClick?: React.MouseEventHandler<HTMLElement>;
|
|
219
|
+
onAuxClickCapture?: React.MouseEventHandler<HTMLElement>;
|
|
220
|
+
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
221
|
+
onClickCapture?: React.MouseEventHandler<HTMLElement>;
|
|
222
|
+
onContextMenu?: React.MouseEventHandler<HTMLElement>;
|
|
223
|
+
onContextMenuCapture?: React.MouseEventHandler<HTMLElement>;
|
|
224
|
+
onDoubleClick?: React.MouseEventHandler<HTMLElement>;
|
|
225
|
+
onDoubleClickCapture?: React.MouseEventHandler<HTMLElement>;
|
|
226
|
+
onDrag?: React.DragEventHandler<HTMLElement>;
|
|
227
|
+
onDragCapture?: React.DragEventHandler<HTMLElement>;
|
|
228
|
+
onDragEnd?: React.DragEventHandler<HTMLElement>;
|
|
229
|
+
onDragEndCapture?: React.DragEventHandler<HTMLElement>;
|
|
230
|
+
onDragEnter?: React.DragEventHandler<HTMLElement>;
|
|
231
|
+
onDragEnterCapture?: React.DragEventHandler<HTMLElement>;
|
|
232
|
+
onDragExit?: React.DragEventHandler<HTMLElement>;
|
|
233
|
+
onDragExitCapture?: React.DragEventHandler<HTMLElement>;
|
|
234
|
+
onDragLeave?: React.DragEventHandler<HTMLElement>;
|
|
235
|
+
onDragLeaveCapture?: React.DragEventHandler<HTMLElement>;
|
|
236
|
+
onDragOver?: React.DragEventHandler<HTMLElement>;
|
|
237
|
+
onDragOverCapture?: React.DragEventHandler<HTMLElement>;
|
|
238
|
+
onDragStart?: React.DragEventHandler<HTMLElement>;
|
|
239
|
+
onDragStartCapture?: React.DragEventHandler<HTMLElement>;
|
|
240
|
+
onDrop?: React.DragEventHandler<HTMLElement>;
|
|
241
|
+
onDropCapture?: React.DragEventHandler<HTMLElement>;
|
|
242
|
+
onMouseDown?: React.MouseEventHandler<HTMLElement>;
|
|
243
|
+
onMouseDownCapture?: React.MouseEventHandler<HTMLElement>;
|
|
244
|
+
onMouseEnter?: React.MouseEventHandler<HTMLElement>;
|
|
245
|
+
onMouseLeave?: React.MouseEventHandler<HTMLElement>;
|
|
246
|
+
onMouseMove?: React.MouseEventHandler<HTMLElement>;
|
|
247
|
+
onMouseMoveCapture?: React.MouseEventHandler<HTMLElement>;
|
|
248
|
+
onMouseOut?: React.MouseEventHandler<HTMLElement>;
|
|
249
|
+
onMouseOutCapture?: React.MouseEventHandler<HTMLElement>;
|
|
250
|
+
onMouseOver?: React.MouseEventHandler<HTMLElement>;
|
|
251
|
+
onMouseOverCapture?: React.MouseEventHandler<HTMLElement>;
|
|
252
|
+
onMouseUp?: React.MouseEventHandler<HTMLElement>;
|
|
253
|
+
onMouseUpCapture?: React.MouseEventHandler<HTMLElement>;
|
|
254
|
+
onSelect?: React.ReactEventHandler<HTMLElement>;
|
|
255
|
+
onSelectCapture?: React.ReactEventHandler<HTMLElement>;
|
|
256
|
+
onTouchCancel?: React.TouchEventHandler<HTMLElement>;
|
|
257
|
+
onTouchCancelCapture?: React.TouchEventHandler<HTMLElement>;
|
|
258
|
+
onTouchEnd?: React.TouchEventHandler<HTMLElement>;
|
|
259
|
+
onTouchEndCapture?: React.TouchEventHandler<HTMLElement>;
|
|
260
|
+
onTouchMove?: React.TouchEventHandler<HTMLElement>;
|
|
261
|
+
onTouchMoveCapture?: React.TouchEventHandler<HTMLElement>;
|
|
262
|
+
onTouchStart?: React.TouchEventHandler<HTMLElement>;
|
|
263
|
+
onTouchStartCapture?: React.TouchEventHandler<HTMLElement>;
|
|
264
|
+
onPointerDown?: React.PointerEventHandler<HTMLElement>;
|
|
265
|
+
onPointerDownCapture?: React.PointerEventHandler<HTMLElement>;
|
|
266
|
+
onPointerMove?: React.PointerEventHandler<HTMLElement>;
|
|
267
|
+
onPointerMoveCapture?: React.PointerEventHandler<HTMLElement>;
|
|
268
|
+
onPointerUp?: React.PointerEventHandler<HTMLElement>;
|
|
269
|
+
onPointerUpCapture?: React.PointerEventHandler<HTMLElement>;
|
|
270
|
+
onPointerCancel?: React.PointerEventHandler<HTMLElement>;
|
|
271
|
+
onPointerCancelCapture?: React.PointerEventHandler<HTMLElement>;
|
|
272
|
+
onPointerEnter?: React.PointerEventHandler<HTMLElement>;
|
|
273
|
+
onPointerLeave?: React.PointerEventHandler<HTMLElement>;
|
|
274
|
+
onPointerOver?: React.PointerEventHandler<HTMLElement>;
|
|
275
|
+
onPointerOverCapture?: React.PointerEventHandler<HTMLElement>;
|
|
276
|
+
onPointerOut?: React.PointerEventHandler<HTMLElement>;
|
|
277
|
+
onPointerOutCapture?: React.PointerEventHandler<HTMLElement>;
|
|
278
|
+
onGotPointerCapture?: React.PointerEventHandler<HTMLElement>;
|
|
279
|
+
onGotPointerCaptureCapture?: React.PointerEventHandler<HTMLElement>;
|
|
280
|
+
onLostPointerCapture?: React.PointerEventHandler<HTMLElement>;
|
|
281
|
+
onLostPointerCaptureCapture?: React.PointerEventHandler<HTMLElement>;
|
|
282
|
+
onScroll?: React.UIEventHandler<HTMLElement>;
|
|
283
|
+
onScrollCapture?: React.UIEventHandler<HTMLElement>;
|
|
284
|
+
onScrollEnd?: React.UIEventHandler<HTMLElement>;
|
|
285
|
+
onScrollEndCapture?: React.UIEventHandler<HTMLElement>;
|
|
286
|
+
onWheel?: React.WheelEventHandler<HTMLElement>;
|
|
287
|
+
onWheelCapture?: React.WheelEventHandler<HTMLElement>;
|
|
288
|
+
onAnimationStart?: React.AnimationEventHandler<HTMLElement>;
|
|
289
|
+
onAnimationStartCapture?: React.AnimationEventHandler<HTMLElement>;
|
|
290
|
+
onAnimationEnd?: React.AnimationEventHandler<HTMLElement>;
|
|
291
|
+
onAnimationEndCapture?: React.AnimationEventHandler<HTMLElement>;
|
|
292
|
+
onAnimationIteration?: React.AnimationEventHandler<HTMLElement>;
|
|
293
|
+
onAnimationIterationCapture?: React.AnimationEventHandler<HTMLElement>;
|
|
294
|
+
onToggle?: React.ToggleEventHandler<HTMLElement>;
|
|
295
|
+
onBeforeToggle?: React.ToggleEventHandler<HTMLElement>;
|
|
296
|
+
onTransitionCancel?: React.TransitionEventHandler<HTMLElement>;
|
|
297
|
+
onTransitionCancelCapture?: React.TransitionEventHandler<HTMLElement>;
|
|
298
|
+
onTransitionEnd?: React.TransitionEventHandler<HTMLElement>;
|
|
299
|
+
onTransitionEndCapture?: React.TransitionEventHandler<HTMLElement>;
|
|
300
|
+
onTransitionRun?: React.TransitionEventHandler<HTMLElement>;
|
|
301
|
+
onTransitionRunCapture?: React.TransitionEventHandler<HTMLElement>;
|
|
302
|
+
onTransitionStart?: React.TransitionEventHandler<HTMLElement>;
|
|
303
|
+
onTransitionStartCapture?: React.TransitionEventHandler<HTMLElement>;
|
|
304
|
+
}, Element>;
|
|
305
|
+
type PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {
|
|
306
|
+
/** Render the only child instead, with this part's props merged onto it. */
|
|
307
|
+
asChild?: boolean;
|
|
308
|
+
};
|
|
309
|
+
export type InputProps = PartProps<'input'>;
|
|
310
|
+
/** The password field. Its `type` starts as "password" and the element switches it. */
|
|
311
|
+
export declare function Input({ asChild, ...props }: InputProps): React.JSX.Element;
|
|
312
|
+
export type ToggleProps = PartProps<'button'>;
|
|
313
|
+
/** The show and hide button. Hidden until the element upgrades, which then sets its text and label. */
|
|
314
|
+
export declare function Toggle({ asChild, children, ...props }: ToggleProps): React.JSX.Element;
|
|
315
|
+
export type StatusProps = PartProps<'div'>;
|
|
316
|
+
/** A live region for the announcements. Make it visually hidden. */
|
|
317
|
+
export declare function Status({ asChild, ...props }: StatusProps): React.JSX.Element;
|
|
318
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Slot } from '../utils/slot.js';
|
|
4
|
+
import { tagName } from './element.js';
|
|
5
|
+
export function Root({ showText, hideText, showLabel, hideLabel, shownAnnouncement, hiddenAnnouncement, ...props }) {
|
|
6
|
+
return React.createElement(tagName, {
|
|
7
|
+
...props,
|
|
8
|
+
'show-text': showText,
|
|
9
|
+
'hide-text': hideText,
|
|
10
|
+
'show-label': showLabel,
|
|
11
|
+
'hide-label': hideLabel,
|
|
12
|
+
'shown-announcement': shownAnnouncement,
|
|
13
|
+
'hidden-announcement': hiddenAnnouncement,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** The password field. Its `type` starts as "password" and the element switches it. */
|
|
17
|
+
export function Input({ asChild, ...props }) {
|
|
18
|
+
if (asChild)
|
|
19
|
+
return React.createElement(Slot, { "data-password-input": "", suppressHydrationWarning: true, ...props });
|
|
20
|
+
// The element sets `type` after upgrade, so it can differ from the server's.
|
|
21
|
+
return React.createElement("input", { type: "password", "data-password-input": "", suppressHydrationWarning: true, ...props });
|
|
22
|
+
}
|
|
23
|
+
/** The show and hide button. Hidden until the element upgrades, which then sets its text and label. */
|
|
24
|
+
export function Toggle({ asChild, children = 'Show', ...props }) {
|
|
25
|
+
const shared = { 'data-password-toggle': '', hidden: true, suppressHydrationWarning: true };
|
|
26
|
+
if (asChild)
|
|
27
|
+
return (React.createElement(Slot, { ...shared, ...props }, children));
|
|
28
|
+
return (React.createElement("button", { type: "button", "aria-label": "Show password", ...shared, ...props }, children));
|
|
29
|
+
}
|
|
30
|
+
/** A live region for the announcements. Make it visually hidden. */
|
|
31
|
+
export function Status({ asChild, ...props }) {
|
|
32
|
+
const Element = asChild ? Slot : 'div';
|
|
33
|
+
return React.createElement(Element, { "data-password-status": "", "aria-live": "polite", suppressHydrationWarning: true, ...props });
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/password-input/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,OAA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AAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IACvC,OAAO,oBAAC,OAAO,4BAAsB,EAAE,eAAW,QAAQ,EAAC,wBAAwB,WAAK,KAAK,GAAI,CAAC;AACpG,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\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"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface HTMLElementEventMap {
|
|
3
|
+
'govuk-react-tabs:change': CustomEvent<{
|
|
4
|
+
value: string;
|
|
5
|
+
}>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare const tagName = "govuk-react-tabs";
|
|
9
|
+
export interface TabsElement extends HTMLElement {
|
|
10
|
+
/** The selected tab's value, once upgraded. */
|
|
11
|
+
readonly selectedValue: string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The tab the user picked before React hydrated, through the no-JS fallback, the URL hash or
|
|
14
|
+
* the upgraded tabs, when it differs from the tab that would otherwise be selected.
|
|
15
|
+
*/
|
|
16
|
+
readonly pickedValue: string | undefined;
|
|
17
|
+
/** Select a tab without reporting a change, such as to apply a controlled value. */
|
|
18
|
+
select(value: string): void;
|
|
19
|
+
}
|