@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.
Files changed (142) hide show
  1. package/accordion/index.js +47 -84
  2. package/accordion-item/index.js +30 -53
  3. package/action-menu/index.d.ts +0 -1
  4. package/action-menu/index.js +177 -223
  5. package/action-menu/types.d.ts +8 -18
  6. package/action-menu-option/index.d.ts +1 -0
  7. package/action-menu-option/index.js +52 -62
  8. package/action-menu-option/types.d.ts +9 -0
  9. package/action-menu-option/utils.d.ts +2 -0
  10. package/action-menu-option/utils.js +3 -0
  11. package/alert/index.js +6 -20
  12. package/avatar/index.js +12 -31
  13. package/avatar-badge/index.js +8 -22
  14. package/avatar-status/index.js +1 -1
  15. package/button/index.js +46 -92
  16. package/button/types.d.ts +1 -1
  17. package/card/index.js +21 -59
  18. package/chat-avatar/index.js +8 -22
  19. package/chat-block/index.js +29 -69
  20. package/chat-bubble/index.js +6 -20
  21. package/checkbox/index.js +59 -107
  22. package/chip/index.d.ts +13 -0
  23. package/chip/index.js +140 -0
  24. package/chip/types.d.ts +37 -0
  25. package/color-menu/index.d.ts +14 -0
  26. package/color-menu/index.js +450 -0
  27. package/color-menu/types.d.ts +36 -0
  28. package/color-menu/utils.d.ts +1 -0
  29. package/color-menu/utils.js +15 -0
  30. package/color-swatch/index.d.ts +13 -0
  31. package/color-swatch/index.js +60 -0
  32. package/color-swatch/types.d.ts +11 -0
  33. package/colors.json +61 -49
  34. package/date-picker/index.js +162 -293
  35. package/dialog/index.js +70 -142
  36. package/field/index.js +44 -65
  37. package/file-drop/index.js +123 -200
  38. package/file-picker/index.d.ts +0 -1
  39. package/file-picker/index.js +55 -108
  40. package/file-status/index.js +15 -39
  41. package/help-tooltip/index.js +11 -28
  42. package/horizontal-stepper/index.js +33 -59
  43. package/horizontal-stepper-item/index.js +13 -37
  44. package/icon-button/index.d.ts +1 -0
  45. package/icon-button/index.js +51 -85
  46. package/icon-button/types.d.ts +16 -2
  47. package/icons-channel/notify/index.d.ts +11 -0
  48. package/icons-channel/notify/index.js +4 -0
  49. package/illustrations/create-illustration-class.js +1 -1
  50. package/inline-alert/index.js +29 -81
  51. package/input/index.js +117 -222
  52. package/link/index.js +51 -97
  53. package/list-item/index.js +1 -1
  54. package/package.json +12 -14
  55. package/pagination/index.js +113 -163
  56. package/pop/index.d.ts +11 -0
  57. package/pop/index.js +391 -0
  58. package/pop/types.d.ts +35 -0
  59. package/pop/utils.d.ts +7 -0
  60. package/pop/utils.js +18 -0
  61. package/popover/index.d.ts +1 -0
  62. package/popover/index.js +105 -314
  63. package/popover/types.d.ts +8 -1
  64. package/popover/utils.d.ts +5 -0
  65. package/popover/utils.js +17 -1
  66. package/progress/index.js +9 -28
  67. package/radio/index.js +103 -169
  68. package/radio-option/index.js +28 -48
  69. package/segment/index.js +49 -130
  70. package/segment-collapse/index.js +28 -49
  71. package/segmented-control/index.js +36 -73
  72. package/segmented-control-option/index.js +45 -87
  73. package/segmented-icon-control/index.js +47 -84
  74. package/segmented-icon-control-option/index.js +42 -79
  75. package/select-button/index.d.ts +13 -0
  76. package/select-button/index.js +158 -0
  77. package/select-button/types.d.ts +43 -0
  78. package/select-menu/index.d.ts +11 -0
  79. package/select-menu/index.js +345 -0
  80. package/select-menu/types.d.ts +29 -0
  81. package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
  82. package/select-menu-option/index.js +76 -0
  83. package/{select-option → select-menu-option}/types.d.ts +8 -9
  84. package/stop-events/index.js +7 -20
  85. package/table-head-cell/index.js +7 -21
  86. package/tabs/index.js +103 -165
  87. package/tabs-option/index.js +24 -44
  88. package/tag/index.d.ts +0 -1
  89. package/tag/index.js +35 -38
  90. package/tag/types.d.ts +12 -7
  91. package/textarea/index.js +96 -167
  92. package/theme.css +146 -49
  93. package/tile-control/index.js +55 -96
  94. package/tile-control-option/index.js +45 -87
  95. package/time-picker/index.js +216 -368
  96. package/title/index.js +6 -20
  97. package/toast/index.js +32 -70
  98. package/toast-manager/index.js +141 -217
  99. package/toggle/index.js +59 -107
  100. package/tooltip/index.d.ts +2 -0
  101. package/tooltip/index.js +160 -17
  102. package/tooltip/types.d.ts +13 -0
  103. package/tooltip/utils.d.ts +5 -0
  104. package/tooltip/utils.js +25 -1
  105. package/utils/animation.d.ts +17 -0
  106. package/utils/animation.js +142 -0
  107. package/utils/colors.d.ts +5 -0
  108. package/utils/colors.js +5 -0
  109. package/utils/context.d.ts +15 -0
  110. package/utils/context.js +57 -0
  111. package/{utils.d.ts → utils/index.d.ts} +15 -11
  112. package/{utils.js → utils/index.js} +104 -48
  113. package/vertical-stepper/index.js +29 -50
  114. package/vertical-stepper-item/index.js +13 -37
  115. package/dropdown/index.d.ts +0 -12
  116. package/dropdown/index.js +0 -415
  117. package/dropdown/types.d.ts +0 -32
  118. package/dropdown-checkbox-option/index.d.ts +0 -11
  119. package/dropdown-checkbox-option/index.js +0 -88
  120. package/dropdown-checkbox-option/types.d.ts +0 -15
  121. package/dropdown-radio-option/index.d.ts +0 -11
  122. package/dropdown-radio-option/index.js +0 -88
  123. package/dropdown-radio-option/types.d.ts +0 -15
  124. package/dropdown-text-option/index.js +0 -104
  125. package/dropdown-text-option/types.d.ts +0 -16
  126. package/select/index.d.ts +0 -13
  127. package/select/index.js +0 -316
  128. package/select/types.d.ts +0 -53
  129. package/select-option/index.d.ts +0 -11
  130. package/select-option/index.js +0 -8
  131. package/tag/utils.d.ts +0 -5
  132. package/tag/utils.js +0 -6
  133. package/tag-close/index.d.ts +0 -12
  134. package/tag-close/index.js +0 -42
  135. package/tag-close/types.d.ts +0 -5
  136. /package/{dropdown-checkbox-option → chip}/types.js +0 -0
  137. /package/{dropdown-radio-option → color-menu}/types.js +0 -0
  138. /package/{dropdown-text-option → color-swatch}/types.js +0 -0
  139. /package/{dropdown → pop}/types.js +0 -0
  140. /package/{select-option → select-button}/types.js +0 -0
  141. /package/{tag-close → select-menu}/types.js +0 -0
  142. /package/{select → select-menu-option}/types.js +0 -0
package/popover/index.js CHANGED
@@ -1,234 +1,63 @@
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
- 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
- const POPOVER_OFFSET = 4;
21
- defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new WeakMap(), _isConnected = new WeakMap(), _resizeThrottle = new WeakMap(), _originalOverflowValue = new WeakMap(), _$targetSlot = new WeakMap(), _$targetOpenSlot = new WeakMap(), _$targetOpenWrapper = new WeakMap(), _targetActiveElement = new WeakMap(), _onExpand = new WeakSet(), _onCollapse = new WeakSet(), _isOpen = new WeakSet(), _onResize = new WeakMap(), _updateOrientation = new WeakMap(), _onBackdropMouseDown = new WeakMap(), _onCancel = new WeakMap(), _onCloseReactHandler = new WeakMap(), _dispatchCloseEvent = new WeakSet(), _captureActiveElement = new WeakMap(), _stopPropagation = new WeakMap(), class extends NectaryElement {
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
- _classPrivateFieldSet(this, _$target, shadowRoot.querySelector('#target'));
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.setAttribute('role', 'dialog');
202
-
203
- _classPrivateFieldGet(this, _$dialog).addEventListener('cancel', _classPrivateFieldGet(this, _onCancel));
204
-
205
- _classPrivateFieldGet(this, _$dialog).addEventListener('mousedown', _classPrivateFieldGet(this, _onBackdropMouseDown));
206
-
207
- this.addEventListener('-close', _classPrivateFieldGet(this, _onCloseReactHandler));
208
-
209
- _classPrivateFieldSet(this, _isConnected, true);
210
-
211
- if (getBooleanAttribute(this, 'open')) {
212
- _classPrivateMethodGet(this, _onExpand, _onExpand2).call(this);
213
- } else {
214
- _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
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
- _classPrivateFieldGet(this, _$dialog).removeEventListener('cancel', _classPrivateFieldGet(this, _onCancel));
220
-
221
- _classPrivateFieldGet(this, _$dialog).removeEventListener('mousedown', _classPrivateFieldGet(this, _onBackdropMouseDown));
222
-
223
- this.removeEventListener('-close', _classPrivateFieldGet(this, _onCloseReactHandler));
43
+ dispatchContextDisconnectEvent(this.#$content, 'visibility');
44
+ this.#controller.abort();
45
+ }
224
46
 
225
- _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
47
+ #onPopClose = () => {
48
+ this.#dispatchCloseEvent();
49
+ };
50
+ #onCloseReactHandler = e => {
51
+ getReactEventHandler(this, 'onClose')?.();
52
+ getReactEventHandler(this, 'on-close')?.(e);
53
+ };
226
54
 
227
- _classPrivateFieldSet(this, _isConnected, false);
55
+ #dispatchCloseEvent() {
56
+ this.dispatchEvent(new CustomEvent('-close'));
228
57
  }
229
58
 
230
59
  static get observedAttributes() {
231
- return ['modal', 'orientation', 'open'];
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 getRect(_classPrivateFieldGet(this, _$dialog));
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 'open':
109
+ case 'orientation':
269
110
  {
270
- if (isAttrTrue(newVal)) {
271
- _classPrivateMethodGet(this, _onExpand, _onExpand2).call(this);
272
- } else {
273
- _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
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 'orientation':
121
+ case 'tip':
281
122
  {
282
- if (_classPrivateMethodGet(this, _isOpen, _isOpen2).call(this)) {
283
- _classPrivateFieldGet(this, _updateOrientation).call(this);
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 'modal':
132
+ case 'open':
290
133
  {
291
- if (_classPrivateMethodGet(this, _isOpen, _isOpen2).call(this)) {
292
- _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
134
+ const isOpen = isAttrTrue(newVal);
135
+ updateBooleanAttribute(this.#$pop, name, isOpen);
136
+ updateBooleanAttribute(this, name, isOpen);
137
+ break;
138
+ }
293
139
 
294
- _classPrivateMethodGet(this, _onExpand, _onExpand2).call(this);
295
- }
140
+ default:
141
+ {
142
+ updateAttribute(this.#$pop, name, newVal);
296
143
  }
297
144
  }
298
145
  }
299
146
 
300
- }));
301
-
302
- function _onExpand2() {
303
- if (!_classPrivateFieldGet(this, _isConnected) || _classPrivateMethodGet(this, _isOpen, _isOpen2).call(this)) {
304
- return;
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
- _classPrivateFieldSet(this, _originalOverflowValue, document.body.style.overflow);
348
-
349
- document.body.style.overflow = 'hidden';
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
- _classPrivateFieldGet(this, _$targetSlot).addEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
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
- if (_classPrivateFieldGet(this, _targetActiveElement) !== null) {
361
- _classPrivateFieldGet(this, _$targetOpenSlot).addEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
167
+ if (orientation === 'bottom-left' || orientation === 'top-left') {
168
+ desiredX = Math.max(desiredX, contentRect.width * 0.75);
169
+ }
362
170
 
363
- _classPrivateFieldGet(this, _targetActiveElement).focus();
171
+ if (orientation === 'bottom-right' || orientation === 'top-right') {
172
+ desiredX = Math.min(desiredX, contentRect.width * 0.25);
173
+ }
364
174
 
365
- _classPrivateFieldSet(this, _targetActiveElement, null);
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
- _classPrivateFieldGet(this, _$targetOpenSlot).removeEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
180
+ #isOpen() {
181
+ return this.#$pop.open;
368
182
  }
369
183
 
370
- _classPrivateFieldGet(this, _$targetOpenSlot).assignedElements()[0]?.setAttribute('slot', 'target');
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
+ });
@@ -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: boolean): void;
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 */
@@ -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', (_$bar = new WeakMap(), _$text = new WeakMap(), class extends NectaryElement {
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
- _classPrivateFieldSet(this, _$bar, shadowRoot.querySelector('#bar'));
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
- _classPrivateFieldGet(this, _$bar).style.width = intCss;
80
- _classPrivateFieldGet(this, _$text).textContent = intCss;
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
+ });