@c2n/text-field 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{text-field-DkffSesv.js → text-field-CEaLhsMN.js} +70 -6
- package/dist/text-field-clear.js +3 -2
- package/dist/text-field.js +1 -1
- package/package.json +20 -8
- package/react.d.ts +26 -0
- package/react.js +3 -0
- package/types/src/text-field-clear.d.ts.map +1 -1
- package/types/src/text-field.d.ts +36 -1
- package/types/src/text-field.d.ts.map +1 -1
- package/vue.d.ts +47 -0
- package/vue.js +3 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { LitElement, html, nothing, unsafeCSS } from "lit";
|
|
2
|
-
import {
|
|
2
|
+
import { property, query, state } from "lit/decorators.js";
|
|
3
|
+
import { customElement } from "@c2n/core/element-helper.js";
|
|
3
4
|
import { ifDefined } from "lit/directives/if-defined.js";
|
|
4
5
|
import { classMap } from "lit/directives/class-map.js";
|
|
5
6
|
import { live } from "lit/directives/live.js";
|
|
6
7
|
import { addClasses } from "@c2n/core/css-helper.js";
|
|
7
8
|
import { redispatchEvent } from "@c2n/core/dom-helper.js";
|
|
8
9
|
//#region src/text-field.scss?inline
|
|
9
|
-
var text_field_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: inline-flex;\n flex-direction: column;\n gap: var(--c2-text-field__supporting-text--gap,4px);\n vertical-align: middle;\n}\n\n:host([hidden]) {\n display: none;\n}\n\n.c2-text-field-row {\n display: flex;\n align-items: center;\n gap: var(--c2-text-field__help-icon--gap,8px);\n}\n\n.c2-text-field {\n display: flex;\n flex: 1;\n min-width: 0;\n align-items: center;\n box-sizing: border-box;\n position: relative;\n cursor: text;\n text-align: inherit;\n min-height: var(--c2-text-field--min-height,36px);\n gap: var(--c2-text-field--gap,8px);\n padding-top: var(--c2-text-field--padding-top,6px);\n padding-bottom: var(--c2-text-field--padding-bottom,6px);\n padding-right: var(--c2-text-field--padding-right,10px);\n padding-left: var(--c2-text-field--padding-left,12px);\n border-top: var(--c2-text-field--border-top,1px solid #bcbcc6);\n border-bottom: var(--c2-text-field--border-bottom,1px solid #bcbcc6);\n border-right: var(--c2-text-field--border-right,1px solid #bcbcc6);\n border-left: var(--c2-text-field--border-left,1px solid #bcbcc6);\n border-top-left-radius: var(--c2-text-field--border-top-left-radius,6px);\n border-top-right-radius: var(--c2-text-field--border-top-right-radius,6px);\n border-bottom-left-radius: var(--c2-text-field--border-bottom-left-radius,6px);\n border-bottom-right-radius: var(--c2-text-field--border-bottom-right-radius,6px);\n color: var(--c2-text-field--color,#18181b);\n background: var(--c2-text-field--background,#ffffff);\n font-size: var(--c2-text-field--font-size,14px);\n font-weight: var(--c2-text-field--font-weight);\n font-style: var(--c2-text-field--font-style);\n font-family: var(--c2-text-field--font-family);\n line-height: var(--c2-text-field--line-height,20px);\n outline: var(--c2-text-field__focus--outline,3px solid rgba(71, 110, 249, 0.2));\n outline-color: transparent;\n outline-offset: var(--c2-text-field__focus--outline-offset,0px);\n will-change: border, background, outline-color;\n transition: border 250ms cubic-bezier(0.2, 0, 0, 1), background 250ms cubic-bezier(0.2, 0, 0, 1), outline-color 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.c2-text-field .input {\n flex: 1;\n min-width: 0;\n width: 100%;\n margin: 0;\n padding: 0;\n border: none;\n outline: none;\n background: transparent;\n color: inherit;\n caret-color: inherit;\n font: inherit;\n line-height: inherit;\n text-align: inherit;\n}\n.c2-text-field .input::placeholder {\n font-weight: var(--c2-text-field__placeholder--font-weight);\n font-style: var(--c2-text-field__placeholder--font-style);\n color: var(--c2-text-field__placeholder--color,#71717a);\n opacity: var(--c2-text-field__placeholder--opacity,1);\n}\n.c2-text-field .input::-webkit-search-cancel-button, .c2-text-field .input::-webkit-search-decoration {\n appearance: none;\n}\n@media (forced-colors: active) {\n .c2-text-field .input {\n background: Field;\n }\n}\n.c2-text-field:hover {\n border-top: var(--c2-text-field__hover--border-top,var(--c2-text-field--border-top,1px solid #a1a1aa));\n border-bottom: var(--c2-text-field__hover--border-bottom,var(--c2-text-field--border-bottom,1px solid #a1a1aa));\n border-right: var(--c2-text-field__hover--border-right,var(--c2-text-field--border-right,1px solid #a1a1aa));\n border-left: var(--c2-text-field__hover--border-left,var(--c2-text-field--border-left,1px solid #a1a1aa));\n}\n.c2-text-field.focus-within {\n border-top: var(--c2-text-field__focus--border-top,var(--c2-text-field--border-top,1px solid #476ef9));\n border-bottom: var(--c2-text-field__focus--border-bottom,var(--c2-text-field--border-bottom,1px solid #476ef9));\n border-right: var(--c2-text-field__focus--border-right,var(--c2-text-field--border-right,1px solid #476ef9));\n border-left: var(--c2-text-field__focus--border-left,var(--c2-text-field--border-left,1px solid #476ef9));\n color: var(--c2-text-field__focus--color,var(--c2-text-field--color,#18181b));\n background: var(--c2-text-field__focus--background,var(--c2-text-field--background,#ffffff));\n outline: var(--c2-text-field__focus--outline,3px solid rgba(71, 110, 249, 0.2));\n outline-offset: var(--c2-text-field__focus--outline-offset,0px);\n}\n.c2-text-field.error {\n border-top: var(--c2-text-field__error--border-top,1px solid #dc2626);\n border-bottom: var(--c2-text-field__error--border-bottom,1px solid #dc2626);\n border-right: var(--c2-text-field__error--border-right,1px solid #dc2626);\n border-left: var(--c2-text-field__error--border-left,1px solid #dc2626);\n color: var(--c2-text-field__error--color,var(--c2-text-field--color,#18181b));\n background: var(--c2-text-field__error--background,var(--c2-text-field--background,#ffffff));\n}\n.c2-text-field.error.focus-within {\n outline: var(--c2-text-field__error__focus--outline,3px solid rgba(220, 38, 38, 0.2));\n}\n.c2-text-field.read-only {\n cursor: default;\n border-top: var(--c2-text-field__read-only--border-top,1px solid #e4e4e7);\n border-bottom: var(--c2-text-field__read-only--border-bottom,1px solid #e4e4e7);\n border-right: var(--c2-text-field__read-only--border-right,1px solid #e4e4e7);\n border-left: var(--c2-text-field__read-only--border-left,1px solid #e4e4e7);\n color: var(--c2-text-field__read-only--color,var(--c2-text-field--color,#18181b));\n background: var(--c2-text-field__read-only--background,#fafafa);\n}\n.c2-text-field.disabled {\n cursor: default;\n opacity: var(--c2-text-field__disabled--opacity,0.38);\n pointer-events: none;\n}\n\n::slotted([slot=prefix-icon]),\n::slotted([slot=suffix-icon]) {\n flex: none;\n
|
|
10
|
+
var text_field_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: inline-flex;\n flex-direction: column;\n gap: var(--c2-text-field__supporting-text--gap,4px);\n vertical-align: middle;\n}\n\n:host([hidden]) {\n display: none;\n}\n\n.c2-text-field-row {\n display: flex;\n align-items: center;\n gap: var(--c2-text-field__help-icon--gap,8px);\n}\n\n.c2-text-field {\n display: flex;\n flex: 1;\n min-width: 0;\n align-items: center;\n box-sizing: border-box;\n position: relative;\n cursor: text;\n text-align: inherit;\n min-height: var(--c2-text-field--min-height,36px);\n gap: var(--c2-text-field--gap,8px);\n padding-top: var(--c2-text-field--padding-top,6px);\n padding-bottom: var(--c2-text-field--padding-bottom,6px);\n padding-right: var(--c2-text-field--padding-right,10px);\n padding-left: var(--c2-text-field--padding-left,12px);\n border-top: var(--c2-text-field--border-top,1px solid #bcbcc6);\n border-bottom: var(--c2-text-field--border-bottom,1px solid #bcbcc6);\n border-right: var(--c2-text-field--border-right,1px solid #bcbcc6);\n border-left: var(--c2-text-field--border-left,1px solid #bcbcc6);\n border-top-left-radius: var(--c2-text-field--border-top-left-radius,6px);\n border-top-right-radius: var(--c2-text-field--border-top-right-radius,6px);\n border-bottom-left-radius: var(--c2-text-field--border-bottom-left-radius,6px);\n border-bottom-right-radius: var(--c2-text-field--border-bottom-right-radius,6px);\n color: var(--c2-text-field--color,#18181b);\n background: var(--c2-text-field--background,#ffffff);\n font-size: var(--c2-text-field--font-size,14px);\n font-weight: var(--c2-text-field--font-weight);\n font-style: var(--c2-text-field--font-style);\n font-family: var(--c2-text-field--font-family);\n line-height: var(--c2-text-field--line-height,20px);\n outline: var(--c2-text-field__focus--outline,3px solid rgba(71, 110, 249, 0.2));\n outline-color: transparent;\n outline-offset: var(--c2-text-field__focus--outline-offset,0px);\n will-change: border, background, outline-color;\n transition: border 250ms cubic-bezier(0.2, 0, 0, 1), background 250ms cubic-bezier(0.2, 0, 0, 1), outline-color 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.c2-text-field .input {\n flex: 1;\n min-width: 0;\n width: 100%;\n margin: 0;\n padding: 0;\n border: none;\n outline: none;\n background: transparent;\n color: inherit;\n caret-color: inherit;\n font: inherit;\n line-height: inherit;\n text-align: inherit;\n}\n.c2-text-field .input::placeholder {\n font-weight: var(--c2-text-field__placeholder--font-weight);\n font-style: var(--c2-text-field__placeholder--font-style);\n color: var(--c2-text-field__placeholder--color,#71717a);\n opacity: var(--c2-text-field__placeholder--opacity,1);\n}\n.c2-text-field .input::-webkit-search-cancel-button, .c2-text-field .input::-webkit-search-decoration {\n appearance: none;\n}\n@media (forced-colors: active) {\n .c2-text-field .input {\n background: Field;\n }\n}\n.c2-text-field:hover {\n border-top: var(--c2-text-field__hover--border-top,var(--c2-text-field--border-top,1px solid #a1a1aa));\n border-bottom: var(--c2-text-field__hover--border-bottom,var(--c2-text-field--border-bottom,1px solid #a1a1aa));\n border-right: var(--c2-text-field__hover--border-right,var(--c2-text-field--border-right,1px solid #a1a1aa));\n border-left: var(--c2-text-field__hover--border-left,var(--c2-text-field--border-left,1px solid #a1a1aa));\n}\n.c2-text-field.focus-within {\n border-top: var(--c2-text-field__focus--border-top,var(--c2-text-field--border-top,1px solid #476ef9));\n border-bottom: var(--c2-text-field__focus--border-bottom,var(--c2-text-field--border-bottom,1px solid #476ef9));\n border-right: var(--c2-text-field__focus--border-right,var(--c2-text-field--border-right,1px solid #476ef9));\n border-left: var(--c2-text-field__focus--border-left,var(--c2-text-field--border-left,1px solid #476ef9));\n color: var(--c2-text-field__focus--color,var(--c2-text-field--color,#18181b));\n background: var(--c2-text-field__focus--background,var(--c2-text-field--background,#ffffff));\n outline: var(--c2-text-field__focus--outline,3px solid rgba(71, 110, 249, 0.2));\n outline-offset: var(--c2-text-field__focus--outline-offset,0px);\n}\n.c2-text-field.error {\n border-top: var(--c2-text-field__error--border-top,1px solid #dc2626);\n border-bottom: var(--c2-text-field__error--border-bottom,1px solid #dc2626);\n border-right: var(--c2-text-field__error--border-right,1px solid #dc2626);\n border-left: var(--c2-text-field__error--border-left,1px solid #dc2626);\n color: var(--c2-text-field__error--color,var(--c2-text-field--color,#18181b));\n background: var(--c2-text-field__error--background,var(--c2-text-field--background,#ffffff));\n}\n.c2-text-field.error.focus-within {\n outline: var(--c2-text-field__error__focus--outline,3px solid rgba(220, 38, 38, 0.2));\n}\n.c2-text-field.read-only {\n cursor: default;\n border-top: var(--c2-text-field__read-only--border-top,1px solid #e4e4e7);\n border-bottom: var(--c2-text-field__read-only--border-bottom,1px solid #e4e4e7);\n border-right: var(--c2-text-field__read-only--border-right,1px solid #e4e4e7);\n border-left: var(--c2-text-field__read-only--border-left,1px solid #e4e4e7);\n color: var(--c2-text-field__read-only--color,var(--c2-text-field--color,#18181b));\n background: var(--c2-text-field__read-only--background,#fafafa);\n}\n.c2-text-field.disabled {\n cursor: default;\n opacity: var(--c2-text-field__disabled--opacity,0.38);\n pointer-events: none;\n}\n\n::slotted([slot=prefix-icon]),\n::slotted([slot=suffix-icon]) {\n flex: none;\n color: var(--c2-text-field__icon--color,#71717a);\n --c2-feather-icon--size: var(--c2-text-field__icon--size,16px);\n --c2-mat-icon--font-size: var(--c2-text-field__icon--size,16px);\n}\n\n::slotted(svg[slot=prefix-icon]),\n::slotted(svg[slot=suffix-icon]) {\n width: var(--c2-text-field__icon--size,16px);\n height: var(--c2-text-field__icon--size,16px);\n}\n\n.clear-button {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n margin: 0;\n padding: 0;\n border: none;\n background: transparent;\n cursor: pointer;\n width: var(--c2-text-field__clear-icon--size,16px);\n height: var(--c2-text-field__clear-icon--size,16px);\n color: var(--c2-text-field__clear-icon--color,#a1a1aa);\n transition: color 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.clear-button:hover, .clear-button:focus-visible {\n color: var(--c2-text-field__clear-icon__hover--color,#18181b);\n}\n.clear-button:focus-visible {\n outline: var(--c2-text-field__focus--outline,3px solid rgba(71, 110, 249, 0.2));\n outline-offset: 2px;\n border-radius: 4px;\n}\n.clear-button svg,\n.clear-button ::slotted(*) {\n width: 100%;\n height: 100%;\n --c2-feather-icon--size: var(--c2-text-field__clear-icon--size,16px);\n --c2-mat-icon--font-size: var(--c2-text-field__clear-icon--size,16px);\n}\n\n::slotted([slot=help-icon]) {\n flex: none;\n width: var(--c2-text-field__help-icon--size,16px);\n height: var(--c2-text-field__help-icon--size,16px);\n color: var(--c2-text-field__help-icon--color,#71717a);\n --c2-feather-icon--size: var(--c2-text-field__help-icon--size,16px);\n --c2-mat-icon--font-size: var(--c2-text-field__help-icon--size,16px);\n}\n\n.supporting-text {\n display: flex;\n align-items: baseline;\n justify-content: space-between;\n gap: 12px;\n font-size: var(--c2-text-field__supporting-text--font-size,12px);\n line-height: var(--c2-text-field__supporting-text--line-height,16px);\n color: var(--c2-text-field__supporting-text--color,#71717a);\n}\n.supporting-text.error {\n color: var(--c2-text-field__supporting-text__error--color,#dc2626);\n}\n.supporting-text .supporting-text__message {\n flex: 1;\n min-width: 0;\n}\n.supporting-text .supporting-text__counter {\n flex: none;\n font-variant-numeric: tabular-nums;\n}";
|
|
10
11
|
//#endregion
|
|
11
12
|
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
|
|
12
13
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -20,6 +21,9 @@ function __decorate(decorators, target, key, desc) {
|
|
|
20
21
|
var TextField = class TextField extends LitElement {
|
|
21
22
|
constructor(..._args) {
|
|
22
23
|
super(..._args);
|
|
24
|
+
this.internals = this.attachInternals();
|
|
25
|
+
this.customValidityMessage = "";
|
|
26
|
+
this.disabledByForm = false;
|
|
23
27
|
this.readOnly = false;
|
|
24
28
|
this.disabled = false;
|
|
25
29
|
this.error = false;
|
|
@@ -31,6 +35,7 @@ var TextField = class TextField extends LitElement {
|
|
|
31
35
|
this.name = "";
|
|
32
36
|
this.autocomplete = "";
|
|
33
37
|
this.placeholder = "";
|
|
38
|
+
this.ariaLabel = null;
|
|
34
39
|
this.value = "";
|
|
35
40
|
this.errorText = "";
|
|
36
41
|
this.help = "";
|
|
@@ -62,15 +67,58 @@ var TextField = class TextField extends LitElement {
|
|
|
62
67
|
}));
|
|
63
68
|
};
|
|
64
69
|
}
|
|
70
|
+
static {
|
|
71
|
+
this.formAssociated = true;
|
|
72
|
+
}
|
|
65
73
|
static {
|
|
66
74
|
this.styles = unsafeCSS(text_field_default);
|
|
67
75
|
}
|
|
76
|
+
/** The containing form, when this control is associated with one. */
|
|
77
|
+
get form() {
|
|
78
|
+
return this.internals.form;
|
|
79
|
+
}
|
|
80
|
+
/** Labels associated with this form control. */
|
|
81
|
+
get labels() {
|
|
82
|
+
return this.internals.labels;
|
|
83
|
+
}
|
|
84
|
+
get validity() {
|
|
85
|
+
return this.internals.validity;
|
|
86
|
+
}
|
|
87
|
+
get validationMessage() {
|
|
88
|
+
return this.internals.validationMessage;
|
|
89
|
+
}
|
|
90
|
+
get willValidate() {
|
|
91
|
+
return this.internals.willValidate;
|
|
92
|
+
}
|
|
68
93
|
/** Restores the initial value (the `value` attribute) and clears the dirty and error flags. */
|
|
69
94
|
reset() {
|
|
70
95
|
this.dirty = false;
|
|
71
96
|
this.value = this.getAttribute("value") ?? "";
|
|
72
97
|
this.error = false;
|
|
73
98
|
}
|
|
99
|
+
formResetCallback() {
|
|
100
|
+
this.reset();
|
|
101
|
+
}
|
|
102
|
+
formDisabledCallback(disabled) {
|
|
103
|
+
this.disabledByForm = disabled && !this.hasAttribute("disabled");
|
|
104
|
+
}
|
|
105
|
+
formStateRestoreCallback(state) {
|
|
106
|
+
if (typeof state === "string") this.value = state;
|
|
107
|
+
}
|
|
108
|
+
/** Checks all current constraints and fires `invalid` on this element when they fail. */
|
|
109
|
+
checkValidity() {
|
|
110
|
+
return this.internals.checkValidity();
|
|
111
|
+
}
|
|
112
|
+
/** Checks all current constraints and asks the browser to show validation feedback. */
|
|
113
|
+
reportValidity() {
|
|
114
|
+
return this.internals.reportValidity();
|
|
115
|
+
}
|
|
116
|
+
/** Sets or clears a custom validation error. */
|
|
117
|
+
setCustomValidity(message) {
|
|
118
|
+
this.customValidityMessage = message;
|
|
119
|
+
this.input?.setCustomValidity(message);
|
|
120
|
+
this.syncFormState();
|
|
121
|
+
}
|
|
74
122
|
/** True once the user has typed in the field. */
|
|
75
123
|
isDirty() {
|
|
76
124
|
return this.dirty;
|
|
@@ -123,7 +171,7 @@ var TextField = class TextField extends LitElement {
|
|
|
123
171
|
return html`<slot name="help-icon"></slot>`;
|
|
124
172
|
}
|
|
125
173
|
renderClearButton() {
|
|
126
|
-
if (!this.clearable || !this.value || this.
|
|
174
|
+
if (!this.clearable || !this.value || this.effectiveDisabled || this.readOnly) return nothing;
|
|
127
175
|
return html`<button class="clear-button" type="button" aria-label="Clear" tabindex="-1" @click=${this.handleClear}>
|
|
128
176
|
<slot name="clear-icon">
|
|
129
177
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
@@ -150,11 +198,24 @@ var TextField = class TextField extends LitElement {
|
|
|
150
198
|
}
|
|
151
199
|
updated(changed) {
|
|
152
200
|
if (changed.has("disabled") || changed.has("error") || changed.has("readOnly") || changed.has("focused")) addClasses(this, this.stateClasses);
|
|
201
|
+
this.syncFormState();
|
|
202
|
+
}
|
|
203
|
+
syncFormState() {
|
|
204
|
+
this.internals.setFormValue(this.value, this.value);
|
|
205
|
+
if (!this.input || this.effectiveDisabled) {
|
|
206
|
+
this.internals.setValidity({});
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
this.input.setCustomValidity(this.customValidityMessage);
|
|
210
|
+
this.internals.setValidity(this.input.validity, this.input.validationMessage, this.input);
|
|
211
|
+
}
|
|
212
|
+
get effectiveDisabled() {
|
|
213
|
+
return this.disabled || this.disabledByForm;
|
|
153
214
|
}
|
|
154
215
|
get stateClasses() {
|
|
155
216
|
return {
|
|
156
|
-
disabled: this.
|
|
157
|
-
error: !this.
|
|
217
|
+
disabled: this.effectiveDisabled,
|
|
218
|
+
error: !this.effectiveDisabled && this.error,
|
|
158
219
|
"read-only": this.readOnly,
|
|
159
220
|
"focus-within": this.focused
|
|
160
221
|
};
|
|
@@ -165,6 +226,7 @@ var TextField = class TextField extends LitElement {
|
|
|
165
226
|
<div class="c2-text-field ${classMap(classes)}" @click=${this.forwardFocusin}>
|
|
166
227
|
${this.renderPrefixSlot()}
|
|
167
228
|
<input
|
|
229
|
+
aria-label=${ifDefined(this.ariaLabel || void 0)}
|
|
168
230
|
type=${this.type}
|
|
169
231
|
class="input"
|
|
170
232
|
name=${ifDefined(this.name || void 0)}
|
|
@@ -172,7 +234,7 @@ var TextField = class TextField extends LitElement {
|
|
|
172
234
|
maxlength=${ifDefined(this.maxLength > -1 ? this.maxLength : void 0)}
|
|
173
235
|
minlength=${ifDefined(this.minLength > -1 ? this.minLength : void 0)}
|
|
174
236
|
pattern=${ifDefined(this.pattern || void 0)}
|
|
175
|
-
?disabled=${this.
|
|
237
|
+
?disabled=${this.effectiveDisabled}
|
|
176
238
|
?readonly=${this.readOnly}
|
|
177
239
|
?required=${this.required}
|
|
178
240
|
aria-invalid=${this.error ? "true" : nothing}
|
|
@@ -191,6 +253,7 @@ var TextField = class TextField extends LitElement {
|
|
|
191
253
|
${this.renderSupportingText()}`;
|
|
192
254
|
}
|
|
193
255
|
};
|
|
256
|
+
__decorate([state()], TextField.prototype, "disabledByForm", void 0);
|
|
194
257
|
__decorate([property({
|
|
195
258
|
type: Boolean,
|
|
196
259
|
reflect: true
|
|
@@ -214,6 +277,7 @@ __decorate([property({ type: String })], TextField.prototype, "type", void 0);
|
|
|
214
277
|
__decorate([property({ type: String })], TextField.prototype, "name", void 0);
|
|
215
278
|
__decorate([property({ type: String })], TextField.prototype, "autocomplete", void 0);
|
|
216
279
|
__decorate([property({ type: String })], TextField.prototype, "placeholder", void 0);
|
|
280
|
+
__decorate([property({ attribute: "aria-label" })], TextField.prototype, "ariaLabel", void 0);
|
|
217
281
|
__decorate([property({ type: String })], TextField.prototype, "value", void 0);
|
|
218
282
|
__decorate([property({ attribute: "error-text" })], TextField.prototype, "errorText", void 0);
|
|
219
283
|
__decorate([property({ type: String })], TextField.prototype, "help", void 0);
|
package/dist/text-field-clear.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { n as __decorate, t as TextField } from "./chunks/text-field-
|
|
1
|
+
import { n as __decorate, t as TextField } from "./chunks/text-field-CEaLhsMN.js";
|
|
2
2
|
import { html, nothing, unsafeCSS } from "lit";
|
|
3
|
-
import {
|
|
3
|
+
import { state } from "lit/decorators.js";
|
|
4
|
+
import { customElement } from "@c2n/core/element-helper.js";
|
|
4
5
|
//#region src/text-field-clear.scss?inline
|
|
5
6
|
var text_field_clear_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n.clear-icon {\n cursor: pointer;\n width: var(--c2-text-field-clear__clear-icon--size,24px);\n color: var(--c2-text-field-clear__clear-icon--color,rgb(70, 70, 70));\n display: flex;\n align-items: center;\n}";
|
|
6
7
|
//#endregion
|
package/dist/text-field.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as TextField } from "./chunks/text-field-
|
|
1
|
+
import { t as TextField } from "./chunks/text-field-CEaLhsMN.js";
|
|
2
2
|
export { TextField };
|
package/package.json
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c2n/text-field",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/text-field.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"types": "./types/src/text-field.d.ts",
|
|
9
|
+
"default": "./dist/text-field.js"
|
|
10
10
|
},
|
|
11
11
|
"./text-field-clear.js": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"types": "./types/src/text-field-clear.d.ts",
|
|
13
|
+
"default": "./dist/text-field-clear.js"
|
|
14
|
+
},
|
|
15
|
+
"./react": {
|
|
16
|
+
"types": "./react.d.ts",
|
|
17
|
+
"default": "./react.js"
|
|
18
|
+
},
|
|
19
|
+
"./vue": {
|
|
20
|
+
"types": "./vue.d.ts",
|
|
21
|
+
"default": "./vue.js"
|
|
14
22
|
},
|
|
15
23
|
"./custom-elements.json": "./custom-elements.json"
|
|
16
24
|
},
|
|
17
25
|
"files": [
|
|
18
26
|
"dist",
|
|
19
|
-
"types"
|
|
27
|
+
"types",
|
|
28
|
+
"react.d.ts",
|
|
29
|
+
"react.js",
|
|
30
|
+
"vue.d.ts",
|
|
31
|
+
"vue.js"
|
|
20
32
|
],
|
|
21
33
|
"keywords": [
|
|
22
34
|
"text-field",
|
|
@@ -52,12 +64,12 @@
|
|
|
52
64
|
}
|
|
53
65
|
},
|
|
54
66
|
"dependencies": {
|
|
55
|
-
"@c2n/core": "0.0.
|
|
67
|
+
"@c2n/core": "0.0.8",
|
|
56
68
|
"lit": "3.3.3"
|
|
57
69
|
},
|
|
58
70
|
"devDependencies": {
|
|
59
71
|
"@c2n/config": "*"
|
|
60
72
|
},
|
|
61
73
|
"customElements": "custom-elements.json",
|
|
62
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "be59cbccee1d33ca248e39f69b05c0b595ec6c6d"
|
|
63
75
|
}
|
package/react.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// GENERATED by @c2n/framework-types. Do not edit by hand.
|
|
2
|
+
//
|
|
3
|
+
// JSX types for the custom elements of @c2n/text-field. Import once, anywhere in the program:
|
|
4
|
+
//
|
|
5
|
+
// import '@c2n/text-field/react'
|
|
6
|
+
//
|
|
7
|
+
// Register the elements at module scope before React renders, or React writes an object prop as an
|
|
8
|
+
// attribute and it stringifies.
|
|
9
|
+
|
|
10
|
+
import type { DetailedHTMLProps, HTMLAttributes } from 'react'
|
|
11
|
+
import type { TextField } from '@c2n/text-field'
|
|
12
|
+
import type { TextFieldClear } from '@c2n/text-field/text-field-clear.js'
|
|
13
|
+
|
|
14
|
+
/** Standard React host-element attributes plus the element's own public properties. */
|
|
15
|
+
type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
|
|
16
|
+
|
|
17
|
+
declare module 'react' {
|
|
18
|
+
namespace JSX {
|
|
19
|
+
interface IntrinsicElements {
|
|
20
|
+
'c2-text-field': C2Props<TextField>
|
|
21
|
+
'c2-text-field-clear': C2Props<TextFieldClear>
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {}
|
package/react.js
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-field-clear.d.ts","sourceRoot":"","sources":["../../src/text-field-clear.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAQ,OAAO,EAAa,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"text-field-clear.d.ts","sourceRoot":"","sources":["../../src/text-field-clear.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAQ,OAAO,EAAa,MAAM,KAAK,CAAA;AAKzD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC;;;;;;;;;;;GAWG;AACH,qBACa,cAAe,SAAQ,SAAS;IAC3C,OAAgB,MAAM,EAAE,SAAS,GAAG,SAAS,EAAE,CAAqD;IAE3F,SAAS,UAAQ;cAEP,WAAW,CAAC,KAAK,EAAE,UAAU;IAKhD,SAAS,CAAC,WAAW,aAGpB;IAED,eAAe;cAqBI,gBAAgB;CAGpC;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,qBAAqB,EAAE,cAAc,CAAA;KACtC;CACF"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { CSSResult, LitElement, nothing, type PropertyValues } from 'lit';
|
|
2
|
+
import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
|
|
2
3
|
export type TextFieldType = 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'number';
|
|
4
|
+
/** Events fired by {@link TextField}, keyed for `addEventListener`. */
|
|
5
|
+
export interface TextFieldEventMap {
|
|
6
|
+
input: InputEvent;
|
|
7
|
+
change: Event;
|
|
8
|
+
clear: Event;
|
|
9
|
+
}
|
|
10
|
+
export interface TextField {
|
|
11
|
+
addEventListener: TypedAddEventListener<TextField, TextFieldEventMap>;
|
|
12
|
+
removeEventListener: TypedRemoveEventListener<TextField, TextFieldEventMap>;
|
|
13
|
+
}
|
|
3
14
|
/**
|
|
4
15
|
* A single-line input wrapped in a themeable field. The native `<input>` keeps its behaviour (`type`, `name`,
|
|
5
16
|
* `autocomplete`, `maxlength`, `pattern`, `input`/`change` events); the field adds `prefix-icon` / `suffix-icon` slots
|
|
@@ -9,7 +20,7 @@ export type TextFieldType = 'text' | 'email' | 'password' | 'search' | 'tel' | '
|
|
|
9
20
|
*
|
|
10
21
|
* @tag c2-text-field
|
|
11
22
|
*
|
|
12
|
-
* @slot prefix-icon - Icon (or short adornment text) at the start of the field: an inline SVG, a `c2-feather-*` icon or a `c2-mat-icon`.
|
|
23
|
+
* @slot prefix-icon - Icon (or short adornment text) at the start of the field: an inline SVG, a `c2-feather-*` icon or a `c2-mat-icon`. Icons are sized by `--c2-text-field__icon--size`; an adornment keeps its own width.
|
|
13
24
|
* @slot suffix-icon - Icon or adornment at the end of the field, after the clear button.
|
|
14
25
|
* @slot clear-icon - Replaces the default cross of the clear button.
|
|
15
26
|
* @slot help-icon - Icon shown beside the field, outside the border, e.g. a tooltip trigger.
|
|
@@ -100,7 +111,11 @@ export type TextFieldType = 'text' | 'email' | 'password' | 'search' | 'tel' | '
|
|
|
100
111
|
* @cssproperty {color} [--c2-text-field__supporting-text__error--color=#dc2626]
|
|
101
112
|
*/
|
|
102
113
|
export declare class TextField extends LitElement {
|
|
114
|
+
static formAssociated: boolean;
|
|
103
115
|
static styles: CSSResult | CSSResult[];
|
|
116
|
+
private readonly internals;
|
|
117
|
+
private customValidityMessage;
|
|
118
|
+
private disabledByForm;
|
|
104
119
|
/** Shows the value but refuses edits. Rendered on a light grey background. */
|
|
105
120
|
readOnly: boolean;
|
|
106
121
|
/** Disables the input and dims the field. */
|
|
@@ -123,6 +138,8 @@ export declare class TextField extends LitElement {
|
|
|
123
138
|
autocomplete: string;
|
|
124
139
|
/** Text shown while the field is empty. */
|
|
125
140
|
placeholder: string;
|
|
141
|
+
/** Accessible name forwarded to the native input. */
|
|
142
|
+
ariaLabel: string | null;
|
|
126
143
|
/** The current text. Setting the attribute after the user has typed no longer updates it, like a native input. */
|
|
127
144
|
value: string;
|
|
128
145
|
/** Message shown under the field while `error` is set. */
|
|
@@ -135,8 +152,24 @@ export declare class TextField extends LitElement {
|
|
|
135
152
|
private focused;
|
|
136
153
|
private hasSupportingSlot;
|
|
137
154
|
private readonly input?;
|
|
155
|
+
/** The containing form, when this control is associated with one. */
|
|
156
|
+
get form(): HTMLFormElement | null;
|
|
157
|
+
/** Labels associated with this form control. */
|
|
158
|
+
get labels(): NodeList;
|
|
159
|
+
get validity(): ValidityState;
|
|
160
|
+
get validationMessage(): string;
|
|
161
|
+
get willValidate(): boolean;
|
|
138
162
|
/** Restores the initial value (the `value` attribute) and clears the dirty and error flags. */
|
|
139
163
|
reset(): void;
|
|
164
|
+
formResetCallback(): void;
|
|
165
|
+
formDisabledCallback(disabled: boolean): void;
|
|
166
|
+
formStateRestoreCallback(state: string | File | FormData | null): void;
|
|
167
|
+
/** Checks all current constraints and fires `invalid` on this element when they fail. */
|
|
168
|
+
checkValidity(): boolean;
|
|
169
|
+
/** Checks all current constraints and asks the browser to show validation feedback. */
|
|
170
|
+
reportValidity(): boolean;
|
|
171
|
+
/** Sets or clears a custom validation error. */
|
|
172
|
+
setCustomValidity(message: string): void;
|
|
140
173
|
handleFocus: () => void;
|
|
141
174
|
/** True once the user has typed in the field. */
|
|
142
175
|
isDirty(): boolean;
|
|
@@ -159,6 +192,8 @@ export declare class TextField extends LitElement {
|
|
|
159
192
|
protected renderSupportingText(): import("lit-html").TemplateResult<1>;
|
|
160
193
|
private redispatchEvent;
|
|
161
194
|
protected updated(changed: PropertyValues): void;
|
|
195
|
+
private syncFormState;
|
|
196
|
+
private get effectiveDisabled();
|
|
162
197
|
private get stateClasses();
|
|
163
198
|
render(): import("lit-html").TemplateResult<1>;
|
|
164
199
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-field.d.ts","sourceRoot":"","sources":["../../src/text-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAQ,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"text-field.d.ts","sourceRoot":"","sources":["../../src/text-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAQ,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAG1F,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAQhG,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAA;AAE/F,uEAAuE;AACvE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,UAAU,CAAA;IACjB,MAAM,EAAE,KAAK,CAAA;IACb,KAAK,EAAE,KAAK,CAAA;CACb;AAED,MAAM,WAAW,SAAS;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AO,KAAK,iBAAiB,GAE5B;IAED,OAAO,KAAK,YAAY,GAOvB;IAEQ,MAAM;CAgChB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,eAAe,EAAE,SAAS,CAAA;KAC3B;CACF"}
|
package/vue.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// GENERATED by @c2n/framework-types. Do not edit by hand.
|
|
2
|
+
//
|
|
3
|
+
// Vue template types for the custom elements of @c2n/text-field. Import once, anywhere in the program:
|
|
4
|
+
//
|
|
5
|
+
// import '@c2n/text-field/vue'
|
|
6
|
+
//
|
|
7
|
+
// Tell the compiler about the tags as well, or every c2-* tag is resolved as a Vue component and renders
|
|
8
|
+
// nothing: template.compilerOptions.isCustomElement = (tag) => tag.startsWith('c2-') in vite.config.ts.
|
|
9
|
+
|
|
10
|
+
import type { DefineComponent, HTMLAttributes } from 'vue'
|
|
11
|
+
import type { TextField, TextFieldEventMap } from '@c2n/text-field'
|
|
12
|
+
import type { TextFieldClear, TextFieldClearEventMap } from '@c2n/text-field/text-field-clear.js'
|
|
13
|
+
|
|
14
|
+
/** The element's own public properties, plus every attribute Vue understands on a host element. */
|
|
15
|
+
type C2Props<T> = Partial<Omit<T, keyof HTMLElement>> & HTMLAttributes
|
|
16
|
+
|
|
17
|
+
declare module 'vue' {
|
|
18
|
+
interface GlobalComponents {
|
|
19
|
+
'c2-text-field': DefineComponent<
|
|
20
|
+
C2Props<TextField> & {
|
|
21
|
+
'aria-label'?: unknown
|
|
22
|
+
'error-text'?: unknown
|
|
23
|
+
onInput?: (event: TextFieldEventMap['input']) => void
|
|
24
|
+
onChange?: (event: TextFieldEventMap['change']) => void
|
|
25
|
+
onClear?: (event: TextFieldEventMap['clear']) => void
|
|
26
|
+
}
|
|
27
|
+
>
|
|
28
|
+
'c2-text-field-clear': DefineComponent<
|
|
29
|
+
C2Props<TextFieldClear> & {
|
|
30
|
+
'aria-label'?: unknown
|
|
31
|
+
'error-text'?: unknown
|
|
32
|
+
onInput?: (event: TextFieldClearEventMap['input']) => void
|
|
33
|
+
onChange?: (event: TextFieldClearEventMap['change']) => void
|
|
34
|
+
onClear?: (event: TextFieldClearEventMap['clear']) => void
|
|
35
|
+
}
|
|
36
|
+
>
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare module '@vue/runtime-dom' {
|
|
41
|
+
interface HTMLAttributes {
|
|
42
|
+
/** Vue's own definition omits it, and slotting a plain element into a component needs it. */
|
|
43
|
+
slot?: string
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {}
|
package/vue.js
ADDED