@sondor-technology/sondor-components 1.0.1-develop.8 → 1.0.1-develop.9
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/components/checkbox/checkbox.d.ts +3 -0
- package/dist/components/checkbox/checkbox.d.ts.map +1 -1
- package/dist/components/checkbox/checkbox.js +38 -20
- package/dist/components/form/form.d.ts.map +1 -1
- package/dist/components/form/form.js +11 -6
- package/dist/components/icon/icon.d.ts +2 -1
- package/dist/components/icon/icon.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/checkbox/checkbox.ts +54 -26
- package/src/components/form/form.ts +15 -9
- package/src/components/icon/icon.ts +3 -1
|
@@ -11,11 +11,14 @@ export declare class StCheckbox extends LitElement {
|
|
|
11
11
|
disabled: boolean;
|
|
12
12
|
invalid: boolean;
|
|
13
13
|
required: boolean;
|
|
14
|
+
errorMessage: string;
|
|
14
15
|
ariaLabel: string;
|
|
15
16
|
constructor();
|
|
16
17
|
static styles: import("lit").CSSResult[];
|
|
17
18
|
updated(changedProperties: PropertyValues<this>): void;
|
|
18
19
|
private _syncValidity;
|
|
20
|
+
checkValidity(): boolean;
|
|
21
|
+
reportValidity(): boolean;
|
|
19
22
|
formResetCallback(): void;
|
|
20
23
|
private _handleChange;
|
|
21
24
|
render(): import("lit-html").TemplateResult<1>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../../src/components/checkbox/checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAa,cAAc,EAAC,MAAM,KAAK,CAAC;AAI1D,qBACa,UAAW,SAAQ,UAAU;IACxC,MAAM,CAAC,cAAc,UAAQ;IAC7B,OAAO,CAAC,UAAU,CAAmB;IAErB,OAAO,CAAC,QAAQ,CAAoB;IAEX,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAQ;IAChC,IAAI,SAAM;
|
|
1
|
+
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../../src/components/checkbox/checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAa,cAAc,EAAC,MAAM,KAAK,CAAC;AAI1D,qBACa,UAAW,SAAQ,UAAU;IACxC,MAAM,CAAC,cAAc,UAAQ;IAC7B,OAAO,CAAC,UAAU,CAAmB;IAErB,OAAO,CAAC,QAAQ,CAAoB;IAEX,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAQ;IAChC,IAAI,SAAM;IACzB,KAAK,SAAQ;IAEG,OAAO,UAAS;IAChB,aAAa,UAAS;IAEtB,QAAQ,UAAS;IACjB,OAAO,UAAS;IAChB,QAAQ,UAAS;IACjC,YAAY,SAAM;IAEP,SAAS,SAAM;IAEpD,cAWC;IAED,MAAM,CAAC,MAAM,4BA6GX;IAEO,OAAO,CAAC,iBAAiB,EAAE,cAAc,CAAC,IAAI,CAAC,QAWvD;IAED,OAAO,CAAC,aAAa;IAmBd,aAAa,IAAI,OAAO,CAkB9B;IAEM,cAAc,IAAI,OAAO,CAK/B;IAED,iBAAiB,SAMhB;IAED,OAAO,CAAC,aAAa;IAkBrB,MAAM,yCAwBL;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,UAAU,CAAC;KAC3B;CACF"}
|
|
@@ -12,28 +12,25 @@ let StCheckbox = class StCheckbox extends LitElement {
|
|
|
12
12
|
super();
|
|
13
13
|
this.size = "md";
|
|
14
14
|
this.name = "";
|
|
15
|
-
// Checkboxes default to 'on' natively if no value is provided
|
|
16
15
|
this.value = "on";
|
|
17
16
|
this.checked = false;
|
|
18
17
|
this.indeterminate = false;
|
|
19
18
|
this.disabled = false;
|
|
20
19
|
this.invalid = false;
|
|
21
20
|
this.required = false;
|
|
21
|
+
this.errorMessage = "";
|
|
22
22
|
this.ariaLabel = "";
|
|
23
23
|
this._internals = this.attachInternals();
|
|
24
|
-
// 1. Trigger error state if the user clicks away and the field is invalid
|
|
25
24
|
this.addEventListener('focusout', () => {
|
|
26
|
-
this.invalid = !this.
|
|
25
|
+
this.invalid = !this.checkValidity();
|
|
27
26
|
});
|
|
28
|
-
// 2. Trigger error state if the st-form tries to submit and fails
|
|
29
27
|
this.addEventListener('invalid', () => {
|
|
30
|
-
this.invalid =
|
|
28
|
+
this.invalid = !this.checkValidity();
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
31
|
updated(changedProperties) {
|
|
34
32
|
super.updated(changedProperties);
|
|
35
|
-
if (changedProperties.has("checked") || changedProperties.has("value")) {
|
|
36
|
-
// Form API: If checked, submit the value. If unchecked, submit null to remove it from FormData.
|
|
33
|
+
if (changedProperties.has("checked") || changedProperties.has("value") || changedProperties.has("errorMessage")) {
|
|
37
34
|
this._internals.setFormValue(this.checked ? this.value : null);
|
|
38
35
|
this._syncValidity();
|
|
39
36
|
}
|
|
@@ -44,11 +41,38 @@ let StCheckbox = class StCheckbox extends LitElement {
|
|
|
44
41
|
_syncValidity() {
|
|
45
42
|
if (!this._inputEl)
|
|
46
43
|
return;
|
|
47
|
-
|
|
44
|
+
if (this.required && !this.checked) {
|
|
45
|
+
const message = this.errorMessage || this._inputEl.validationMessage || "Please check this box if you want to proceed.";
|
|
46
|
+
this._internals.setValidity({ valueMissing: true }, message, this._inputEl);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this._internals.setValidity(this._inputEl.validity, this._inputEl.validationMessage, this._inputEl);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
checkValidity() {
|
|
53
|
+
if (!this._inputEl)
|
|
54
|
+
return true;
|
|
55
|
+
if (this.required && !this.checked) {
|
|
56
|
+
const message = this.errorMessage || this._inputEl.validationMessage || "Please check this box if you want to proceed.";
|
|
57
|
+
this._internals.setValidity({ valueMissing: true }, message, this._inputEl);
|
|
58
|
+
this.invalid = true;
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const isValid = this._inputEl.checkValidity();
|
|
62
|
+
this._syncValidity();
|
|
63
|
+
this.invalid = !isValid;
|
|
64
|
+
return isValid;
|
|
65
|
+
}
|
|
66
|
+
reportValidity() {
|
|
67
|
+
this._syncValidity();
|
|
68
|
+
const isValid = this._internals.reportValidity();
|
|
69
|
+
this.invalid = !isValid;
|
|
70
|
+
return isValid;
|
|
48
71
|
}
|
|
49
72
|
formResetCallback() {
|
|
50
73
|
this.checked = false;
|
|
51
74
|
this.indeterminate = false;
|
|
75
|
+
this.invalid = false;
|
|
52
76
|
this._internals.setFormValue(null);
|
|
53
77
|
this.updateComplete.then(() => this._syncValidity());
|
|
54
78
|
}
|
|
@@ -56,11 +80,13 @@ let StCheckbox = class StCheckbox extends LitElement {
|
|
|
56
80
|
e.stopPropagation();
|
|
57
81
|
if (this.disabled)
|
|
58
82
|
return;
|
|
59
|
-
// Standard native behavior: clicking an indeterminate checkbox unsets the indeterminate state
|
|
60
83
|
if (this.indeterminate) {
|
|
61
84
|
this.indeterminate = false;
|
|
62
85
|
}
|
|
63
86
|
this.checked = this._inputEl.checked;
|
|
87
|
+
if (this.checkValidity()) {
|
|
88
|
+
this.invalid = false;
|
|
89
|
+
}
|
|
64
90
|
this.dispatchEvent(new Event("change", { bubbles: true, composed: true }));
|
|
65
91
|
}
|
|
66
92
|
render() {
|
|
@@ -78,7 +104,6 @@ let StCheckbox = class StCheckbox extends LitElement {
|
|
|
78
104
|
@change=${this._handleChange}
|
|
79
105
|
/>
|
|
80
106
|
<div class="control">
|
|
81
|
-
<!-- Render both SVGs and use CSS to conditionally reveal them based on host attributes -->
|
|
82
107
|
${this.indeterminate
|
|
83
108
|
? html `<svg class="icon-minus" viewBox="0 0 24 24"><path d="M5 12h14"></path></svg>`
|
|
84
109
|
: html `<svg class="icon-check" viewBox="0 0 24 24">
|
|
@@ -120,7 +145,6 @@ StCheckbox.styles = [
|
|
|
120
145
|
font-size: var(--st-font-size-base);
|
|
121
146
|
}
|
|
122
147
|
|
|
123
|
-
/* Visually hide the native input but keep it in the DOM for focus/screen readers */
|
|
124
148
|
input {
|
|
125
149
|
position: absolute;
|
|
126
150
|
width: var(--checkbox-size);
|
|
@@ -133,7 +157,6 @@ StCheckbox.styles = [
|
|
|
133
157
|
border-width: 0;
|
|
134
158
|
}
|
|
135
159
|
|
|
136
|
-
/* Custom Checkbox Box */
|
|
137
160
|
.control {
|
|
138
161
|
display: flex;
|
|
139
162
|
align-items: center;
|
|
@@ -145,30 +168,25 @@ StCheckbox.styles = [
|
|
|
145
168
|
background-color: var(--st-color-bg);
|
|
146
169
|
transition: all 0.2s ease;
|
|
147
170
|
flex-shrink: 0;
|
|
148
|
-
/* Aligns the box nicely with standard text line-height */
|
|
149
171
|
margin-top: 0.125rem;
|
|
150
172
|
}
|
|
151
173
|
|
|
152
|
-
/* Hover State */
|
|
153
174
|
label:hover .control {
|
|
154
175
|
border-color: var(--st-color-primary-hover);
|
|
155
176
|
}
|
|
156
177
|
|
|
157
|
-
/* Focus State */
|
|
158
178
|
input:focus-visible + .control {
|
|
159
179
|
box-shadow:
|
|
160
180
|
0 0 0 2px var(--st-color-bg),
|
|
161
181
|
0 0 0 4px var(--st-color-primary);
|
|
162
182
|
}
|
|
163
183
|
|
|
164
|
-
/* Checked & Indeterminate States */
|
|
165
184
|
:host([checked]) .control,
|
|
166
185
|
:host([indeterminate]) .control {
|
|
167
186
|
border-color: var(--st-color-primary);
|
|
168
187
|
background-color: var(--st-color-primary);
|
|
169
188
|
}
|
|
170
189
|
|
|
171
|
-
/* SVG Icons */
|
|
172
190
|
svg {
|
|
173
191
|
width: var(--checkbox-icon-size);
|
|
174
192
|
height: var(--checkbox-icon-size);
|
|
@@ -184,14 +202,12 @@ StCheckbox.styles = [
|
|
|
184
202
|
opacity 0.2s ease;
|
|
185
203
|
}
|
|
186
204
|
|
|
187
|
-
/* Reveal Icons */
|
|
188
205
|
:host([checked]) svg.icon-check,
|
|
189
206
|
:host([indeterminate]) svg.icon-minus {
|
|
190
207
|
opacity: 1;
|
|
191
208
|
transform: scale(1);
|
|
192
209
|
}
|
|
193
210
|
|
|
194
|
-
/* Disabled State */
|
|
195
211
|
:host([disabled]) {
|
|
196
212
|
pointer-events: none;
|
|
197
213
|
}
|
|
@@ -200,7 +216,6 @@ StCheckbox.styles = [
|
|
|
200
216
|
cursor: not-allowed;
|
|
201
217
|
}
|
|
202
218
|
|
|
203
|
-
/* Invalid State */
|
|
204
219
|
:host([invalid]) .control {
|
|
205
220
|
border-color: var(--st-color-error);
|
|
206
221
|
}
|
|
@@ -238,6 +253,9 @@ __decorate([
|
|
|
238
253
|
__decorate([
|
|
239
254
|
property({ type: Boolean, reflect: true })
|
|
240
255
|
], StCheckbox.prototype, "required", void 0);
|
|
256
|
+
__decorate([
|
|
257
|
+
property({ type: String })
|
|
258
|
+
], StCheckbox.prototype, "errorMessage", void 0);
|
|
241
259
|
__decorate([
|
|
242
260
|
property({ attribute: "aria-label" })
|
|
243
261
|
], StCheckbox.prototype, "ariaLabel", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../src/components/form/form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAY,MAAM,KAAK,CAAC;AAK1C,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,CAAC;AAE9D,qBACa,MAAO,SAAQ,UAAU;IACK,MAAM,EAAE,UAAU,CAAc;IAC/B,OAAO,UAAS;IAChC,KAAK,SAAM;IAE5B,OAAO,CAAC,iBAAiB,CAAK;IAGvC,OAAO,CAAC,aAAa,CAAgB;IAEtB,OAAO,CAAC,OAAO,CAAmB;IAEjD,MAAM,CAAC,MAAM,4BA8IX;IAEF,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,qBAAqB;IAO7B,OAAO,CAAC,uBAAuB;
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../src/components/form/form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAY,MAAM,KAAK,CAAC;AAK1C,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,CAAC;AAE9D,qBACa,MAAO,SAAQ,UAAU;IACK,MAAM,EAAE,UAAU,CAAc;IAC/B,OAAO,UAAS;IAChC,KAAK,SAAM;IAE5B,OAAO,CAAC,iBAAiB,CAAK;IAGvC,OAAO,CAAC,aAAa,CAAgB;IAEtB,OAAO,CAAC,OAAO,CAAmB;IAEjD,MAAM,CAAC,MAAM,4BA8IX;IAEF,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,qBAAqB;IAO7B,OAAO,CAAC,uBAAuB;IAoC/B,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,gBAAgB;IAuCxB,OAAO,CAAC,aAAa;IA4BrB,MAAM,yCAkFL;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,SAAS,EAAE,MAAM,CAAC;KACnB;CACF"}
|
|
@@ -27,13 +27,12 @@ let StForm = class StForm extends LitElement {
|
|
|
27
27
|
this.requestUpdate();
|
|
28
28
|
}
|
|
29
29
|
_validateCurrentContext() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const currentStep = this._stepElements[this._currentStepIndex];
|
|
30
|
+
const scope = this._stepElements.length > 0
|
|
31
|
+
? this._stepElements[this._currentStepIndex]
|
|
32
|
+
: this;
|
|
34
33
|
let isValid = true;
|
|
35
|
-
// Find all
|
|
36
|
-
const inputs = Array.from(
|
|
34
|
+
// Find all elements that expose validation functions (e.g. checkValidity / reportValidity)
|
|
35
|
+
const inputs = Array.from(scope.querySelectorAll("*"));
|
|
37
36
|
for (const input of inputs) {
|
|
38
37
|
if (typeof input.checkValidity === "function") {
|
|
39
38
|
if (!input.checkValidity()) {
|
|
@@ -45,6 +44,12 @@ let StForm = class StForm extends LitElement {
|
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
}
|
|
47
|
+
// Also check standard form elements if not using steps
|
|
48
|
+
if (this._stepElements.length === 0 && this._formEl) {
|
|
49
|
+
if (!this._formEl.checkValidity()) {
|
|
50
|
+
isValid = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
48
53
|
return isValid;
|
|
49
54
|
}
|
|
50
55
|
_triggerSubmission() {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
2
|
import { IconName } from './icon-paths.js';
|
|
3
|
+
export type IconVariant = 'outline' | 'solid';
|
|
3
4
|
export declare class StIcon extends LitElement {
|
|
4
5
|
name: IconName | string;
|
|
5
|
-
variant:
|
|
6
|
+
variant: IconVariant;
|
|
6
7
|
color: 'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info';
|
|
7
8
|
size: 'sm' | 'md' | 'lg' | 'xl';
|
|
8
9
|
static styles: import("lit").CSSResult[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon.d.ts","sourceRoot":"","sources":["../../../src/components/icon/icon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAE5C,OAAO,EAAa,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGtD,qBACa,MAAO,SAAQ,UAAU;IACR,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAM;IAC7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"icon.d.ts","sourceRoot":"","sources":["../../../src/components/icon/icon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAE5C,OAAO,EAAa,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGtD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE9C,qBACa,MAAO,SAAQ,UAAU;IACR,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAM;IAC7B,OAAO,EAAE,WAAW,CAAa;IAGlB,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAa;IAGlG,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAQ;IAElF,MAAM,CAAC,MAAM,4BAsCX;IAEF,MAAM,yCAmBL;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,SAAS,EAAE,MAAM,CAAC;KACnB;CACF"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,6 @@ export class StCheckbox extends LitElement {
|
|
|
11
11
|
|
|
12
12
|
@property({type: String, reflect: true}) size: "sm" | "md" | "lg" = "md";
|
|
13
13
|
@property({type: String, reflect: true}) name = "";
|
|
14
|
-
// Checkboxes default to 'on' natively if no value is provided
|
|
15
14
|
@property({type: String}) value = "on";
|
|
16
15
|
|
|
17
16
|
@property({type: Boolean, reflect: true}) checked = false;
|
|
@@ -20,21 +19,20 @@ export class StCheckbox extends LitElement {
|
|
|
20
19
|
@property({type: Boolean, reflect: true}) disabled = false;
|
|
21
20
|
@property({type: Boolean, reflect: true}) invalid = false;
|
|
22
21
|
@property({type: Boolean, reflect: true}) required = false;
|
|
22
|
+
@property({type: String}) errorMessage = "";
|
|
23
23
|
|
|
24
24
|
@property({attribute: "aria-label"}) ariaLabel = "";
|
|
25
25
|
|
|
26
|
-
constructor() {
|
|
26
|
+
constructor() {
|
|
27
27
|
super();
|
|
28
28
|
this._internals = this.attachInternals();
|
|
29
29
|
|
|
30
|
-
// 1. Trigger error state if the user clicks away and the field is invalid
|
|
31
30
|
this.addEventListener('focusout', () => {
|
|
32
|
-
this.invalid = !this.
|
|
31
|
+
this.invalid = !this.checkValidity();
|
|
33
32
|
});
|
|
34
33
|
|
|
35
|
-
// 2. Trigger error state if the st-form tries to submit and fails
|
|
36
34
|
this.addEventListener('invalid', () => {
|
|
37
|
-
this.invalid =
|
|
35
|
+
this.invalid = !this.checkValidity();
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
38
|
|
|
@@ -67,7 +65,6 @@ constructor() {
|
|
|
67
65
|
font-size: var(--st-font-size-base);
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
/* Visually hide the native input but keep it in the DOM for focus/screen readers */
|
|
71
68
|
input {
|
|
72
69
|
position: absolute;
|
|
73
70
|
width: var(--checkbox-size);
|
|
@@ -80,7 +77,6 @@ constructor() {
|
|
|
80
77
|
border-width: 0;
|
|
81
78
|
}
|
|
82
79
|
|
|
83
|
-
/* Custom Checkbox Box */
|
|
84
80
|
.control {
|
|
85
81
|
display: flex;
|
|
86
82
|
align-items: center;
|
|
@@ -92,30 +88,25 @@ constructor() {
|
|
|
92
88
|
background-color: var(--st-color-bg);
|
|
93
89
|
transition: all 0.2s ease;
|
|
94
90
|
flex-shrink: 0;
|
|
95
|
-
/* Aligns the box nicely with standard text line-height */
|
|
96
91
|
margin-top: 0.125rem;
|
|
97
92
|
}
|
|
98
93
|
|
|
99
|
-
/* Hover State */
|
|
100
94
|
label:hover .control {
|
|
101
95
|
border-color: var(--st-color-primary-hover);
|
|
102
96
|
}
|
|
103
97
|
|
|
104
|
-
/* Focus State */
|
|
105
98
|
input:focus-visible + .control {
|
|
106
99
|
box-shadow:
|
|
107
100
|
0 0 0 2px var(--st-color-bg),
|
|
108
101
|
0 0 0 4px var(--st-color-primary);
|
|
109
102
|
}
|
|
110
103
|
|
|
111
|
-
/* Checked & Indeterminate States */
|
|
112
104
|
:host([checked]) .control,
|
|
113
105
|
:host([indeterminate]) .control {
|
|
114
106
|
border-color: var(--st-color-primary);
|
|
115
107
|
background-color: var(--st-color-primary);
|
|
116
108
|
}
|
|
117
109
|
|
|
118
|
-
/* SVG Icons */
|
|
119
110
|
svg {
|
|
120
111
|
width: var(--checkbox-icon-size);
|
|
121
112
|
height: var(--checkbox-icon-size);
|
|
@@ -131,14 +122,12 @@ constructor() {
|
|
|
131
122
|
opacity 0.2s ease;
|
|
132
123
|
}
|
|
133
124
|
|
|
134
|
-
/* Reveal Icons */
|
|
135
125
|
:host([checked]) svg.icon-check,
|
|
136
126
|
:host([indeterminate]) svg.icon-minus {
|
|
137
127
|
opacity: 1;
|
|
138
128
|
transform: scale(1);
|
|
139
129
|
}
|
|
140
130
|
|
|
141
|
-
/* Disabled State */
|
|
142
131
|
:host([disabled]) {
|
|
143
132
|
pointer-events: none;
|
|
144
133
|
}
|
|
@@ -147,7 +136,6 @@ constructor() {
|
|
|
147
136
|
cursor: not-allowed;
|
|
148
137
|
}
|
|
149
138
|
|
|
150
|
-
/* Invalid State */
|
|
151
139
|
:host([invalid]) .control {
|
|
152
140
|
border-color: var(--st-color-error);
|
|
153
141
|
}
|
|
@@ -162,8 +150,7 @@ constructor() {
|
|
|
162
150
|
override updated(changedProperties: PropertyValues<this>) {
|
|
163
151
|
super.updated(changedProperties);
|
|
164
152
|
|
|
165
|
-
if (changedProperties.has("checked") || changedProperties.has("value")) {
|
|
166
|
-
// Form API: If checked, submit the value. If unchecked, submit null to remove it from FormData.
|
|
153
|
+
if (changedProperties.has("checked") || changedProperties.has("value") || changedProperties.has("errorMessage")) {
|
|
167
154
|
this._internals.setFormValue(this.checked ? this.value : null);
|
|
168
155
|
this._syncValidity();
|
|
169
156
|
}
|
|
@@ -175,16 +162,54 @@ constructor() {
|
|
|
175
162
|
|
|
176
163
|
private _syncValidity() {
|
|
177
164
|
if (!this._inputEl) return;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this._inputEl.validationMessage
|
|
181
|
-
this.
|
|
182
|
-
|
|
165
|
+
|
|
166
|
+
if (this.required && !this.checked) {
|
|
167
|
+
const message = this.errorMessage || this._inputEl.validationMessage || "Please check this box if you want to proceed.";
|
|
168
|
+
this._internals.setValidity(
|
|
169
|
+
{valueMissing: true},
|
|
170
|
+
message,
|
|
171
|
+
this._inputEl,
|
|
172
|
+
);
|
|
173
|
+
} else {
|
|
174
|
+
this._internals.setValidity(
|
|
175
|
+
this._inputEl.validity,
|
|
176
|
+
this._inputEl.validationMessage,
|
|
177
|
+
this._inputEl,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public checkValidity(): boolean {
|
|
183
|
+
if (!this._inputEl) return true;
|
|
184
|
+
|
|
185
|
+
if (this.required && !this.checked) {
|
|
186
|
+
const message = this.errorMessage || this._inputEl.validationMessage || "Please check this box if you want to proceed.";
|
|
187
|
+
this._internals.setValidity(
|
|
188
|
+
{valueMissing: true},
|
|
189
|
+
message,
|
|
190
|
+
this._inputEl,
|
|
191
|
+
);
|
|
192
|
+
this.invalid = true;
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const isValid = this._inputEl.checkValidity();
|
|
197
|
+
this._syncValidity();
|
|
198
|
+
this.invalid = !isValid;
|
|
199
|
+
return isValid;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public reportValidity(): boolean {
|
|
203
|
+
this._syncValidity();
|
|
204
|
+
const isValid = this._internals.reportValidity();
|
|
205
|
+
this.invalid = !isValid;
|
|
206
|
+
return isValid;
|
|
183
207
|
}
|
|
184
208
|
|
|
185
209
|
formResetCallback() {
|
|
186
210
|
this.checked = false;
|
|
187
211
|
this.indeterminate = false;
|
|
212
|
+
this.invalid = false;
|
|
188
213
|
this._internals.setFormValue(null);
|
|
189
214
|
this.updateComplete.then(() => this._syncValidity());
|
|
190
215
|
}
|
|
@@ -194,12 +219,16 @@ constructor() {
|
|
|
194
219
|
|
|
195
220
|
if (this.disabled) return;
|
|
196
221
|
|
|
197
|
-
// Standard native behavior: clicking an indeterminate checkbox unsets the indeterminate state
|
|
198
222
|
if (this.indeterminate) {
|
|
199
223
|
this.indeterminate = false;
|
|
200
224
|
}
|
|
201
225
|
|
|
202
226
|
this.checked = this._inputEl.checked;
|
|
227
|
+
|
|
228
|
+
if (this.checkValidity()) {
|
|
229
|
+
this.invalid = false;
|
|
230
|
+
}
|
|
231
|
+
|
|
203
232
|
this.dispatchEvent(new Event("change", {bubbles: true, composed: true}));
|
|
204
233
|
}
|
|
205
234
|
|
|
@@ -218,7 +247,6 @@ constructor() {
|
|
|
218
247
|
@change=${this._handleChange}
|
|
219
248
|
/>
|
|
220
249
|
<div class="control">
|
|
221
|
-
<!-- Render both SVGs and use CSS to conditionally reveal them based on host attributes -->
|
|
222
250
|
${this.indeterminate
|
|
223
251
|
? html`<svg class="icon-minus" viewBox="0 0 24 24"><path d="M5 12h14"></path></svg>`
|
|
224
252
|
: html`<svg class="icon-check" viewBox="0 0 24 24">
|
|
@@ -235,4 +263,4 @@ declare global {
|
|
|
235
263
|
interface HTMLElementTagNameMap {
|
|
236
264
|
"st-checkbox": StCheckbox;
|
|
237
265
|
}
|
|
238
|
-
}
|
|
266
|
+
}
|
|
@@ -176,20 +176,19 @@ export class StForm extends LitElement {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
private _validateCurrentContext(): boolean {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
const scope: ParentNode = this._stepElements.length > 0
|
|
180
|
+
? this._stepElements[this._currentStepIndex]
|
|
181
|
+
: this;
|
|
182
182
|
|
|
183
|
-
const currentStep = this._stepElements[this._currentStepIndex];
|
|
184
183
|
let isValid = true;
|
|
185
184
|
|
|
186
|
-
// Find all
|
|
185
|
+
// Find all elements that expose validation functions (e.g. checkValidity / reportValidity)
|
|
187
186
|
const inputs = Array.from(
|
|
188
|
-
|
|
189
|
-
HTMLElement & {checkValidity?: () => boolean; reportValidity?: () =>
|
|
187
|
+
scope.querySelectorAll<
|
|
188
|
+
HTMLElement & {checkValidity?: () => boolean; reportValidity?: () => boolean}
|
|
190
189
|
>("*"),
|
|
191
190
|
);
|
|
192
|
-
|
|
191
|
+
|
|
193
192
|
for (const input of inputs) {
|
|
194
193
|
if (typeof input.checkValidity === "function") {
|
|
195
194
|
if (!input.checkValidity()) {
|
|
@@ -202,6 +201,13 @@ export class StForm extends LitElement {
|
|
|
202
201
|
}
|
|
203
202
|
}
|
|
204
203
|
|
|
204
|
+
// Also check standard form elements if not using steps
|
|
205
|
+
if (this._stepElements.length === 0 && this._formEl) {
|
|
206
|
+
if (!this._formEl.checkValidity()) {
|
|
207
|
+
isValid = false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
205
211
|
return isValid;
|
|
206
212
|
}
|
|
207
213
|
|
|
@@ -373,4 +379,4 @@ declare global {
|
|
|
373
379
|
interface HTMLElementTagNameMap {
|
|
374
380
|
"st-form": StForm;
|
|
375
381
|
}
|
|
376
|
-
}
|
|
382
|
+
}
|
|
@@ -3,10 +3,12 @@ import { customElement, property } from 'lit/decorators.js';
|
|
|
3
3
|
import { iconPaths, IconName } from './icon-paths.js';
|
|
4
4
|
import { resetStyles } from '../../styles/reset.js';
|
|
5
5
|
|
|
6
|
+
export type IconVariant = 'outline' | 'solid';
|
|
7
|
+
|
|
6
8
|
@customElement('st-icon')
|
|
7
9
|
export class StIcon extends LitElement {
|
|
8
10
|
@property({ type: String }) name: IconName | string = '';
|
|
9
|
-
@property({ type: String }) variant:
|
|
11
|
+
@property({ type: String }) variant: IconVariant = 'outline';
|
|
10
12
|
|
|
11
13
|
// Semantic Colors
|
|
12
14
|
@property({ type: String, reflect: true }) color: 'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info' = 'default';
|