@nectary/components 0.39.0 → 0.41.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-item/index.js +30 -53
- package/action-menu/index.d.ts +0 -1
- package/action-menu/index.js +177 -223
- package/action-menu/types.d.ts +8 -18
- package/action-menu-option/index.d.ts +1 -0
- package/action-menu-option/index.js +52 -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 +46 -92
- package/button/types.d.ts +1 -1
- package/card/index.js +21 -59
- 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 +59 -107
- package/chip/index.d.ts +13 -0
- package/chip/index.js +140 -0
- package/chip/types.d.ts +37 -0
- package/color-menu/index.d.ts +14 -0
- package/color-menu/index.js +450 -0
- package/color-menu/types.d.ts +36 -0
- package/color-menu/utils.d.ts +1 -0
- package/color-menu/utils.js +15 -0
- package/color-swatch/index.d.ts +13 -0
- package/color-swatch/index.js +60 -0
- package/color-swatch/types.d.ts +11 -0
- package/colors.json +61 -49
- package/date-picker/index.js +162 -293
- package/dialog/index.js +70 -142
- package/field/index.js +44 -65
- 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 +11 -28
- package/horizontal-stepper/index.js +33 -59
- package/horizontal-stepper-item/index.js +13 -37
- package/icon-button/index.d.ts +1 -0
- package/icon-button/index.js +51 -85
- package/icon-button/types.d.ts +16 -2
- 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 +29 -81
- package/input/index.js +117 -222
- package/link/index.js +51 -97
- package/list-item/index.js +1 -1
- package/package.json +12 -14
- package/pagination/index.js +113 -163
- package/pop/index.d.ts +11 -0
- package/pop/index.js +391 -0
- package/pop/types.d.ts +35 -0
- package/pop/utils.d.ts +7 -0
- package/pop/utils.js +18 -0
- package/popover/index.d.ts +1 -0
- package/popover/index.js +105 -314
- package/popover/types.d.ts +8 -1
- package/popover/utils.d.ts +5 -0
- package/popover/utils.js +17 -1
- package/progress/index.js +9 -28
- package/radio/index.js +103 -169
- package/radio-option/index.js +28 -48
- package/segment/index.js +49 -130
- package/segment-collapse/index.js +28 -49
- package/segmented-control/index.js +36 -73
- package/segmented-control-option/index.js +45 -87
- package/segmented-icon-control/index.js +47 -84
- package/segmented-icon-control-option/index.js +42 -79
- package/select-button/index.d.ts +13 -0
- package/select-button/index.js +158 -0
- package/select-button/types.d.ts +43 -0
- package/select-menu/index.d.ts +11 -0
- package/select-menu/index.js +345 -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-option/index.js +24 -44
- package/tag/index.d.ts +0 -1
- package/tag/index.js +35 -38
- package/tag/types.d.ts +12 -7
- package/textarea/index.js +96 -167
- package/theme.css +146 -49
- package/tile-control/index.js +55 -96
- package/tile-control-option/index.js +45 -87
- package/time-picker/index.js +216 -368
- package/title/index.js +6 -20
- package/toast/index.js +32 -70
- package/toast-manager/index.js +141 -217
- package/toggle/index.js +59 -107
- package/tooltip/index.d.ts +2 -0
- package/tooltip/index.js +160 -17
- package/tooltip/types.d.ts +13 -0
- package/tooltip/utils.d.ts +5 -0
- package/tooltip/utils.js +25 -1
- package/utils/animation.d.ts +17 -0
- package/utils/animation.js +142 -0
- package/utils/colors.d.ts +5 -0
- package/utils/colors.js +5 -0
- package/utils/context.d.ts +15 -0
- package/utils/context.js +57 -0
- package/{utils.d.ts → utils/index.d.ts} +15 -11
- package/{utils.js → utils/index.js} +104 -48
- package/vertical-stepper/index.js +29 -50
- package/vertical-stepper-item/index.js +13 -37
- package/dropdown/index.d.ts +0 -12
- package/dropdown/index.js +0 -415
- package/dropdown/types.d.ts +0 -32
- package/dropdown-checkbox-option/index.d.ts +0 -11
- package/dropdown-checkbox-option/index.js +0 -88
- package/dropdown-checkbox-option/types.d.ts +0 -15
- package/dropdown-radio-option/index.d.ts +0 -11
- package/dropdown-radio-option/index.js +0 -88
- package/dropdown-radio-option/types.d.ts +0 -15
- package/dropdown-text-option/index.js +0 -104
- package/dropdown-text-option/types.d.ts +0 -16
- 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 -5
- package/tag/utils.js +0 -6
- package/tag-close/index.d.ts +0 -12
- package/tag-close/index.js +0 -42
- package/tag-close/types.d.ts +0 -5
- /package/{dropdown-checkbox-option → chip}/types.js +0 -0
- /package/{dropdown-radio-option → color-menu}/types.js +0 -0
- /package/{dropdown-text-option → color-swatch}/types.js +0 -0
- /package/{dropdown → pop}/types.js +0 -0
- /package/{select-option → select-button}/types.js +0 -0
- /package/{tag-close → select-menu}/types.js +0 -0
- /package/{select → select-menu-option}/types.js +0 -0
package/popover/index.js
CHANGED
|
@@ -1,234 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
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-popover-shape-radius,var(--sinch-shape-radius-l));outline:0}#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" tabindex="-1"><slot name="content"></slot></div></dialog></div>';
|
|
17
|
-
import { orientationValues } from './utils';
|
|
1
|
+
import '../pop';
|
|
2
|
+
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, updateBooleanAttribute, NectaryElement, updateAttribute, getReactEventHandler, isAttrTrue, setClass, rectOverlap } from '../utils';
|
|
3
|
+
import { dispatchContextConnectEvent, dispatchContextDisconnectEvent } from '../utils/context';
|
|
4
|
+
const templateHTML = '<style>:host{display:contents}#content-wrapper{position:relative;padding-top:4px}#content{font:var(--sinch-font-body);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-100);border:1px solid var(--sinch-color-snow-500);border-radius:var(--sinch-shape-radius-m);box-shadow:var(--sinch-elevation-level-2);overflow:hidden}#tip{position:absolute;left:50%;top:13px;transform:translateX(-50%) rotate(180deg);transform-origin:top center;fill:var(--sinch-color-snow-100);stroke:var(--sinch-color-snow-500);stroke-linecap:square;pointer-events:none;display:none}:host([orientation^=top]) #tip{transform:translateX(-50%) rotate(0);top:calc(100% - 13px)}:host([tip]) #tip:not(.hidden){display:block}:host([tip]) #content{box-shadow:none}:host([tip]) #content-wrapper{padding-top:12px;filter:drop-shadow(var(--sinch-elevation-level-2))}:host([orientation^=top]) #content-wrapper{padding-top:0;padding-bottom:4px}:host([orientation^=top][tip]) #content-wrapper{padding-top:0;padding-bottom:12px}</style><sinch-pop id="pop" inset="4"><slot name="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content"><slot name="content"></slot></div><svg id="tip" width="16" height="9" aria-hidden="true"><path d="m0 0 8 8 8 -8"/></svg></div></sinch-pop>';
|
|
5
|
+
import { assertOrientation, getPopOrientation, orientationValues } from './utils';
|
|
6
|
+
const TIP_SIZE = 16;
|
|
18
7
|
const template = document.createElement('template');
|
|
19
8
|
template.innerHTML = templateHTML;
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
10
|
+
#$pop;
|
|
11
|
+
#$content;
|
|
12
|
+
#$tip;
|
|
13
|
+
#controller = null;
|
|
14
|
+
|
|
22
15
|
constructor() {
|
|
23
16
|
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
17
|
const shadowRoot = this.attachShadow();
|
|
179
18
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
_classPrivateFieldSet(this, _$dialog, shadowRoot.querySelector('#dialog'));
|
|
184
|
-
|
|
185
|
-
_classPrivateFieldSet(this, _$targetSlot, shadowRoot.querySelector('slot[name="target"]'));
|
|
186
|
-
|
|
187
|
-
_classPrivateFieldSet(this, _$targetOpenSlot, shadowRoot.querySelector('slot[name="target-open"]'));
|
|
188
|
-
|
|
189
|
-
_classPrivateFieldSet(this, _$targetOpenWrapper, shadowRoot.querySelector('#target-open'));
|
|
190
|
-
|
|
191
|
-
_classPrivateFieldSet(this, _isConnected, false);
|
|
192
|
-
|
|
193
|
-
_classPrivateFieldSet(this, _resizeThrottle, throttleAnimationFrame(_classPrivateFieldGet(this, _updateOrientation)));
|
|
194
|
-
|
|
195
|
-
dialogPolyfill.registerDialog(_classPrivateFieldGet(this, _$dialog));
|
|
196
|
-
|
|
197
|
-
dialogPolyfill.dm.handleFocus_ = function () {};
|
|
19
|
+
this.#$pop = shadowRoot.querySelector('#pop');
|
|
20
|
+
this.#$content = shadowRoot.querySelector('#content');
|
|
21
|
+
this.#$tip = shadowRoot.querySelector('#tip');
|
|
198
22
|
}
|
|
199
23
|
|
|
200
24
|
connectedCallback() {
|
|
201
|
-
this
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
25
|
+
this.#controller = new AbortController();
|
|
26
|
+
const {
|
|
27
|
+
signal
|
|
28
|
+
} = this.#controller;
|
|
29
|
+
this.addEventListener('-close', this.#onCloseReactHandler, {
|
|
30
|
+
signal
|
|
31
|
+
});
|
|
32
|
+
this.#$pop.addEventListener('-close', this.#onPopClose, {
|
|
33
|
+
signal
|
|
34
|
+
});
|
|
35
|
+
this.#$content.addEventListener('-visibility', this.#onContextVisibility, {
|
|
36
|
+
signal
|
|
37
|
+
});
|
|
38
|
+
dispatchContextConnectEvent(this.#$content, 'visibility');
|
|
39
|
+
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
216
40
|
}
|
|
217
41
|
|
|
218
42
|
disconnectedCallback() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.removeEventListener('-close', _classPrivateFieldGet(this, _onCloseReactHandler));
|
|
43
|
+
dispatchContextDisconnectEvent(this.#$content, 'visibility');
|
|
44
|
+
this.#controller.abort();
|
|
45
|
+
}
|
|
224
46
|
|
|
225
|
-
|
|
47
|
+
#onPopClose = () => {
|
|
48
|
+
this.#dispatchCloseEvent();
|
|
49
|
+
};
|
|
50
|
+
#onCloseReactHandler = e => {
|
|
51
|
+
getReactEventHandler(this, 'onClose')?.();
|
|
52
|
+
getReactEventHandler(this, 'on-close')?.(e);
|
|
53
|
+
};
|
|
226
54
|
|
|
227
|
-
|
|
55
|
+
#dispatchCloseEvent() {
|
|
56
|
+
this.dispatchEvent(new CustomEvent('-close'));
|
|
228
57
|
}
|
|
229
58
|
|
|
230
59
|
static get observedAttributes() {
|
|
231
|
-
return ['
|
|
60
|
+
return ['orientation', 'open', 'modal', 'tip'];
|
|
232
61
|
}
|
|
233
62
|
|
|
234
63
|
set modal(isModal) {
|
|
@@ -247,16 +76,28 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
|
|
|
247
76
|
return getBooleanAttribute(this, 'open');
|
|
248
77
|
}
|
|
249
78
|
|
|
79
|
+
set tip(hasTip) {
|
|
80
|
+
updateBooleanAttribute(this, 'tip', hasTip);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get tip() {
|
|
84
|
+
return getBooleanAttribute(this, 'tip');
|
|
85
|
+
}
|
|
86
|
+
|
|
250
87
|
get orientation() {
|
|
251
|
-
return getLiteralAttribute(this, orientationValues, 'orientation', 'bottom');
|
|
88
|
+
return getLiteralAttribute(this, orientationValues, 'orientation', 'bottom-left');
|
|
252
89
|
}
|
|
253
90
|
|
|
254
91
|
set orientation(value) {
|
|
255
92
|
updateLiteralAttribute(this, orientationValues, 'orientation', value);
|
|
256
93
|
}
|
|
257
94
|
|
|
95
|
+
get footprintRect() {
|
|
96
|
+
return this.#$pop.footprintRect;
|
|
97
|
+
}
|
|
98
|
+
|
|
258
99
|
get popoverRect() {
|
|
259
|
-
return
|
|
100
|
+
return this.#$pop.popoverRect;
|
|
260
101
|
}
|
|
261
102
|
|
|
262
103
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
@@ -265,129 +106,79 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
|
|
|
265
106
|
}
|
|
266
107
|
|
|
267
108
|
switch (name) {
|
|
268
|
-
case '
|
|
109
|
+
case 'orientation':
|
|
269
110
|
{
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
111
|
+
assertOrientation(newVal);
|
|
112
|
+
updateAttribute(this.#$pop, 'orientation', getPopOrientation(newVal));
|
|
113
|
+
|
|
114
|
+
if (this.#isOpen()) {
|
|
115
|
+
this.#updateTipOrientation();
|
|
274
116
|
}
|
|
275
117
|
|
|
276
|
-
updateBooleanAttribute(this, 'open', isAttrTrue(newVal));
|
|
277
118
|
break;
|
|
278
119
|
}
|
|
279
120
|
|
|
280
|
-
case '
|
|
121
|
+
case 'tip':
|
|
281
122
|
{
|
|
282
|
-
|
|
283
|
-
|
|
123
|
+
updateBooleanAttribute(this, 'tip', isAttrTrue(newVal));
|
|
124
|
+
|
|
125
|
+
if (newVal === '' && this.#isOpen()) {
|
|
126
|
+
this.#updateTipOrientation();
|
|
284
127
|
}
|
|
285
128
|
|
|
286
129
|
break;
|
|
287
130
|
}
|
|
288
131
|
|
|
289
|
-
case '
|
|
132
|
+
case 'open':
|
|
290
133
|
{
|
|
291
|
-
|
|
292
|
-
|
|
134
|
+
const isOpen = isAttrTrue(newVal);
|
|
135
|
+
updateBooleanAttribute(this.#$pop, name, isOpen);
|
|
136
|
+
updateBooleanAttribute(this, name, isOpen);
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
293
139
|
|
|
294
|
-
|
|
295
|
-
|
|
140
|
+
default:
|
|
141
|
+
{
|
|
142
|
+
updateAttribute(this.#$pop, name, newVal);
|
|
296
143
|
}
|
|
297
144
|
}
|
|
298
145
|
}
|
|
299
146
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
const isNonModal = !this.modal;
|
|
308
|
-
|
|
309
|
-
_classPrivateFieldGet(this, _$targetSlot).addEventListener('blur', _classPrivateFieldGet(this, _stopPropagation), true);
|
|
310
|
-
|
|
311
|
-
if (isNonModal) {
|
|
312
|
-
_classPrivateFieldGet(this, _$targetOpenSlot).addEventListener('blur', _classPrivateFieldGet(this, _captureActiveElement), true);
|
|
313
|
-
|
|
314
|
-
const targetRect = _classPrivateFieldGet(this, _$target).getBoundingClientRect();
|
|
315
|
-
|
|
316
|
-
const widthPx = `${targetRect.width}px`;
|
|
317
|
-
const heightPx = `${targetRect.height}px`;
|
|
318
|
-
_classPrivateFieldGet(this, _$target).style.width = widthPx;
|
|
319
|
-
_classPrivateFieldGet(this, _$target).style.height = heightPx;
|
|
320
|
-
_classPrivateFieldGet(this, _$targetOpenWrapper).style.width = widthPx;
|
|
321
|
-
_classPrivateFieldGet(this, _$targetOpenWrapper).style.height = heightPx;
|
|
322
|
-
_classPrivateFieldGet(this, _$targetSlot).assignedElements()[0]?.setAttribute('slot', 'target-open');
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
_classPrivateFieldGet(this, _$dialog).showModal();
|
|
326
|
-
|
|
327
|
-
_classPrivateFieldGet(this, _updateOrientation).call(this);
|
|
328
|
-
|
|
329
|
-
_classPrivateFieldGet(this, _$target).setAttribute('aria-expanded', 'true');
|
|
330
|
-
|
|
331
|
-
_classPrivateFieldGet(this, _$targetSlot).removeEventListener('blur', _classPrivateFieldGet(this, _stopPropagation), true);
|
|
332
|
-
|
|
333
|
-
if (isNonModal) {
|
|
334
|
-
_classPrivateFieldGet(this, _$targetOpenSlot).removeEventListener('blur', _classPrivateFieldGet(this, _captureActiveElement), true);
|
|
335
|
-
|
|
336
|
-
if (_classPrivateFieldGet(this, _targetActiveElement) !== null) {
|
|
337
|
-
requestAnimationFrame(() => {
|
|
338
|
-
_classPrivateFieldGet(this, _$targetOpenSlot).addEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
|
|
339
|
-
|
|
340
|
-
_classPrivateFieldGet(this, _targetActiveElement)?.focus();
|
|
341
|
-
|
|
342
|
-
_classPrivateFieldGet(this, _$targetOpenSlot).removeEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
|
|
343
|
-
});
|
|
147
|
+
#onContextVisibility = e => {
|
|
148
|
+
if (e.detail) {
|
|
149
|
+
this.#updateTipOrientation();
|
|
150
|
+
} else {
|
|
151
|
+
this.#resetTipOrientation();
|
|
344
152
|
}
|
|
345
|
-
}
|
|
153
|
+
};
|
|
346
154
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
window.addEventListener('resize', _classPrivateFieldGet(this, _onResize));
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
function _onCollapse2() {
|
|
354
|
-
if (!_classPrivateMethodGet(this, _isOpen, _isOpen2).call(this)) {
|
|
355
|
-
return;
|
|
155
|
+
#resetTipOrientation() {
|
|
156
|
+
this.#$tip.style.top = '';
|
|
157
|
+
this.#$tip.style.left = '';
|
|
356
158
|
}
|
|
357
159
|
|
|
358
|
-
|
|
160
|
+
#updateTipOrientation = () => {
|
|
161
|
+
const orientation = this.orientation;
|
|
162
|
+
const targetRect = this.#$pop.footprintRect;
|
|
163
|
+
const contentRect = this.#$content.getBoundingClientRect();
|
|
164
|
+
const diffX = targetRect.x - contentRect.x;
|
|
165
|
+
let desiredX = diffX + targetRect.width / 2;
|
|
359
166
|
|
|
360
|
-
|
|
361
|
-
|
|
167
|
+
if (orientation === 'bottom-left' || orientation === 'top-left') {
|
|
168
|
+
desiredX = Math.max(desiredX, contentRect.width * 0.75);
|
|
169
|
+
}
|
|
362
170
|
|
|
363
|
-
|
|
171
|
+
if (orientation === 'bottom-right' || orientation === 'top-right') {
|
|
172
|
+
desiredX = Math.min(desiredX, contentRect.width * 0.25);
|
|
173
|
+
}
|
|
364
174
|
|
|
365
|
-
|
|
175
|
+
const xPos = Math.max(TIP_SIZE, Math.min(desiredX, contentRect.width - TIP_SIZE));
|
|
176
|
+
this.#$tip.style.left = `${xPos}px`;
|
|
177
|
+
setClass(this.#$tip, 'hidden', rectOverlap(targetRect, contentRect));
|
|
178
|
+
};
|
|
366
179
|
|
|
367
|
-
|
|
180
|
+
#isOpen() {
|
|
181
|
+
return this.#$pop.open;
|
|
368
182
|
}
|
|
369
183
|
|
|
370
|
-
|
|
371
|
-
_classPrivateFieldGet(this, _$target).style.width = 'unset';
|
|
372
|
-
_classPrivateFieldGet(this, _$target).style.height = 'unset';
|
|
373
|
-
|
|
374
|
-
_classPrivateFieldGet(this, _$dialog).close();
|
|
375
|
-
|
|
376
|
-
_classPrivateFieldGet(this, _$target).setAttribute('aria-expanded', 'false');
|
|
377
|
-
|
|
378
|
-
_classPrivateFieldGet(this, _$targetSlot).removeEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
|
|
379
|
-
|
|
380
|
-
document.body.style.overflow = _classPrivateFieldGet(this, _originalOverflowValue);
|
|
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
|
-
}
|
|
390
|
-
|
|
391
|
-
function _dispatchCloseEvent2() {
|
|
392
|
-
this.dispatchEvent(new CustomEvent('-close'));
|
|
393
|
-
}
|
|
184
|
+
});
|
package/popover/types.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export declare type TSinchPopoverElement = HTMLElement & {
|
|
|
7
7
|
orientation: TSinchPopoverOrientation;
|
|
8
8
|
/** Modal/non-modal mode */
|
|
9
9
|
modal: boolean;
|
|
10
|
+
/** Show tip */
|
|
11
|
+
tip: boolean;
|
|
12
|
+
readonly footprintRect: TRect;
|
|
10
13
|
readonly popoverRect: TRect;
|
|
11
14
|
/** Close event */
|
|
12
15
|
addEventListener(type: '-close', listener: (e: CustomEvent<void>) => void): void;
|
|
@@ -15,7 +18,9 @@ export declare type TSinchPopoverElement = HTMLElement & {
|
|
|
15
18
|
/** Orientation, where it *points to* from origin */
|
|
16
19
|
setAttribute(name: 'orientation', value: TSinchPopoverOrientation): void;
|
|
17
20
|
/** Modal/non-modal mode */
|
|
18
|
-
setAttribute(name: 'modal', value:
|
|
21
|
+
setAttribute(name: 'modal', value: ''): void;
|
|
22
|
+
/** Show tip */
|
|
23
|
+
setAttribute(name: 'tip', value: ''): void;
|
|
19
24
|
};
|
|
20
25
|
export declare type TSinchPopoverReact = TSinchElementReact<TSinchPopoverElement> & {
|
|
21
26
|
/** Open/close state */
|
|
@@ -24,6 +29,8 @@ export declare type TSinchPopoverReact = TSinchElementReact<TSinchPopoverElement
|
|
|
24
29
|
orientation?: TSinchPopoverOrientation;
|
|
25
30
|
/** Modal/non-modal mode */
|
|
26
31
|
modal?: boolean;
|
|
32
|
+
/** Show tip */
|
|
33
|
+
tip?: boolean;
|
|
27
34
|
/** Label that is used for a11y */
|
|
28
35
|
'aria-label': string;
|
|
29
36
|
/** Close event handler */
|
package/popover/utils.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import type { TSinchPopOrientation } from '../pop/types';
|
|
1
2
|
import type { TSinchPopoverOrientation } from './types';
|
|
2
3
|
export declare const orientationValues: readonly TSinchPopoverOrientation[];
|
|
4
|
+
export declare const getPopOrientation: (orientation: TSinchPopoverOrientation) => TSinchPopOrientation;
|
|
5
|
+
declare type TAssertOrientation = (value: string | null) => asserts value is TSinchPopoverOrientation;
|
|
6
|
+
export declare const assertOrientation: TAssertOrientation;
|
|
7
|
+
export {};
|
package/popover/utils.js
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
export const orientationValues = ['top-left', 'top-right', 'bottom-left', 'bottom-right', 'bottom', 'top'];
|
|
1
|
+
export const orientationValues = ['top-left', 'top-right', 'bottom-left', 'bottom-right', 'bottom', 'top'];
|
|
2
|
+
export const getPopOrientation = orientation => {
|
|
3
|
+
if (orientation === 'top') {
|
|
4
|
+
return 'top-stretch';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
if (orientation === 'bottom') {
|
|
8
|
+
return 'bottom-stretch';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return orientation;
|
|
12
|
+
};
|
|
13
|
+
export const assertOrientation = value => {
|
|
14
|
+
if (value === null || !orientationValues.includes(value)) {
|
|
15
|
+
throw new Error(`sinch-popover: invalid orientation attribute: ${value}`);
|
|
16
|
+
}
|
|
17
|
+
};
|
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
|
+
});
|