diginet-core-ui 1.3.69-beta.1 → 1.3.69-beta.4
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.
|
@@ -6,7 +6,7 @@ import { createPortal } from 'react-dom';
|
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { jsx, css } from '@emotion/core';
|
|
8
8
|
import OptionWrapper from '../others/option-wrapper';
|
|
9
|
-
import { borderRadius4px, displayBlock, flexCol, overflowAuto, parseWidthHeight, positionAbsolute, positionRelative } from '../../styles/general';
|
|
9
|
+
import { borderRadius4px, displayBlock, flexCol, overflowAuto, parseWidthHeight, positionAbsolute, positionFixed, positionRelative } from '../../styles/general';
|
|
10
10
|
import theme from '../../theme/settings';
|
|
11
11
|
import { classNames, refType as ref } from '../../utils';
|
|
12
12
|
const {
|
|
@@ -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,
|
|
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
|
-
|
|
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
|
|
290
|
+
|
|
296
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.
|
|
295
|
+
const topPos = ((_anchorRect = anchorRect) === null || _anchorRect === void 0 ? void 0 : _anchorRect.bottom) + arrowSize;
|
|
299
296
|
const verticalCenterPos = verticalCenter - popoverHeight / 2;
|
|
300
|
-
const bottomPos =
|
|
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.
|
|
299
|
+
const leftPos = ((_anchorRect3 = anchorRect) === null || _anchorRect3 === void 0 ? void 0 : _anchorRect3.right) + arrowSize;
|
|
303
300
|
const horizontalCenterPos = horizontalCenter - popoverWidth / 2;
|
|
304
|
-
const rightPos =
|
|
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
|
-
|
|
308
|
-
|
|
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
|
-
|
|
311
|
-
|
|
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
|
-
|
|
317
|
-
|
|
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
|
-
|
|
320
|
-
|
|
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
|
|
353
|
+
arrowPosition.top = Math.round(top) - arrowSize + 'px';
|
|
329
354
|
break;
|
|
330
355
|
|
|
331
356
|
case 'bottom':
|
|
332
|
-
arrowPosition.left = ((
|
|
333
|
-
arrowPosition
|
|
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 = ((
|
|
338
|
-
arrowPosition
|
|
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 = ((
|
|
343
|
-
arrowPosition
|
|
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:
|
|
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
|
};
|
|
@@ -430,7 +455,10 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
430
455
|
instance: {
|
|
431
456
|
show: el => !openState && el ? updatePositionPopover(el, onOpenPopover()) : onOpenPopover(),
|
|
432
457
|
close: () => onClosePopover(),
|
|
433
|
-
setPosition: el => updatePositionPopover(el)
|
|
458
|
+
setPosition: el => updatePositionPopover(el),
|
|
459
|
+
__proto__: {
|
|
460
|
+
hide: () => onClosePopover()
|
|
461
|
+
}
|
|
434
462
|
},
|
|
435
463
|
show: el => !openState && el ? updatePositionPopover(el, onOpenPopover()) : onOpenPopover(),
|
|
436
464
|
close: () => onClosePopover(),
|
|
@@ -472,7 +500,7 @@ const Popover = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
472
500
|
}));
|
|
473
501
|
|
|
474
502
|
const PortalPopoverCSS = (zIndex, fullScreen) => css`
|
|
475
|
-
${
|
|
503
|
+
${positionFixed};
|
|
476
504
|
z-index: ${zIndex};
|
|
477
505
|
pointer-events: ${fullScreen ? 'initial' : 'none'};
|
|
478
506
|
inset: 0;
|
|
@@ -485,10 +513,10 @@ const PopoverContainerCSS = (bgColor, width, height) => css`
|
|
|
485
513
|
${borderRadius4px};
|
|
486
514
|
${paragraph1};
|
|
487
515
|
${parseWidthHeight(width, height)};
|
|
488
|
-
min-width:
|
|
489
|
-
min-height:
|
|
490
|
-
max-width: calc(100% -
|
|
491
|
-
max-height: calc(100% -
|
|
516
|
+
min-width: ${spacing([4])};
|
|
517
|
+
min-height: ${spacing([4])};
|
|
518
|
+
max-width: calc(100% - ${spacing([8])});
|
|
519
|
+
max-height: calc(100% - ${spacing([8])});
|
|
492
520
|
transition: opacity 0.3s ease;
|
|
493
521
|
pointer-events: initial;
|
|
494
522
|
opacity: 0;
|
|
@@ -516,6 +544,7 @@ Popover.defaultProps = {
|
|
|
516
544
|
clickOutsideToClose: true,
|
|
517
545
|
fullScreen: false,
|
|
518
546
|
height: 'max-content',
|
|
547
|
+
marginThreshold: spacing(4),
|
|
519
548
|
pressESCToClose: true,
|
|
520
549
|
style: {},
|
|
521
550
|
transformOrigin: {
|
|
@@ -524,8 +553,7 @@ Popover.defaultProps = {
|
|
|
524
553
|
},
|
|
525
554
|
trigger: 'click',
|
|
526
555
|
width: 'max-content',
|
|
527
|
-
zIndex: zIndexCORE(1)
|
|
528
|
-
marginThreshold: 16
|
|
556
|
+
zIndex: zIndexCORE(1)
|
|
529
557
|
};
|
|
530
558
|
Popover.propTypes = {
|
|
531
559
|
/** If `true`, the component is shown. */
|
|
@@ -575,6 +603,9 @@ Popover.propTypes = {
|
|
|
575
603
|
/** Height of the component. */
|
|
576
604
|
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
577
605
|
|
|
606
|
+
/** Specifies how close to the edge of the window the popover can appear. */
|
|
607
|
+
marginThreshold: PropTypes.oneOfType([PropTypes.number]),
|
|
608
|
+
|
|
578
609
|
/** Callback fired when the component requests to be closed. */
|
|
579
610
|
onClose: PropTypes.func,
|
|
580
611
|
|
package/package.json
CHANGED
package/utils/sb-teamplate.js
CHANGED