@getflip/swirl-components 0.65.0 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components.json +206 -3
- package/dist/cjs/index-506fe4ea.js +8 -4
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/maska-895c9954.js +6259 -0
- package/dist/cjs/swirl-action-list_3.cjs.entry.js +1 -2
- package/dist/cjs/swirl-app-layout_7.cjs.entry.js +1 -1
- package/dist/cjs/swirl-banner.cjs.entry.js +1 -2
- package/dist/cjs/swirl-button.cjs.entry.js +1 -2
- package/dist/cjs/swirl-chip.cjs.entry.js +1 -2
- package/dist/cjs/swirl-components.cjs.js +1 -1
- package/dist/cjs/swirl-date-input.cjs.entry.js +17 -6268
- package/dist/cjs/swirl-icon-check-small_3.cjs.entry.js +1 -2
- package/dist/cjs/swirl-icon-error_3.cjs.entry.js +1 -2
- package/dist/cjs/swirl-inline-status.cjs.entry.js +1 -2
- package/dist/cjs/swirl-menu.cjs.entry.js +1 -2
- package/dist/cjs/swirl-resource-list-file-item.cjs.entry.js +1 -2
- package/dist/cjs/swirl-search.cjs.entry.js +1 -2
- package/dist/cjs/swirl-shell-layout.cjs.entry.js +1 -2
- package/dist/cjs/swirl-tab-bar.cjs.entry.js +1 -1
- package/dist/cjs/swirl-text-input.cjs.entry.js +1 -2
- package/dist/cjs/swirl-time-input.cjs.entry.js +131 -0
- package/dist/cjs/swirl-toast.cjs.entry.js +1 -2
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/swirl-action-list-item/swirl-action-list-item.js +1 -2
- package/dist/collection/components/swirl-app-layout/swirl-app-layout.css +6 -3
- package/dist/collection/components/swirl-banner/swirl-banner.js +1 -2
- package/dist/collection/components/swirl-button/swirl-button.js +1 -2
- package/dist/collection/components/swirl-chip/swirl-chip.js +1 -2
- package/dist/collection/components/swirl-date-input/swirl-date-input.js +1 -2
- package/dist/collection/components/swirl-form-control/swirl-form-control.stories.js +5 -1
- package/dist/collection/components/swirl-inline-error/swirl-inline-error.js +1 -2
- package/dist/collection/components/swirl-inline-status/swirl-inline-status.js +1 -2
- package/dist/collection/components/swirl-menu/swirl-menu.js +1 -2
- package/dist/collection/components/swirl-option-list-item/swirl-option-list-item.js +1 -2
- package/dist/collection/components/swirl-resource-list-file-item/swirl-resource-list-file-item.js +1 -2
- package/dist/collection/components/swirl-search/swirl-search.js +1 -2
- package/dist/collection/components/swirl-shell-layout/swirl-shell-layout.js +1 -2
- package/dist/collection/components/swirl-tab-bar/swirl-tab-bar.css +3 -2
- package/dist/collection/components/swirl-text-input/swirl-text-input.js +1 -2
- package/dist/collection/components/swirl-time-input/swirl-time-input.css +78 -0
- package/dist/collection/components/swirl-time-input/swirl-time-input.js +334 -0
- package/dist/collection/components/swirl-time-input/swirl-time-input.spec.js +70 -0
- package/dist/collection/components/swirl-time-input/swirl-time-input.stories.js +38 -0
- package/dist/collection/components/swirl-toast/swirl-toast.js +1 -2
- package/dist/components/maska.js +6254 -0
- package/dist/components/swirl-action-list-item2.js +1 -2
- package/dist/components/swirl-app-layout2.js +1 -1
- package/dist/components/swirl-banner.js +1 -2
- package/dist/components/swirl-button2.js +1 -2
- package/dist/components/swirl-chip.js +1 -2
- package/dist/components/swirl-date-input.js +3 -6254
- package/dist/components/swirl-icon-time-outlined.js +1 -35
- package/dist/components/swirl-icon-time-outlined2.js +37 -0
- package/dist/components/swirl-inline-error2.js +1 -2
- package/dist/components/swirl-inline-status.js +1 -2
- package/dist/components/swirl-menu.js +1 -2
- package/dist/components/swirl-option-list-item2.js +1 -2
- package/dist/components/swirl-resource-list-file-item.js +1 -2
- package/dist/components/swirl-search.js +1 -2
- package/dist/components/swirl-shell-layout.js +1 -2
- package/dist/components/swirl-tab-bar2.js +1 -1
- package/dist/components/swirl-text-input2.js +1 -2
- package/dist/components/swirl-time-input.d.ts +11 -0
- package/dist/components/swirl-time-input.js +163 -0
- package/dist/components/swirl-toast2.js +1 -2
- package/dist/esm/index-99d0060d.js +8 -4
- package/dist/esm/loader.js +1 -1
- package/dist/esm/maska-4866b970.js +6254 -0
- package/dist/esm/swirl-action-list_3.entry.js +1 -2
- package/dist/esm/swirl-app-layout_7.entry.js +1 -1
- package/dist/esm/swirl-banner.entry.js +1 -2
- package/dist/esm/swirl-button.entry.js +1 -2
- package/dist/esm/swirl-chip.entry.js +1 -2
- package/dist/esm/swirl-components.js +1 -1
- package/dist/esm/swirl-date-input.entry.js +3 -6254
- package/dist/esm/swirl-icon-check-small_3.entry.js +1 -2
- package/dist/esm/swirl-icon-error_3.entry.js +1 -2
- package/dist/esm/swirl-inline-status.entry.js +1 -2
- package/dist/esm/swirl-menu.entry.js +1 -2
- package/dist/esm/swirl-resource-list-file-item.entry.js +1 -2
- package/dist/esm/swirl-search.entry.js +1 -2
- package/dist/esm/swirl-shell-layout.entry.js +1 -2
- package/dist/esm/swirl-tab-bar.entry.js +1 -1
- package/dist/esm/swirl-text-input.entry.js +1 -2
- package/dist/esm/swirl-time-input.entry.js +127 -0
- package/dist/esm/swirl-toast.entry.js +1 -2
- package/dist/swirl-components/p-059f706f.entry.js +1 -0
- package/dist/swirl-components/p-06012b5a.entry.js +1 -0
- package/dist/swirl-components/p-22c58025.entry.js +1 -0
- package/dist/swirl-components/p-27bdb25e.entry.js +1 -0
- package/dist/swirl-components/p-29147daa.entry.js +1 -0
- package/dist/swirl-components/p-2d5438ae.entry.js +1 -0
- package/dist/swirl-components/p-34edf304.entry.js +1 -0
- package/dist/swirl-components/p-3e3b59a3.entry.js +1 -0
- package/dist/swirl-components/p-5875e90e.entry.js +1 -0
- package/dist/swirl-components/p-6339561b.js +7 -0
- package/dist/swirl-components/p-70db5c75.entry.js +1 -0
- package/dist/swirl-components/p-84d89f53.entry.js +1 -0
- package/dist/swirl-components/p-85052283.entry.js +1 -0
- package/dist/swirl-components/p-873a1d91.entry.js +1 -0
- package/dist/swirl-components/p-9d9427ab.entry.js +1 -0
- package/dist/swirl-components/{p-0696894f.entry.js → p-ab7f6735.entry.js} +1 -1
- package/dist/swirl-components/p-b28fadcf.entry.js +1 -0
- package/dist/swirl-components/p-bbf0621a.entry.js +1 -0
- package/dist/swirl-components/swirl-components.css +1 -1
- package/dist/swirl-components/swirl-components.esm.js +1 -1
- package/dist/types/components/swirl-time-input/swirl-time-input.d.ts +33 -0
- package/dist/types/components/swirl-time-input/swirl-time-input.stories.d.ts +30 -0
- package/dist/types/components.d.ts +38 -0
- package/package.json +1 -1
- package/vscode-data.json +49 -0
- package/dist/swirl-components/p-422ac359.entry.js +0 -1
- package/dist/swirl-components/p-46f752bb.entry.js +0 -1
- package/dist/swirl-components/p-4eb2bee3.entry.js +0 -1
- package/dist/swirl-components/p-53d9fb46.entry.js +0 -1
- package/dist/swirl-components/p-54b3a0a0.entry.js +0 -1
- package/dist/swirl-components/p-5f4a027e.entry.js +0 -1
- package/dist/swirl-components/p-90c4e476.entry.js +0 -1
- package/dist/swirl-components/p-9be03b1a.entry.js +0 -1
- package/dist/swirl-components/p-9ca2aef0.entry.js +0 -1
- package/dist/swirl-components/p-a3097f0e.entry.js +0 -1
- package/dist/swirl-components/p-b0ac778b.entry.js +0 -1
- package/dist/swirl-components/p-bb9f3008.entry.js +0 -7
- package/dist/swirl-components/p-cf0ec939.entry.js +0 -1
- package/dist/swirl-components/p-d881f2c4.entry.js +0 -1
- package/dist/swirl-components/p-e9845c3a.entry.js +0 -1
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { h, Host, } from "@stencil/core";
|
|
2
|
+
import classnames from "classnames";
|
|
3
|
+
import { format, isValid, parse } from "date-fns";
|
|
4
|
+
import { create as createMask } from "maska/dist/es6/maska";
|
|
5
|
+
import { getDesktopMediaQuery } from "../../utils";
|
|
6
|
+
const internalTimeFormat = "HH:mm:ss";
|
|
7
|
+
export class SwirlTimeInput {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.desktopMediaQuery = getDesktopMediaQuery();
|
|
10
|
+
this.desktopMediaQueryHandler = (event) => {
|
|
11
|
+
this.updateIconSize(event.matches);
|
|
12
|
+
};
|
|
13
|
+
this.onChange = (event) => {
|
|
14
|
+
const value = event.target.value;
|
|
15
|
+
let newValue;
|
|
16
|
+
if (value === "") {
|
|
17
|
+
this.value = undefined;
|
|
18
|
+
this.valueChange.emit(undefined);
|
|
19
|
+
}
|
|
20
|
+
const newDate = parse(value, this.format, new Date());
|
|
21
|
+
const formatRegExp = new RegExp(`^${this.format.replace(/[Hhms]/g, "\\d")}$`);
|
|
22
|
+
if (!Boolean(value.match(formatRegExp))) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!isValid(newDate)) {
|
|
26
|
+
newValue = format(new Date(), internalTimeFormat);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
newValue = format(newDate, internalTimeFormat);
|
|
30
|
+
}
|
|
31
|
+
this.value = newValue;
|
|
32
|
+
this.valueChange.emit(newValue);
|
|
33
|
+
};
|
|
34
|
+
this.onBlur = (event) => {
|
|
35
|
+
const input = event.target;
|
|
36
|
+
const dateValue = parse(input.value, this.format, new Date());
|
|
37
|
+
if (!isValid(dateValue) && Boolean(this.value)) {
|
|
38
|
+
const currentDateValue = Boolean(this.value)
|
|
39
|
+
? parse(this.value, internalTimeFormat, new Date())
|
|
40
|
+
: undefined;
|
|
41
|
+
if (!Boolean(currentDateValue) || !isValid(currentDateValue)) {
|
|
42
|
+
this.value = "";
|
|
43
|
+
}
|
|
44
|
+
input.value = format(currentDateValue, this.format);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
this.onInput = (event) => {
|
|
48
|
+
this.onChange(event);
|
|
49
|
+
};
|
|
50
|
+
this.onClick = (event) => {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
};
|
|
53
|
+
this.onFocus = (event) => {
|
|
54
|
+
this.handleAutoSelect(event);
|
|
55
|
+
};
|
|
56
|
+
this.autoFocus = undefined;
|
|
57
|
+
this.autoSelect = undefined;
|
|
58
|
+
this.disabled = undefined;
|
|
59
|
+
this.format = "HH:mm";
|
|
60
|
+
this.inline = undefined;
|
|
61
|
+
this.invalid = undefined;
|
|
62
|
+
this.placeholder = "hh:mm";
|
|
63
|
+
this.required = undefined;
|
|
64
|
+
this.swirlAriaDescribedby = undefined;
|
|
65
|
+
this.value = undefined;
|
|
66
|
+
this.iconSize = 24;
|
|
67
|
+
}
|
|
68
|
+
componentWillLoad() {
|
|
69
|
+
const index = Array.from(document.querySelectorAll("swirl-time-input")).indexOf(this.el);
|
|
70
|
+
this.id = `swirl-time-input-${index}`;
|
|
71
|
+
}
|
|
72
|
+
componentDidLoad() {
|
|
73
|
+
this.setupMask();
|
|
74
|
+
this.updateIconSize(this.desktopMediaQuery.matches);
|
|
75
|
+
this.desktopMediaQuery.onchange = this.desktopMediaQueryHandler;
|
|
76
|
+
}
|
|
77
|
+
disconnectedCallback() {
|
|
78
|
+
var _a, _b, _c;
|
|
79
|
+
(_a = this.mask) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
80
|
+
(_c = (_b = this.desktopMediaQuery).removeEventListener) === null || _c === void 0 ? void 0 : _c.call(_b, "change", this.desktopMediaQueryHandler);
|
|
81
|
+
}
|
|
82
|
+
watchFormat() {
|
|
83
|
+
this.setupMask();
|
|
84
|
+
}
|
|
85
|
+
updateIconSize(smallIcon) {
|
|
86
|
+
this.iconSize = smallIcon ? 20 : 24;
|
|
87
|
+
}
|
|
88
|
+
handleAutoSelect(event) {
|
|
89
|
+
if (!this.autoSelect) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
event.target.select();
|
|
93
|
+
}
|
|
94
|
+
setupMask() {
|
|
95
|
+
var _a;
|
|
96
|
+
(_a = this.mask) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
97
|
+
this.mask = createMask(`#${this.id}`, {
|
|
98
|
+
mask: this.format.replace(/[Hhms]/g, "#"),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
render() {
|
|
102
|
+
const ariaInvalid = this.invalid === true || this.invalid === false
|
|
103
|
+
? String(this.invalid)
|
|
104
|
+
: undefined;
|
|
105
|
+
const dateValue = Boolean(this.value)
|
|
106
|
+
? parse(this.value, internalTimeFormat, new Date())
|
|
107
|
+
: undefined;
|
|
108
|
+
const displayValue = isValid(dateValue)
|
|
109
|
+
? format(dateValue, this.format)
|
|
110
|
+
: undefined;
|
|
111
|
+
const className = classnames("time-input", {
|
|
112
|
+
"time-input--inline": this.inline,
|
|
113
|
+
});
|
|
114
|
+
return (h(Host, null, h("div", { class: className }, h("input", { "aria-describedby": this.swirlAriaDescribedby, "aria-disabled": this.disabled ? "true" : undefined, "aria-invalid": ariaInvalid, autoFocus: this.autoFocus, class: "time-input__input", disabled: this.disabled, id: this.id, onBlur: this.onBlur, onClick: this.onClick, onFocus: this.onFocus, onInput: this.onInput, placeholder: this.placeholder, required: this.required, type: "text", value: displayValue }), h("span", { class: "time-input__icon" }, h("swirl-icon-time-outlined", { size: this.iconSize })))));
|
|
115
|
+
}
|
|
116
|
+
static get is() { return "swirl-time-input"; }
|
|
117
|
+
static get encapsulation() { return "scoped"; }
|
|
118
|
+
static get originalStyleUrls() {
|
|
119
|
+
return {
|
|
120
|
+
"$": ["swirl-time-input.css"]
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
static get styleUrls() {
|
|
124
|
+
return {
|
|
125
|
+
"$": ["swirl-time-input.css"]
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
static get properties() {
|
|
129
|
+
return {
|
|
130
|
+
"autoFocus": {
|
|
131
|
+
"type": "boolean",
|
|
132
|
+
"mutable": false,
|
|
133
|
+
"complexType": {
|
|
134
|
+
"original": "boolean",
|
|
135
|
+
"resolved": "boolean",
|
|
136
|
+
"references": {}
|
|
137
|
+
},
|
|
138
|
+
"required": false,
|
|
139
|
+
"optional": true,
|
|
140
|
+
"docs": {
|
|
141
|
+
"tags": [],
|
|
142
|
+
"text": ""
|
|
143
|
+
},
|
|
144
|
+
"attribute": "auto-focus",
|
|
145
|
+
"reflect": false
|
|
146
|
+
},
|
|
147
|
+
"autoSelect": {
|
|
148
|
+
"type": "boolean",
|
|
149
|
+
"mutable": false,
|
|
150
|
+
"complexType": {
|
|
151
|
+
"original": "boolean",
|
|
152
|
+
"resolved": "boolean",
|
|
153
|
+
"references": {}
|
|
154
|
+
},
|
|
155
|
+
"required": false,
|
|
156
|
+
"optional": true,
|
|
157
|
+
"docs": {
|
|
158
|
+
"tags": [],
|
|
159
|
+
"text": ""
|
|
160
|
+
},
|
|
161
|
+
"attribute": "auto-select",
|
|
162
|
+
"reflect": false
|
|
163
|
+
},
|
|
164
|
+
"disabled": {
|
|
165
|
+
"type": "boolean",
|
|
166
|
+
"mutable": false,
|
|
167
|
+
"complexType": {
|
|
168
|
+
"original": "boolean",
|
|
169
|
+
"resolved": "boolean",
|
|
170
|
+
"references": {}
|
|
171
|
+
},
|
|
172
|
+
"required": false,
|
|
173
|
+
"optional": true,
|
|
174
|
+
"docs": {
|
|
175
|
+
"tags": [],
|
|
176
|
+
"text": ""
|
|
177
|
+
},
|
|
178
|
+
"attribute": "disabled",
|
|
179
|
+
"reflect": false
|
|
180
|
+
},
|
|
181
|
+
"format": {
|
|
182
|
+
"type": "string",
|
|
183
|
+
"mutable": false,
|
|
184
|
+
"complexType": {
|
|
185
|
+
"original": "string",
|
|
186
|
+
"resolved": "string",
|
|
187
|
+
"references": {}
|
|
188
|
+
},
|
|
189
|
+
"required": false,
|
|
190
|
+
"optional": true,
|
|
191
|
+
"docs": {
|
|
192
|
+
"tags": [],
|
|
193
|
+
"text": ""
|
|
194
|
+
},
|
|
195
|
+
"attribute": "format",
|
|
196
|
+
"reflect": false,
|
|
197
|
+
"defaultValue": "\"HH:mm\""
|
|
198
|
+
},
|
|
199
|
+
"inline": {
|
|
200
|
+
"type": "boolean",
|
|
201
|
+
"mutable": false,
|
|
202
|
+
"complexType": {
|
|
203
|
+
"original": "boolean",
|
|
204
|
+
"resolved": "boolean",
|
|
205
|
+
"references": {}
|
|
206
|
+
},
|
|
207
|
+
"required": false,
|
|
208
|
+
"optional": true,
|
|
209
|
+
"docs": {
|
|
210
|
+
"tags": [],
|
|
211
|
+
"text": ""
|
|
212
|
+
},
|
|
213
|
+
"attribute": "inline",
|
|
214
|
+
"reflect": false
|
|
215
|
+
},
|
|
216
|
+
"invalid": {
|
|
217
|
+
"type": "boolean",
|
|
218
|
+
"mutable": false,
|
|
219
|
+
"complexType": {
|
|
220
|
+
"original": "boolean",
|
|
221
|
+
"resolved": "boolean",
|
|
222
|
+
"references": {}
|
|
223
|
+
},
|
|
224
|
+
"required": false,
|
|
225
|
+
"optional": true,
|
|
226
|
+
"docs": {
|
|
227
|
+
"tags": [],
|
|
228
|
+
"text": ""
|
|
229
|
+
},
|
|
230
|
+
"attribute": "invalid",
|
|
231
|
+
"reflect": false
|
|
232
|
+
},
|
|
233
|
+
"placeholder": {
|
|
234
|
+
"type": "string",
|
|
235
|
+
"mutable": false,
|
|
236
|
+
"complexType": {
|
|
237
|
+
"original": "string",
|
|
238
|
+
"resolved": "string",
|
|
239
|
+
"references": {}
|
|
240
|
+
},
|
|
241
|
+
"required": false,
|
|
242
|
+
"optional": true,
|
|
243
|
+
"docs": {
|
|
244
|
+
"tags": [],
|
|
245
|
+
"text": ""
|
|
246
|
+
},
|
|
247
|
+
"attribute": "placeholder",
|
|
248
|
+
"reflect": false,
|
|
249
|
+
"defaultValue": "\"hh:mm\""
|
|
250
|
+
},
|
|
251
|
+
"required": {
|
|
252
|
+
"type": "boolean",
|
|
253
|
+
"mutable": false,
|
|
254
|
+
"complexType": {
|
|
255
|
+
"original": "boolean",
|
|
256
|
+
"resolved": "boolean",
|
|
257
|
+
"references": {}
|
|
258
|
+
},
|
|
259
|
+
"required": false,
|
|
260
|
+
"optional": true,
|
|
261
|
+
"docs": {
|
|
262
|
+
"tags": [],
|
|
263
|
+
"text": ""
|
|
264
|
+
},
|
|
265
|
+
"attribute": "required",
|
|
266
|
+
"reflect": false
|
|
267
|
+
},
|
|
268
|
+
"swirlAriaDescribedby": {
|
|
269
|
+
"type": "string",
|
|
270
|
+
"mutable": false,
|
|
271
|
+
"complexType": {
|
|
272
|
+
"original": "string",
|
|
273
|
+
"resolved": "string",
|
|
274
|
+
"references": {}
|
|
275
|
+
},
|
|
276
|
+
"required": false,
|
|
277
|
+
"optional": true,
|
|
278
|
+
"docs": {
|
|
279
|
+
"tags": [],
|
|
280
|
+
"text": ""
|
|
281
|
+
},
|
|
282
|
+
"attribute": "swirl-aria-describedby",
|
|
283
|
+
"reflect": false
|
|
284
|
+
},
|
|
285
|
+
"value": {
|
|
286
|
+
"type": "string",
|
|
287
|
+
"mutable": true,
|
|
288
|
+
"complexType": {
|
|
289
|
+
"original": "string",
|
|
290
|
+
"resolved": "string",
|
|
291
|
+
"references": {}
|
|
292
|
+
},
|
|
293
|
+
"required": false,
|
|
294
|
+
"optional": true,
|
|
295
|
+
"docs": {
|
|
296
|
+
"tags": [],
|
|
297
|
+
"text": ""
|
|
298
|
+
},
|
|
299
|
+
"attribute": "value",
|
|
300
|
+
"reflect": true
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
static get states() {
|
|
305
|
+
return {
|
|
306
|
+
"iconSize": {}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
static get events() {
|
|
310
|
+
return [{
|
|
311
|
+
"method": "valueChange",
|
|
312
|
+
"name": "valueChange",
|
|
313
|
+
"bubbles": true,
|
|
314
|
+
"cancelable": true,
|
|
315
|
+
"composed": true,
|
|
316
|
+
"docs": {
|
|
317
|
+
"tags": [],
|
|
318
|
+
"text": ""
|
|
319
|
+
},
|
|
320
|
+
"complexType": {
|
|
321
|
+
"original": "string",
|
|
322
|
+
"resolved": "string",
|
|
323
|
+
"references": {}
|
|
324
|
+
}
|
|
325
|
+
}];
|
|
326
|
+
}
|
|
327
|
+
static get elementRef() { return "el"; }
|
|
328
|
+
static get watchers() {
|
|
329
|
+
return [{
|
|
330
|
+
"propName": "format",
|
|
331
|
+
"methodName": "watchFormat"
|
|
332
|
+
}];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const maskSpy = jest.fn();
|
|
2
|
+
jest.mock("maska/dist/es6/maska", () => ({
|
|
3
|
+
create: maskSpy,
|
|
4
|
+
}));
|
|
5
|
+
import { newSpecPage } from "@stencil/core/testing";
|
|
6
|
+
import { SwirlTimeInput } from "./swirl-time-input";
|
|
7
|
+
describe("swirl-time-input", () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
maskSpy.mockReset();
|
|
10
|
+
});
|
|
11
|
+
it("renders the input", async () => {
|
|
12
|
+
const page = await newSpecPage({
|
|
13
|
+
components: [SwirlTimeInput],
|
|
14
|
+
html: `<swirl-time-input></swirl-time-input>`,
|
|
15
|
+
});
|
|
16
|
+
expect(page.root).toEqualHtml(`
|
|
17
|
+
<swirl-time-input>
|
|
18
|
+
<div class="time-input">
|
|
19
|
+
<input class="time-input__input" id="swirl-time-input-0" placeholder="hh:mm" type="text">
|
|
20
|
+
<span class="time-input__icon">
|
|
21
|
+
<swirl-icon-time-outlined size="24"></swirl-icon-time-outlined>
|
|
22
|
+
</span>
|
|
23
|
+
</div>
|
|
24
|
+
</swirl-time-input>
|
|
25
|
+
`);
|
|
26
|
+
});
|
|
27
|
+
it("handles different formats", async () => {
|
|
28
|
+
const page = await newSpecPage({
|
|
29
|
+
components: [SwirlTimeInput],
|
|
30
|
+
html: `<swirl-time-input value="12:30:00"></swirl-time-input>`,
|
|
31
|
+
});
|
|
32
|
+
const input = page.root.querySelector("input");
|
|
33
|
+
expect(input.value).toBe("12:30");
|
|
34
|
+
page.root.format = "HH:mm:ss";
|
|
35
|
+
await page.waitForChanges();
|
|
36
|
+
expect(input.value).toBe("12:30:00");
|
|
37
|
+
});
|
|
38
|
+
it("masks values according to the format", async () => {
|
|
39
|
+
const page = await newSpecPage({
|
|
40
|
+
components: [SwirlTimeInput],
|
|
41
|
+
html: `<swirl-time-input value="12:30:00"></swirl-time-input>`,
|
|
42
|
+
});
|
|
43
|
+
expect(maskSpy).toHaveBeenCalledWith("#swirl-time-input-0", {
|
|
44
|
+
mask: "##:##",
|
|
45
|
+
});
|
|
46
|
+
page.root.format = "HH:mm:ss";
|
|
47
|
+
expect(maskSpy).toHaveBeenCalledWith("#swirl-time-input-0", {
|
|
48
|
+
mask: "##:##:##",
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it("fires valueChange events for valid values", async () => {
|
|
52
|
+
const page = await newSpecPage({
|
|
53
|
+
components: [SwirlTimeInput],
|
|
54
|
+
html: `<swirl-time-input></swirl-time-input>`,
|
|
55
|
+
});
|
|
56
|
+
const spy = jest.fn();
|
|
57
|
+
const input = page.root.querySelector("input");
|
|
58
|
+
page.root.addEventListener("valueChange", spy);
|
|
59
|
+
input.value = "12:";
|
|
60
|
+
input.dispatchEvent(new Event("input"));
|
|
61
|
+
expect(spy).toHaveBeenCalledTimes(0);
|
|
62
|
+
input.value = "12:30";
|
|
63
|
+
input.dispatchEvent(new Event("input"));
|
|
64
|
+
expect(spy.mock.calls[0][0].detail).toBe("12:30:00");
|
|
65
|
+
page.root.format = "HH:mm:ss";
|
|
66
|
+
input.value = "12:30:20";
|
|
67
|
+
input.dispatchEvent(new Event("input"));
|
|
68
|
+
expect(spy.mock.calls[1][0].detail).toBe("12:30:20");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { generateStoryElement } from "../../utils";
|
|
2
|
+
import Docs from "./swirl-time-input.mdx";
|
|
3
|
+
export default {
|
|
4
|
+
argTypes: {
|
|
5
|
+
format: {
|
|
6
|
+
description: "See https://date-fns.org/v2.29.3/docs/format.",
|
|
7
|
+
table: {
|
|
8
|
+
type: {
|
|
9
|
+
detail: '"h", "H", "m", "s", and separators (e.g. ":")',
|
|
10
|
+
summary: "Allowed patterns",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
locale: {
|
|
15
|
+
control: { type: "object" },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
component: "swirl-time-input",
|
|
19
|
+
tags: ["autodocs"],
|
|
20
|
+
parameters: {
|
|
21
|
+
docs: {
|
|
22
|
+
page: Docs,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
title: "Components/SwirlTimeInput",
|
|
26
|
+
};
|
|
27
|
+
const Template = (args) => {
|
|
28
|
+
const formControl = document.createElement("swirl-form-control");
|
|
29
|
+
const element = generateStoryElement("swirl-time-input", args);
|
|
30
|
+
formControl.setAttribute("label", "Time");
|
|
31
|
+
formControl.append("\n ", element, "\n");
|
|
32
|
+
element.addEventListener("valueChange", (event) => {
|
|
33
|
+
console.log(event);
|
|
34
|
+
});
|
|
35
|
+
return formControl;
|
|
36
|
+
};
|
|
37
|
+
export const SwirlTimeInput = Template.bind({});
|
|
38
|
+
SwirlTimeInput.args = {};
|
|
@@ -22,10 +22,9 @@ export class SwirlToast {
|
|
|
22
22
|
this.startTimer();
|
|
23
23
|
}
|
|
24
24
|
componentDidLoad() {
|
|
25
|
-
var _a, _b;
|
|
26
25
|
this.startTimer();
|
|
27
26
|
this.forceIconProps(this.desktopMediaQuery.matches);
|
|
28
|
-
|
|
27
|
+
this.desktopMediaQuery.onchange = this.desktopMediaQueryHandler;
|
|
29
28
|
}
|
|
30
29
|
disconnectedCallback() {
|
|
31
30
|
var _a, _b;
|