@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/popover/index.js
CHANGED
|
@@ -1,234 +1,77 @@
|
|
|
1
|
-
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
-
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
-
|
|
4
|
-
var _$target, _$dialog, _isConnected, _resizeThrottle, _originalOverflowValue, _$targetSlot, _$targetOpenSlot, _$targetOpenWrapper, _targetActiveElement, _onExpand, _onCollapse, _isOpen, _onResize, _updateOrientation, _onBackdropMouseDown, _onCancel, _onCloseReactHandler, _dispatchCloseEvent, _captureActiveElement, _stopPropagation;
|
|
5
|
-
|
|
6
|
-
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
7
|
-
|
|
8
|
-
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
9
|
-
|
|
10
|
-
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
11
|
-
|
|
12
|
-
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
13
|
-
|
|
14
1
|
import dialogPolyfill from 'dialog-polyfill';
|
|
15
|
-
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, updateLiteralAttribute, getReactEventHandler, updateBooleanAttribute, NectaryElement, throttleAnimationFrame } from '../utils';
|
|
16
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative}dialog{position:fixed;top:0;left:0;margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:1;background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}dialog+.backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background-color:transparent}dialog.fixed{position:fixed;top:50%;transform:translate(0,-50%)}._dialog_overlay{position:fixed;top:0;right:0;bottom:0;left:0}#target{display:flex;flex-direction:column}#content{position:relative;font:var(--sinch-font-body);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-100);box-shadow:var(--sinch-elevation-level-2);border:1px solid var(--sinch-color-snow-500);border-radius:var(--sinch-
|
|
2
|
+
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, updateLiteralAttribute, getReactEventHandler, updateBooleanAttribute, NectaryElement, throttleAnimationFrame, Context, getFirstSlotElement, isElementFocused } from '../utils';
|
|
3
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative}dialog{position:fixed;top:0;left:0;margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:1;background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}dialog+.backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background-color:transparent}dialog.fixed{position:fixed;top:50%;transform:translate(0,-50%)}._dialog_overlay{position:fixed;top:0;right:0;bottom:0;left:0}#target{display:flex;flex-direction:column}#content{position:relative;font:var(--sinch-font-body);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-100);box-shadow:var(--sinch-elevation-level-2);border:1px solid var(--sinch-color-snow-500);border-radius:var(--sinch-shape-radius-m);outline:0;overflow:hidden}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}</style><div id="wrapper"><div id="target" aria-haspopup="dialog" aria-expanded="false"><slot name="target"></slot></div><dialog id="dialog"><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog></div>';
|
|
17
4
|
import { orientationValues } from './utils';
|
|
18
5
|
const template = document.createElement('template');
|
|
19
6
|
template.innerHTML = templateHTML;
|
|
20
7
|
const POPOVER_OFFSET = 4;
|
|
21
|
-
defineCustomElement('sinch-popover',
|
|
8
|
+
defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
9
|
+
#$target;
|
|
10
|
+
#$dialog;
|
|
11
|
+
#isConnected;
|
|
12
|
+
#resizeThrottle;
|
|
13
|
+
#originalOverflowValue = '';
|
|
14
|
+
#$targetSlot;
|
|
15
|
+
#$targetOpenSlot;
|
|
16
|
+
#$contentSlot;
|
|
17
|
+
#$targetOpenWrapper;
|
|
18
|
+
#targetActiveElement = null;
|
|
19
|
+
#controller = new AbortController();
|
|
20
|
+
#keydownContext;
|
|
21
|
+
#visibilityContext;
|
|
22
|
+
|
|
22
23
|
constructor() {
|
|
23
24
|
super();
|
|
24
|
-
|
|
25
|
-
_classPrivateMethodInitSpec(this, _dispatchCloseEvent);
|
|
26
|
-
|
|
27
|
-
_classPrivateMethodInitSpec(this, _isOpen);
|
|
28
|
-
|
|
29
|
-
_classPrivateMethodInitSpec(this, _onCollapse);
|
|
30
|
-
|
|
31
|
-
_classPrivateMethodInitSpec(this, _onExpand);
|
|
32
|
-
|
|
33
|
-
_classPrivateFieldInitSpec(this, _$target, {
|
|
34
|
-
writable: true,
|
|
35
|
-
value: void 0
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
_classPrivateFieldInitSpec(this, _$dialog, {
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
_classPrivateFieldInitSpec(this, _isConnected, {
|
|
44
|
-
writable: true,
|
|
45
|
-
value: void 0
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
_classPrivateFieldInitSpec(this, _resizeThrottle, {
|
|
49
|
-
writable: true,
|
|
50
|
-
value: void 0
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
_classPrivateFieldInitSpec(this, _originalOverflowValue, {
|
|
54
|
-
writable: true,
|
|
55
|
-
value: ''
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
_classPrivateFieldInitSpec(this, _$targetSlot, {
|
|
59
|
-
writable: true,
|
|
60
|
-
value: void 0
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
_classPrivateFieldInitSpec(this, _$targetOpenSlot, {
|
|
64
|
-
writable: true,
|
|
65
|
-
value: void 0
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
_classPrivateFieldInitSpec(this, _$targetOpenWrapper, {
|
|
69
|
-
writable: true,
|
|
70
|
-
value: void 0
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
_classPrivateFieldInitSpec(this, _targetActiveElement, {
|
|
74
|
-
writable: true,
|
|
75
|
-
value: null
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
_classPrivateFieldInitSpec(this, _onResize, {
|
|
79
|
-
writable: true,
|
|
80
|
-
value: () => {
|
|
81
|
-
_classPrivateFieldGet(this, _resizeThrottle).fn();
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
_classPrivateFieldInitSpec(this, _updateOrientation, {
|
|
86
|
-
writable: true,
|
|
87
|
-
value: () => {
|
|
88
|
-
_classPrivateFieldGet(this, _$dialog).style.width = 'max-content';
|
|
89
|
-
|
|
90
|
-
const targetRect = _classPrivateFieldGet(this, _$target).getBoundingClientRect();
|
|
91
|
-
|
|
92
|
-
const modalRect = _classPrivateFieldGet(this, _$dialog).getBoundingClientRect();
|
|
93
|
-
|
|
94
|
-
let leftPos = 0;
|
|
95
|
-
let topPos = 0;
|
|
96
|
-
const orient = this.orientation;
|
|
97
|
-
const shouldExpandWidthToTarget = orient === 'top' || orient === 'bottom';
|
|
98
|
-
const resultWidth = shouldExpandWidthToTarget ? Math.max(modalRect.width, targetRect.width) : modalRect.width;
|
|
99
|
-
|
|
100
|
-
if (orient === 'bottom-right' || orient === 'top-right' || orient === 'top' || orient === 'bottom') {
|
|
101
|
-
leftPos = Math.max(POPOVER_OFFSET, Math.min(targetRect.x, window.innerWidth - resultWidth - POPOVER_OFFSET));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (orient === 'bottom-left' || orient === 'top-left') {
|
|
105
|
-
leftPos = Math.max(POPOVER_OFFSET, targetRect.right - resultWidth);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (orient === 'bottom-left' || orient === 'bottom-right' || orient === 'bottom') {
|
|
109
|
-
topPos = Math.max(POPOVER_OFFSET, Math.min(targetRect.bottom + POPOVER_OFFSET, window.innerHeight - modalRect.height - POPOVER_OFFSET));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (orient === 'top-left' || orient === 'top-right' || orient === 'top') {
|
|
113
|
-
topPos = Math.max(POPOVER_OFFSET, targetRect.top - POPOVER_OFFSET - modalRect.height);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
_classPrivateFieldGet(this, _$dialog).style.left = `${leftPos}px`;
|
|
117
|
-
_classPrivateFieldGet(this, _$dialog).style.top = `${topPos}px`;
|
|
118
|
-
_classPrivateFieldGet(this, _$dialog).style.width = `${resultWidth}px`;
|
|
119
|
-
|
|
120
|
-
if (!this.modal) {
|
|
121
|
-
const targetLeftPos = targetRect.left - leftPos;
|
|
122
|
-
const targetTopPos = targetRect.top - topPos;
|
|
123
|
-
_classPrivateFieldGet(this, _$targetOpenWrapper).style.left = `${targetLeftPos}px`;
|
|
124
|
-
_classPrivateFieldGet(this, _$targetOpenWrapper).style.top = `${targetTopPos}px`;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
_classPrivateFieldInitSpec(this, _onBackdropMouseDown, {
|
|
130
|
-
writable: true,
|
|
131
|
-
value: e => {
|
|
132
|
-
if (e.target !== _classPrivateFieldGet(this, _$dialog)) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const rect = this.popoverRect;
|
|
137
|
-
const isInside = e.x >= rect.x && e.x < rect.x + rect.width && e.y >= rect.y && e.y < rect.y + rect.height;
|
|
138
|
-
|
|
139
|
-
if (!isInside) {
|
|
140
|
-
_classPrivateMethodGet(this, _dispatchCloseEvent, _dispatchCloseEvent2).call(this);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
_classPrivateFieldInitSpec(this, _onCancel, {
|
|
146
|
-
writable: true,
|
|
147
|
-
value: e => {
|
|
148
|
-
e.preventDefault();
|
|
149
|
-
|
|
150
|
-
_classPrivateMethodGet(this, _dispatchCloseEvent, _dispatchCloseEvent2).call(this);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
_classPrivateFieldInitSpec(this, _onCloseReactHandler, {
|
|
155
|
-
writable: true,
|
|
156
|
-
value: e => {
|
|
157
|
-
getReactEventHandler(this, 'onClose')?.();
|
|
158
|
-
getReactEventHandler(this, 'on-close')?.(e);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
_classPrivateFieldInitSpec(this, _captureActiveElement, {
|
|
163
|
-
writable: true,
|
|
164
|
-
value: e => {
|
|
165
|
-
e.stopPropagation();
|
|
166
|
-
|
|
167
|
-
_classPrivateFieldSet(this, _targetActiveElement, e.target);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
_classPrivateFieldInitSpec(this, _stopPropagation, {
|
|
172
|
-
writable: true,
|
|
173
|
-
value: e => {
|
|
174
|
-
e.stopPropagation();
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
|
|
178
25
|
const shadowRoot = this.attachShadow();
|
|
179
26
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
_classPrivateFieldSet(this, _isConnected, false);
|
|
192
|
-
|
|
193
|
-
_classPrivateFieldSet(this, _resizeThrottle, throttleAnimationFrame(_classPrivateFieldGet(this, _updateOrientation)));
|
|
194
|
-
|
|
195
|
-
dialogPolyfill.registerDialog(_classPrivateFieldGet(this, _$dialog));
|
|
27
|
+
this.#$target = shadowRoot.querySelector('#target');
|
|
28
|
+
this.#$dialog = shadowRoot.querySelector('#dialog');
|
|
29
|
+
this.#$targetSlot = shadowRoot.querySelector('slot[name="target"]');
|
|
30
|
+
this.#$targetOpenSlot = shadowRoot.querySelector('slot[name="target-open"]');
|
|
31
|
+
this.#$contentSlot = shadowRoot.querySelector('slot[name="content"]');
|
|
32
|
+
this.#$targetOpenWrapper = shadowRoot.querySelector('#target-open');
|
|
33
|
+
this.#isConnected = false;
|
|
34
|
+
this.#resizeThrottle = throttleAnimationFrame(this.#updateOrientation);
|
|
35
|
+
this.#keydownContext = new Context(this.#$contentSlot, 'keydown');
|
|
36
|
+
this.#visibilityContext = new Context(this.#$contentSlot, 'visibility');
|
|
37
|
+
dialogPolyfill.registerDialog(this.#$dialog);
|
|
196
38
|
|
|
197
39
|
dialogPolyfill.dm.handleFocus_ = function () {};
|
|
198
40
|
}
|
|
199
41
|
|
|
200
42
|
connectedCallback() {
|
|
43
|
+
const {
|
|
44
|
+
signal
|
|
45
|
+
} = this.#controller;
|
|
201
46
|
this.setAttribute('role', 'dialog');
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
47
|
+
this.#$dialog.addEventListener('cancel', this.#onCancel, {
|
|
48
|
+
signal
|
|
49
|
+
});
|
|
50
|
+
this.#$dialog.addEventListener('mousedown', this.#onBackdropMouseDown, {
|
|
51
|
+
signal
|
|
52
|
+
});
|
|
53
|
+
this.addEventListener('-close', this.#onCloseReactHandler, {
|
|
54
|
+
signal
|
|
55
|
+
});
|
|
56
|
+
this.#isConnected = true;
|
|
57
|
+
this.#keydownContext.subscribe();
|
|
58
|
+
this.#visibilityContext.subscribe();
|
|
210
59
|
|
|
211
60
|
if (getBooleanAttribute(this, 'open')) {
|
|
212
|
-
|
|
213
|
-
} else {
|
|
214
|
-
_classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
|
|
61
|
+
this.#onExpand();
|
|
215
62
|
}
|
|
216
63
|
}
|
|
217
64
|
|
|
218
65
|
disconnectedCallback() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.
|
|
224
|
-
|
|
225
|
-
_classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
|
|
226
|
-
|
|
227
|
-
_classPrivateFieldSet(this, _isConnected, false);
|
|
66
|
+
this.#controller.abort();
|
|
67
|
+
this.#onCollapse();
|
|
68
|
+
this.#isConnected = false;
|
|
69
|
+
this.#keydownContext.unsubscribe();
|
|
70
|
+
this.#visibilityContext.unsubscribe();
|
|
228
71
|
}
|
|
229
72
|
|
|
230
73
|
static get observedAttributes() {
|
|
231
|
-
return ['
|
|
74
|
+
return ['orientation', 'open'];
|
|
232
75
|
}
|
|
233
76
|
|
|
234
77
|
set modal(isModal) {
|
|
@@ -248,7 +91,7 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
|
|
|
248
91
|
}
|
|
249
92
|
|
|
250
93
|
get orientation() {
|
|
251
|
-
return getLiteralAttribute(this, orientationValues, 'orientation', 'bottom');
|
|
94
|
+
return getLiteralAttribute(this, orientationValues, 'orientation', 'bottom-left');
|
|
252
95
|
}
|
|
253
96
|
|
|
254
97
|
set orientation(value) {
|
|
@@ -256,7 +99,7 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
|
|
|
256
99
|
}
|
|
257
100
|
|
|
258
101
|
get popoverRect() {
|
|
259
|
-
return getRect(
|
|
102
|
+
return getRect(this.#$dialog);
|
|
260
103
|
}
|
|
261
104
|
|
|
262
105
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
@@ -268,9 +111,11 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
|
|
|
268
111
|
case 'open':
|
|
269
112
|
{
|
|
270
113
|
if (isAttrTrue(newVal)) {
|
|
271
|
-
|
|
114
|
+
requestAnimationFrame(() => {
|
|
115
|
+
this.#onExpand();
|
|
116
|
+
});
|
|
272
117
|
} else {
|
|
273
|
-
|
|
118
|
+
this.#onCollapse();
|
|
274
119
|
}
|
|
275
120
|
|
|
276
121
|
updateBooleanAttribute(this, 'open', isAttrTrue(newVal));
|
|
@@ -279,115 +124,200 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
|
|
|
279
124
|
|
|
280
125
|
case 'orientation':
|
|
281
126
|
{
|
|
282
|
-
if (
|
|
283
|
-
|
|
127
|
+
if (this.#isOpen()) {
|
|
128
|
+
this.#updateOrientation();
|
|
284
129
|
}
|
|
285
130
|
|
|
286
131
|
break;
|
|
287
132
|
}
|
|
288
|
-
|
|
289
|
-
case 'modal':
|
|
290
|
-
{
|
|
291
|
-
if (_classPrivateMethodGet(this, _isOpen, _isOpen2).call(this)) {
|
|
292
|
-
_classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
|
|
293
|
-
|
|
294
|
-
_classPrivateMethodGet(this, _onExpand, _onExpand2).call(this);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
133
|
}
|
|
298
134
|
}
|
|
299
135
|
|
|
300
|
-
|
|
136
|
+
#onExpand() {
|
|
137
|
+
if (!this.#isConnected || this.#isOpen()) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
301
140
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
141
|
+
const isNonModal = !this.modal;
|
|
142
|
+
this.#$targetSlot.addEventListener('blur', this.#captureActiveElement, true);
|
|
143
|
+
|
|
144
|
+
if (isNonModal) {
|
|
145
|
+
this.#$targetOpenSlot.addEventListener('blur', this.#captureActiveElement, true);
|
|
146
|
+
this.#$targetOpenSlot.addEventListener('focus', this.#stopPropagation, true);
|
|
147
|
+
const targetRect = this.#$target.getBoundingClientRect();
|
|
148
|
+
const widthPx = `${targetRect.width}px`;
|
|
149
|
+
const heightPx = `${targetRect.height}px`;
|
|
150
|
+
this.#$target.style.width = widthPx;
|
|
151
|
+
this.#$target.style.height = heightPx;
|
|
152
|
+
this.#$targetOpenWrapper.style.width = widthPx;
|
|
153
|
+
this.#$targetOpenWrapper.style.height = heightPx;
|
|
154
|
+
getFirstSlotElement(this.#$targetSlot)?.setAttribute('slot', 'target-open');
|
|
155
|
+
this.#$targetOpenSlot.addEventListener('keydown', this.#onTargetKeydown);
|
|
156
|
+
}
|
|
306
157
|
|
|
307
|
-
|
|
158
|
+
this.#$dialog.showModal();
|
|
159
|
+
this.#updateOrientation();
|
|
160
|
+
this.#$target.setAttribute('aria-expanded', 'true');
|
|
161
|
+
this.#$targetSlot.removeEventListener('blur', this.#captureActiveElement, true);
|
|
162
|
+
|
|
163
|
+
if (isNonModal) {
|
|
164
|
+
this.#$targetOpenSlot.removeEventListener('blur', this.#captureActiveElement, true);
|
|
165
|
+
this.#$targetOpenSlot.removeEventListener('focus', this.#stopPropagation, true);
|
|
166
|
+
|
|
167
|
+
if (this.#targetActiveElement !== null) {
|
|
168
|
+
if (!isElementFocused(this.#targetActiveElement)) {
|
|
169
|
+
requestAnimationFrame(() => {
|
|
170
|
+
this.#$targetOpenSlot.addEventListener('focus', this.#stopPropagation, true);
|
|
171
|
+
this.#targetActiveElement?.focus();
|
|
172
|
+
this.#$targetOpenSlot.removeEventListener('focus', this.#stopPropagation, true);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
if (document.activeElement === document.body) {
|
|
178
|
+
getFirstSlotElement(this.#$contentSlot)?.focus();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
308
181
|
|
|
309
|
-
|
|
182
|
+
this.#originalOverflowValue = document.body.style.overflow;
|
|
183
|
+
document.body.style.overflow = 'hidden';
|
|
184
|
+
window.addEventListener('resize', this.#onResize);
|
|
185
|
+
this.#dispatchContentVisibility(true);
|
|
186
|
+
}
|
|
310
187
|
|
|
311
|
-
|
|
312
|
-
|
|
188
|
+
#onCollapse() {
|
|
189
|
+
if (!this.#isOpen()) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
313
192
|
|
|
314
|
-
|
|
193
|
+
this.#dispatchContentVisibility(false);
|
|
194
|
+
this.#$targetSlot.addEventListener('focus', this.#stopPropagation, true);
|
|
195
|
+
getFirstSlotElement(this.#$targetOpenSlot)?.setAttribute('slot', 'target');
|
|
196
|
+
this.#$target.style.width = 'unset';
|
|
197
|
+
this.#$target.style.height = 'unset';
|
|
198
|
+
this.#$dialog.close();
|
|
199
|
+
this.#$target.setAttribute('aria-expanded', 'false');
|
|
200
|
+
|
|
201
|
+
if (this.#targetActiveElement !== null) {
|
|
202
|
+
if (!isElementFocused(this.#targetActiveElement)) {
|
|
203
|
+
requestAnimationFrame(() => {
|
|
204
|
+
this.#$targetSlot.addEventListener('focus', this.#stopPropagation, true);
|
|
205
|
+
this.#targetActiveElement.focus();
|
|
206
|
+
this.#targetActiveElement = null;
|
|
207
|
+
this.#$targetSlot.removeEventListener('focus', this.#stopPropagation, true);
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
this.#targetActiveElement = null;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
315
213
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
_classPrivateFieldGet(this, _$targetOpenWrapper).style.height = heightPx;
|
|
322
|
-
_classPrivateFieldGet(this, _$targetSlot).assignedElements()[0]?.setAttribute('slot', 'target-open');
|
|
214
|
+
this.#$targetSlot.removeEventListener('focus', this.#stopPropagation, true);
|
|
215
|
+
this.#$targetOpenSlot.removeEventListener('keydown', this.#onTargetKeydown);
|
|
216
|
+
document.body.style.overflow = this.#originalOverflowValue;
|
|
217
|
+
this.#resizeThrottle.cancel();
|
|
218
|
+
window.removeEventListener('resize', this.#onResize);
|
|
323
219
|
}
|
|
324
220
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
221
|
+
#isOpen() {
|
|
222
|
+
return getBooleanAttribute(this.#$dialog, 'open');
|
|
223
|
+
}
|
|
328
224
|
|
|
329
|
-
|
|
225
|
+
#onResize = () => {
|
|
226
|
+
this.#resizeThrottle.fn();
|
|
227
|
+
};
|
|
228
|
+
#updateOrientation = () => {
|
|
229
|
+
this.#$dialog.style.width = 'max-content';
|
|
230
|
+
const targetRect = this.#$target.getBoundingClientRect();
|
|
231
|
+
const modalRect = this.#$dialog.getBoundingClientRect();
|
|
232
|
+
let leftPos = 0;
|
|
233
|
+
let topPos = 0;
|
|
234
|
+
const orient = this.orientation;
|
|
235
|
+
const shouldSetWidthToTarget = orient === 'top' || orient === 'bottom';
|
|
236
|
+
const resultWidth = shouldSetWidthToTarget ? targetRect.width : modalRect.width;
|
|
237
|
+
|
|
238
|
+
if (orient === 'bottom-right' || orient === 'top-right' || orient === 'top' || orient === 'bottom') {
|
|
239
|
+
leftPos = Math.max(POPOVER_OFFSET, Math.min(targetRect.x, window.innerWidth - resultWidth - POPOVER_OFFSET));
|
|
240
|
+
}
|
|
330
241
|
|
|
331
|
-
|
|
242
|
+
if (orient === 'bottom-left' || orient === 'top-left') {
|
|
243
|
+
leftPos = Math.max(POPOVER_OFFSET, targetRect.right - resultWidth);
|
|
244
|
+
}
|
|
332
245
|
|
|
333
|
-
|
|
334
|
-
|
|
246
|
+
if (orient === 'bottom-left' || orient === 'bottom-right' || orient === 'bottom') {
|
|
247
|
+
topPos = Math.max(POPOVER_OFFSET, Math.min(targetRect.bottom + POPOVER_OFFSET, window.innerHeight - modalRect.height - POPOVER_OFFSET));
|
|
248
|
+
}
|
|
335
249
|
|
|
336
|
-
if (
|
|
337
|
-
|
|
338
|
-
|
|
250
|
+
if (orient === 'top-left' || orient === 'top-right' || orient === 'top') {
|
|
251
|
+
topPos = Math.max(POPOVER_OFFSET, targetRect.top - POPOVER_OFFSET - modalRect.height);
|
|
252
|
+
}
|
|
339
253
|
|
|
340
|
-
|
|
254
|
+
this.#$dialog.style.left = `${leftPos}px`;
|
|
255
|
+
this.#$dialog.style.top = `${topPos}px`;
|
|
256
|
+
this.#$dialog.style.width = `${resultWidth}px`;
|
|
341
257
|
|
|
342
|
-
|
|
343
|
-
|
|
258
|
+
if (!this.modal) {
|
|
259
|
+
const targetLeftPos = targetRect.left - leftPos;
|
|
260
|
+
const targetTopPos = targetRect.top - topPos;
|
|
261
|
+
this.#$targetOpenWrapper.style.left = `${targetLeftPos}px`;
|
|
262
|
+
this.#$targetOpenWrapper.style.top = `${targetTopPos}px`;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
#onBackdropMouseDown = e => {
|
|
266
|
+
if (e.target !== this.#$dialog) {
|
|
267
|
+
return;
|
|
344
268
|
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
_classPrivateFieldSet(this, _originalOverflowValue, document.body.style.overflow);
|
|
348
269
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
270
|
+
const rect = this.popoverRect;
|
|
271
|
+
const isInside = e.x >= rect.x && e.x < rect.x + rect.width && e.y >= rect.y && e.y < rect.y + rect.height;
|
|
352
272
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
273
|
+
if (!isInside) {
|
|
274
|
+
this.#dispatchCloseEvent();
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
#onCancel = e => {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
this.#dispatchCloseEvent();
|
|
280
|
+
};
|
|
281
|
+
#onCloseReactHandler = e => {
|
|
282
|
+
getReactEventHandler(this, 'onClose')?.();
|
|
283
|
+
getReactEventHandler(this, 'on-close')?.(e);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
#dispatchCloseEvent() {
|
|
287
|
+
this.dispatchEvent(new CustomEvent('-close'));
|
|
356
288
|
}
|
|
357
289
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
290
|
+
#captureActiveElement = e => {
|
|
291
|
+
e.stopPropagation();
|
|
292
|
+
this.#targetActiveElement = e.target;
|
|
293
|
+
};
|
|
294
|
+
#stopPropagation = e => {
|
|
295
|
+
e.stopPropagation();
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
#dispatchContentVisibility(isVisible) {
|
|
299
|
+
for (const $el of this.#visibilityContext.elements) {
|
|
300
|
+
$el.dispatchEvent(new CustomEvent('-visibility', {
|
|
301
|
+
detail: isVisible
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
368
304
|
}
|
|
369
305
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
_classPrivateFieldGet(this, _resizeThrottle).cancel();
|
|
383
|
-
|
|
384
|
-
window.removeEventListener('resize', _classPrivateFieldGet(this, _onResize));
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function _isOpen2() {
|
|
388
|
-
return getBooleanAttribute(_classPrivateFieldGet(this, _$dialog), 'open');
|
|
389
|
-
}
|
|
306
|
+
#onTargetKeydown = e => {
|
|
307
|
+
for (const $el of this.#keydownContext.elements) {
|
|
308
|
+
let isPrevented = false;
|
|
309
|
+
$el.dispatchEvent(new CustomEvent('-keydown', {
|
|
310
|
+
detail: {
|
|
311
|
+
code: e.code,
|
|
312
|
+
preventDefault: () => {
|
|
313
|
+
isPrevented = true;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}));
|
|
390
317
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
318
|
+
if (isPrevented) {
|
|
319
|
+
e.preventDefault();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
});
|
package/progress/index.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
-
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
-
|
|
4
|
-
var _$bar, _$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 '../spinner';
|
|
11
2
|
import '../icons/check-circle';
|
|
12
3
|
import '../icons/report';
|
|
@@ -17,26 +8,16 @@ import { defineCustomElement, updateAttribute, NectaryElement, updateBooleanAttr
|
|
|
17
8
|
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;align-items:center;height:24px}#bar,#progress{height:8px;border-radius:4px}#progress{background-color:var(--sinch-color-tropical-100);flex:1;min-width:0}#bar{background-color:var(--sinch-color-tropical-500);width:0}#text{display:none;width:46px}:host([detailed]:not([detailed=false])) #text{display:block}</style><div id="wrapper"><sinch-text id="text" type="m"></sinch-text><div id="progress"><div id="bar"></div></div></div>';
|
|
18
9
|
const template = document.createElement('template');
|
|
19
10
|
template.innerHTML = templateHTML;
|
|
20
|
-
defineCustomElement('sinch-progress',
|
|
11
|
+
defineCustomElement('sinch-progress', class extends NectaryElement {
|
|
12
|
+
#$bar;
|
|
13
|
+
#$text;
|
|
14
|
+
|
|
21
15
|
constructor() {
|
|
22
16
|
super();
|
|
23
|
-
|
|
24
|
-
_classPrivateFieldInitSpec(this, _$bar, {
|
|
25
|
-
writable: true,
|
|
26
|
-
value: void 0
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
_classPrivateFieldInitSpec(this, _$text, {
|
|
30
|
-
writable: true,
|
|
31
|
-
value: void 0
|
|
32
|
-
});
|
|
33
|
-
|
|
34
17
|
const shadowRoot = this.attachShadow();
|
|
35
18
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_classPrivateFieldSet(this, _$text, shadowRoot.querySelector('#text'));
|
|
19
|
+
this.#$bar = shadowRoot.querySelector('#bar');
|
|
20
|
+
this.#$text = shadowRoot.querySelector('#text');
|
|
40
21
|
}
|
|
41
22
|
|
|
42
23
|
connectedCallback() {
|
|
@@ -76,12 +57,12 @@ defineCustomElement('sinch-progress', (_$bar = new WeakMap(), _$text = new WeakM
|
|
|
76
57
|
max: 100
|
|
77
58
|
});
|
|
78
59
|
const intCss = int === null ? '0%' : `${int}%`;
|
|
79
|
-
|
|
80
|
-
|
|
60
|
+
this.#$bar.style.width = intCss;
|
|
61
|
+
this.#$text.textContent = intCss;
|
|
81
62
|
this.setAttribute('valuenow', int !== null ? String(int) : '0');
|
|
82
63
|
break;
|
|
83
64
|
}
|
|
84
65
|
}
|
|
85
66
|
}
|
|
86
67
|
|
|
87
|
-
})
|
|
68
|
+
});
|