@firstprateek/vastu 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +51 -2
- package/custom-elements.json +3046 -0
- package/dist/dev/all.d.ts +9 -0
- package/dist/dev/all.d.ts.map +1 -0
- package/dist/dev/all.js +10 -0
- package/dist/dev/all.js.map +1 -0
- package/dist/dev/button/button.d.ts +98 -0
- package/dist/dev/button/button.d.ts.map +1 -0
- package/dist/dev/button/button.js +292 -0
- package/dist/dev/button/button.js.map +1 -0
- package/dist/dev/button/index.d.ts +4 -0
- package/dist/dev/button/index.d.ts.map +1 -0
- package/dist/dev/button/index.js +5 -0
- package/dist/dev/button/index.js.map +1 -0
- package/dist/dev/checkbox/checkbox.d.ts +71 -0
- package/dist/dev/checkbox/checkbox.d.ts.map +1 -0
- package/dist/dev/checkbox/checkbox.js +232 -0
- package/dist/dev/checkbox/checkbox.js.map +1 -0
- package/dist/dev/checkbox/index.d.ts +3 -0
- package/dist/dev/checkbox/index.d.ts.map +1 -0
- package/dist/dev/checkbox/index.js +5 -0
- package/dist/dev/checkbox/index.js.map +1 -0
- package/dist/dev/core/define.d.ts +3 -0
- package/dist/dev/core/define.d.ts.map +1 -0
- package/dist/dev/core/define.js +6 -0
- package/dist/dev/core/define.js.map +1 -0
- package/dist/dev/core/dev-mode.d.ts +6 -0
- package/dist/dev/core/dev-mode.d.ts.map +1 -0
- package/dist/dev/core/dev-mode.js +6 -0
- package/dist/dev/core/dev-mode.js.map +1 -0
- package/dist/dev/core/focus-ring.d.ts +3 -0
- package/dist/dev/core/focus-ring.d.ts.map +1 -0
- package/dist/dev/core/focus-ring.js +14 -0
- package/dist/dev/core/focus-ring.js.map +1 -0
- package/dist/dev/core/form-control.d.ts +47 -0
- package/dist/dev/core/form-control.d.ts.map +1 -0
- package/dist/dev/core/form-control.js +75 -0
- package/dist/dev/core/form-control.js.map +1 -0
- package/dist/dev/core/warn.d.ts +12 -0
- package/dist/dev/core/warn.d.ts.map +1 -0
- package/dist/dev/core/warn.js +35 -0
- package/dist/dev/core/warn.js.map +1 -0
- package/dist/dev/dialog/dialog.d.ts +77 -0
- package/dist/dev/dialog/dialog.d.ts.map +1 -0
- package/dist/dev/dialog/dialog.js +253 -0
- package/dist/dev/dialog/dialog.js.map +1 -0
- package/dist/dev/dialog/index.d.ts +4 -0
- package/dist/dev/dialog/index.d.ts.map +1 -0
- package/dist/dev/dialog/index.js +5 -0
- package/dist/dev/dialog/index.js.map +1 -0
- package/dist/dev/menu/index.d.ts +3 -0
- package/dist/dev/menu/index.d.ts.map +1 -0
- package/dist/dev/menu/index.js +5 -0
- package/dist/dev/menu/index.js.map +1 -0
- package/dist/dev/menu/menu.d.ts +71 -0
- package/dist/dev/menu/menu.d.ts.map +1 -0
- package/dist/dev/menu/menu.js +330 -0
- package/dist/dev/menu/menu.js.map +1 -0
- package/dist/dev/switch/index.d.ts +3 -0
- package/dist/dev/switch/index.d.ts.map +1 -0
- package/dist/dev/switch/index.js +5 -0
- package/dist/dev/switch/index.js.map +1 -0
- package/dist/dev/switch/switch.d.ts +69 -0
- package/dist/dev/switch/switch.d.ts.map +1 -0
- package/dist/dev/switch/switch.js +213 -0
- package/dist/dev/switch/switch.js.map +1 -0
- package/dist/dev/tabs/index.d.ts +3 -0
- package/dist/dev/tabs/index.d.ts.map +1 -0
- package/dist/dev/tabs/index.js +5 -0
- package/dist/dev/tabs/index.js.map +1 -0
- package/dist/dev/tabs/tabs.d.ts +64 -0
- package/dist/dev/tabs/tabs.d.ts.map +1 -0
- package/dist/dev/tabs/tabs.js +212 -0
- package/dist/dev/tabs/tabs.js.map +1 -0
- package/dist/dev/text-field/index.d.ts +3 -0
- package/dist/dev/text-field/index.d.ts.map +1 -0
- package/dist/dev/text-field/index.js +5 -0
- package/dist/dev/text-field/index.js.map +1 -0
- package/dist/dev/text-field/text-field.d.ts +91 -0
- package/dist/dev/text-field/text-field.d.ts.map +1 -0
- package/dist/dev/text-field/text-field.js +267 -0
- package/dist/dev/text-field/text-field.js.map +1 -0
- package/dist/dev/toast/index.d.ts +4 -0
- package/dist/dev/toast/index.d.ts.map +1 -0
- package/dist/dev/toast/index.js +5 -0
- package/dist/dev/toast/index.js.map +1 -0
- package/dist/dev/toast/toast.d.ts +71 -0
- package/dist/dev/toast/toast.d.ts.map +1 -0
- package/dist/dev/toast/toast.js +258 -0
- package/dist/dev/toast/toast.js.map +1 -0
- package/dist/prod/all.js +10 -0
- package/dist/prod/button/button.js +292 -0
- package/dist/prod/button/index.js +5 -0
- package/dist/prod/checkbox/checkbox.js +232 -0
- package/dist/prod/checkbox/index.js +5 -0
- package/dist/prod/core/define.js +6 -0
- package/dist/prod/core/dev-mode.js +1 -0
- package/dist/prod/core/focus-ring.js +14 -0
- package/dist/prod/core/form-control.js +75 -0
- package/dist/prod/core/warn.js +2 -0
- package/dist/prod/dialog/dialog.js +253 -0
- package/dist/prod/dialog/index.js +5 -0
- package/dist/prod/menu/index.js +5 -0
- package/dist/prod/menu/menu.js +330 -0
- package/dist/prod/switch/index.js +5 -0
- package/dist/prod/switch/switch.js +213 -0
- package/dist/prod/tabs/index.js +5 -0
- package/dist/prod/tabs/tabs.js +212 -0
- package/dist/prod/text-field/index.js +5 -0
- package/dist/prod/text-field/text-field.js +267 -0
- package/dist/prod/toast/index.js +5 -0
- package/dist/prod/toast/toast.js +258 -0
- package/package.json +95 -3
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type PropertyDeclarations, type PropertyValues } from 'lit';
|
|
2
|
+
import { FormControl } from '../core/form-control.js';
|
|
3
|
+
/**
|
|
4
|
+
* A single-line text input with a visible label, help text and error message.
|
|
5
|
+
*
|
|
6
|
+
* @tag va-text-field
|
|
7
|
+
* @summary Collects a short piece of text, such as a name, an email address or a search term.
|
|
8
|
+
*
|
|
9
|
+
* @slot start - An icon or prefix inside the field, before the text.
|
|
10
|
+
* @slot end - An icon or suffix inside the field, after the text.
|
|
11
|
+
*
|
|
12
|
+
* @csspart label - The visible label.
|
|
13
|
+
* @csspart field - The box around the input and its icons.
|
|
14
|
+
* @csspart input - The native input.
|
|
15
|
+
* @csspart help-text - The help text.
|
|
16
|
+
* @csspart error - The error message.
|
|
17
|
+
*
|
|
18
|
+
* @cssprop {<color>} --va-text-field-bg - Background colour of the field.
|
|
19
|
+
* @cssprop {<color>} --va-text-field-border - Border colour of the field.
|
|
20
|
+
* @cssprop {<color>} --va-text-field-border-invalid - Border colour while the field shows an error.
|
|
21
|
+
* @cssprop {<length>} --va-text-field-radius - Corner radius of the field.
|
|
22
|
+
* @cssprop {<length>} --va-text-field-height - Minimum height of the field.
|
|
23
|
+
*
|
|
24
|
+
* @cssprop-applies --va-text-field-bg field background-color
|
|
25
|
+
* @cssprop-applies --va-text-field-border field border-top-color
|
|
26
|
+
* @cssprop-applies --va-text-field-border-invalid field:invalid border-top-color
|
|
27
|
+
* @cssprop-applies --va-text-field-radius field border-top-left-radius
|
|
28
|
+
* @cssprop-applies --va-text-field-height field min-height
|
|
29
|
+
*
|
|
30
|
+
* @keyboard Tab | focus-next | Moves focus to the next control.
|
|
31
|
+
*
|
|
32
|
+
* @a11y-role textbox
|
|
33
|
+
* @a11y-name-from label
|
|
34
|
+
* @replaces input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="tel"], input[type="url"]
|
|
35
|
+
* @a11y-name The `label` attribute, shown above the field. Every text field needs one.
|
|
36
|
+
* @a11y-note Help text and the error message are linked with `aria-describedby`; the error also sets `aria-invalid`.
|
|
37
|
+
* @a11y-note Errors appear after the user leaves the field or submits the form, not while they type.
|
|
38
|
+
*
|
|
39
|
+
* @guidance-use For short, free-form text: names, email addresses, search terms, codes.
|
|
40
|
+
* @guidance-avoid For long text, or for picking from a fixed set of options.
|
|
41
|
+
* @guidance-instead A textarea for long text; a select or radio group for fixed options.
|
|
42
|
+
*
|
|
43
|
+
* @fires input - The native input event, on every keystroke. Read `event.target.value`.
|
|
44
|
+
* @fires change - When the user commits a change, by leaving the field or pressing Enter.
|
|
45
|
+
* @event-trigger input | press a
|
|
46
|
+
* @event-trigger change | commit
|
|
47
|
+
*/
|
|
48
|
+
export declare class VaTextField extends FormControl {
|
|
49
|
+
#private;
|
|
50
|
+
static shadowRootOptions: ShadowRootInit;
|
|
51
|
+
static properties: PropertyDeclarations;
|
|
52
|
+
/** The visible label above the field. Required: it is also the field's accessible name. */
|
|
53
|
+
label: string;
|
|
54
|
+
/** The kind of text. Sets the keyboard on phones and the built-in validation. */
|
|
55
|
+
type: 'text' | 'email' | 'password' | 'search' | 'tel' | 'url';
|
|
56
|
+
/** The current text. */
|
|
57
|
+
value: string;
|
|
58
|
+
/** Example text shown while the field is empty. Never a substitute for `label`. */
|
|
59
|
+
placeholder: string;
|
|
60
|
+
/** Help text under the field, such as the expected format. */
|
|
61
|
+
helpText: string;
|
|
62
|
+
/** A custom error message. While set, the field is invalid and shows it. */
|
|
63
|
+
error: string;
|
|
64
|
+
/** The text can be selected and submitted, but not changed. */
|
|
65
|
+
readOnly: boolean;
|
|
66
|
+
/** The minimum number of characters. */
|
|
67
|
+
minLength: number;
|
|
68
|
+
/** The maximum number of characters. */
|
|
69
|
+
maxLength: number;
|
|
70
|
+
/** A regular expression the whole value must match. */
|
|
71
|
+
pattern: string;
|
|
72
|
+
/** A hint for the browser's autofill, such as `email` or `name`. */
|
|
73
|
+
autocomplete: string;
|
|
74
|
+
private _showError;
|
|
75
|
+
constructor();
|
|
76
|
+
connectedCallback(): void;
|
|
77
|
+
firstUpdated(): void;
|
|
78
|
+
updated(changed: PropertyValues): void;
|
|
79
|
+
/** @internal */
|
|
80
|
+
formResetCallback(): void;
|
|
81
|
+
/** Selects all the text in the field. */
|
|
82
|
+
select(): void;
|
|
83
|
+
render(): import("lit").TemplateResult<1>;
|
|
84
|
+
static styles: import("lit").CSSResult;
|
|
85
|
+
}
|
|
86
|
+
declare global {
|
|
87
|
+
interface HTMLElementTagNameMap {
|
|
88
|
+
'va-text-field': VaTextField;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=text-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-field.d.ts","sourceRoot":"","sources":["../../../src/text-field/text-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,oBAAoB,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAYtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,qBAAa,WAAY,SAAQ,WAAW;;IAC1C,OAAgB,iBAAiB,EAAE,cAAc,CAA8D;IAE/G,OAAgB,UAAU,EAAE,oBAAoB,CAa9C;IAEF,2FAA2F;IACnF,KAAK,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACzE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAC;IACvE,wBAAwB;IAChB,KAAK,EAAE,MAAM,CAAC;IACtB,mFAAmF;IAC3E,WAAW,EAAE,MAAM,CAAC;IAC5B,8DAA8D;IACtD,QAAQ,EAAE,MAAM,CAAC;IACzB,4EAA4E;IACpE,KAAK,EAAE,MAAM,CAAC;IACtB,+DAA+D;IACvD,QAAQ,EAAE,OAAO,CAAC;IAC1B,wCAAwC;IAChC,SAAS,EAAE,MAAM,CAAC;IAC1B,wCAAwC;IAChC,SAAS,EAAE,MAAM,CAAC;IAC1B,uDAAuD;IAC/C,OAAO,EAAE,MAAM,CAAC;IACxB,oEAAoE;IAC5D,YAAY,EAAE,MAAM,CAAC;IAE7B,QAAgB,UAAU,CAAU;;IAmB3B,iBAAiB,IAAI,IAAI;IAMzB,YAAY,IAAI,IAAI;IAUpB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAS/C,gBAAgB;IACP,iBAAiB,IAAI,IAAI;IAKlC,yCAAyC;IACzC,MAAM,IAAI,IAAI;IAuBL,MAAM;IAmCf,OAAgB,MAAM,0BA4FpB;CACH;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,eAAe,EAAE,WAAW,CAAC;KAC9B;CACF"}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { FormControl } from '../core/form-control.js';
|
|
3
|
+
import { checkTokensLoaded, devWarn } from '../core/warn.js';
|
|
4
|
+
// Whether a pointer button is down anywhere on the page. Used to delay error messages that
|
|
5
|
+
// would otherwise appear mid-click and move the layout under the pointer (see #onBlur).
|
|
6
|
+
let pointerDown = false;
|
|
7
|
+
if (typeof document !== 'undefined') {
|
|
8
|
+
document.addEventListener('pointerdown', () => (pointerDown = true), true);
|
|
9
|
+
document.addEventListener('pointerup', () => (pointerDown = false), true);
|
|
10
|
+
document.addEventListener('pointercancel', () => (pointerDown = false), true);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A single-line text input with a visible label, help text and error message.
|
|
14
|
+
*
|
|
15
|
+
* @tag va-text-field
|
|
16
|
+
* @summary Collects a short piece of text, such as a name, an email address or a search term.
|
|
17
|
+
*
|
|
18
|
+
* @slot start - An icon or prefix inside the field, before the text.
|
|
19
|
+
* @slot end - An icon or suffix inside the field, after the text.
|
|
20
|
+
*
|
|
21
|
+
* @csspart label - The visible label.
|
|
22
|
+
* @csspart field - The box around the input and its icons.
|
|
23
|
+
* @csspart input - The native input.
|
|
24
|
+
* @csspart help-text - The help text.
|
|
25
|
+
* @csspart error - The error message.
|
|
26
|
+
*
|
|
27
|
+
* @cssprop {<color>} --va-text-field-bg - Background colour of the field.
|
|
28
|
+
* @cssprop {<color>} --va-text-field-border - Border colour of the field.
|
|
29
|
+
* @cssprop {<color>} --va-text-field-border-invalid - Border colour while the field shows an error.
|
|
30
|
+
* @cssprop {<length>} --va-text-field-radius - Corner radius of the field.
|
|
31
|
+
* @cssprop {<length>} --va-text-field-height - Minimum height of the field.
|
|
32
|
+
*
|
|
33
|
+
* @cssprop-applies --va-text-field-bg field background-color
|
|
34
|
+
* @cssprop-applies --va-text-field-border field border-top-color
|
|
35
|
+
* @cssprop-applies --va-text-field-border-invalid field:invalid border-top-color
|
|
36
|
+
* @cssprop-applies --va-text-field-radius field border-top-left-radius
|
|
37
|
+
* @cssprop-applies --va-text-field-height field min-height
|
|
38
|
+
*
|
|
39
|
+
* @keyboard Tab | focus-next | Moves focus to the next control.
|
|
40
|
+
*
|
|
41
|
+
* @a11y-role textbox
|
|
42
|
+
* @a11y-name-from label
|
|
43
|
+
* @replaces input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="tel"], input[type="url"]
|
|
44
|
+
* @a11y-name The `label` attribute, shown above the field. Every text field needs one.
|
|
45
|
+
* @a11y-note Help text and the error message are linked with `aria-describedby`; the error also sets `aria-invalid`.
|
|
46
|
+
* @a11y-note Errors appear after the user leaves the field or submits the form, not while they type.
|
|
47
|
+
*
|
|
48
|
+
* @guidance-use For short, free-form text: names, email addresses, search terms, codes.
|
|
49
|
+
* @guidance-avoid For long text, or for picking from a fixed set of options.
|
|
50
|
+
* @guidance-instead A textarea for long text; a select or radio group for fixed options.
|
|
51
|
+
*
|
|
52
|
+
* @fires input - The native input event, on every keystroke. Read `event.target.value`.
|
|
53
|
+
* @fires change - When the user commits a change, by leaving the field or pressing Enter.
|
|
54
|
+
* @event-trigger input | press a
|
|
55
|
+
* @event-trigger change | commit
|
|
56
|
+
*/
|
|
57
|
+
export class VaTextField extends FormControl {
|
|
58
|
+
static { this.shadowRootOptions = { ...FormControl.shadowRootOptions, delegatesFocus: true }; }
|
|
59
|
+
static { this.properties = {
|
|
60
|
+
label: {},
|
|
61
|
+
type: {},
|
|
62
|
+
value: {},
|
|
63
|
+
placeholder: {},
|
|
64
|
+
helpText: { attribute: 'help-text' },
|
|
65
|
+
error: {},
|
|
66
|
+
readOnly: { type: Boolean, reflect: true, attribute: 'readonly' },
|
|
67
|
+
minLength: { type: Number, attribute: 'minlength' },
|
|
68
|
+
maxLength: { type: Number, attribute: 'maxlength' },
|
|
69
|
+
pattern: {},
|
|
70
|
+
autocomplete: {},
|
|
71
|
+
_showError: { state: true },
|
|
72
|
+
}; }
|
|
73
|
+
#defaultValue = '';
|
|
74
|
+
constructor() {
|
|
75
|
+
super();
|
|
76
|
+
this.label = '';
|
|
77
|
+
this.type = 'text';
|
|
78
|
+
this.value = '';
|
|
79
|
+
this.placeholder = '';
|
|
80
|
+
this.helpText = '';
|
|
81
|
+
this.error = '';
|
|
82
|
+
this.readOnly = false;
|
|
83
|
+
this.pattern = '';
|
|
84
|
+
this.autocomplete = '';
|
|
85
|
+
this._showError = false;
|
|
86
|
+
// Fired on the host when the form's submit is blocked: show the error from then on.
|
|
87
|
+
this.addEventListener('invalid', () => (this._showError = true));
|
|
88
|
+
}
|
|
89
|
+
connectedCallback() {
|
|
90
|
+
super.connectedCallback();
|
|
91
|
+
this.#defaultValue = this.getAttribute('value') ?? '';
|
|
92
|
+
checkTokensLoaded(this);
|
|
93
|
+
}
|
|
94
|
+
firstUpdated() {
|
|
95
|
+
if (!this.label) {
|
|
96
|
+
devWarn('va-text-field', 'This text field has no label.', 'Add label="…" that says what to type (e.g. label="Email address"). A placeholder is not a label.');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
get #input() {
|
|
100
|
+
return this.shadowRoot?.querySelector('input') ?? null;
|
|
101
|
+
}
|
|
102
|
+
updated(changed) {
|
|
103
|
+
const input = this.#input;
|
|
104
|
+
if (!input)
|
|
105
|
+
return;
|
|
106
|
+
if (changed.has('error') && this.error)
|
|
107
|
+
this._showError = true;
|
|
108
|
+
this._internals.setFormValue(this.value);
|
|
109
|
+
input.setCustomValidity(this.error);
|
|
110
|
+
this._internals.setValidity(input.validity, input.validationMessage, input);
|
|
111
|
+
}
|
|
112
|
+
/** @internal */
|
|
113
|
+
formResetCallback() {
|
|
114
|
+
this.value = this.#defaultValue;
|
|
115
|
+
this._showError = false;
|
|
116
|
+
}
|
|
117
|
+
/** Selects all the text in the field. */
|
|
118
|
+
select() {
|
|
119
|
+
this.#input?.select();
|
|
120
|
+
}
|
|
121
|
+
#onInput(event) {
|
|
122
|
+
this.value = event.target.value;
|
|
123
|
+
}
|
|
124
|
+
#onChange() {
|
|
125
|
+
this._emit('change');
|
|
126
|
+
}
|
|
127
|
+
#onBlur() {
|
|
128
|
+
const show = () => {
|
|
129
|
+
this._showError = true;
|
|
130
|
+
this.requestUpdate();
|
|
131
|
+
};
|
|
132
|
+
// Focus left because the user is clicking something else. Showing the error now would push
|
|
133
|
+
// the content below down between mousedown and mouseup, and the click would be lost.
|
|
134
|
+
if (pointerDown)
|
|
135
|
+
window.addEventListener('pointerup', () => setTimeout(show), { once: true, capture: true });
|
|
136
|
+
else
|
|
137
|
+
show();
|
|
138
|
+
}
|
|
139
|
+
render() {
|
|
140
|
+
const input = this.#input;
|
|
141
|
+
const invalid = this._showError && !!(this.error || (input && !input.validity.valid));
|
|
142
|
+
const message = this.error || (invalid ? input?.validationMessage : '');
|
|
143
|
+
const describedBy = [this.helpText ? 'help-text' : '', invalid ? 'error' : ''].filter(Boolean).join(' ');
|
|
144
|
+
return html `
|
|
145
|
+
<label part="label" class="label ${this._isDisabled ? 'disabled' : ''}" for="input">${this.label}${this.required ? html `<span class="required" aria-hidden="true"> *</span>` : nothing}</label>
|
|
146
|
+
<div part="field" class="field ${invalid ? 'invalid' : ''} ${this._isDisabled ? 'disabled' : ''}">
|
|
147
|
+
<slot name="start"></slot>
|
|
148
|
+
<input
|
|
149
|
+
part="input"
|
|
150
|
+
id="input"
|
|
151
|
+
.value=${this.value}
|
|
152
|
+
type=${this.type}
|
|
153
|
+
placeholder=${this.placeholder || nothing}
|
|
154
|
+
?disabled=${this._isDisabled}
|
|
155
|
+
?readonly=${this.readOnly}
|
|
156
|
+
?required=${this.required}
|
|
157
|
+
minlength=${this.minLength ?? nothing}
|
|
158
|
+
maxlength=${this.maxLength ?? nothing}
|
|
159
|
+
pattern=${this.pattern || nothing}
|
|
160
|
+
autocomplete=${(this.autocomplete || nothing)}
|
|
161
|
+
aria-invalid=${invalid ? 'true' : nothing}
|
|
162
|
+
aria-describedby=${describedBy || nothing}
|
|
163
|
+
@input=${this.#onInput}
|
|
164
|
+
@change=${this.#onChange}
|
|
165
|
+
@blur=${this.#onBlur}
|
|
166
|
+
/>
|
|
167
|
+
<slot name="end"></slot>
|
|
168
|
+
</div>
|
|
169
|
+
<div part="help-text" id="help-text" class="help-text" ?hidden=${!this.helpText}>${this.helpText}</div>
|
|
170
|
+
<div part="error" id="error" class="error" ?hidden=${!invalid}>${message}</div>
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
static { this.styles = css `
|
|
174
|
+
:host {
|
|
175
|
+
--_border: var(--va-text-field-border, var(--va-color-border-control));
|
|
176
|
+
display: inline-flex;
|
|
177
|
+
flex-direction: column;
|
|
178
|
+
gap: var(--va-space-gap-sm);
|
|
179
|
+
min-width: 12rem;
|
|
180
|
+
font-family: var(--va-font-family-ui);
|
|
181
|
+
font-size: var(--va-font-size-md);
|
|
182
|
+
color: var(--va-color-text-default);
|
|
183
|
+
vertical-align: top;
|
|
184
|
+
}
|
|
185
|
+
:host([hidden]) {
|
|
186
|
+
display: none;
|
|
187
|
+
}
|
|
188
|
+
.label {
|
|
189
|
+
font-weight: var(--va-font-weight-medium);
|
|
190
|
+
font-size: var(--va-font-size-sm);
|
|
191
|
+
}
|
|
192
|
+
.required {
|
|
193
|
+
color: var(--va-color-danger-default);
|
|
194
|
+
}
|
|
195
|
+
.field {
|
|
196
|
+
box-sizing: border-box;
|
|
197
|
+
display: flex;
|
|
198
|
+
align-items: center;
|
|
199
|
+
gap: var(--va-space-gap-md);
|
|
200
|
+
min-height: var(--va-text-field-height, var(--va-size-control-md));
|
|
201
|
+
padding: 0 var(--va-space-inline-md);
|
|
202
|
+
border: 1px solid var(--_border);
|
|
203
|
+
border-radius: var(--va-text-field-radius, var(--va-radius-control));
|
|
204
|
+
background-color: var(--va-text-field-bg, var(--va-color-surface-default));
|
|
205
|
+
}
|
|
206
|
+
.field:focus-within {
|
|
207
|
+
outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);
|
|
208
|
+
outline-offset: 1px;
|
|
209
|
+
}
|
|
210
|
+
.field.invalid {
|
|
211
|
+
border-color: var(--va-text-field-border-invalid, var(--va-color-danger-default));
|
|
212
|
+
}
|
|
213
|
+
input {
|
|
214
|
+
flex: 1;
|
|
215
|
+
min-width: 0;
|
|
216
|
+
margin: 0;
|
|
217
|
+
padding: 0.5rem 0;
|
|
218
|
+
border: none;
|
|
219
|
+
outline: none;
|
|
220
|
+
background: transparent;
|
|
221
|
+
color: inherit;
|
|
222
|
+
font: inherit;
|
|
223
|
+
}
|
|
224
|
+
input::placeholder {
|
|
225
|
+
color: var(--va-color-text-muted);
|
|
226
|
+
}
|
|
227
|
+
::slotted([slot='start']),
|
|
228
|
+
::slotted([slot='end']) {
|
|
229
|
+
flex: none;
|
|
230
|
+
color: var(--va-color-text-muted);
|
|
231
|
+
}
|
|
232
|
+
/* Only the box fades: the label and help text (often saying why it's disabled) stay readable. */
|
|
233
|
+
.field.disabled {
|
|
234
|
+
opacity: 0.5;
|
|
235
|
+
}
|
|
236
|
+
.label.disabled {
|
|
237
|
+
color: var(--va-color-text-muted);
|
|
238
|
+
}
|
|
239
|
+
:host([readonly]) .field {
|
|
240
|
+
background-color: var(--va-color-surface-subtle);
|
|
241
|
+
}
|
|
242
|
+
.help-text {
|
|
243
|
+
color: var(--va-color-text-muted);
|
|
244
|
+
font-size: var(--va-font-size-sm);
|
|
245
|
+
}
|
|
246
|
+
.error {
|
|
247
|
+
color: var(--va-color-danger-default);
|
|
248
|
+
font-size: var(--va-font-size-sm);
|
|
249
|
+
}
|
|
250
|
+
.help-text[hidden],
|
|
251
|
+
.error[hidden] {
|
|
252
|
+
display: none;
|
|
253
|
+
}
|
|
254
|
+
@media (forced-colors: active) {
|
|
255
|
+
.field {
|
|
256
|
+
border-color: FieldText;
|
|
257
|
+
}
|
|
258
|
+
.field.invalid {
|
|
259
|
+
border-width: 2px;
|
|
260
|
+
}
|
|
261
|
+
.field:focus-within {
|
|
262
|
+
outline-color: Highlight;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
`; }
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=text-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-field.js","sourceRoot":"","sources":["../../../src/text-field/text-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAkD,MAAM,KAAK,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE7D,2FAA2F;AAC3F,wFAAwF;AACxF,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;IACpC,QAAQ,CAAC,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3E,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,GAAG,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;IAC1E,QAAQ,CAAC,gBAAgB,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,GAAG,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;AAChF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,OAAO,WAAY,SAAQ,WAAW;aAC1B,sBAAiB,GAAmB,EAAE,GAAG,WAAW,CAAC,iBAAiB,EA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C,CAAC,OAAO;uCACrJ,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;;;;;mBAKlF,IAAI,CAAC,KAAK;iBACZ,IAAI,CAAC,IAAI;wBACF,IAAI,CAAC,WAAW,IAAI,OAAO;sBAC7B,IAAI,CAAC,WAAW;sBAChB,IAAI,CAAC,QAAQ;sBACb,IAAI,CAAC,QAAQ;sBACb,IAAI,CAAC,SAAS,IAAI,OAAO;sBACzB,IAAI,CAAC,SAAS,IAAI,OAAO;oBAC3B,IAAI,CAAC,OAAO,IAAI,OAAO;yBAClB,CAAC,IAAI,CAAC,YAAY,IAAI,OAAO,CAAU;yBACvC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;6BACtB,WAAW,IAAI,OAAO;mBAChC,IAAI,CAAC,QAAQ;oBACZ,IAAI,CAAC,SAAS;kBAChB,IAAI,CAAC,OAAO;;;;uEAIyC,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ;2DAC3C,CAAC,OAAO,IAAI,OAAO;KACzE,CAAC;IACJ,CAAC;aAEe,WAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4F3B,CAAC","sourcesContent":["import { css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { FormControl } from '../core/form-control.js';\nimport { checkTokensLoaded, devWarn } from '../core/warn.js';\n\n// Whether a pointer button is down anywhere on the page. Used to delay error messages that\n// would otherwise appear mid-click and move the layout under the pointer (see #onBlur).\nlet pointerDown = false;\nif (typeof document !== 'undefined') {\n document.addEventListener('pointerdown', () => (pointerDown = true), true);\n document.addEventListener('pointerup', () => (pointerDown = false), true);\n document.addEventListener('pointercancel', () => (pointerDown = false), true);\n}\n\n/**\n * A single-line text input with a visible label, help text and error message.\n *\n * @tag va-text-field\n * @summary Collects a short piece of text, such as a name, an email address or a search term.\n *\n * @slot start - An icon or prefix inside the field, before the text.\n * @slot end - An icon or suffix inside the field, after the text.\n *\n * @csspart label - The visible label.\n * @csspart field - The box around the input and its icons.\n * @csspart input - The native input.\n * @csspart help-text - The help text.\n * @csspart error - The error message.\n *\n * @cssprop {<color>} --va-text-field-bg - Background colour of the field.\n * @cssprop {<color>} --va-text-field-border - Border colour of the field.\n * @cssprop {<color>} --va-text-field-border-invalid - Border colour while the field shows an error.\n * @cssprop {<length>} --va-text-field-radius - Corner radius of the field.\n * @cssprop {<length>} --va-text-field-height - Minimum height of the field.\n *\n * @cssprop-applies --va-text-field-bg field background-color\n * @cssprop-applies --va-text-field-border field border-top-color\n * @cssprop-applies --va-text-field-border-invalid field:invalid border-top-color\n * @cssprop-applies --va-text-field-radius field border-top-left-radius\n * @cssprop-applies --va-text-field-height field min-height\n *\n * @keyboard Tab | focus-next | Moves focus to the next control.\n *\n * @a11y-role textbox\n * @a11y-name-from label\n * @replaces input:not([type]), input[type=\"text\"], input[type=\"email\"], input[type=\"password\"], input[type=\"search\"], input[type=\"tel\"], input[type=\"url\"]\n * @a11y-name The `label` attribute, shown above the field. Every text field needs one.\n * @a11y-note Help text and the error message are linked with `aria-describedby`; the error also sets `aria-invalid`.\n * @a11y-note Errors appear after the user leaves the field or submits the form, not while they type.\n *\n * @guidance-use For short, free-form text: names, email addresses, search terms, codes.\n * @guidance-avoid For long text, or for picking from a fixed set of options.\n * @guidance-instead A textarea for long text; a select or radio group for fixed options.\n *\n * @fires input - The native input event, on every keystroke. Read `event.target.value`.\n * @fires change - When the user commits a change, by leaving the field or pressing Enter.\n * @event-trigger input | press a\n * @event-trigger change | commit\n */\nexport class VaTextField extends FormControl {\n static override shadowRootOptions: ShadowRootInit = { ...FormControl.shadowRootOptions, delegatesFocus: true };\n\n static override properties: PropertyDeclarations = {\n label: {},\n type: {},\n value: {},\n placeholder: {},\n helpText: { attribute: 'help-text' },\n error: {},\n readOnly: { type: Boolean, reflect: true, attribute: 'readonly' },\n minLength: { type: Number, attribute: 'minlength' },\n maxLength: { type: Number, attribute: 'maxlength' },\n pattern: {},\n autocomplete: {},\n _showError: { state: true },\n };\n\n /** The visible label above the field. Required: it is also the field's accessible name. */\n declare label: string;\n /** The kind of text. Sets the keyboard on phones and the built-in validation. */\n declare type: 'text' | 'email' | 'password' | 'search' | 'tel' | 'url';\n /** The current text. */\n declare value: string;\n /** Example text shown while the field is empty. Never a substitute for `label`. */\n declare placeholder: string;\n /** Help text under the field, such as the expected format. */\n declare helpText: string;\n /** A custom error message. While set, the field is invalid and shows it. */\n declare error: string;\n /** The text can be selected and submitted, but not changed. */\n declare readOnly: boolean;\n /** The minimum number of characters. */\n declare minLength: number;\n /** The maximum number of characters. */\n declare maxLength: number;\n /** A regular expression the whole value must match. */\n declare pattern: string;\n /** A hint for the browser's autofill, such as `email` or `name`. */\n declare autocomplete: string;\n\n declare private _showError: boolean;\n #defaultValue = '';\n\n constructor() {\n super();\n this.label = '';\n this.type = 'text';\n this.value = '';\n this.placeholder = '';\n this.helpText = '';\n this.error = '';\n this.readOnly = false;\n this.pattern = '';\n this.autocomplete = '';\n this._showError = false;\n // Fired on the host when the form's submit is blocked: show the error from then on.\n this.addEventListener('invalid', () => (this._showError = true));\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.#defaultValue = this.getAttribute('value') ?? '';\n checkTokensLoaded(this);\n }\n\n override firstUpdated(): void {\n if (!this.label) {\n devWarn('va-text-field', 'This text field has no label.', 'Add label=\"…\" that says what to type (e.g. label=\"Email address\"). A placeholder is not a label.');\n }\n }\n\n get #input(): HTMLInputElement | null {\n return this.shadowRoot?.querySelector('input') ?? null;\n }\n\n override updated(changed: PropertyValues): void {\n const input = this.#input;\n if (!input) return;\n if (changed.has('error') && this.error) this._showError = true;\n this._internals.setFormValue(this.value);\n input.setCustomValidity(this.error);\n this._internals.setValidity(input.validity, input.validationMessage, input);\n }\n\n /** @internal */\n override formResetCallback(): void {\n this.value = this.#defaultValue;\n this._showError = false;\n }\n\n /** Selects all the text in the field. */\n select(): void {\n this.#input?.select();\n }\n\n #onInput(event: Event): void {\n this.value = (event.target as HTMLInputElement).value;\n }\n\n #onChange(): void {\n this._emit('change');\n }\n\n #onBlur(): void {\n const show = () => {\n this._showError = true;\n this.requestUpdate();\n };\n // Focus left because the user is clicking something else. Showing the error now would push\n // the content below down between mousedown and mouseup, and the click would be lost.\n if (pointerDown) window.addEventListener('pointerup', () => setTimeout(show), { once: true, capture: true });\n else show();\n }\n\n override render() {\n const input = this.#input;\n const invalid = this._showError && !!(this.error || (input && !input.validity.valid));\n const message = this.error || (invalid ? input?.validationMessage : '');\n const describedBy = [this.helpText ? 'help-text' : '', invalid ? 'error' : ''].filter(Boolean).join(' ');\n return html`\n <label part=\"label\" class=\"label ${this._isDisabled ? 'disabled' : ''}\" for=\"input\">${this.label}${this.required ? html`<span class=\"required\" aria-hidden=\"true\"> *</span>` : nothing}</label>\n <div part=\"field\" class=\"field ${invalid ? 'invalid' : ''} ${this._isDisabled ? 'disabled' : ''}\">\n <slot name=\"start\"></slot>\n <input\n part=\"input\"\n id=\"input\"\n .value=${this.value}\n type=${this.type}\n placeholder=${this.placeholder || nothing}\n ?disabled=${this._isDisabled}\n ?readonly=${this.readOnly}\n ?required=${this.required}\n minlength=${this.minLength ?? nothing}\n maxlength=${this.maxLength ?? nothing}\n pattern=${this.pattern || nothing}\n autocomplete=${(this.autocomplete || nothing) as never}\n aria-invalid=${invalid ? 'true' : nothing}\n aria-describedby=${describedBy || nothing}\n @input=${this.#onInput}\n @change=${this.#onChange}\n @blur=${this.#onBlur}\n />\n <slot name=\"end\"></slot>\n </div>\n <div part=\"help-text\" id=\"help-text\" class=\"help-text\" ?hidden=${!this.helpText}>${this.helpText}</div>\n <div part=\"error\" id=\"error\" class=\"error\" ?hidden=${!invalid}>${message}</div>\n `;\n }\n\n static override styles = css`\n :host {\n --_border: var(--va-text-field-border, var(--va-color-border-control));\n display: inline-flex;\n flex-direction: column;\n gap: var(--va-space-gap-sm);\n min-width: 12rem;\n font-family: var(--va-font-family-ui);\n font-size: var(--va-font-size-md);\n color: var(--va-color-text-default);\n vertical-align: top;\n }\n :host([hidden]) {\n display: none;\n }\n .label {\n font-weight: var(--va-font-weight-medium);\n font-size: var(--va-font-size-sm);\n }\n .required {\n color: var(--va-color-danger-default);\n }\n .field {\n box-sizing: border-box;\n display: flex;\n align-items: center;\n gap: var(--va-space-gap-md);\n min-height: var(--va-text-field-height, var(--va-size-control-md));\n padding: 0 var(--va-space-inline-md);\n border: 1px solid var(--_border);\n border-radius: var(--va-text-field-radius, var(--va-radius-control));\n background-color: var(--va-text-field-bg, var(--va-color-surface-default));\n }\n .field:focus-within {\n outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);\n outline-offset: 1px;\n }\n .field.invalid {\n border-color: var(--va-text-field-border-invalid, var(--va-color-danger-default));\n }\n input {\n flex: 1;\n min-width: 0;\n margin: 0;\n padding: 0.5rem 0;\n border: none;\n outline: none;\n background: transparent;\n color: inherit;\n font: inherit;\n }\n input::placeholder {\n color: var(--va-color-text-muted);\n }\n ::slotted([slot='start']),\n ::slotted([slot='end']) {\n flex: none;\n color: var(--va-color-text-muted);\n }\n /* Only the box fades: the label and help text (often saying why it's disabled) stay readable. */\n .field.disabled {\n opacity: 0.5;\n }\n .label.disabled {\n color: var(--va-color-text-muted);\n }\n :host([readonly]) .field {\n background-color: var(--va-color-surface-subtle);\n }\n .help-text {\n color: var(--va-color-text-muted);\n font-size: var(--va-font-size-sm);\n }\n .error {\n color: var(--va-color-danger-default);\n font-size: var(--va-font-size-sm);\n }\n .help-text[hidden],\n .error[hidden] {\n display: none;\n }\n @media (forced-colors: active) {\n .field {\n border-color: FieldText;\n }\n .field.invalid {\n border-width: 2px;\n }\n .field:focus-within {\n outline-color: Highlight;\n }\n }\n `;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'va-text-field': VaTextField;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/toast/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,CAAC;AACnB,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/toast/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,CAAC;AAGnB,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC","sourcesContent":["import { define } from '../core/define.js';\nimport { VaToast } from './toast.js';\n\nexport { VaToast };\nexport type { ToastDismissReason, ToastVariant } from './toast.js';\n\ndefine('va-toast', VaToast);\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { LitElement, type PropertyDeclarations } from 'lit';
|
|
2
|
+
/** How a toast looks and how urgently it is announced. */
|
|
3
|
+
export type ToastVariant = 'info' | 'success' | 'error';
|
|
4
|
+
/** Why a message closed, in the `va-dismiss` event's `detail.reason`. */
|
|
5
|
+
export type ToastDismissReason = 'timeout' | 'close-button' | 'escape' | 'method';
|
|
6
|
+
/**
|
|
7
|
+
* A region for short, non-blocking status messages ("toasts"). Place one per page and call `show()`,
|
|
8
|
+
* or point a `va-button` at it with `command="--show"`; the button's `value` is the message.
|
|
9
|
+
*
|
|
10
|
+
* @tag va-toast
|
|
11
|
+
* @summary Shows short status messages, such as "Changes saved", without interrupting the user.
|
|
12
|
+
*
|
|
13
|
+
* @csspart region - The fixed area the toasts appear in.
|
|
14
|
+
* @csspart toast - Each message.
|
|
15
|
+
* @csspart close-button - Each message's close button.
|
|
16
|
+
*
|
|
17
|
+
* @cssprop {<color>} --va-toast-bg - Background colour of a message.
|
|
18
|
+
* @cssprop {<color>} --va-toast-fg - Text colour of a message.
|
|
19
|
+
* @cssprop {<length>} --va-toast-radius - Corner radius of a message.
|
|
20
|
+
*
|
|
21
|
+
* @cssprop-applies --va-toast-bg toast:open background-color
|
|
22
|
+
* @cssprop-applies --va-toast-fg toast:open color
|
|
23
|
+
* @cssprop-applies --va-toast-radius toast:open border-top-left-radius
|
|
24
|
+
*
|
|
25
|
+
* @keyboard-items [part~="close-button"]
|
|
26
|
+
* @keyboard open: Escape | closes | Dismisses the message that has focus.
|
|
27
|
+
*
|
|
28
|
+
* @a11y-role status
|
|
29
|
+
* @a11y-name The `accessible-label` attribute, "Notifications" by default (not shown).
|
|
30
|
+
* @a11y-note Info and success messages are announced politely; errors use `role="alert"` and are announced at once.
|
|
31
|
+
* @a11y-note Messages pause their timer while hovered or focused, and errors stay until dismissed (WCAG 2.2.1).
|
|
32
|
+
* @a11y-note While a modal dialog is open, the element moves itself into that dialog (a light-DOM move, so its messages stay clickable and announced) and back to its place when the dialog closes. Don't render it from a framework that would fight the move; place it once, outside framework-managed DOM.
|
|
33
|
+
*
|
|
34
|
+
* @guidance-use To confirm that something happened, such as "Changes saved" or "Link copied", or to report a background failure.
|
|
35
|
+
* @guidance-avoid For anything the user must act on or read in full, or for form validation errors.
|
|
36
|
+
* @guidance-instead `va-dialog` for decisions; `va-text-field`'s `error` for field errors.
|
|
37
|
+
*
|
|
38
|
+
* @command --show | Shows the sending button's `value` as a message. Its `data-toast-variant` sets the look: `info` (default), `success` or `error`.
|
|
39
|
+
* @command-data --show | toast-variant | info success error
|
|
40
|
+
* @fires {CustomEvent<{ id: number, reason: 'timeout' | 'close-button' | 'escape' | 'method' }>} va-dismiss - After a message has closed. `event.detail.id` is the id `show()` returned.
|
|
41
|
+
* @event-trigger va-dismiss | press Escape | open
|
|
42
|
+
*/
|
|
43
|
+
export declare class VaToast extends LitElement {
|
|
44
|
+
#private;
|
|
45
|
+
static properties: PropertyDeclarations;
|
|
46
|
+
/** Milliseconds before an info or success message closes by itself. Errors stay until dismissed. */
|
|
47
|
+
duration: number;
|
|
48
|
+
/** Accessible name of the region. Not shown. */
|
|
49
|
+
accessibleLabel: string;
|
|
50
|
+
private _toasts;
|
|
51
|
+
constructor();
|
|
52
|
+
connectedCallback(): void;
|
|
53
|
+
disconnectedCallback(): void;
|
|
54
|
+
/** True while at least one message is showing. */
|
|
55
|
+
get hasMessages(): boolean;
|
|
56
|
+
/** Shows a message and returns its id. `variant` defaults to `info`; errors stay until dismissed. */
|
|
57
|
+
show(message: string, options?: {
|
|
58
|
+
variant?: 'info' | 'success' | 'error';
|
|
59
|
+
duration?: number;
|
|
60
|
+
}): number;
|
|
61
|
+
/** Closes one message by id, or every message when no id is given. */
|
|
62
|
+
dismiss(id?: number): void;
|
|
63
|
+
render(): import("lit").TemplateResult<1>;
|
|
64
|
+
static styles: import("lit").CSSResult[];
|
|
65
|
+
}
|
|
66
|
+
declare global {
|
|
67
|
+
interface HTMLElementTagNameMap {
|
|
68
|
+
'va-toast': VaToast;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=toast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../../../src/toast/toast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,KAAK,oBAAoB,EAAE,MAAM,KAAK,CAAC;AAKhF,0DAA0D;AAC1D,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AACxD,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,cAAc,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAelF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,OAAQ,SAAQ,UAAU;;IACrC,OAAgB,UAAU,EAAE,oBAAoB,CAI9C;IAEF,oGAAoG;IAC5F,QAAQ,EAAE,MAAM,CAAC;IACzB,gDAAgD;IACxC,eAAe,EAAE,MAAM,CAAC;IAEhC,QAAgB,OAAO,CAAU;;IAUxB,iBAAiB,IAAI,IAAI;IAKzB,oBAAoB,IAAI,IAAI;IAKrC,kDAAkD;IAClD,IAAI,WAAW,IAAI,OAAO,CAEzB;IA0BD,qGAAqG;IACrG,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,MAAM;IAU1G,sEAAsE;IACtE,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAgDjB,MAAM;IA8Bf,OAAgB,MAAM,4BAwEpB;CACH;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,UAAU,EAAE,OAAO,CAAC;KACrB;CACF"}
|