@nectary/components 0.38.0 → 0.40.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/accordion/index.js +47 -84
- package/accordion/types.d.ts +1 -0
- package/accordion-item/index.js +26 -53
- package/action-menu/index.d.ts +0 -1
- package/action-menu/index.js +179 -223
- package/action-menu/types.d.ts +8 -18
- package/action-menu-option/index.d.ts +1 -0
- package/action-menu-option/index.js +51 -62
- package/action-menu-option/types.d.ts +9 -0
- package/action-menu-option/utils.d.ts +2 -0
- package/action-menu-option/utils.js +3 -0
- package/alert/index.js +6 -20
- package/avatar/index.js +12 -31
- package/avatar-badge/index.js +8 -22
- package/avatar-status/index.js +1 -1
- package/button/index.js +42 -92
- package/card/index.d.ts +2 -0
- package/card/index.js +24 -87
- package/chat-avatar/index.js +8 -22
- package/chat-block/index.js +29 -69
- package/chat-bubble/index.js +6 -20
- package/checkbox/index.js +55 -107
- package/chip/index.d.ts +13 -0
- package/chip/index.js +137 -0
- package/chip/types.d.ts +38 -0
- package/color-menu/index.d.ts +13 -0
- package/color-menu/index.js +464 -0
- package/color-menu/types.d.ts +37 -0
- package/color-swatch/index.d.ts +13 -0
- package/color-swatch/index.js +59 -0
- package/color-swatch/types.d.ts +12 -0
- package/colors.json +57 -49
- package/date-picker/index.js +196 -287
- package/date-picker/types.d.ts +25 -1
- package/dialog/index.d.ts +1 -0
- package/dialog/index.js +72 -143
- package/dropdown-checkbox-option/index.js +6 -20
- package/dropdown-radio-option/index.js +6 -20
- package/field/index.js +25 -63
- package/file-drop/index.js +123 -200
- package/file-picker/index.d.ts +0 -1
- package/file-picker/index.js +55 -108
- package/file-status/index.js +15 -39
- package/help-tooltip/index.js +1 -1
- package/horizontal-stepper/index.js +33 -59
- package/horizontal-stepper-item/index.js +13 -37
- package/icon-button/index.js +39 -84
- package/icons-channel/notify/index.d.ts +11 -0
- package/icons-channel/notify/index.js +4 -0
- package/illustrations/create-illustration-class.js +1 -1
- package/inline-alert/index.js +30 -82
- package/input/index.js +113 -222
- package/link/index.js +46 -96
- package/list-item/index.js +1 -1
- package/package.json +12 -14
- package/pagination/index.js +109 -163
- package/pagination/types.d.ts +1 -0
- package/popover/index.js +224 -294
- package/progress/index.js +9 -28
- package/radio/index.js +103 -169
- package/radio/types.d.ts +1 -0
- package/radio-option/index.js +24 -48
- package/segment/index.js +50 -131
- package/segment-collapse/index.js +24 -49
- package/segment-collapse/types.d.ts +1 -0
- package/segmented-control/index.js +36 -73
- package/segmented-control/types.d.ts +1 -0
- package/segmented-control-option/index.js +41 -87
- package/segmented-icon-control/index.js +47 -84
- package/segmented-icon-control/types.d.ts +1 -0
- package/segmented-icon-control-option/index.js +38 -79
- package/select-button/index.d.ts +13 -0
- package/select-button/index.js +153 -0
- package/select-button/types.d.ts +43 -0
- package/select-menu/index.d.ts +11 -0
- package/select-menu/index.js +346 -0
- package/select-menu/types.d.ts +29 -0
- package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
- package/select-menu-option/index.js +76 -0
- package/{select-option → select-menu-option}/types.d.ts +8 -9
- package/stop-events/index.js +7 -20
- package/table-head-cell/index.js +7 -21
- package/tabs/index.js +103 -165
- package/tabs/types.d.ts +1 -0
- package/tabs-option/index.js +20 -44
- package/tag/index.d.ts +1 -1
- package/tag/index.js +42 -36
- package/tag/types.d.ts +13 -7
- package/textarea/index.js +92 -167
- package/theme.css +80 -49
- package/tile-control/index.js +55 -96
- package/tile-control-option/index.js +40 -86
- package/time-picker/index.js +224 -368
- package/time-picker/types.d.ts +5 -1
- package/title/index.js +6 -20
- package/toast/index.d.ts +17 -0
- package/toast/index.js +115 -0
- package/toast/types.d.ts +28 -0
- package/toast/utils.d.ts +5 -0
- package/toast/utils.js +6 -0
- package/toast-manager/index.d.ts +17 -0
- package/toast-manager/index.js +195 -0
- package/toast-manager/types.d.ts +7 -0
- package/toggle/index.js +55 -108
- package/toggle/types.d.ts +1 -0
- package/types.d.ts +7 -0
- package/utils/colors.d.ts +10 -0
- package/utils/colors.js +121 -0
- package/{utils.d.ts → utils/index.d.ts} +18 -9
- package/{utils.js → utils/index.js} +118 -39
- package/vertical-stepper/index.js +29 -50
- package/vertical-stepper-item/index.js +13 -37
- package/card-button/index.d.ts +0 -11
- package/card-button/index.js +0 -77
- package/card-button/types.d.ts +0 -12
- package/card-link/index.d.ts +0 -12
- package/card-link/index.js +0 -115
- package/card-link/types.d.ts +0 -14
- package/dropdown/index.d.ts +0 -12
- package/dropdown/index.js +0 -415
- package/dropdown/types.d.ts +0 -30
- package/dropdown-text-option/index.js +0 -104
- package/dropdown-text-option/types.d.ts +0 -16
- package/search/index.d.ts +0 -14
- package/search/index.js +0 -523
- package/search/types.d.ts +0 -25
- package/search-option/index.d.ts +0 -11
- package/search-option/index.js +0 -55
- package/search-option/types.d.ts +0 -9
- package/select/index.d.ts +0 -13
- package/select/index.js +0 -316
- package/select/types.d.ts +0 -53
- package/select-option/index.d.ts +0 -11
- package/select-option/index.js +0 -8
- package/tag/utils.d.ts +0 -2
- package/tag/utils.js +0 -1
- package/tag-close/index.d.ts +0 -12
- package/tag-close/index.js +0 -38
- package/tag-close/types.d.ts +0 -3
- package/tag-close/types.js +0 -1
- /package/{card-button → chip}/types.js +0 -0
- /package/{card-link → color-menu}/types.js +0 -0
- /package/{dropdown-text-option → color-swatch}/types.js +0 -0
- /package/{dropdown → select-button}/types.js +0 -0
- /package/{search → select-menu}/types.js +0 -0
- /package/{search-option → select-menu-option}/types.js +0 -0
- /package/{select → toast}/types.js +0 -0
- /package/{select-option → toast-manager}/types.js +0 -0
package/time-picker/types.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export declare type TSinchTimePickerElement = HTMLElement & {
|
|
|
5
5
|
value: string;
|
|
6
6
|
/** AM/PM 12-hour clock system, `false` by default */
|
|
7
7
|
ampm: boolean;
|
|
8
|
+
/** Submit button label that is used for a11y */
|
|
9
|
+
submitAriaLabel: string;
|
|
8
10
|
readonly submitButtonRect: TRect;
|
|
9
11
|
readonly amButtonRect: TRect | null;
|
|
10
12
|
readonly pmButtonRect: TRect | null;
|
|
@@ -16,6 +18,8 @@ export declare type TSinchTimePickerElement = HTMLElement & {
|
|
|
16
18
|
setAttribute(name: 'value', value: string): void;
|
|
17
19
|
/** AM/PM 12-hour clock system, `false` by default */
|
|
18
20
|
setAttribute(name: 'ampm', value: boolean): void;
|
|
21
|
+
/** Submit button label that is used for a11y */
|
|
22
|
+
setAttribute(name: 'submit-aria-label', value: string): void;
|
|
19
23
|
};
|
|
20
24
|
export declare type TSinchTimePickerReact = TSinchElementReact<TSinchTimePickerElement> & {
|
|
21
25
|
/** Time value in ISO 8601 format */
|
|
@@ -26,7 +30,7 @@ export declare type TSinchTimePickerReact = TSinchElementReact<TSinchTimePickerE
|
|
|
26
30
|
'aria-label': string;
|
|
27
31
|
/** Submit button label that is used for a11y */
|
|
28
32
|
'submit-aria-label': string;
|
|
29
|
-
/** Change value handler, return time in ISO 8601 format */
|
|
33
|
+
/** @deprecated Change value handler, return time in ISO 8601 format */
|
|
30
34
|
onChange?: (e: SyntheticEvent<TSinchTimePickerElement, CustomEvent<string>>) => void;
|
|
31
35
|
/** Change value handler, return time in ISO 8601 format */
|
|
32
36
|
'on-change'?: (e: CustomEvent<string>) => void;
|
package/title/index.js
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
-
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
-
|
|
4
|
-
var _$text;
|
|
5
|
-
|
|
6
|
-
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
7
|
-
|
|
8
|
-
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
9
|
-
|
|
10
1
|
import '../icons/cancel';
|
|
11
2
|
import { defineCustomElement, getAttribute, updateAttribute, updateLiteralAttribute, getLiteralAttribute, NectaryElement, updateBooleanAttribute, getBooleanAttribute } from '../utils';
|
|
12
3
|
const templateHTML = '<style>:host{display:block}:host([type=xl]) #text{font:var(--sinch-font-title-xl)}:host([type="l"]) #text{font:var(--sinch-font-title-l)}:host([type="m"]) #text{font:var(--sinch-font-title-m)}:host([type="s"]) #text{font:var(--sinch-font-title-s)}:host([type=xs]) #text{font:var(--sinch-font-title-xs)}:host([ellipsis]:not([ellipsis=false])) #text{display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}</style><span id="text"></span>';
|
|
13
4
|
import { assertLevel, assertType, typeValues } from './utils';
|
|
14
5
|
const template = document.createElement('template');
|
|
15
6
|
template.innerHTML = templateHTML;
|
|
16
|
-
defineCustomElement('sinch-title',
|
|
7
|
+
defineCustomElement('sinch-title', class extends NectaryElement {
|
|
8
|
+
#$text;
|
|
9
|
+
|
|
17
10
|
constructor() {
|
|
18
11
|
super();
|
|
19
|
-
|
|
20
|
-
_classPrivateFieldInitSpec(this, _$text, {
|
|
21
|
-
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
|
|
25
12
|
const shadowRoot = this.attachShadow();
|
|
26
13
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
27
|
-
|
|
28
|
-
_classPrivateFieldSet(this, _$text, shadowRoot.querySelector('#text'));
|
|
14
|
+
this.#$text = shadowRoot.querySelector('#text');
|
|
29
15
|
}
|
|
30
16
|
|
|
31
17
|
connectedCallback() {
|
|
@@ -64,7 +50,7 @@ defineCustomElement('sinch-title', (_$text = new WeakMap(), class extends Nectar
|
|
|
64
50
|
switch (name) {
|
|
65
51
|
case 'text':
|
|
66
52
|
{
|
|
67
|
-
|
|
53
|
+
this.#$text.textContent = newVal;
|
|
68
54
|
break;
|
|
69
55
|
}
|
|
70
56
|
|
|
@@ -83,4 +69,4 @@ defineCustomElement('sinch-title', (_$text = new WeakMap(), class extends Nectar
|
|
|
83
69
|
}
|
|
84
70
|
}
|
|
85
71
|
|
|
86
|
-
})
|
|
72
|
+
});
|
package/toast/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import '../icons/report-problem';
|
|
2
|
+
import '../icons/report';
|
|
3
|
+
import '../icons/check-circle';
|
|
4
|
+
import '../icons/info';
|
|
5
|
+
import '../title';
|
|
6
|
+
import '../text';
|
|
7
|
+
import type { TSinchToastElement, TSinchToastReact } from './types';
|
|
8
|
+
declare global {
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
'sinch-toast': TSinchToastReact;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
interface HTMLElementTagNameMap {
|
|
15
|
+
'sinch-toast': TSinchToastElement;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/toast/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import '../icons/report-problem';
|
|
2
|
+
import '../icons/report';
|
|
3
|
+
import '../icons/check-circle';
|
|
4
|
+
import '../icons/info';
|
|
5
|
+
import '../title';
|
|
6
|
+
import '../text';
|
|
7
|
+
import { defineCustomElement, getAttribute, getLiteralAttribute, updateAttribute, updateLiteralAttribute, NectaryElement, getReactEventHandler, getBooleanAttribute, updateBooleanAttribute } from '../utils';
|
|
8
|
+
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:row;align-items:center;gap:8px;width:328px;padding:8px 16px;box-sizing:border-box;border-radius:var(--sinch-shape-radius-l);box-shadow:var(--sinch-elevation-level-3)}#text{color:var(--sinch-color-stormy-500);padding:4px 0 4px 4px;flex:1;min-width:0}#icon-error,#icon-info,#icon-success,#icon-warn{display:none;align-self:flex-start;margin:4px 0}:host([type=success]) #wrapper{background-color:var(--sinch-color-success-200)}:host([type=warn]) #wrapper{background-color:var(--sinch-color-warning-200)}:host([type=error]) #wrapper{background-color:var(--sinch-color-error-200)}:host([type=info]) #wrapper{background-color:var(--sinch-color-informative-200)}:host([type=success]) #icon-success{display:block;--sinch-color-icon:var(--sinch-color-success-500)}:host([type=warn]) #icon-warn{display:block;--sinch-color-icon:var(--sinch-color-warning-500)}:host([type=error]) #icon-error{display:block;--sinch-color-icon:var(--sinch-color-error-500)}:host([type=info]) #icon-info{display:block;--sinch-color-icon:var(--sinch-color-informative-500)}</style><div id="wrapper"><sinch-icon-info id="icon-info"></sinch-icon-info><sinch-icon-check-circle id="icon-success"></sinch-icon-check-circle><sinch-icon-report-problem id="icon-warn"></sinch-icon-report-problem><sinch-icon-report id="icon-error"></sinch-icon-report><sinch-text id="text" type="m"></sinch-text><slot name="action"></slot><slot name="close"></slot></div>';
|
|
9
|
+
import { assertType, typeValues } from './utils';
|
|
10
|
+
const TIMEOUT = 5000;
|
|
11
|
+
const template = document.createElement('template');
|
|
12
|
+
template.innerHTML = templateHTML;
|
|
13
|
+
defineCustomElement('sinch-toast', class extends NectaryElement {
|
|
14
|
+
#$text;
|
|
15
|
+
#tid = null;
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
const shadowRoot = this.attachShadow();
|
|
20
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
21
|
+
this.#$text = shadowRoot.querySelector('#text');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
connectedCallback() {
|
|
25
|
+
this.setAttribute('aria-atomic', 'true');
|
|
26
|
+
this.setAttribute('aria-live', 'polite');
|
|
27
|
+
this.addEventListener('-timeout', this.#onTimeoutReactHandler);
|
|
28
|
+
this.#updateTimeout();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
disconnectedCallback() {
|
|
32
|
+
this.removeEventListener('-timeout', this.#onTimeoutReactHandler);
|
|
33
|
+
this.#clearTimeout();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get type() {
|
|
37
|
+
return getLiteralAttribute(this, typeValues, 'type');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
set type(value) {
|
|
41
|
+
updateLiteralAttribute(this, typeValues, 'type', value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get text() {
|
|
45
|
+
return getAttribute(this, 'text', '');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
set text(value) {
|
|
49
|
+
updateAttribute(this, 'text', value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get persistent() {
|
|
53
|
+
return getBooleanAttribute(this, 'persistent');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
set persistent(isPersistent) {
|
|
57
|
+
updateBooleanAttribute(this, 'persistent', isPersistent);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static get observedAttributes() {
|
|
61
|
+
return ['text', 'type', 'persistent'];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
65
|
+
if (oldVal === newVal) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
switch (name) {
|
|
70
|
+
case 'type':
|
|
71
|
+
{
|
|
72
|
+
assertType(newVal);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
case 'text':
|
|
77
|
+
{
|
|
78
|
+
this.#$text.textContent = newVal;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
case 'persistent':
|
|
83
|
+
{
|
|
84
|
+
this.#updateTimeout();
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#updateTimeout() {
|
|
91
|
+
if (this.persistent) {
|
|
92
|
+
this.#clearTimeout();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (this.#tid === null) {
|
|
97
|
+
this.#tid = window.setTimeout(this.#onTimeout, TIMEOUT);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#onTimeout = () => {
|
|
102
|
+
this.dispatchEvent(new CustomEvent('-timeout'));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
#clearTimeout() {
|
|
106
|
+
if (this.#tid !== null) {
|
|
107
|
+
window.clearTimeout(this.#tid);
|
|
108
|
+
this.#tid = null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#onTimeoutReactHandler = e => {
|
|
113
|
+
getReactEventHandler(this, 'on-timeout')?.(e);
|
|
114
|
+
};
|
|
115
|
+
});
|
package/toast/types.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
2
|
+
export declare type TSinchToastType = 'info' | 'warn' | 'error' | 'success';
|
|
3
|
+
export declare type TSinchToastElement = HTMLElement & {
|
|
4
|
+
/** Type */
|
|
5
|
+
type: TSinchToastType;
|
|
6
|
+
/** Text */
|
|
7
|
+
text: string;
|
|
8
|
+
/** Persistent, i.e. doesn't automatically dissapear after 5s */
|
|
9
|
+
persistent: boolean;
|
|
10
|
+
/** Timeout event */
|
|
11
|
+
addEventListener(type: '-timeout', listener: (e: CustomEvent<void>) => void): void;
|
|
12
|
+
/** Type */
|
|
13
|
+
setAttribute(name: 'type', value: TSinchToastType): void;
|
|
14
|
+
/** Text */
|
|
15
|
+
setAttribute(name: 'text', value: string): void;
|
|
16
|
+
/** Persistent, i.e. doesn't automatically dissapear after 5s */
|
|
17
|
+
setAttribute(name: 'persistent', value: ''): void;
|
|
18
|
+
};
|
|
19
|
+
export declare type TSinchToastReact = TSinchElementReact<TSinchToastElement> & {
|
|
20
|
+
/** Type */
|
|
21
|
+
type: TSinchToastType;
|
|
22
|
+
/** Text */
|
|
23
|
+
text: string;
|
|
24
|
+
/** Persistent, i.e. doesn't automatically dissapear after 5s */
|
|
25
|
+
persistent?: boolean;
|
|
26
|
+
/** Timeout handler */
|
|
27
|
+
'on-timeout'?: (e: CustomEvent<void>) => void;
|
|
28
|
+
};
|
package/toast/utils.d.ts
ADDED
package/toast/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import '../icons/report-problem';
|
|
2
|
+
import '../icons/report';
|
|
3
|
+
import '../icons/check-circle';
|
|
4
|
+
import '../icons/info';
|
|
5
|
+
import '../title';
|
|
6
|
+
import '../text';
|
|
7
|
+
import type { TSinchToastManagerElement, TSinchToastManagerReact } from './types';
|
|
8
|
+
declare global {
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
'sinch-toast-manager': TSinchToastManagerReact;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
interface HTMLElementTagNameMap {
|
|
15
|
+
'sinch-toast-manager': TSinchToastManagerElement;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import '../icons/report-problem';
|
|
2
|
+
import '../icons/report';
|
|
3
|
+
import '../icons/check-circle';
|
|
4
|
+
import '../icons/info';
|
|
5
|
+
import '../title';
|
|
6
|
+
import '../text';
|
|
7
|
+
import { cloneNode, defineCustomElement, getRect, NectaryElement } from '../utils';
|
|
8
|
+
const templateHTML = '<style>:host{display:block}#items{display:block;width:0;height:0;visibility:hidden;overflow:hidden}#list{display:flex;flex-direction:column;position:fixed;bottom:0;right:16px}.item-wrapper{height:0;opacity:0;position:relative}.item-wrapper[data-deleting]::after{content:"";position:absolute;top:0;left:0;bottom:0;right:0}</style><slot id="items"></slot><div id="list"></div>';
|
|
9
|
+
const DURATION_ADD = 250;
|
|
10
|
+
const DURATION_REMOVE = 250;
|
|
11
|
+
const ITEMS_GAP = 16;
|
|
12
|
+
const template = document.createElement('template');
|
|
13
|
+
template.innerHTML = templateHTML;
|
|
14
|
+
defineCustomElement('sinch-toast-manager', class extends NectaryElement {
|
|
15
|
+
#$slot;
|
|
16
|
+
#$list;
|
|
17
|
+
#map = new WeakMap();
|
|
18
|
+
#shouldReduceMotion = false;
|
|
19
|
+
#animations = new Set();
|
|
20
|
+
|
|
21
|
+
constructor() {
|
|
22
|
+
super();
|
|
23
|
+
const shadowRoot = this.attachShadow();
|
|
24
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
25
|
+
this.#$slot = shadowRoot.querySelector('slot');
|
|
26
|
+
this.#$list = shadowRoot.querySelector('#list');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
this.#$slot.addEventListener('slotchange', this.#onSlotChange);
|
|
31
|
+
this.#shouldReduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
disconnectedCallback() {
|
|
35
|
+
this.#$slot.removeEventListener('slotchange', this.#onSlotChange);
|
|
36
|
+
this.#clear();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get containerRect() {
|
|
40
|
+
return getRect(this.#$list);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
nthActionRect(nth) {
|
|
44
|
+
const item = this.#$list.children[nth]?.querySelector('[slot=action]');
|
|
45
|
+
return item != null ? getRect(item) : null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
nthCloseRect(nth) {
|
|
49
|
+
const item = this.#$list.children[nth]?.querySelector('[slot=close]');
|
|
50
|
+
return item != null ? getRect(item) : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#onAnimateAdd(item, index, height) {
|
|
54
|
+
const duration = this.#shouldReduceMotion ? 0 : DURATION_ADD;
|
|
55
|
+
const addAnim = item.animate({
|
|
56
|
+
height: ['0', `${height + ITEMS_GAP}px`],
|
|
57
|
+
opacity: [0, 1]
|
|
58
|
+
}, {
|
|
59
|
+
delay: index * duration,
|
|
60
|
+
duration,
|
|
61
|
+
iterations: 1,
|
|
62
|
+
fill: 'forwards'
|
|
63
|
+
});
|
|
64
|
+
this.#storeAnimation(addAnim);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#onAnimateRemove(item, index) {
|
|
68
|
+
const rect = item.getBoundingClientRect();
|
|
69
|
+
const duration = this.#shouldReduceMotion ? 0 : DURATION_REMOVE;
|
|
70
|
+
const indexInQueue = item.hasAttribute('data-delete-now') ? 0 : index;
|
|
71
|
+
const heightAnim = item.animate({
|
|
72
|
+
height: [`${rect.height}px`, '0']
|
|
73
|
+
}, {
|
|
74
|
+
delay: duration + indexInQueue * duration,
|
|
75
|
+
duration,
|
|
76
|
+
iterations: 1,
|
|
77
|
+
fill: 'forwards'
|
|
78
|
+
});
|
|
79
|
+
const opacityAnim = item.animate({
|
|
80
|
+
opacity: [1, 0]
|
|
81
|
+
}, {
|
|
82
|
+
delay: indexInQueue * duration,
|
|
83
|
+
duration,
|
|
84
|
+
iterations: 1,
|
|
85
|
+
fill: 'forwards'
|
|
86
|
+
});
|
|
87
|
+
item.setAttribute('data-deleting', '');
|
|
88
|
+
this.#storeAnimation(heightAnim, () => item.remove());
|
|
89
|
+
this.#storeAnimation(opacityAnim);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#onSlotChange = () => {
|
|
93
|
+
const slotItems = this.#$slot.assignedElements();
|
|
94
|
+
const listItems = Array.from(this.#$list.children);
|
|
95
|
+
let removeIndex = 0;
|
|
96
|
+
|
|
97
|
+
for (const item of listItems) {
|
|
98
|
+
if (item.hasAttribute('data-deleting')) {
|
|
99
|
+
++removeIndex;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const orig = this.#map.get(item);
|
|
104
|
+
|
|
105
|
+
if (orig != null && slotItems.includes(orig)) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.#map.delete(item);
|
|
110
|
+
|
|
111
|
+
if (orig != null) {
|
|
112
|
+
this.#map.delete(orig);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.#unsubscribeChildren(item);
|
|
116
|
+
this.#onAnimateRemove(item, removeIndex);
|
|
117
|
+
++removeIndex;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let addIndex = 0;
|
|
121
|
+
|
|
122
|
+
for (const item of slotItems) {
|
|
123
|
+
if (this.#map.has(item)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const cloned = cloneNode(item, true);
|
|
128
|
+
const rect = item.getBoundingClientRect();
|
|
129
|
+
const wrapper = document.createElement('div');
|
|
130
|
+
wrapper.className = 'item-wrapper';
|
|
131
|
+
wrapper.appendChild(cloned);
|
|
132
|
+
this.#$list.appendChild(wrapper);
|
|
133
|
+
this.#map.set(item, wrapper);
|
|
134
|
+
this.#map.set(wrapper, item);
|
|
135
|
+
this.#subscribeChildren(cloned);
|
|
136
|
+
this.#onAnimateAdd(wrapper, addIndex, rect.height);
|
|
137
|
+
addIndex++;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
#storeAnimation(anim, cb) {
|
|
142
|
+
const onAnimEnd = () => {
|
|
143
|
+
this.#animations.delete(anim);
|
|
144
|
+
cb?.();
|
|
145
|
+
anim.removeEventListener('finish', onAnimEnd);
|
|
146
|
+
anim.removeEventListener('remove', onAnimEnd);
|
|
147
|
+
anim.removeEventListener('cancel', onAnimEnd);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
anim.addEventListener('finish', onAnimEnd);
|
|
151
|
+
anim.addEventListener('remove', onAnimEnd);
|
|
152
|
+
anim.addEventListener('cancel', onAnimEnd);
|
|
153
|
+
this.#animations.add(anim);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#clear() {
|
|
157
|
+
const listItems = Array.from(this.#$list.children);
|
|
158
|
+
|
|
159
|
+
for (const item of listItems) {
|
|
160
|
+
this.#map.delete(item);
|
|
161
|
+
this.#unsubscribeChildren(item);
|
|
162
|
+
item.remove();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (const anim of this.#animations) {
|
|
166
|
+
anim.cancel();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
#subscribeChildren(item) {
|
|
171
|
+
item.querySelector('[slot=close]')?.addEventListener('-click', this.#onCloneCloseClick);
|
|
172
|
+
item.querySelector('[slot=action]')?.addEventListener('-click', this.#onCloneActionClick);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#unsubscribeChildren(item) {
|
|
176
|
+
item.querySelector('[slot=close]')?.removeEventListener('-click', this.#onCloneCloseClick);
|
|
177
|
+
item.querySelector('[slot=action]')?.removeEventListener('-click', this.#onCloneActionClick);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#onCloneCloseClick = e => {
|
|
181
|
+
const item = e.target.parentElement?.parentElement;
|
|
182
|
+
|
|
183
|
+
if (item != null) {
|
|
184
|
+
item.setAttribute('data-delete-now', '');
|
|
185
|
+
this.#map.get(item)?.querySelector('[slot=close]')?.dispatchEvent(new CustomEvent('-click'));
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
#onCloneActionClick = e => {
|
|
189
|
+
const item = e.target.parentElement?.parentElement;
|
|
190
|
+
|
|
191
|
+
if (item != null) {
|
|
192
|
+
this.#map.get(item)?.querySelector('[slot=action]')?.dispatchEvent(new CustomEvent('-click'));
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TRect, TSinchElementReact } from '../types';
|
|
2
|
+
export declare type TSinchToastManagerElement = HTMLElement & {
|
|
3
|
+
readonly containerRect: TRect;
|
|
4
|
+
nthActionRect: (nth: number) => TRect | null;
|
|
5
|
+
nthCloseRect: (nth: number) => TRect | null;
|
|
6
|
+
};
|
|
7
|
+
export declare type TSinchToastManagerReact = TSinchElementReact<TSinchToastManagerElement> & {};
|