@mustib/web-components 0.0.0-alpha.5 → 0.0.0-alpha.7
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/common-BBjg-zl9.js +604 -0
- package/components/mu-element.d.ts +3 -1
- package/components/mu-element.js +2 -1
- package/components/mu-icon.d.ts +4 -0
- package/components/mu-icon.js +14 -1
- package/components/mu-range-fill.js +2 -1
- package/components/mu-range-thumb-value.js +2 -1
- package/components/mu-range-thumb.js +2 -1
- package/components/mu-range.d.ts +46 -1
- package/components/mu-range.js +97 -19
- package/components/mu-select-item.js +2 -1
- package/components/mu-select-items.js +2 -1
- package/components/mu-select-label-content.js +2 -1
- package/components/mu-select-label.js +2 -1
- package/components/mu-select.js +2 -1
- package/components/mu-sortable-item.js +2 -1
- package/components/mu-sortable-trigger.js +2 -1
- package/components/mu-sortable.js +2 -1
- package/components/mu-toast-item.d.ts +6 -0
- package/components/mu-toast-item.js +229 -0
- package/components/mu-toast.d.ts +6 -0
- package/components/mu-toast.js +216 -0
- package/components/mu-transparent.js +2 -1
- package/components/mu-trigger.js +2 -1
- package/constants-DPnKJ57t.js +8 -0
- package/index.d.ts +9 -2
- package/index.js +11 -1
- package/{mu-element-CEvBHYiI.js → mu-element-yEZ17QUl.js} +2 -195
- package/mu-toast-DfNHcc7U.d.ts +276 -0
- package/package.json +7 -2
- package/utils/Toast.d.ts +6 -0
- package/utils/Toast.js +321 -0
- package/utils/ToastController.d.ts +6 -0
- package/utils/ToastController.js +189 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { M as MuElement, _ as __decorate, g as getElementBoundaries } from '../mu-element-
|
|
1
|
+
import { M as MuElement, _ as __decorate, g as getElementBoundaries } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { css, html } from 'lit';
|
|
3
3
|
import { state, property, query } from 'lit/decorators.js';
|
|
4
4
|
import { MuTransparent } from './mu-transparent.js';
|
|
5
5
|
import { MuRangeThumbValue } from './mu-range-thumb-value.js';
|
|
6
|
+
import '../common-BBjg-zl9.js';
|
|
6
7
|
|
|
7
8
|
class MuRangeThumb extends MuElement {
|
|
8
9
|
get range() {
|
package/components/mu-range.d.ts
CHANGED
|
@@ -29,6 +29,24 @@ type RangeFill = {
|
|
|
29
29
|
};
|
|
30
30
|
type ChangeEventSrc = 'pointerdown' | 'pointerup' | 'pointermove' | 'keydown' | 'insert';
|
|
31
31
|
type Events = {
|
|
32
|
+
/**
|
|
33
|
+
* Emitted before change event
|
|
34
|
+
*/
|
|
35
|
+
'mu-range-start': CustomEvent<{
|
|
36
|
+
/**
|
|
37
|
+
* The source of start event
|
|
38
|
+
*/
|
|
39
|
+
src: 'pointerdown' | 'keydown';
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Emitted at the end of change event
|
|
43
|
+
*/
|
|
44
|
+
'mu-range-end': CustomEvent<{
|
|
45
|
+
/**
|
|
46
|
+
* The source of end event
|
|
47
|
+
*/
|
|
48
|
+
src: 'pointerup' | 'keyup';
|
|
49
|
+
}>;
|
|
32
50
|
/**
|
|
33
51
|
* Emitted when pointerdown on a non-thumb element and empty-area attribute has a value of "dispatch".
|
|
34
52
|
*
|
|
@@ -45,6 +63,9 @@ type Events = {
|
|
|
45
63
|
name: string;
|
|
46
64
|
value: number;
|
|
47
65
|
}[];
|
|
66
|
+
/**
|
|
67
|
+
* The source of change event
|
|
68
|
+
*/
|
|
48
69
|
src: ChangeEventSrc;
|
|
49
70
|
}>;
|
|
50
71
|
/**
|
|
@@ -132,11 +153,28 @@ declare class MuRange extends MuElement {
|
|
|
132
153
|
/**
|
|
133
154
|
* this is used to prevent focus listener from running when the pointer is down otherwise active thumb will gain focus when the pointer is down
|
|
134
155
|
*/
|
|
135
|
-
protected
|
|
156
|
+
protected get _isPointerDownStart(): boolean;
|
|
157
|
+
protected get _isKeyDownStart(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* the event that started change event
|
|
160
|
+
*/
|
|
161
|
+
protected _startEvent?: 'pointerdown' | 'keydown';
|
|
162
|
+
protected get _hasStarted(): boolean;
|
|
136
163
|
set activeThumb(thumb: RangeThumb | undefined);
|
|
137
164
|
get activeThumb(): RangeThumb | undefined;
|
|
138
165
|
constructor();
|
|
139
166
|
disconnectedCallback(): void;
|
|
167
|
+
/**
|
|
168
|
+
* start thumb move
|
|
169
|
+
*/
|
|
170
|
+
protected _start(data: {
|
|
171
|
+
activeThumb?: RangeThumb;
|
|
172
|
+
src: 'pointerdown' | 'keydown';
|
|
173
|
+
}): void;
|
|
174
|
+
/**
|
|
175
|
+
* end thumb move
|
|
176
|
+
*/
|
|
177
|
+
protected _end(): void;
|
|
140
178
|
/**
|
|
141
179
|
*
|
|
142
180
|
* @returns an array of objects containing the name and value of each thumb
|
|
@@ -153,6 +191,12 @@ declare class MuRange extends MuElement {
|
|
|
153
191
|
* Switches the active thumb for keyboard navigation
|
|
154
192
|
*/
|
|
155
193
|
switchNavigationActiveItem(direction: 'next' | 'prev'): boolean;
|
|
194
|
+
dispatchStartEvent(data: {
|
|
195
|
+
src: Events['mu-range-start']['detail']['src'];
|
|
196
|
+
}): void;
|
|
197
|
+
dispatchEndEvent(data: {
|
|
198
|
+
src: Events['mu-range-end']['detail']['src'];
|
|
199
|
+
}): void;
|
|
156
200
|
dispatchChangeEvent(thumbs: {
|
|
157
201
|
name: string;
|
|
158
202
|
value: number;
|
|
@@ -202,6 +246,7 @@ declare class MuRange extends MuElement {
|
|
|
202
246
|
*/
|
|
203
247
|
setValueFromString(valueString: string): Promise<void>;
|
|
204
248
|
_keydownHandler: (e: KeyboardEvent) => void;
|
|
249
|
+
_documentKeyupHandler: () => void;
|
|
205
250
|
_pointerdownHandler: (e: PointerEvent) => void;
|
|
206
251
|
_documentPointerupHandler: (e: PointerEvent) => void;
|
|
207
252
|
_pointermoveHandler: (e: PointerEvent) => void;
|
package/components/mu-range.js
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import { M as MuElement, _ as __decorate,
|
|
1
|
+
import { M as MuElement, _ as __decorate, g as getElementBoundaries } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { css, html } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
4
|
import { MuTransparent } from './mu-transparent.js';
|
|
5
5
|
import { MuRangeFill } from './mu-range-fill.js';
|
|
6
6
|
import { MuRangeThumb } from './mu-range-thumb.js';
|
|
7
|
+
import { t as throttle, d as debounce, w as wait } from '../common-BBjg-zl9.js';
|
|
7
8
|
import './mu-range-thumb-value.js';
|
|
8
9
|
|
|
9
10
|
class MuRange extends MuElement {
|
|
10
11
|
get isControlled() {
|
|
11
12
|
return this.value !== undefined;
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* this is used to prevent focus listener from running when the pointer is down otherwise active thumb will gain focus when the pointer is down
|
|
16
|
+
*/
|
|
17
|
+
get _isPointerDownStart() {
|
|
18
|
+
return this._startEvent === 'pointerdown';
|
|
19
|
+
}
|
|
20
|
+
get _isKeyDownStart() {
|
|
21
|
+
return this._startEvent === 'keydown';
|
|
22
|
+
}
|
|
23
|
+
get _hasStarted() {
|
|
24
|
+
return this._startEvent !== undefined;
|
|
25
|
+
}
|
|
13
26
|
set activeThumb(thumb) {
|
|
14
27
|
if (thumb &&
|
|
15
28
|
(thumb.element.transparent ||
|
|
@@ -64,10 +77,6 @@ class MuRange extends MuElement {
|
|
|
64
77
|
this._thumbs = [];
|
|
65
78
|
this._thumbsElementsMap = new Map();
|
|
66
79
|
this._thumbsNamesMap = new Map();
|
|
67
|
-
/**
|
|
68
|
-
* this is used to prevent focus listener from running when the pointer is down otherwise active thumb will gain focus when the pointer is down
|
|
69
|
-
*/
|
|
70
|
-
this._isPointerDown = false;
|
|
71
80
|
this._slotChangeHandler = async () => {
|
|
72
81
|
const previousThumbsElementsMap = new Map(this._thumbsElementsMap);
|
|
73
82
|
this._thumbs = [];
|
|
@@ -188,6 +197,7 @@ class MuRange extends MuElement {
|
|
|
188
197
|
const thumb = this.activeThumb;
|
|
189
198
|
if (this.disabled || this.readonly || !thumb || e.defaultPrevented)
|
|
190
199
|
return;
|
|
200
|
+
this.dispatchStartEvent({ src: 'keydown' });
|
|
191
201
|
let increaseKey = 'ArrowRight';
|
|
192
202
|
let decreaseKey = 'ArrowLeft';
|
|
193
203
|
switch (this.axis) {
|
|
@@ -212,7 +222,15 @@ class MuRange extends MuElement {
|
|
|
212
222
|
break;
|
|
213
223
|
}
|
|
214
224
|
const setValue = (value) => {
|
|
225
|
+
if (this._hasStarted && !this._isKeyDownStart)
|
|
226
|
+
return;
|
|
215
227
|
e.preventDefault();
|
|
228
|
+
if (!this._isKeyDownStart) {
|
|
229
|
+
this._start({
|
|
230
|
+
activeThumb: thumb,
|
|
231
|
+
src: 'keydown',
|
|
232
|
+
});
|
|
233
|
+
}
|
|
216
234
|
this.focus();
|
|
217
235
|
thumb.element.focused = true;
|
|
218
236
|
this._setThumbValue({ thumb, value, src: 'keydown' });
|
|
@@ -246,19 +264,25 @@ class MuRange extends MuElement {
|
|
|
246
264
|
break;
|
|
247
265
|
}
|
|
248
266
|
};
|
|
267
|
+
this._documentKeyupHandler = () => {
|
|
268
|
+
this._end();
|
|
269
|
+
};
|
|
249
270
|
this._pointerdownHandler = (e) => {
|
|
250
|
-
if (this.disabled ||
|
|
271
|
+
if (this.disabled ||
|
|
272
|
+
this.readonly ||
|
|
273
|
+
e.defaultPrevented ||
|
|
274
|
+
this._hasStarted)
|
|
251
275
|
return;
|
|
252
|
-
this._isPointerDown = true;
|
|
253
|
-
document.addEventListener('pointermove', this._documentPointermoveHandler);
|
|
254
|
-
document.addEventListener('pointerup', this._documentPointerupHandler);
|
|
255
276
|
const thumbEl = MuElement.closestPierce('mu-range-thumb', e.target);
|
|
256
277
|
if ((thumbEl && (thumbEl.disabled || thumbEl.readonly)) ||
|
|
257
278
|
this.emptyArea === 'prevent')
|
|
258
279
|
return;
|
|
259
280
|
if (thumbEl && !thumbEl.transparent) {
|
|
260
281
|
const activeThumb = this._thumbsElementsMap.get(thumbEl);
|
|
261
|
-
this.
|
|
282
|
+
this._start({
|
|
283
|
+
activeThumb,
|
|
284
|
+
src: 'pointerdown',
|
|
285
|
+
});
|
|
262
286
|
return;
|
|
263
287
|
}
|
|
264
288
|
if (this.emptyArea === 'dispatch') {
|
|
@@ -317,18 +341,19 @@ class MuRange extends MuElement {
|
|
|
317
341
|
: rightThumb;
|
|
318
342
|
}
|
|
319
343
|
if (candidateThumb) {
|
|
344
|
+
this._start({
|
|
345
|
+
activeThumb: candidateThumb,
|
|
346
|
+
src: 'pointerdown',
|
|
347
|
+
});
|
|
320
348
|
this._setThumbValue({ thumb: candidateThumb, value, src: 'pointerdown' });
|
|
321
|
-
this.activeThumb = candidateThumb;
|
|
322
349
|
}
|
|
323
350
|
};
|
|
324
351
|
this._documentPointerupHandler = (e) => {
|
|
325
|
-
this.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const { value } = this._getValuesFromEvent(e);
|
|
331
|
-
this._setThumbValue({ thumb: this.activeThumb, value, src: 'pointerup' });
|
|
352
|
+
if (this.activeThumb) {
|
|
353
|
+
const { value } = this._getValuesFromEvent(e);
|
|
354
|
+
this._setThumbValue({ thumb: this.activeThumb, value, src: 'pointerup' });
|
|
355
|
+
}
|
|
356
|
+
this._end();
|
|
332
357
|
};
|
|
333
358
|
this._pointermoveHandler = (e) => {
|
|
334
359
|
if (!this.activeThumb)
|
|
@@ -349,7 +374,7 @@ class MuRange extends MuElement {
|
|
|
349
374
|
}
|
|
350
375
|
});
|
|
351
376
|
this.addEventListener('focus', (e) => {
|
|
352
|
-
if (this.
|
|
377
|
+
if (this._isPointerDownStart ||
|
|
353
378
|
this.disabled ||
|
|
354
379
|
this.readonly ||
|
|
355
380
|
e.defaultPrevented)
|
|
@@ -369,6 +394,41 @@ class MuRange extends MuElement {
|
|
|
369
394
|
disconnectedCallback() {
|
|
370
395
|
document.removeEventListener('pointermove', this._documentPointermoveHandler);
|
|
371
396
|
document.removeEventListener('pointerup', this._documentPointerupHandler);
|
|
397
|
+
document.removeEventListener('keyup', this._documentKeyupHandler);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* start thumb move
|
|
401
|
+
*/
|
|
402
|
+
_start(data) {
|
|
403
|
+
if (this._hasStarted)
|
|
404
|
+
return;
|
|
405
|
+
this._activeThumb = data.activeThumb;
|
|
406
|
+
if (!data.activeThumb)
|
|
407
|
+
return;
|
|
408
|
+
this._startEvent = data.src;
|
|
409
|
+
this.dispatchStartEvent({ src: data.src });
|
|
410
|
+
if (data.src === 'pointerdown') {
|
|
411
|
+
document.addEventListener('pointermove', this._documentPointermoveHandler);
|
|
412
|
+
document.addEventListener('pointerup', this._documentPointerupHandler);
|
|
413
|
+
}
|
|
414
|
+
if (data.src === 'keydown') {
|
|
415
|
+
document.addEventListener('keyup', this._documentKeyupHandler);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* end thumb move
|
|
420
|
+
*/
|
|
421
|
+
_end() {
|
|
422
|
+
document.removeEventListener('pointermove', this._documentPointermoveHandler);
|
|
423
|
+
document.removeEventListener('pointerup', this._documentPointerupHandler);
|
|
424
|
+
document.removeEventListener('keyup', this._documentKeyupHandler);
|
|
425
|
+
if (this._startEvent === 'pointerdown') {
|
|
426
|
+
this.dispatchEndEvent({ src: 'pointerup' });
|
|
427
|
+
}
|
|
428
|
+
if (this._startEvent === 'keydown') {
|
|
429
|
+
this.dispatchEndEvent({ src: 'keyup' });
|
|
430
|
+
}
|
|
431
|
+
this._startEvent = undefined;
|
|
372
432
|
}
|
|
373
433
|
/**
|
|
374
434
|
*
|
|
@@ -414,6 +474,24 @@ class MuRange extends MuElement {
|
|
|
414
474
|
navigationThumb.element.focused = true;
|
|
415
475
|
return true;
|
|
416
476
|
}
|
|
477
|
+
dispatchStartEvent(data) {
|
|
478
|
+
const eventName = 'mu-range-start';
|
|
479
|
+
this.dispatchEvent(new CustomEvent(eventName, {
|
|
480
|
+
bubbles: true,
|
|
481
|
+
composed: true,
|
|
482
|
+
cancelable: true,
|
|
483
|
+
detail: data,
|
|
484
|
+
}));
|
|
485
|
+
}
|
|
486
|
+
dispatchEndEvent(data) {
|
|
487
|
+
const eventName = 'mu-range-end';
|
|
488
|
+
this.dispatchEvent(new CustomEvent(eventName, {
|
|
489
|
+
bubbles: true,
|
|
490
|
+
composed: true,
|
|
491
|
+
cancelable: true,
|
|
492
|
+
detail: data,
|
|
493
|
+
}));
|
|
494
|
+
}
|
|
417
495
|
dispatchChangeEvent(thumbs = this._thumbs, src) {
|
|
418
496
|
const eventName = 'mu-range-change';
|
|
419
497
|
const data = thumbs.map((thumb) => ({ name: thumb.name, value: thumb.value }));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { M as MuElement, _ as __decorate } from '../mu-element-
|
|
1
|
+
import { M as MuElement, _ as __decorate } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { css, html } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
|
+
import '../common-BBjg-zl9.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* This element is designed to be stateless, its purpose is to provide a means of adding custom markup and attributes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { M as MuElement, E as EventAction, _ as __decorate, g as getElementBoundaries, d as
|
|
1
|
+
import { M as MuElement, E as EventAction, _ as __decorate, g as getElementBoundaries, d as disableElementScroll, e as enableElementScroll } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { css, html } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
4
|
import { MuTransparent } from './mu-transparent.js';
|
|
5
5
|
import { MuSelectItem } from './mu-select-item.js';
|
|
6
|
+
import { d as debounce } from '../common-BBjg-zl9.js';
|
|
6
7
|
|
|
7
8
|
class MuSelectItems extends MuElement {
|
|
8
9
|
constructor() {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { M as MuElement, _ as __decorate } from '../mu-element-
|
|
1
|
+
import { M as MuElement, _ as __decorate } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { css, nothing, html } from 'lit';
|
|
3
3
|
import { property, state } from 'lit/decorators.js';
|
|
4
4
|
import { repeat } from 'lit/directives/repeat.js';
|
|
5
|
+
import '../common-BBjg-zl9.js';
|
|
5
6
|
|
|
6
7
|
const types = ['label', 'value', 'autocomplete', 'template'];
|
|
7
8
|
const contentSelector = '[data-is="content"]';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { M as MuElement, _ as __decorate } from '../mu-element-
|
|
1
|
+
import { M as MuElement, _ as __decorate } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { css, html, nothing } from 'lit';
|
|
3
3
|
import './mu-trigger.js';
|
|
4
4
|
import { property, state } from 'lit/decorators.js';
|
|
5
5
|
import { MuTransparent } from './mu-transparent.js';
|
|
6
6
|
import { MuSelectLabelContent } from './mu-select-label-content.js';
|
|
7
7
|
import './mu-icon.js';
|
|
8
|
+
import '../common-BBjg-zl9.js';
|
|
8
9
|
import 'lit/directives/repeat.js';
|
|
9
10
|
|
|
10
11
|
class MuSelectLabel extends MuElement {
|
package/components/mu-select.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { M as MuElement, E as EventAction, _ as __decorate } from '../mu-element-
|
|
1
|
+
import { M as MuElement, E as EventAction, _ as __decorate } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { css, html } from 'lit';
|
|
3
3
|
import { property, queryAssignedElements } from 'lit/decorators.js';
|
|
4
4
|
import { MuTransparent } from './mu-transparent.js';
|
|
5
5
|
import { MuSelectItems } from './mu-select-items.js';
|
|
6
6
|
import { MuSelectLabel } from './mu-select-label.js';
|
|
7
|
+
import '../common-BBjg-zl9.js';
|
|
7
8
|
import './mu-select-item.js';
|
|
8
9
|
import './mu-trigger.js';
|
|
9
10
|
import './mu-select-label-content.js';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { M as MuElement, _ as __decorate } from '../mu-element-
|
|
1
|
+
import { M as MuElement, _ as __decorate } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { css, html } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
4
|
import { MuTransparent } from './mu-transparent.js';
|
|
5
5
|
import { MuSortableTrigger } from './mu-sortable-trigger.js';
|
|
6
|
+
import '../common-BBjg-zl9.js';
|
|
6
7
|
import './mu-icon.js';
|
|
7
8
|
|
|
8
9
|
class MuSortableItem extends MuElement {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { css, html } from 'lit';
|
|
2
|
-
import { M as MuElement } from '../mu-element-
|
|
2
|
+
import { M as MuElement } from '../mu-element-yEZ17QUl.js';
|
|
3
3
|
import './mu-icon.js';
|
|
4
|
+
import '../common-BBjg-zl9.js';
|
|
4
5
|
import 'lit/decorators.js';
|
|
5
6
|
|
|
6
7
|
class MuSortableTrigger extends MuElement {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { M as MuElement, E as EventAction,
|
|
1
|
+
import { M as MuElement, E as EventAction, _ as __decorate } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { html } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
4
|
import { MuTransparent } from './mu-transparent.js';
|
|
5
5
|
import { MuSortableItem } from './mu-sortable-item.js';
|
|
6
6
|
import { MuSortableTrigger } from './mu-sortable-trigger.js';
|
|
7
|
+
import { t as throttle } from '../common-BBjg-zl9.js';
|
|
7
8
|
import './mu-icon.js';
|
|
8
9
|
|
|
9
10
|
class MuSortable extends MuElement {
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { M as MuElement, _ as __decorate } from '../mu-element-yEZ17QUl.js';
|
|
2
|
+
import { css, nothing, html } from 'lit';
|
|
3
|
+
import './mu-icon.js';
|
|
4
|
+
import { query } from 'lit/decorators.js';
|
|
5
|
+
import { isTemplateResult } from 'lit/directive-helpers.js';
|
|
6
|
+
import { T as TOAST_LOCK_SYMBOL } from '../constants-DPnKJ57t.js';
|
|
7
|
+
import '../common-BBjg-zl9.js';
|
|
8
|
+
|
|
9
|
+
class MuToastItem extends MuElement {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.eventActionData = undefined;
|
|
13
|
+
this._addEventActionAttributes = undefined;
|
|
14
|
+
this.pausedByEvents = new Set();
|
|
15
|
+
}
|
|
16
|
+
firstUpdated(_changedProperties) {
|
|
17
|
+
super.firstUpdated(_changedProperties);
|
|
18
|
+
this.toast.emitter.dispatch('state.toast-item.first.rendered', {
|
|
19
|
+
element: this,
|
|
20
|
+
}, {
|
|
21
|
+
lockSymbol: TOAST_LOCK_SYMBOL,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
const pauseHandler = this.toast.interactingBehavior === 'nothing'
|
|
26
|
+
? nothing
|
|
27
|
+
: async (e) => {
|
|
28
|
+
this.pausedByEvents.add(e.type);
|
|
29
|
+
await this.toast.pauseProgress();
|
|
30
|
+
if (this.toast.interactingBehavior === 'reset-progress')
|
|
31
|
+
await this.toast.resetProgress();
|
|
32
|
+
};
|
|
33
|
+
const resumeHandler = this.toast.interactingBehavior === 'nothing'
|
|
34
|
+
? nothing
|
|
35
|
+
: (e) => {
|
|
36
|
+
if (e.type === 'pointerleave')
|
|
37
|
+
this.pausedByEvents.delete('pointerenter');
|
|
38
|
+
if (e.type === 'focusout')
|
|
39
|
+
this.pausedByEvents.delete('focusin');
|
|
40
|
+
if (this.pausedByEvents.size === 0) {
|
|
41
|
+
this.toast.resumeProgress();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
let spinner = nothing;
|
|
45
|
+
if (isTemplateResult(this.toast.spinner))
|
|
46
|
+
spinner = this.toast.spinner;
|
|
47
|
+
else if (this.toast.spinner)
|
|
48
|
+
spinner = html `<span id="spinner" part="spinner"></span>`;
|
|
49
|
+
let labelIcon = nothing;
|
|
50
|
+
if (isTemplateResult(this.toast.labelIcon))
|
|
51
|
+
labelIcon = this.toast.labelIcon;
|
|
52
|
+
else if (typeof this.toast.labelIcon === 'string' &&
|
|
53
|
+
this.toast.labelIcon !== '')
|
|
54
|
+
labelIcon = html `
|
|
55
|
+
<mu-icon
|
|
56
|
+
id="label-icon"
|
|
57
|
+
part="label-icon"
|
|
58
|
+
name="${this.toast.labelIcon}"
|
|
59
|
+
>
|
|
60
|
+
</mu-icon>
|
|
61
|
+
`;
|
|
62
|
+
let label = nothing;
|
|
63
|
+
if (isTemplateResult(this.toast.label))
|
|
64
|
+
label = this.toast.label;
|
|
65
|
+
else if (this.toast.label)
|
|
66
|
+
label = html `<span id="label" part="label">${this.toast.label}</span>`;
|
|
67
|
+
let message = nothing;
|
|
68
|
+
if (isTemplateResult(this.toast.message))
|
|
69
|
+
message = this.toast.message;
|
|
70
|
+
else if (this.toast.message)
|
|
71
|
+
message = html `<span id="message" part="message"
|
|
72
|
+
>${this.toast.message}</span
|
|
73
|
+
>`;
|
|
74
|
+
let closeBtn = nothing;
|
|
75
|
+
if (isTemplateResult(this.toast.closeBtn))
|
|
76
|
+
closeBtn = this.toast.closeBtn;
|
|
77
|
+
else if (this.toast.closeBtn)
|
|
78
|
+
closeBtn = html `
|
|
79
|
+
<button
|
|
80
|
+
id="close-btn"
|
|
81
|
+
part="close-btn"
|
|
82
|
+
type="button"
|
|
83
|
+
aria-label="Close notification"
|
|
84
|
+
@click=${() => this.toast.gracefulRemove()}
|
|
85
|
+
>
|
|
86
|
+
<mu-icon name="close"></mu-icon>
|
|
87
|
+
</button
|
|
88
|
+
`;
|
|
89
|
+
let action = nothing;
|
|
90
|
+
if (typeof this.toast.action === 'function')
|
|
91
|
+
action = this.toast.action(this.toast);
|
|
92
|
+
else if (this.toast.action)
|
|
93
|
+
action = html `
|
|
94
|
+
<button
|
|
95
|
+
id="action-btn"
|
|
96
|
+
part="action-btn"
|
|
97
|
+
type="button"
|
|
98
|
+
@click=${() => this.toast.action.onClick(this.toast)}
|
|
99
|
+
>
|
|
100
|
+
${this.toast.action.label}
|
|
101
|
+
</button>
|
|
102
|
+
`;
|
|
103
|
+
return html `
|
|
104
|
+
<div
|
|
105
|
+
id="container"
|
|
106
|
+
part="container"
|
|
107
|
+
style="
|
|
108
|
+
--hue: ${this.toast.colorHue};
|
|
109
|
+
"
|
|
110
|
+
role=${this.toast.role}
|
|
111
|
+
aria-atomic="true"
|
|
112
|
+
aria-live=${this.toast.role === 'alert' ? 'assertive' : 'polite'}
|
|
113
|
+
@pointerenter=${pauseHandler}
|
|
114
|
+
@pointerleave=${resumeHandler}
|
|
115
|
+
@focusin=${pauseHandler}
|
|
116
|
+
@focusout=${resumeHandler}
|
|
117
|
+
>
|
|
118
|
+
${labelIcon}
|
|
119
|
+
|
|
120
|
+
<p id="content" part="content">
|
|
121
|
+
${label} ${message} ${spinner} ${action}
|
|
122
|
+
</p>
|
|
123
|
+
|
|
124
|
+
${closeBtn}
|
|
125
|
+
|
|
126
|
+
<div id="progress" part="progress"></div>
|
|
127
|
+
</div>
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
MuToastItem.styles = [
|
|
132
|
+
MuElement.cssBase,
|
|
133
|
+
css `
|
|
134
|
+
#container {
|
|
135
|
+
--color: hsl(var(--hue), 100%, 75%);
|
|
136
|
+
--bg: hsl(var(--hue), 50%, 20%);
|
|
137
|
+
position: relative;
|
|
138
|
+
box-shadow: 0 0 5px 0 var(--color);
|
|
139
|
+
pointer-events: auto;
|
|
140
|
+
padding: var(--mu-base-rem);
|
|
141
|
+
display: flex;
|
|
142
|
+
gap: var(--mu-base-rem);
|
|
143
|
+
align-items: center;
|
|
144
|
+
transition: all 0.3s;
|
|
145
|
+
transform-origin: 100%;
|
|
146
|
+
border-radius: var(--mu-base-rem);
|
|
147
|
+
overflow: hidden;
|
|
148
|
+
color: var(--color);
|
|
149
|
+
--mu-icon-fill: var(--color);
|
|
150
|
+
background-color: var(--bg);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#progress {
|
|
154
|
+
position: absolute;
|
|
155
|
+
pointer-events: none;
|
|
156
|
+
visibility: hidden;
|
|
157
|
+
inset: 0;
|
|
158
|
+
top: unset;
|
|
159
|
+
height: 2px;
|
|
160
|
+
background-color: var(--color);
|
|
161
|
+
user-select: none;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#action-btn {
|
|
165
|
+
margin-inline: 0.5ch;
|
|
166
|
+
background-color: transparent;
|
|
167
|
+
outline: 1px solid var(--color);
|
|
168
|
+
color: var(--color);
|
|
169
|
+
padding: 0 0.5ch;
|
|
170
|
+
border-radius: 0.5ch;
|
|
171
|
+
transition: inherit;
|
|
172
|
+
cursor: pointer;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#action-btn:hover,
|
|
176
|
+
#action-btn:focus-visible {
|
|
177
|
+
background-color: var(--color);
|
|
178
|
+
color: var(--bg);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#close-btn {
|
|
182
|
+
margin-inline-start: auto;
|
|
183
|
+
background-color: transparent;
|
|
184
|
+
display: grid;
|
|
185
|
+
align-items: center;
|
|
186
|
+
justify-content: center;
|
|
187
|
+
cursor: pointer;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#close-btn:focus-visible {
|
|
191
|
+
outline: 1px solid var(--color);
|
|
192
|
+
outline-offset: 2px;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#label {
|
|
196
|
+
font-weight: bold;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
#spinner {
|
|
200
|
+
animation: spin 1s linear infinite;
|
|
201
|
+
display: inline-grid;
|
|
202
|
+
border-top: 2px solid;
|
|
203
|
+
border-left: 2px solid;
|
|
204
|
+
width: 1rem;
|
|
205
|
+
translate: 0 12.5%;
|
|
206
|
+
aspect-ratio: 1;
|
|
207
|
+
border-radius: 50%;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@keyframes spin {
|
|
211
|
+
to {
|
|
212
|
+
transform: rotate(360deg);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@media (prefers-color-scheme: light) {
|
|
217
|
+
#container {
|
|
218
|
+
--bg: hsl(var(--hue), 100%, 75%);
|
|
219
|
+
--color: hsl(var(--hue), 50%, 20%);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
`,
|
|
223
|
+
];
|
|
224
|
+
__decorate([
|
|
225
|
+
query('#progress', true)
|
|
226
|
+
], MuToastItem.prototype, "progressElement", void 0);
|
|
227
|
+
MuToastItem.register('mu-toast-item');
|
|
228
|
+
|
|
229
|
+
export { MuToastItem };
|