diginet-core-ui 1.3.69-beta.2 → 1.3.69-beta.3

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.
@@ -167,8 +167,6 @@ Radio.defaultProps = {
167
167
  disabled: false,
168
168
  readOnly: false,
169
169
  defaultChecked: false,
170
- label: '',
171
- value: '',
172
170
  className: '',
173
171
  width: 20,
174
172
  labelProps: {}
@@ -18,6 +18,7 @@ const {
18
18
  typography: {
19
19
  paragraph1
20
20
  },
21
+ spacing,
21
22
  zIndex: zIndexCORE
22
23
  } = theme;
23
24
  const eventMap = new Map([['click', ['click']], ['hover', ['mouseenter', 'mouseleave']], ['focus', ['focus', 'blur']]]);
@@ -139,9 +140,9 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
139
140
  direction,
140
141
  fullScreen,
141
142
  height,
143
+ marginThreshold,
142
144
  onClose,
143
145
  open,
144
- marginThreshold,
145
146
  pressESCToClose,
146
147
  style,
147
148
  transformOrigin,
@@ -160,7 +161,7 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
160
161
 
161
162
  const _PopoverArrowCSS = PopoverArrowCSS(bgColor);
162
163
 
163
- const arrowSize = 6;
164
+ const arrowSize = arrow ? 6 : 0;
164
165
 
165
166
  if (direction) {
166
167
  const directionObject = getDirectionPopover(direction);
@@ -202,7 +203,7 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
202
203
  };
203
204
 
204
205
  const updatePositionPopover = (el = null, cb) => {
205
- var _window, _window2, _anchor6, _anchorRect, _anchorRect2, _anchor7, _anchorRect3, _anchorRect4, _anchorRect5, _anchorRect6, _anchorRect7, _anchorRect8, _anchorRect9, _anchorRect10, _anchorRect11, _anchorRect12, _anchorRect13, _anchorRect14, _anchorRect15, _anchorRect16, _anchorRect17, _anchorRect18, _anchorRect19;
206
+ var _window, _window2, _anchor6, _anchorRect, _anchorRect2, _anchor7, _anchorRect3, _anchorRect4, _anchorRect5, _anchorRect6, _anchorRect7, _anchorRect8, _anchorRect9, _anchorRect10, _anchorRect11, _anchorRect12, _newDirectionObject, _newDirectionObject$t, _transformOrigin, _newDirectionObject2, _newDirectionObject2$, _transformOrigin2;
206
207
 
207
208
  setElement(el instanceof Element ? el : null);
208
209
 
@@ -224,7 +225,7 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
224
225
  },
225
226
  anchorRect = null,
226
227
  aPosition = '',
227
- isOverflow = false;
228
+ newDirectionObject = null;
228
229
 
229
230
  if (transformOrigin === 'center') {
230
231
  transformOrigin = {
@@ -240,13 +241,6 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
240
241
  anchor = ((_anchor5 = anchor) === null || _anchor5 === void 0 ? void 0 : _anchor5.element) || ((_anchor$current = anchor.current) === null || _anchor$current === void 0 ? void 0 : _anchor$current.element) || anchor.current;
241
242
  }
242
243
 
243
- if (anchorOrigin === 'center') {
244
- anchorOrigin = {
245
- vertical: 'center',
246
- horizontal: 'center'
247
- };
248
- }
249
-
250
244
  if (arrow && anchorOrigin.vertical !== anchorOrigin.horizontal && transformOrigin.vertical !== transformOrigin.horizontal) {
251
245
  aPosition = getArrowPosition(anchorOrigin, transformOrigin, translate);
252
246
  }
@@ -292,32 +286,63 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
292
286
  default:
293
287
  left = horizontal;
294
288
  break;
295
- }
289
+ } // Variables for check if needs shifting
296
290
 
291
+
292
+ const heightThreshold = containerWindow.height - marginThreshold;
293
+ const widthThreshold = containerWindow.width - marginThreshold;
297
294
  const bottomOfAnchor = top + ((_anchor6 = anchor) === null || _anchor6 === void 0 ? void 0 : _anchor6.offsetHeight);
298
- const topPos = ((_anchorRect = anchorRect) === null || _anchorRect === void 0 ? void 0 : _anchorRect.height) + arrowSize;
295
+ const topPos = ((_anchorRect = anchorRect) === null || _anchorRect === void 0 ? void 0 : _anchorRect.bottom) + arrowSize;
299
296
  const verticalCenterPos = verticalCenter - popoverHeight / 2;
300
- const bottomPos = containerWindow.height - popoverHeight - (marginThreshold + ((_anchorRect2 = anchorRect) === null || _anchorRect2 === void 0 ? void 0 : _anchorRect2.height) + arrowSize);
297
+ const bottomPos = ((_anchorRect2 = anchorRect) === null || _anchorRect2 === void 0 ? void 0 : _anchorRect2.top) - (popoverHeight + arrowSize);
301
298
  const rightOfAnchor = left + ((_anchor7 = anchor) === null || _anchor7 === void 0 ? void 0 : _anchor7.offsetWidth);
302
- const leftPos = ((_anchorRect3 = anchorRect) === null || _anchorRect3 === void 0 ? void 0 : _anchorRect3.width) + arrowSize;
299
+ const leftPos = ((_anchorRect3 = anchorRect) === null || _anchorRect3 === void 0 ? void 0 : _anchorRect3.right) + arrowSize;
303
300
  const horizontalCenterPos = horizontalCenter - popoverWidth / 2;
304
- const rightPos = containerWindow.width - popoverWidth - (marginThreshold + ((_anchorRect4 = anchorRect) === null || _anchorRect4 === void 0 ? void 0 : _anchorRect4.width) + arrowSize); // Check if the vertical axis needs shifting
301
+ const rightPos = ((_anchorRect4 = anchorRect) === null || _anchorRect4 === void 0 ? void 0 : _anchorRect4.left) - (popoverWidth + arrowSize); // Check if the vertical axis needs shifting
305
302
 
306
303
  if (top < marginThreshold) {
307
- isOverflow = true;
308
- top = marginThreshold + topPos > containerWindow.height ? verticalCenterPos : marginThreshold + topPos;
304
+ if (topPos > heightThreshold) {
305
+ top = verticalCenterPos;
306
+ newDirectionObject = getDirectionPopover('center');
307
+ aPosition = '';
308
+ } else {
309
+ top = topPos;
310
+ newDirectionObject = getDirectionPopover('bottom');
311
+ aPosition = getArrowPosition(newDirectionObject.anchorOrigin, newDirectionObject.transformOrigin, translate);
312
+ }
309
313
  } else if (top + popoverHeight > containerWindow.height) {
310
- isOverflow = true;
311
- top = bottomPos < bottomOfAnchor && bottomPos < marginThreshold ? verticalCenterPos : bottomPos;
314
+ if (bottomPos < bottomOfAnchor && bottomPos < marginThreshold) {
315
+ top = verticalCenterPos;
316
+ newDirectionObject = getDirectionPopover('center');
317
+ aPosition = '';
318
+ } else {
319
+ top = bottomPos;
320
+ newDirectionObject = getDirectionPopover('top');
321
+ aPosition = getArrowPosition(newDirectionObject.anchorOrigin, newDirectionObject.transformOrigin, translate);
322
+ }
312
323
  } // Check if the horizontal axis needs shifting
313
324
 
314
325
 
315
326
  if (left < marginThreshold) {
316
- isOverflow = true;
317
- left = marginThreshold + leftPos + popoverWidth > containerWindow.width ? horizontalCenterPos : marginThreshold + leftPos;
327
+ if (leftPos > widthThreshold) {
328
+ left = horizontalCenterPos;
329
+ newDirectionObject = getDirectionPopover('center');
330
+ aPosition = '';
331
+ } else {
332
+ left = leftPos;
333
+ newDirectionObject = getDirectionPopover('right');
334
+ aPosition = getArrowPosition(newDirectionObject.anchorOrigin, newDirectionObject.transformOrigin, translate);
335
+ }
318
336
  } else if (left + popoverWidth > containerWindow.width) {
319
- isOverflow = true;
320
- left = rightPos < rightOfAnchor && rightPos < marginThreshold ? horizontalCenterPos : rightPos;
337
+ if (rightPos < rightOfAnchor && rightPos < marginThreshold) {
338
+ left = horizontalCenterPos;
339
+ newDirectionObject = getDirectionPopover('center');
340
+ aPosition = '';
341
+ } else {
342
+ left = rightPos;
343
+ newDirectionObject = getDirectionPopover('left');
344
+ aPosition = getArrowPosition(newDirectionObject.anchorOrigin, newDirectionObject.transformOrigin, translate);
345
+ }
321
346
  } // Get arrow's position
322
347
 
323
348
 
@@ -325,22 +350,22 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
325
350
  switch (aPosition) {
326
351
  case 'top':
327
352
  arrowPosition.left = ((_anchorRect5 = anchorRect) === null || _anchorRect5 === void 0 ? void 0 : _anchorRect5.width) / 2 + ((_anchorRect6 = anchorRect) === null || _anchorRect6 === void 0 ? void 0 : _anchorRect6.left) - arrowSize + 'px';
328
- arrowPosition[aPosition] = ((_anchorRect7 = anchorRect) === null || _anchorRect7 === void 0 ? void 0 : _anchorRect7.height) + ((_anchorRect8 = anchorRect) === null || _anchorRect8 === void 0 ? void 0 : _anchorRect8.top) + 'px';
353
+ arrowPosition.top = Math.round(top) - arrowSize + 'px';
329
354
  break;
330
355
 
331
356
  case 'bottom':
332
- arrowPosition.left = ((_anchorRect9 = anchorRect) === null || _anchorRect9 === void 0 ? void 0 : _anchorRect9.width) / 2 + ((_anchorRect10 = anchorRect) === null || _anchorRect10 === void 0 ? void 0 : _anchorRect10.left) - arrowSize + 'px';
333
- arrowPosition[aPosition] = containerWindow.height - ((_anchorRect11 = anchorRect) === null || _anchorRect11 === void 0 ? void 0 : _anchorRect11.top) + 'px';
357
+ arrowPosition.left = ((_anchorRect7 = anchorRect) === null || _anchorRect7 === void 0 ? void 0 : _anchorRect7.width) / 2 + ((_anchorRect8 = anchorRect) === null || _anchorRect8 === void 0 ? void 0 : _anchorRect8.left) - arrowSize + 'px';
358
+ arrowPosition.top = Math.round(top) + popoverHeight + 'px';
334
359
  break;
335
360
 
336
361
  case 'left':
337
- arrowPosition.top = ((_anchorRect12 = anchorRect) === null || _anchorRect12 === void 0 ? void 0 : _anchorRect12.height) / 2 + ((_anchorRect13 = anchorRect) === null || _anchorRect13 === void 0 ? void 0 : _anchorRect13.top) - arrowSize / 2 + 'px';
338
- arrowPosition[aPosition] = ((_anchorRect14 = anchorRect) === null || _anchorRect14 === void 0 ? void 0 : _anchorRect14.width) + ((_anchorRect15 = anchorRect) === null || _anchorRect15 === void 0 ? void 0 : _anchorRect15.left) - arrowSize / 2 + 'px';
362
+ arrowPosition.top = ((_anchorRect9 = anchorRect) === null || _anchorRect9 === void 0 ? void 0 : _anchorRect9.height) / 2 + ((_anchorRect10 = anchorRect) === null || _anchorRect10 === void 0 ? void 0 : _anchorRect10.top) - arrowSize / 2 + 'px';
363
+ arrowPosition.left = Math.round(left) - 1.5 * arrowSize + 'px';
339
364
  break;
340
365
 
341
366
  case 'right':
342
- arrowPosition.top = ((_anchorRect16 = anchorRect) === null || _anchorRect16 === void 0 ? void 0 : _anchorRect16.height) / 2 + ((_anchorRect17 = anchorRect) === null || _anchorRect17 === void 0 ? void 0 : _anchorRect17.top) - arrowSize / 2 + 'px';
343
- arrowPosition[aPosition] = ((_anchorRect18 = anchorRect) === null || _anchorRect18 === void 0 ? void 0 : _anchorRect18.width) + ((_anchorRect19 = anchorRect) === null || _anchorRect19 === void 0 ? void 0 : _anchorRect19.left) - arrowSize / 2 + 'px';
367
+ arrowPosition.top = ((_anchorRect11 = anchorRect) === null || _anchorRect11 === void 0 ? void 0 : _anchorRect11.height) / 2 + ((_anchorRect12 = anchorRect) === null || _anchorRect12 === void 0 ? void 0 : _anchorRect12.top) - arrowSize / 2 + 'px';
368
+ arrowPosition.left = Math.round(left) + popoverWidth - arrowSize / 2 + 'px';
344
369
  break;
345
370
 
346
371
  default:
@@ -350,14 +375,14 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
350
375
  if (arrowRef.current) {
351
376
  Object.assign(arrowRef.current.style, arrowPosition, {
352
377
  transform: translate.transform,
353
- display: isOverflow ? 'none' : 'block'
378
+ display: newDirectionObject === 'center' ? 'none' : 'block'
354
379
  });
355
380
  }
356
381
  }
357
382
 
358
383
  ref.current.style.top = `${Math.round(top)}px`;
359
384
  ref.current.style.left = `${Math.round(left)}px`;
360
- ref.current.style.transformOrigin = `${transformOrigin.horizontal || 'left'} ${transformOrigin.vertical || 'top'}`;
385
+ ref.current.style.transformOrigin = `${((_newDirectionObject = newDirectionObject) === null || _newDirectionObject === void 0 ? void 0 : (_newDirectionObject$t = _newDirectionObject.transformOrigin) === null || _newDirectionObject$t === void 0 ? void 0 : _newDirectionObject$t.horizontal) || ((_transformOrigin = transformOrigin) === null || _transformOrigin === void 0 ? void 0 : _transformOrigin.horizontal) || 'left'} ${((_newDirectionObject2 = newDirectionObject) === null || _newDirectionObject2 === void 0 ? void 0 : (_newDirectionObject2$ = _newDirectionObject2.transformOrigin) === null || _newDirectionObject2$ === void 0 ? void 0 : _newDirectionObject2$.vertical) || ((_transformOrigin2 = transformOrigin) === null || _transformOrigin2 === void 0 ? void 0 : _transformOrigin2.vertical) || 'top'}`;
361
386
  ref.current.style.opacity = 1;
362
387
  cb === null || cb === void 0 ? void 0 : cb();
363
388
  };
@@ -488,10 +513,10 @@ const PopoverContainerCSS = (bgColor, width, height) => css`
488
513
  ${borderRadius4px};
489
514
  ${paragraph1};
490
515
  ${parseWidthHeight(width, height)};
491
- min-width: 16px;
492
- min-height: 16px;
493
- max-width: calc(100% - 32px);
494
- max-height: calc(100% - 32px);
516
+ min-width: ${spacing([4])};
517
+ min-height: ${spacing([4])};
518
+ max-width: calc(100% - ${spacing([8])});
519
+ max-height: calc(100% - ${spacing([8])});
495
520
  transition: opacity 0.3s ease;
496
521
  pointer-events: initial;
497
522
  opacity: 0;
@@ -519,6 +544,7 @@ Popover.defaultProps = {
519
544
  clickOutsideToClose: true,
520
545
  fullScreen: false,
521
546
  height: 'max-content',
547
+ marginThreshold: spacing(4),
522
548
  pressESCToClose: true,
523
549
  style: {},
524
550
  transformOrigin: {
@@ -527,8 +553,7 @@ Popover.defaultProps = {
527
553
  },
528
554
  trigger: 'click',
529
555
  width: 'max-content',
530
- zIndex: zIndexCORE(1),
531
- marginThreshold: 16
556
+ zIndex: zIndexCORE(1)
532
557
  };
533
558
  Popover.propTypes = {
534
559
  /** If `true`, the component is shown. */
@@ -578,6 +603,9 @@ Popover.propTypes = {
578
603
  /** Height of the component. */
579
604
  height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
580
605
 
606
+ /** Specifies how close to the edge of the window the popover can appear. */
607
+ marginThreshold: PropTypes.oneOfType([PropTypes.number]),
608
+
581
609
  /** Callback fired when the component requests to be closed. */
582
610
  onClose: PropTypes.func,
583
611
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.69-beta.2",
3
+ "version": "1.3.69-beta.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",