tyrell-components 1.0.0-RC16 → 1.0.0-RC18
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 +1 -1
- package/css/tyrell-colors-static.css +1 -316
- package/css/tyrell-theme.css +1 -1471
- package/css/tyrell.css +1 -1385
- package/dist/tyrell-colors-static.css +1 -1
- package/dist/tyrell-theme.css +1 -1
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +28 -15
- package/lib/base/ty-component.js +81 -38
- package/lib/components/button.d.ts +14 -0
- package/lib/components/button.js +55 -7
- package/lib/components/calendar-month.d.ts +7 -1
- package/lib/components/calendar-month.js +35 -28
- package/lib/components/calendar-navigation.js +19 -6
- package/lib/components/calendar.d.ts +27 -3
- package/lib/components/calendar.js +107 -63
- package/lib/components/checkbox.d.ts +8 -1
- package/lib/components/checkbox.js +27 -6
- package/lib/components/copy.d.ts +2 -0
- package/lib/components/copy.js +15 -31
- package/lib/components/date-picker.d.ts +53 -18
- package/lib/components/date-picker.js +217 -146
- package/lib/components/file-upload.d.ts +4 -1
- package/lib/components/file-upload.js +23 -5
- package/lib/components/input.d.ts +73 -3
- package/lib/components/input.js +158 -22
- package/lib/components/modal.d.ts +2 -0
- package/lib/components/modal.js +97 -17
- package/lib/components/option.d.ts +19 -0
- package/lib/components/option.js +45 -31
- package/lib/components/popup.js +115 -15
- package/lib/components/radio.d.ts +10 -1
- package/lib/components/radio.js +22 -29
- package/lib/components/resize-observer.js +2 -0
- package/lib/components/scroll-container.js +2 -0
- package/lib/components/select.d.ts +150 -190
- package/lib/components/select.js +501 -796
- package/lib/components/selected-tags.d.ts +14 -4
- package/lib/components/selected-tags.js +35 -8
- package/lib/components/switch.d.ts +9 -1
- package/lib/components/switch.js +27 -6
- package/lib/components/tabs.js +1 -1
- package/lib/components/tag.d.ts +0 -9
- package/lib/components/tag.js +0 -11
- package/lib/components/textarea.d.ts +47 -2
- package/lib/components/textarea.js +81 -17
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/styles/button.js +21 -19
- package/lib/styles/calendar-month.js +1 -1
- package/lib/styles/calendar.js +3 -0
- package/lib/styles/checkbox.js +11 -5
- package/lib/styles/date-picker.js +16 -4
- package/lib/styles/file-upload.d.ts +1 -1
- package/lib/styles/file-upload.js +3 -3
- package/lib/styles/icon.d.ts +1 -1
- package/lib/styles/icon.js +2 -2
- package/lib/styles/input.js +6 -10
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +6 -7
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.js +2 -0
- package/lib/styles/radio.js +12 -6
- package/lib/styles/select-base.js +22 -60
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +13 -2
- package/lib/styles/switch.js +10 -5
- package/lib/styles/tag.js +3 -5
- package/lib/styles/textarea.d.ts +1 -1
- package/lib/styles/textarea.js +7 -0
- package/lib/types/common.d.ts +3 -3
- package/lib/utils/calendar-utils.d.ts +49 -0
- package/lib/utils/calendar-utils.js +63 -6
- package/lib/utils/property-manager.d.ts +6 -5
- package/lib/utils/property-manager.js +14 -15
- package/lib/utils/scroll-lock.d.ts +10 -4
- package/lib/utils/scroll-lock.js +102 -2
- package/lib/utils/upgrade-properties.d.ts +21 -0
- package/lib/utils/upgrade-properties.js +47 -0
- package/lib/utils/validity.d.ts +98 -2
- package/lib/utils/validity.js +244 -8
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +8 -6
- package/lib/base/ty-component.d.ts.map +0 -1
- package/lib/base/ty-component.js.map +0 -1
- package/lib/components/button.d.ts.map +0 -1
- package/lib/components/button.js.map +0 -1
- package/lib/components/calendar-month.d.ts.map +0 -1
- package/lib/components/calendar-month.js.map +0 -1
- package/lib/components/calendar-navigation.d.ts.map +0 -1
- package/lib/components/calendar-navigation.js.map +0 -1
- package/lib/components/calendar.d.ts.map +0 -1
- package/lib/components/calendar.js.map +0 -1
- package/lib/components/checkbox.d.ts.map +0 -1
- package/lib/components/checkbox.js.map +0 -1
- package/lib/components/copy.d.ts.map +0 -1
- package/lib/components/copy.js.map +0 -1
- package/lib/components/date-picker.d.ts.map +0 -1
- package/lib/components/date-picker.js.map +0 -1
- package/lib/components/dropdown.d.ts +0 -403
- package/lib/components/dropdown.d.ts.map +0 -1
- package/lib/components/dropdown.js +0 -1315
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/icon.d.ts.map +0 -1
- package/lib/components/icon.js.map +0 -1
- package/lib/components/input.d.ts.map +0 -1
- package/lib/components/input.js.map +0 -1
- package/lib/components/modal.d.ts.map +0 -1
- package/lib/components/modal.js.map +0 -1
- package/lib/components/multiselect.d.ts +0 -389
- package/lib/components/multiselect.d.ts.map +0 -1
- package/lib/components/multiselect.js +0 -1301
- package/lib/components/multiselect.js.map +0 -1
- package/lib/components/option.d.ts.map +0 -1
- package/lib/components/option.js.map +0 -1
- package/lib/components/popup.d.ts.map +0 -1
- package/lib/components/popup.js.map +0 -1
- package/lib/components/resize-observer.d.ts.map +0 -1
- package/lib/components/resize-observer.js.map +0 -1
- package/lib/components/scroll-container.d.ts.map +0 -1
- package/lib/components/scroll-container.js.map +0 -1
- package/lib/components/step.d.ts.map +0 -1
- package/lib/components/step.js.map +0 -1
- package/lib/components/tab.d.ts.map +0 -1
- package/lib/components/tab.js.map +0 -1
- package/lib/components/tabs.d.ts.map +0 -1
- package/lib/components/tabs.js.map +0 -1
- package/lib/components/tag.d.ts.map +0 -1
- package/lib/components/tag.js.map +0 -1
- package/lib/components/textarea.d.ts.map +0 -1
- package/lib/components/textarea.js.map +0 -1
- package/lib/components/tooltip.d.ts.map +0 -1
- package/lib/components/tooltip.js.map +0 -1
- package/lib/components/wizard.d.ts.map +0 -1
- package/lib/components/wizard.js.map +0 -1
- package/lib/icons/fontawesome/brands.d.ts.map +0 -1
- package/lib/icons/fontawesome/brands.js.map +0 -1
- package/lib/icons/fontawesome/regular.d.ts.map +0 -1
- package/lib/icons/fontawesome/regular.js.map +0 -1
- package/lib/icons/fontawesome/solid.d.ts.map +0 -1
- package/lib/icons/fontawesome/solid.js.map +0 -1
- package/lib/icons/heroicons/micro.d.ts.map +0 -1
- package/lib/icons/heroicons/micro.js.map +0 -1
- package/lib/icons/heroicons/mini.d.ts.map +0 -1
- package/lib/icons/heroicons/mini.js.map +0 -1
- package/lib/icons/heroicons/outline.d.ts.map +0 -1
- package/lib/icons/heroicons/outline.js.map +0 -1
- package/lib/icons/heroicons/solid.d.ts.map +0 -1
- package/lib/icons/heroicons/solid.js.map +0 -1
- package/lib/icons/lucide.d.ts.map +0 -1
- package/lib/icons/lucide.js.map +0 -1
- package/lib/icons/material/filled.d.ts.map +0 -1
- package/lib/icons/material/filled.js.map +0 -1
- package/lib/icons/material/outlined.d.ts.map +0 -1
- package/lib/icons/material/outlined.js.map +0 -1
- package/lib/icons/material/round.d.ts.map +0 -1
- package/lib/icons/material/round.js.map +0 -1
- package/lib/icons/material/sharp.d.ts.map +0 -1
- package/lib/icons/material/sharp.js.map +0 -1
- package/lib/icons/material/two-tone.d.ts.map +0 -1
- package/lib/icons/material/two-tone.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/styles/button.d.ts.map +0 -1
- package/lib/styles/button.js.map +0 -1
- package/lib/styles/calendar-month.d.ts.map +0 -1
- package/lib/styles/calendar-month.js.map +0 -1
- package/lib/styles/calendar-navigation.d.ts.map +0 -1
- package/lib/styles/calendar-navigation.js.map +0 -1
- package/lib/styles/calendar.d.ts.map +0 -1
- package/lib/styles/calendar.js.map +0 -1
- package/lib/styles/copy.d.ts.map +0 -1
- package/lib/styles/copy.js.map +0 -1
- package/lib/styles/date-picker.d.ts.map +0 -1
- package/lib/styles/date-picker.js.map +0 -1
- package/lib/styles/dropdown.d.ts +0 -12
- package/lib/styles/dropdown.d.ts.map +0 -1
- package/lib/styles/dropdown.js +0 -725
- package/lib/styles/dropdown.js.map +0 -1
- package/lib/styles/icon.d.ts.map +0 -1
- package/lib/styles/icon.js.map +0 -1
- package/lib/styles/input.d.ts.map +0 -1
- package/lib/styles/input.js.map +0 -1
- package/lib/styles/modal.d.ts.map +0 -1
- package/lib/styles/modal.js.map +0 -1
- package/lib/styles/multiselect.d.ts +0 -6
- package/lib/styles/multiselect.d.ts.map +0 -1
- package/lib/styles/multiselect.js +0 -568
- package/lib/styles/multiselect.js.map +0 -1
- package/lib/styles/option.d.ts.map +0 -1
- package/lib/styles/option.js.map +0 -1
- package/lib/styles/popup.d.ts.map +0 -1
- package/lib/styles/popup.js.map +0 -1
- package/lib/styles/resize-observer.d.ts.map +0 -1
- package/lib/styles/resize-observer.js.map +0 -1
- package/lib/styles/scroll-container.d.ts.map +0 -1
- package/lib/styles/scroll-container.js.map +0 -1
- package/lib/styles/step.d.ts.map +0 -1
- package/lib/styles/step.js.map +0 -1
- package/lib/styles/tab.d.ts.map +0 -1
- package/lib/styles/tab.js.map +0 -1
- package/lib/styles/tabs.d.ts.map +0 -1
- package/lib/styles/tabs.js.map +0 -1
- package/lib/styles/tag.d.ts.map +0 -1
- package/lib/styles/tag.js.map +0 -1
- package/lib/styles/textarea.d.ts.map +0 -1
- package/lib/styles/textarea.js.map +0 -1
- package/lib/styles/tooltip.d.ts.map +0 -1
- package/lib/styles/tooltip.js.map +0 -1
- package/lib/styles/wizard.d.ts.map +0 -1
- package/lib/styles/wizard.js.map +0 -1
- package/lib/types/common.d.ts.map +0 -1
- package/lib/types/common.js.map +0 -1
- package/lib/utils/calendar-utils.d.ts.map +0 -1
- package/lib/utils/calendar-utils.js.map +0 -1
- package/lib/utils/icon-registry.d.ts.map +0 -1
- package/lib/utils/icon-registry.js.map +0 -1
- package/lib/utils/locale.d.ts.map +0 -1
- package/lib/utils/locale.js.map +0 -1
- package/lib/utils/number-format.d.ts.map +0 -1
- package/lib/utils/number-format.js.map +0 -1
- package/lib/utils/parse-boolean.d.ts +0 -39
- package/lib/utils/parse-boolean.d.ts.map +0 -1
- package/lib/utils/parse-boolean.js +0 -23
- package/lib/utils/parse-boolean.js.map +0 -1
- package/lib/utils/positioning.d.ts.map +0 -1
- package/lib/utils/positioning.js.map +0 -1
- package/lib/utils/property-capture.d.ts.map +0 -1
- package/lib/utils/property-capture.js.map +0 -1
- package/lib/utils/property-manager.d.ts.map +0 -1
- package/lib/utils/property-manager.js.map +0 -1
- package/lib/utils/resize-observer.d.ts.map +0 -1
- package/lib/utils/resize-observer.js.map +0 -1
- package/lib/utils/scroll-lock.d.ts.map +0 -1
- package/lib/utils/scroll-lock.js.map +0 -1
- package/lib/utils/styles.d.ts.map +0 -1
- package/lib/utils/styles.js.map +0 -1
- package/lib/version.d.ts.map +0 -1
- package/lib/version.js.map +0 -1
|
@@ -81,9 +81,12 @@ export declare class TyFileUpload extends TyComponent<FileUploadState> implement
|
|
|
81
81
|
protected onFormReset(): void;
|
|
82
82
|
protected updateFormValue(): void;
|
|
83
83
|
/** Report `required` to the owning form, like ty-input and ty-textarea
|
|
84
|
-
do — without this the asterisk showed but submission went through.
|
|
84
|
+
do — without this the asterisk showed but submission went through.
|
|
85
|
+
The message is a native file input's. */
|
|
85
86
|
private updateValidity;
|
|
86
87
|
protected getFormValue(): FormData | string | null;
|
|
88
|
+
/** Focus the drop zone: the host itself isn't focusable. */
|
|
89
|
+
focus(options?: FocusOptions): void;
|
|
87
90
|
/**
|
|
88
91
|
* Match a file against the `accept` attribute the way native inputs do:
|
|
89
92
|
* comma-separated list of `.ext`, `type/subtype` or `type/*` entries.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { TyComponent } from "../base/ty-component.js";
|
|
2
2
|
import { ensureStyles } from "../utils/styles.js";
|
|
3
3
|
import { fileUploadStyles } from "../styles/file-upload.js";
|
|
4
|
+
import { nativeMessage } from "../utils/validity.js";
|
|
5
|
+
const DEFAULT_PLACEHOLDER = "Drop files here or click to browse";
|
|
4
6
|
const UPLOAD_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>`;
|
|
5
7
|
const FILE_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>`;
|
|
6
8
|
const X_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>`;
|
|
@@ -29,7 +31,9 @@ this._dropHandler = null;
|
|
|
29
31
|
this._inputChangeHandler = null;
|
|
30
32
|
ensureStyles(this.shadowRoot, { css: fileUploadStyles, id: "ty-file-upload" });
|
|
31
33
|
}
|
|
32
|
-
onConnect() {
|
|
34
|
+
onConnect() {
|
|
35
|
+
this.updateFormValue();
|
|
36
|
+
}
|
|
33
37
|
onDisconnect() {
|
|
34
38
|
this.removeEventListeners();
|
|
35
39
|
}
|
|
@@ -50,21 +54,31 @@ this.updateValidity();
|
|
|
50
54
|
updateValidity() {
|
|
51
55
|
if (this.required && !this.disabled && this._files.length === 0) {
|
|
52
56
|
const anchor = this.shadowRoot?.querySelector(".drop-zone");
|
|
53
|
-
this.applyValidity({ valueMissing: true }, "
|
|
57
|
+
this.applyValidity({ valueMissing: true }, nativeMessage("input", { type: "file", required: true, multiple: this.multiple }), anchor ?? undefined);
|
|
54
58
|
}
|
|
55
59
|
else {
|
|
56
60
|
this.applyValidity({});
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
getFormValue() {
|
|
60
|
-
if (
|
|
64
|
+
if (!this.name)
|
|
61
65
|
return null;
|
|
62
66
|
const fd = new FormData();
|
|
67
|
+
if (this._files.length === 0) {
|
|
68
|
+
fd.append(this.name, new File([], '', { type: 'application/octet-stream' }));
|
|
69
|
+
}
|
|
63
70
|
for (const file of this._files) {
|
|
64
71
|
fd.append(this.name, file);
|
|
65
72
|
}
|
|
66
73
|
return fd;
|
|
67
74
|
}
|
|
75
|
+
focus(options) {
|
|
76
|
+
const zone = this.shadowRoot?.querySelector('.drop-zone');
|
|
77
|
+
if (zone)
|
|
78
|
+
zone.focus(options);
|
|
79
|
+
else
|
|
80
|
+
super.focus(options);
|
|
81
|
+
}
|
|
68
82
|
matchesAccept(file) {
|
|
69
83
|
const accept = this.accept?.trim();
|
|
70
84
|
if (!accept)
|
|
@@ -146,6 +160,7 @@ names: this._files.map((f) => f.name),
|
|
|
146
160
|
};
|
|
147
161
|
setTimeout(() => {
|
|
148
162
|
this.dispatchEvent(new CustomEvent("change", { detail, bubbles: true, composed: true }));
|
|
163
|
+
this.revealValidity();
|
|
149
164
|
}, 0);
|
|
150
165
|
}
|
|
151
166
|
removeFile(index) {
|
|
@@ -367,9 +382,12 @@ const hintEl = container.querySelector(".upload-hint");
|
|
|
367
382
|
if (this._files.length > 0) {
|
|
368
383
|
hintEl.innerHTML = `<strong>${this._files.length} file${this._files.length !== 1 ? "s" : ""} selected</strong>`;
|
|
369
384
|
}
|
|
370
|
-
else {
|
|
385
|
+
else if (!this.placeholder || this.placeholder === DEFAULT_PLACEHOLDER) {
|
|
371
386
|
hintEl.innerHTML = `Drop files here or <span class="browse-link">click to browse</span>`;
|
|
372
387
|
}
|
|
388
|
+
else {
|
|
389
|
+
hintEl.textContent = this.placeholder;
|
|
390
|
+
}
|
|
373
391
|
const subHintEl = container.querySelector(".upload-sub-hint");
|
|
374
392
|
if (this.accept && this._files.length === 0) {
|
|
375
393
|
subHintEl.textContent = `Accepted: ${this.accept}`;
|
|
@@ -420,7 +438,7 @@ default: "",
|
|
|
420
438
|
placeholder: {
|
|
421
439
|
type: "string",
|
|
422
440
|
visual: true,
|
|
423
|
-
default:
|
|
441
|
+
default: DEFAULT_PLACEHOLDER,
|
|
424
442
|
},
|
|
425
443
|
error: {
|
|
426
444
|
type: "string",
|
|
@@ -59,6 +59,41 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
59
59
|
visual: boolean;
|
|
60
60
|
default: boolean;
|
|
61
61
|
};
|
|
62
|
+
pattern: {
|
|
63
|
+
type: "string";
|
|
64
|
+
visual: boolean;
|
|
65
|
+
default: string;
|
|
66
|
+
};
|
|
67
|
+
minlength: {
|
|
68
|
+
type: "string";
|
|
69
|
+
visual: boolean;
|
|
70
|
+
default: string;
|
|
71
|
+
};
|
|
72
|
+
maxlength: {
|
|
73
|
+
type: "string";
|
|
74
|
+
visual: boolean;
|
|
75
|
+
default: string;
|
|
76
|
+
};
|
|
77
|
+
min: {
|
|
78
|
+
type: "string";
|
|
79
|
+
visual: boolean;
|
|
80
|
+
default: string;
|
|
81
|
+
};
|
|
82
|
+
max: {
|
|
83
|
+
type: "string";
|
|
84
|
+
visual: boolean;
|
|
85
|
+
default: string;
|
|
86
|
+
};
|
|
87
|
+
tooShortMessage: {
|
|
88
|
+
type: "string";
|
|
89
|
+
visual: boolean;
|
|
90
|
+
default: string;
|
|
91
|
+
};
|
|
92
|
+
tooLongMessage: {
|
|
93
|
+
type: "string";
|
|
94
|
+
visual: boolean;
|
|
95
|
+
default: string;
|
|
96
|
+
};
|
|
62
97
|
error: {
|
|
63
98
|
type: "string";
|
|
64
99
|
visual: boolean;
|
|
@@ -103,7 +138,6 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
103
138
|
private _shadowValue;
|
|
104
139
|
private _isFocused;
|
|
105
140
|
private _listenersSetup;
|
|
106
|
-
private _errorAutoDanger;
|
|
107
141
|
private _customFlavorSheet;
|
|
108
142
|
private _inputHandler;
|
|
109
143
|
private _changeHandler;
|
|
@@ -143,8 +177,24 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
143
177
|
set label(v: string);
|
|
144
178
|
get disabled(): boolean;
|
|
145
179
|
set disabled(v: boolean);
|
|
180
|
+
/** Focus the inner <input>: the host itself isn't focusable. */
|
|
181
|
+
focus(options?: FocusOptions): void;
|
|
146
182
|
get required(): boolean;
|
|
147
183
|
set required(v: boolean);
|
|
184
|
+
get pattern(): string;
|
|
185
|
+
set pattern(v: string);
|
|
186
|
+
get minLength(): number;
|
|
187
|
+
set minLength(v: number);
|
|
188
|
+
get maxLength(): number;
|
|
189
|
+
set maxLength(v: number);
|
|
190
|
+
get min(): string;
|
|
191
|
+
set min(v: string);
|
|
192
|
+
get max(): string;
|
|
193
|
+
set max(v: string);
|
|
194
|
+
get tooShortMessage(): string;
|
|
195
|
+
set tooShortMessage(v: string);
|
|
196
|
+
get tooLongMessage(): string;
|
|
197
|
+
set tooLongMessage(v: string);
|
|
148
198
|
get error(): string;
|
|
149
199
|
set error(v: string);
|
|
150
200
|
get size(): Size;
|
|
@@ -165,6 +215,13 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
165
215
|
private dispatchChangeEvent;
|
|
166
216
|
private removeEventListeners;
|
|
167
217
|
/** IMPORTANT: Only called ONCE, not on every render. */
|
|
218
|
+
/**
|
|
219
|
+
* Enter submits the owning form, like a native input (HTML implicit
|
|
220
|
+
* submission): through the form's default button when it has one (nothing
|
|
221
|
+
* if that button is disabled), otherwise only when this is the form's only
|
|
222
|
+
* text field.
|
|
223
|
+
*/
|
|
224
|
+
private _implicitSubmit;
|
|
168
225
|
private setupEventListeners;
|
|
169
226
|
/** Render the input component with wrapper and slots. */
|
|
170
227
|
render(): void;
|
|
@@ -174,10 +231,23 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
174
231
|
* `type` property stays "password" (form value and API unaffected).
|
|
175
232
|
*/
|
|
176
233
|
private setupPasswordToggle;
|
|
234
|
+
/**
|
|
235
|
+
* pattern, minlength and maxlength go on the inner <input>: pattern for the
|
|
236
|
+
* browser's own patternMismatch check, minlength for its tooShort message
|
|
237
|
+
* after the user types, maxlength so typing stops at the limit like a
|
|
238
|
+
* native field. Formatted (numeric) types show a display string, so they
|
|
239
|
+
* get none.
|
|
240
|
+
*/
|
|
241
|
+
private syncConstraintAttributes;
|
|
177
242
|
/**
|
|
178
243
|
* Reflect constraint validation to the owning <form> via ElementInternals.
|
|
179
|
-
* Without this
|
|
180
|
-
*
|
|
244
|
+
* Without this the inner shadow <input> can't block the outer form.
|
|
245
|
+
* Rules, first failing one supplies the message:
|
|
246
|
+
* - required: empty => valueMissing
|
|
247
|
+
* - email/url: the inner input's own typeMismatch
|
|
248
|
+
* - text types: pattern, minlength, maxlength
|
|
249
|
+
* - number/currency/percent/compact: min, max against the numeric value
|
|
250
|
+
* Empty values only fail `required`, like native inputs.
|
|
181
251
|
* Disabled fields are barred from constraint validation.
|
|
182
252
|
*/
|
|
183
253
|
private updateValidity;
|
package/lib/components/input.js
CHANGED
|
@@ -6,6 +6,7 @@ import { inputStyles, inputCustomFlavorCss } from '../styles/input.js';
|
|
|
6
6
|
import { formatNumber, parseNumericValue, shouldFormat as shouldFormatType } from '../utils/number-format.js';
|
|
7
7
|
import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
|
|
8
8
|
import { REQUIRED_ICON_SVG } from '../utils/icons.js';
|
|
9
|
+
import { nativeMessage, nativeValidity, lengthValidity, toLimit } from '../utils/validity.js';
|
|
9
10
|
const EYE_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/></svg>`;
|
|
10
11
|
const EYE_OFF_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"/><path d="M14.084 14.158a3 3 0 0 1-4.242-4.242"/><path d="M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"/><path d="m2 2 20 20"/></svg>`;
|
|
11
12
|
export class TyInput extends TyComponent {
|
|
@@ -14,7 +15,6 @@ super();
|
|
|
14
15
|
this._shadowValue = null;
|
|
15
16
|
this._isFocused = false;
|
|
16
17
|
this._listenersSetup = false;
|
|
17
|
-
this._errorAutoDanger = false;
|
|
18
18
|
this._customFlavorSheet = null;
|
|
19
19
|
this._inputHandler = null;
|
|
20
20
|
this._changeHandler = null;
|
|
@@ -22,15 +22,48 @@ this._focusHandler = null;
|
|
|
22
22
|
this._blurHandler = null;
|
|
23
23
|
this._inputDebounceTimer = null;
|
|
24
24
|
this._changeDebounceTimer = null;
|
|
25
|
+
this._implicitSubmit = (e) => {
|
|
26
|
+
if (e.key !== 'Enter' || e.isComposing || e.defaultPrevented)
|
|
27
|
+
return;
|
|
28
|
+
const form = this._internals.form;
|
|
29
|
+
if (!form)
|
|
30
|
+
return;
|
|
31
|
+
const controls = Array.from(form.elements);
|
|
32
|
+
const isSubmitter = (el) => (el instanceof HTMLButtonElement && el.type === 'submit') ||
|
|
33
|
+
(el instanceof HTMLInputElement && (el.type === 'submit' || el.type === 'image')) ||
|
|
34
|
+
(el.tagName === 'TY-BUTTON' && !['button', 'reset'].includes(el.getAttribute('type') ?? ''));
|
|
35
|
+
const submitter = controls.find(isSubmitter);
|
|
36
|
+
if (submitter) {
|
|
37
|
+
if (submitter.disabled || submitter.hasAttribute('disabled'))
|
|
38
|
+
return;
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
const target = submitter.tagName === 'TY-BUTTON'
|
|
41
|
+
? submitter.shadowRoot?.querySelector('button') ?? submitter
|
|
42
|
+
: submitter;
|
|
43
|
+
target.click();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const textFields = controls.filter((el) => el.tagName === 'TY-INPUT' ||
|
|
47
|
+
(el instanceof HTMLInputElement && !['button', 'checkbox', 'radio', 'file', 'hidden', 'image', 'reset', 'submit', 'range', 'color'].includes(el.type)));
|
|
48
|
+
if (textFields.length === 1) {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
form.requestSubmit();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
25
53
|
const shadow = this.shadowRoot;
|
|
26
54
|
ensureStyles(shadow, { css: inputStyles, id: 'ty-input' });
|
|
27
55
|
}
|
|
28
56
|
onConnect() {
|
|
57
|
+
if (!this._rendered)
|
|
29
58
|
this.initializeShadowValue();
|
|
30
59
|
this._localeObserver = observeLocaleChanges(this, () => {
|
|
31
60
|
this.render();
|
|
32
61
|
});
|
|
33
62
|
this._syncCustomFlavor();
|
|
63
|
+
if (this._rendered) {
|
|
64
|
+
this.render();
|
|
65
|
+
this.setupEventListeners();
|
|
66
|
+
}
|
|
34
67
|
}
|
|
35
68
|
_syncCustomFlavor() {
|
|
36
69
|
this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => inputCustomFlavorCss(base));
|
|
@@ -63,20 +96,6 @@ case 'type':
|
|
|
63
96
|
const currentValue = this.getProperty('value') || '';
|
|
64
97
|
this._shadowValue = this.parseShadowValue(currentValue);
|
|
65
98
|
break;
|
|
66
|
-
case 'error':
|
|
67
|
-
if (newValue) {
|
|
68
|
-
if (this.getProperty('flavor') === 'neutral') {
|
|
69
|
-
this.setProperty('flavor', 'danger');
|
|
70
|
-
this._errorAutoDanger = true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else if (this._errorAutoDanger) {
|
|
74
|
-
if (this.getProperty('flavor') === 'danger') {
|
|
75
|
-
this.setProperty('flavor', 'neutral');
|
|
76
|
-
}
|
|
77
|
-
this._errorAutoDanger = false;
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
99
|
}
|
|
81
100
|
}
|
|
82
101
|
}
|
|
@@ -95,14 +114,17 @@ this._changeDebounceTimer = null;
|
|
|
95
114
|
this.render();
|
|
96
115
|
}
|
|
97
116
|
getFormValue() {
|
|
98
|
-
const formValue = this._shadowValue !== null ? String(this._shadowValue) :
|
|
117
|
+
const formValue = this._shadowValue !== null ? String(this._shadowValue) : '';
|
|
99
118
|
return formValue;
|
|
100
119
|
}
|
|
101
120
|
initializeShadowValue() {
|
|
102
121
|
const currentValue = this.getProperty('value');
|
|
103
122
|
if (currentValue) {
|
|
104
123
|
this._shadowValue = this.parseShadowValue(currentValue);
|
|
105
|
-
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) :
|
|
124
|
+
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : '');
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
this._internals.setFormValue('');
|
|
106
128
|
}
|
|
107
129
|
}
|
|
108
130
|
parseShadowValue(value) {
|
|
@@ -155,8 +177,25 @@ get label() { return this.getProperty('label'); }
|
|
|
155
177
|
set label(v) { this.setProperty('label', v); }
|
|
156
178
|
get disabled() { return this.getProperty('disabled'); }
|
|
157
179
|
set disabled(v) { this.setProperty('disabled', v); }
|
|
180
|
+
focus(options) {
|
|
181
|
+
this.shadowRoot?.querySelector('input')?.focus(options);
|
|
182
|
+
}
|
|
158
183
|
get required() { return this.getProperty('required'); }
|
|
159
184
|
set required(v) { this.setProperty('required', v); }
|
|
185
|
+
get pattern() { return this.getProperty('pattern'); }
|
|
186
|
+
set pattern(v) { this.setProperty('pattern', v ?? ''); }
|
|
187
|
+
get minLength() { return toLimit(this.getProperty('minlength')) ?? -1; }
|
|
188
|
+
set minLength(v) { this.setProperty('minlength', v == null || v < 0 ? '' : String(v)); }
|
|
189
|
+
get maxLength() { return toLimit(this.getProperty('maxlength')) ?? -1; }
|
|
190
|
+
set maxLength(v) { this.setProperty('maxlength', v == null || v < 0 ? '' : String(v)); }
|
|
191
|
+
get min() { return this.getProperty('min'); }
|
|
192
|
+
set min(v) { this.setProperty('min', v == null ? '' : String(v)); }
|
|
193
|
+
get max() { return this.getProperty('max'); }
|
|
194
|
+
set max(v) { this.setProperty('max', v == null ? '' : String(v)); }
|
|
195
|
+
get tooShortMessage() { return this.getProperty('tooShortMessage'); }
|
|
196
|
+
set tooShortMessage(v) { this.setProperty('tooShortMessage', v ?? ''); }
|
|
197
|
+
get tooLongMessage() { return this.getProperty('tooLongMessage'); }
|
|
198
|
+
set tooLongMessage(v) { this.setProperty('tooLongMessage', v ?? ''); }
|
|
160
199
|
get error() { return this.getProperty('error'); }
|
|
161
200
|
set error(v) { this.setProperty('error', v); }
|
|
162
201
|
get size() { return this.getProperty('size'); }
|
|
@@ -235,6 +274,7 @@ if (this._blurHandler) {
|
|
|
235
274
|
inputEl.removeEventListener('blur', this._blurHandler);
|
|
236
275
|
this._blurHandler = null;
|
|
237
276
|
}
|
|
277
|
+
inputEl.removeEventListener('keydown', this._implicitSubmit);
|
|
238
278
|
this._listenersSetup = false;
|
|
239
279
|
}
|
|
240
280
|
setupEventListeners() {
|
|
@@ -249,12 +289,13 @@ console.warn('[TyInput.setupEventListeners] ⚠️ Input element not found!');
|
|
|
249
289
|
return;
|
|
250
290
|
}
|
|
251
291
|
this._inputHandler = (e) => {
|
|
292
|
+
this._userEdited = true;
|
|
252
293
|
e.stopPropagation();
|
|
253
294
|
e.stopImmediatePropagation();
|
|
254
295
|
const target = e.target;
|
|
255
296
|
const rawValue = target.value;
|
|
256
297
|
this._shadowValue = this.parseShadowValue(rawValue);
|
|
257
|
-
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) :
|
|
298
|
+
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : '');
|
|
258
299
|
this.updateValidity();
|
|
259
300
|
if (this._inputDebounceTimer !== null) {
|
|
260
301
|
clearTimeout(this._inputDebounceTimer);
|
|
@@ -275,7 +316,7 @@ e.stopImmediatePropagation();
|
|
|
275
316
|
const target = e.target;
|
|
276
317
|
const rawValue = target.value;
|
|
277
318
|
this._shadowValue = this.parseShadowValue(rawValue);
|
|
278
|
-
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) :
|
|
319
|
+
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : '');
|
|
279
320
|
this.updateValidity();
|
|
280
321
|
if (this._changeDebounceTimer !== null) {
|
|
281
322
|
clearTimeout(this._changeDebounceTimer);
|
|
@@ -317,6 +358,8 @@ this.dispatchChangeEvent(rawValue, e);
|
|
|
317
358
|
}
|
|
318
359
|
this._isFocused = false;
|
|
319
360
|
wrapperEl.classList.remove('focused');
|
|
361
|
+
if (this._userEdited)
|
|
362
|
+
this.revealValidity();
|
|
320
363
|
if (this.shouldFormat()) {
|
|
321
364
|
inputEl.value = this.getDisplayValue();
|
|
322
365
|
}
|
|
@@ -330,6 +373,7 @@ inputEl.addEventListener('input', this._inputHandler);
|
|
|
330
373
|
inputEl.addEventListener('change', this._changeHandler);
|
|
331
374
|
inputEl.addEventListener('focus', this._focusHandler);
|
|
332
375
|
inputEl.addEventListener('blur', this._blurHandler);
|
|
376
|
+
inputEl.addEventListener('keydown', this._implicitSubmit);
|
|
333
377
|
this._listenersSetup = true;
|
|
334
378
|
}
|
|
335
379
|
render() {
|
|
@@ -339,6 +383,9 @@ const existingWrapper = shadow.querySelector('.input-wrapper');
|
|
|
339
383
|
const existingLabel = shadow.querySelector('.ty-field-label');
|
|
340
384
|
const existingError = shadow.querySelector('.error-message');
|
|
341
385
|
const classes = this.buildClassList();
|
|
386
|
+
const focused = !!existingInput && shadow.activeElement === existingInput;
|
|
387
|
+
if (!focused)
|
|
388
|
+
this._isFocused = false;
|
|
342
389
|
const inputType = ['password', 'email', 'tel', 'url'].includes(this.type)
|
|
343
390
|
? this.type
|
|
344
391
|
: 'text';
|
|
@@ -349,7 +396,10 @@ const inputMode = shouldFormatType(this.type) ? 'decimal'
|
|
|
349
396
|
: undefined;
|
|
350
397
|
const displayValue = this.getDisplayValue();
|
|
351
398
|
if (existingInput && existingWrapper) {
|
|
352
|
-
|
|
399
|
+
const revealed = inputType === 'password' &&
|
|
400
|
+
shadow.querySelector('.password-toggle')?.getAttribute('aria-pressed') === 'true';
|
|
401
|
+
existingInput.type = revealed ? 'text' : inputType;
|
|
402
|
+
if (existingInput.value !== displayValue)
|
|
353
403
|
existingInput.value = displayValue;
|
|
354
404
|
existingInput.placeholder = this.placeholder;
|
|
355
405
|
existingInput.name = this.name;
|
|
@@ -358,6 +408,7 @@ existingInput.inputMode = inputMode;
|
|
|
358
408
|
else
|
|
359
409
|
existingInput.removeAttribute('inputmode');
|
|
360
410
|
existingWrapper.className = `input-wrapper ${classes}`;
|
|
411
|
+
existingWrapper.classList.toggle('focused', focused);
|
|
361
412
|
existingInput.disabled = this.disabled;
|
|
362
413
|
if (this.disabled) {
|
|
363
414
|
existingInput.setAttribute('disabled', '');
|
|
@@ -372,6 +423,7 @@ existingInput.setAttribute('required', '');
|
|
|
372
423
|
else {
|
|
373
424
|
existingInput.removeAttribute('required');
|
|
374
425
|
}
|
|
426
|
+
this.syncConstraintAttributes(existingInput);
|
|
375
427
|
if (this.label)
|
|
376
428
|
existingInput.setAttribute('aria-label', this.label);
|
|
377
429
|
else
|
|
@@ -445,6 +497,7 @@ ${errorHtml}
|
|
|
445
497
|
const inputEl = shadow.querySelector('input');
|
|
446
498
|
inputEl.disabled = this.disabled;
|
|
447
499
|
inputEl.required = this.required;
|
|
500
|
+
this.syncConstraintAttributes(inputEl);
|
|
448
501
|
if (this.label)
|
|
449
502
|
inputEl.setAttribute('aria-label', this.label);
|
|
450
503
|
this.setupPasswordToggle();
|
|
@@ -461,12 +514,24 @@ return;
|
|
|
461
514
|
toggle.addEventListener('mousedown', (e) => e.preventDefault());
|
|
462
515
|
toggle.addEventListener('click', () => {
|
|
463
516
|
const reveal = inputEl.type === 'password';
|
|
517
|
+
const { selectionStart, selectionEnd, selectionDirection } = inputEl;
|
|
464
518
|
inputEl.type = reveal ? 'text' : 'password';
|
|
519
|
+
if (selectionStart !== null && shadow.activeElement === inputEl) {
|
|
520
|
+
inputEl.getBoundingClientRect();
|
|
521
|
+
inputEl.setSelectionRange(selectionStart, selectionEnd, selectionDirection ?? undefined);
|
|
522
|
+
}
|
|
465
523
|
toggle.innerHTML = reveal ? EYE_OFF_ICON_SVG : EYE_ICON_SVG;
|
|
466
524
|
toggle.setAttribute('aria-label', reveal ? 'Hide password' : 'Show password');
|
|
467
525
|
toggle.setAttribute('aria-pressed', String(reveal));
|
|
468
526
|
});
|
|
469
527
|
}
|
|
528
|
+
syncConstraintAttributes(inputEl) {
|
|
529
|
+
const text = !shouldFormatType(this.type);
|
|
530
|
+
const set = (name, v) => text && v !== '' ? inputEl.setAttribute(name, v) : inputEl.removeAttribute(name);
|
|
531
|
+
set('pattern', this.pattern);
|
|
532
|
+
set('minlength', toLimit(this.getProperty('minlength')) != null ? String(this.minLength) : '');
|
|
533
|
+
set('maxlength', toLimit(this.getProperty('maxlength')) != null ? String(this.maxLength) : '');
|
|
534
|
+
}
|
|
470
535
|
updateValidity() {
|
|
471
536
|
const inputEl = this.shadowRoot?.querySelector('input');
|
|
472
537
|
if (this.disabled) {
|
|
@@ -474,12 +539,48 @@ this.applyValidity({});
|
|
|
474
539
|
return;
|
|
475
540
|
}
|
|
476
541
|
const current = inputEl ? inputEl.value : String(this.getProperty('value') ?? '');
|
|
477
|
-
if (
|
|
478
|
-
this.
|
|
542
|
+
if (current.trim() === '') {
|
|
543
|
+
if (this.required) {
|
|
544
|
+
this.applyValidity({ valueMissing: true }, nativeMessage('input', { type: 'text', required: true }), inputEl ?? undefined);
|
|
479
545
|
}
|
|
480
546
|
else {
|
|
481
547
|
this.applyValidity({});
|
|
482
548
|
}
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const flags = {};
|
|
552
|
+
const messages = [];
|
|
553
|
+
const fail = (flag, message) => {
|
|
554
|
+
flags[flag] = true;
|
|
555
|
+
messages.push(message);
|
|
556
|
+
};
|
|
557
|
+
if (shouldFormatType(this.type)) {
|
|
558
|
+
const n = typeof this._shadowValue === 'number' ? this._shadowValue : null;
|
|
559
|
+
if (n !== null && (this.min || this.max)) {
|
|
560
|
+
const { validity, message } = nativeValidity('input', { type: 'number', step: 'any', min: this.min, max: this.max }, String(n));
|
|
561
|
+
if (validity.rangeUnderflow)
|
|
562
|
+
fail('rangeUnderflow', message);
|
|
563
|
+
if (validity.rangeOverflow)
|
|
564
|
+
fail('rangeOverflow', message);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
if (inputEl?.validity.typeMismatch)
|
|
569
|
+
fail('typeMismatch', inputEl.validationMessage);
|
|
570
|
+
if (inputEl?.validity.patternMismatch)
|
|
571
|
+
fail('patternMismatch', inputEl.validationMessage);
|
|
572
|
+
const { tooShort, tooLong } = lengthValidity(current, {
|
|
573
|
+
minlength: this.getProperty('minlength'),
|
|
574
|
+
maxlength: this.getProperty('maxlength'),
|
|
575
|
+
tooShortMessage: this.tooShortMessage,
|
|
576
|
+
tooLongMessage: this.tooLongMessage,
|
|
577
|
+
}, inputEl);
|
|
578
|
+
if (tooShort)
|
|
579
|
+
fail('tooShort', tooShort);
|
|
580
|
+
if (tooLong)
|
|
581
|
+
fail('tooLong', tooLong);
|
|
582
|
+
}
|
|
583
|
+
this.applyValidity(flags, messages[0], inputEl ?? undefined);
|
|
483
584
|
}
|
|
484
585
|
}
|
|
485
586
|
TyInput.formAssociated = true;
|
|
@@ -538,6 +639,41 @@ type: 'boolean',
|
|
|
538
639
|
visual: true,
|
|
539
640
|
default: false
|
|
540
641
|
},
|
|
642
|
+
pattern: {
|
|
643
|
+
type: 'string',
|
|
644
|
+
visual: true,
|
|
645
|
+
default: ''
|
|
646
|
+
},
|
|
647
|
+
minlength: {
|
|
648
|
+
type: 'string',
|
|
649
|
+
visual: true,
|
|
650
|
+
default: ''
|
|
651
|
+
},
|
|
652
|
+
maxlength: {
|
|
653
|
+
type: 'string',
|
|
654
|
+
visual: true,
|
|
655
|
+
default: ''
|
|
656
|
+
},
|
|
657
|
+
min: {
|
|
658
|
+
type: 'string',
|
|
659
|
+
visual: true,
|
|
660
|
+
default: ''
|
|
661
|
+
},
|
|
662
|
+
max: {
|
|
663
|
+
type: 'string',
|
|
664
|
+
visual: true,
|
|
665
|
+
default: ''
|
|
666
|
+
},
|
|
667
|
+
tooShortMessage: {
|
|
668
|
+
type: 'string',
|
|
669
|
+
visual: true,
|
|
670
|
+
default: ''
|
|
671
|
+
},
|
|
672
|
+
tooLongMessage: {
|
|
673
|
+
type: 'string',
|
|
674
|
+
visual: true,
|
|
675
|
+
default: ''
|
|
676
|
+
},
|
|
541
677
|
error: {
|
|
542
678
|
type: 'string',
|
|
543
679
|
visual: true,
|
|
@@ -52,6 +52,8 @@ export declare class TyModal extends HTMLElement {
|
|
|
52
52
|
set open(v: boolean);
|
|
53
53
|
get noBackdrop(): boolean;
|
|
54
54
|
set noBackdrop(v: boolean);
|
|
55
|
+
get noZoom(): boolean;
|
|
56
|
+
set noZoom(v: boolean);
|
|
55
57
|
get preventOutsideClick(): boolean;
|
|
56
58
|
set preventOutsideClick(v: boolean);
|
|
57
59
|
get preventEscape(): boolean;
|