@zohodesk/components 1.4.4 → 1.4.5
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/.cli/propValidation_report.html +1 -1
- package/README.md +19 -0
- package/es/DropBox/DropBox.js +3 -3
- package/es/Modal/Modal.js +35 -14
- package/es/Modal/Portal/Portal.js +33 -0
- package/es/Modal/Portal/__tests__/Portal.spec.js +28 -0
- package/es/Modal/Portal/__tests__/__snapshots__/Portal.spec.js.snap +30 -0
- package/es/Modal/Portal/props/defaultProps.js +3 -0
- package/es/Modal/Portal/props/propTypes.js +5 -0
- package/es/Popup/viewPort.js +15 -16
- package/es/Provider/Config.js +4 -1
- package/es/RippleEffect/RippleEffect.module.css +3 -2
- package/lib/DropBox/DropBox.js +3 -3
- package/lib/Modal/Modal.js +40 -16
- package/lib/Modal/Portal/Portal.js +46 -0
- package/lib/Modal/Portal/__tests__/Portal.spec.js +37 -0
- package/lib/Modal/Portal/__tests__/__snapshots__/Portal.spec.js.snap +30 -0
- package/lib/Modal/Portal/props/defaultProps.js +10 -0
- package/lib/Modal/Portal/props/propTypes.js +16 -0
- package/lib/Popup/viewPort.js +15 -16
- package/lib/Provider/Config.js +4 -1
- package/lib/RippleEffect/RippleEffect.module.css +3 -2
- package/package.json +3 -3
- package/result.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
Dot UI is a customizable React component library built to deliver a clean, accessible, and developer-friendly UI experience. It offers a growing set of reusable components designed to align with modern design systems and streamline application development across projects.
|
|
4
4
|
|
|
5
|
+
# 1.4.5
|
|
6
|
+
|
|
7
|
+
- **Portal**
|
|
8
|
+
- Introduced the `Portal` component to act as a React portal.
|
|
9
|
+
- Supported `getPortalContainer`, `portalPrefix` from the library config.
|
|
10
|
+
|
|
11
|
+
- **Popup**
|
|
12
|
+
- Fixed the auto-repositioning issue during fixed popup resize and improved the position calculation logic.
|
|
13
|
+
|
|
14
|
+
- **Modal**
|
|
15
|
+
- Refactored to use the new `Portal` component for rendering, resolving unwanted rendering issues.
|
|
16
|
+
- Supported `getRootElement` & `portalPrefix` from the library config.
|
|
17
|
+
|
|
18
|
+
- **Dropbox**
|
|
19
|
+
- Updated to use the new `Portal` component for rendering, resolving unwanted rendering issues.
|
|
20
|
+
|
|
21
|
+
- **RippleEffect**
|
|
22
|
+
- Enhanced CSS specificity for `secondary` active background and border color variables.
|
|
23
|
+
|
|
5
24
|
# 1.4.4
|
|
6
25
|
|
|
7
26
|
- **Button** - Strikethrough effect on disabled buttons supported through `shouldStrikeThroughDisabled` prop.
|
package/es/DropBox/DropBox.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useRef, useContext } from 'react';
|
|
2
2
|
import FocusScope from '@zohodesk/a11y/es/FocusScope/FocusScope';
|
|
3
|
-
import
|
|
3
|
+
import Portal from "../Modal/Portal/Portal"; // import { getLibraryConfig } from '../Provider/Config';
|
|
4
4
|
|
|
5
5
|
import LibraryContext from "../Provider/LibraryContextInit";
|
|
6
6
|
import cssJSLogic from "./css/cssJSLogic";
|
|
@@ -62,13 +62,13 @@ export default function DropBox(props) {
|
|
|
62
62
|
...props,
|
|
63
63
|
zIndexStyle: zIndexStyle
|
|
64
64
|
});
|
|
65
|
-
return isModel && isActive ? /*#__PURE__*/React.createElement(
|
|
65
|
+
return isModel && isActive ? /*#__PURE__*/React.createElement(Portal, {
|
|
66
66
|
portalId: portalId
|
|
67
67
|
}, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
68
68
|
className: `${style.freezeLayer} ${style.freeze}`,
|
|
69
69
|
style: zIndexStyle,
|
|
70
70
|
onClick: stopPropagation
|
|
71
|
-
}), dropBoxEle)) : !isAbsolutePositioningNeeded && isActive ? /*#__PURE__*/React.createElement(
|
|
71
|
+
}), dropBoxEle)) : !isAbsolutePositioningNeeded && isActive ? /*#__PURE__*/React.createElement(Portal, {
|
|
72
72
|
portalId: portalId
|
|
73
73
|
}, /*#__PURE__*/React.createElement(React.Fragment, null, isRestrictScroll ? /*#__PURE__*/React.createElement("div", {
|
|
74
74
|
className: style.freezeLayer,
|
package/es/Modal/Modal.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**** Libraries ****/
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import ReactDOM from 'react-dom';
|
|
4
3
|
import { defaultProps } from "./props/defaultProps";
|
|
5
4
|
import { propTypes } from "./props/propTypes";
|
|
5
|
+
import Portal from "./Portal/Portal";
|
|
6
|
+
import { getLibraryConfig } from "../Provider/Config";
|
|
6
7
|
import style from "../AppContainer/AppContainer.module.css";
|
|
7
8
|
let createdPortalIds = [];
|
|
8
9
|
let newPortalPrefix = 'CPortal';
|
|
@@ -13,10 +14,13 @@ export default class Modal extends React.Component {
|
|
|
13
14
|
this.handleAddPortalId = this.handleAddPortalId.bind(this);
|
|
14
15
|
this.handleRemovePortalId = this.handleRemovePortalId.bind(this);
|
|
15
16
|
this.handleInsertPortalDiv = this.handleInsertPortalDiv.bind(this);
|
|
16
|
-
this.
|
|
17
|
+
this.setPortalDiv = this.setPortalDiv.bind(this);
|
|
18
|
+
this.getRootElement = this.getRootElement.bind(this);
|
|
19
|
+
this.getPortalPrefix = this.getPortalPrefix.bind(this);
|
|
17
20
|
this.state = {
|
|
18
21
|
isMounted: false
|
|
19
22
|
};
|
|
23
|
+
this.portalPrefix = this.getPortalPrefix();
|
|
20
24
|
this.portalId = props.portalId;
|
|
21
25
|
this.setRef = this.setRef.bind(this);
|
|
22
26
|
this.ref = null; // this.portalDiv = document.createDocumentFragment();
|
|
@@ -31,24 +35,40 @@ export default class Modal extends React.Component {
|
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
getRootElement() {
|
|
39
|
+
const getRootElement = getLibraryConfig('getRootElement');
|
|
36
40
|
|
|
37
|
-
if (
|
|
41
|
+
if (getRootElement && typeof getRootElement === 'function') {
|
|
42
|
+
const parent = getRootElement();
|
|
43
|
+
|
|
44
|
+
if (parent) {
|
|
45
|
+
return parent;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getPortalPrefix() {
|
|
53
|
+
const portalPrefix = getLibraryConfig('portalPrefix');
|
|
54
|
+
return portalPrefix !== '' ? portalPrefix : '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
setPortalDiv() {
|
|
58
|
+
const modalRoot = this.props.portalId ? document.querySelector(`[data-portal=${this.portalPrefix}${this.props.portalId}]`) : '';
|
|
59
|
+
|
|
60
|
+
if (!modalRoot) {
|
|
38
61
|
this.portalId = this.handleAddPortalId();
|
|
39
62
|
this.newModalRoot = document.createElement('div');
|
|
40
63
|
this.newModalRoot.className = style.container;
|
|
41
|
-
this.newModalRoot.setAttribute('data-portal', this.portalId);
|
|
64
|
+
this.newModalRoot.setAttribute('data-portal', `${this.portalPrefix}${this.portalId}`);
|
|
42
65
|
this.containerDiv && this.containerDiv.appendChild(this.newModalRoot);
|
|
43
|
-
this.modalRoot = this.newModalRoot;
|
|
44
66
|
}
|
|
45
|
-
|
|
46
|
-
return this.modalRoot;
|
|
47
67
|
}
|
|
48
68
|
|
|
49
69
|
componentDidMount() {
|
|
50
|
-
this.containerDiv =
|
|
51
|
-
this.
|
|
70
|
+
this.containerDiv = this.getRootElement() || document.getElementsByTagName('desk')[0] || document.getElementsByTagName('body')[0];
|
|
71
|
+
this.setPortalDiv();
|
|
52
72
|
this.setState({
|
|
53
73
|
isMounted: true
|
|
54
74
|
}, () => {
|
|
@@ -57,7 +77,6 @@ export default class Modal extends React.Component {
|
|
|
57
77
|
}
|
|
58
78
|
|
|
59
79
|
componentWillUnmount() {
|
|
60
|
-
//this.modalRoot && this.modalRoot.removeChild(this.portalDiv);
|
|
61
80
|
if (this.newModalRoot) {
|
|
62
81
|
this.containerDiv && this.containerDiv.removeChild(this.newModalRoot);
|
|
63
82
|
this.handleRemovePortalId();
|
|
@@ -129,10 +148,12 @@ export default class Modal extends React.Component {
|
|
|
129
148
|
|
|
130
149
|
if (isMounted) {
|
|
131
150
|
if (Element) {
|
|
132
|
-
return /*#__PURE__*/
|
|
151
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
|
152
|
+
portalId: `${this.portalPrefix}${this.portalId}`
|
|
153
|
+
}, /*#__PURE__*/React.createElement(Element, {
|
|
133
154
|
ref: this.setRef,
|
|
134
155
|
...elementProps
|
|
135
|
-
})
|
|
156
|
+
}));
|
|
136
157
|
}
|
|
137
158
|
|
|
138
159
|
return null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import BasePortal from '@zohodesk/dotkit/es/react/components/Portal/Portal';
|
|
3
|
+
import { getLibraryConfig } from "../../Provider/Config";
|
|
4
|
+
import { defaultProps } from "./props/defaultProps";
|
|
5
|
+
import { propTypes } from "./props/propTypes";
|
|
6
|
+
export default function Portal(_ref) {
|
|
7
|
+
let {
|
|
8
|
+
children,
|
|
9
|
+
portalId
|
|
10
|
+
} = _ref;
|
|
11
|
+
const portalPrefix = getLibraryConfig("portalPrefix");
|
|
12
|
+
|
|
13
|
+
const getPortalContainer = () => {
|
|
14
|
+
const getPortalContainer = getLibraryConfig('getPortalContainer');
|
|
15
|
+
|
|
16
|
+
if (getPortalContainer && typeof getPortalContainer === 'function') {
|
|
17
|
+
const portal = getPortalContainer();
|
|
18
|
+
|
|
19
|
+
if (portal) {
|
|
20
|
+
return portal;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return /*#__PURE__*/React.createElement(BasePortal, {
|
|
28
|
+
portalId: `${portalPrefix ? `${portalPrefix}` : ''}${portalId}`,
|
|
29
|
+
getFallbackElement: getPortalContainer
|
|
30
|
+
}, children);
|
|
31
|
+
}
|
|
32
|
+
Portal.propTypes = propTypes;
|
|
33
|
+
Portal.defaultProps = defaultProps;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, cleanup } from '@testing-library/react';
|
|
3
|
+
import Portal from "../Portal";
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
cleanup();
|
|
6
|
+
});
|
|
7
|
+
describe('Portal', () => {
|
|
8
|
+
test('rendering the defult props', () => {
|
|
9
|
+
const customPortalContainer = document.createElement('div');
|
|
10
|
+
customPortalContainer.setAttribute('data-portal', 'portal1');
|
|
11
|
+
document.body.appendChild(customPortalContainer);
|
|
12
|
+
const {
|
|
13
|
+
baseElement
|
|
14
|
+
} = render( /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", null, "Portal Div Check")));
|
|
15
|
+
expect(baseElement).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
test('renders with portalId prop', () => {
|
|
18
|
+
const customPortalContainer = document.createElement('div');
|
|
19
|
+
customPortalContainer.setAttribute('data-portal', 'customPortal');
|
|
20
|
+
document.body.appendChild(customPortalContainer);
|
|
21
|
+
const {
|
|
22
|
+
baseElement
|
|
23
|
+
} = render( /*#__PURE__*/React.createElement(Portal, {
|
|
24
|
+
portalId: "customPortal"
|
|
25
|
+
}, /*#__PURE__*/React.createElement("div", null, "Portal Content Check")));
|
|
26
|
+
expect(baseElement).toMatchSnapshot();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Portal rendering the defult props 1`] = `
|
|
4
|
+
<body>
|
|
5
|
+
<div
|
|
6
|
+
data-portal="portal1"
|
|
7
|
+
>
|
|
8
|
+
<div>
|
|
9
|
+
Portal Div Check
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
<div />
|
|
13
|
+
</body>
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
exports[`Portal renders with portalId prop 1`] = `
|
|
17
|
+
<body>
|
|
18
|
+
<div
|
|
19
|
+
data-portal="portal1"
|
|
20
|
+
/>
|
|
21
|
+
<div
|
|
22
|
+
data-portal="customPortal"
|
|
23
|
+
>
|
|
24
|
+
<div>
|
|
25
|
+
Portal Content Check
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
<div />
|
|
29
|
+
</body>
|
|
30
|
+
`;
|
package/es/Popup/viewPort.js
CHANGED
|
@@ -108,24 +108,23 @@ let viewPort = {
|
|
|
108
108
|
let paddingSpace = 5; // space between target and relative element
|
|
109
109
|
|
|
110
110
|
let arrowSize = needArrow ? 10 : 0;
|
|
111
|
-
|
|
112
|
-
rect.width = rect.width + (needArrow ? arrowSize : paddingSpace);
|
|
111
|
+
let padding = needArrow ? arrowSize : paddingSpace;
|
|
113
112
|
let arrowHorizontalBalancePx = !isAbsolute && needArrow ? 30 : 0;
|
|
114
113
|
let arrowVerticalBalancePx = !isAbsolute && needArrow ? 27 : 0;
|
|
115
|
-
let bottomOverFlow = rect.height > relativeBoxGap.bottom;
|
|
116
|
-
let topOverFlow = rect.height > relativeBoxGap.top;
|
|
117
|
-
let rightOverFlow = rect.width > relativeBoxGap.right;
|
|
118
|
-
let leftOverFlow = rect.width > relativeBoxGap.left;
|
|
119
|
-
let horizontalCenterOverFlow = rect.width / 2 > relativeBoxGap.center.right || rect.width / 2 > relativeBoxGap.center.left;
|
|
120
|
-
let verticalCenterOverFlow = rect.height / 2 > relativeBoxGap.center.top || rect.height / 2 > relativeBoxGap.center.bottom;
|
|
121
|
-
let horizontalLeftToRightOverFlow = rect.width > relativeBoxRect.width + relativeBoxGap.right;
|
|
122
|
-
let horizontalCenterToRightOverFlow = rect.width > relativeBoxGap.center.right || arrowHorizontalBalancePx > relativeBoxGap.center.left;
|
|
123
|
-
let horizontalRightToLeft = rect.width > relativeBoxRect.width + relativeBoxGap.left;
|
|
124
|
-
let horizontalCenterToLeft = rect.width > relativeBoxGap.center.left || arrowHorizontalBalancePx > relativeBoxGap.center.right;
|
|
125
|
-
let verticalTopToBottomOverFlow = rect.height > relativeBoxRect.height + relativeBoxGap.bottom;
|
|
126
|
-
let verticalCenterToBottomOverFlow = rect.height > relativeBoxGap.center.bottom || arrowVerticalBalancePx > relativeBoxGap.center.top;
|
|
127
|
-
let verticalBottomToTopOverFlow = rect.height > relativeBoxRect.height + relativeBoxGap.top;
|
|
128
|
-
let verticalCenterToTopOverFlow = rect.height > relativeBoxGap.center.top || arrowVerticalBalancePx > relativeBoxGap.center.bottom;
|
|
114
|
+
let bottomOverFlow = rect.height + padding > relativeBoxGap.bottom;
|
|
115
|
+
let topOverFlow = rect.height + padding > relativeBoxGap.top;
|
|
116
|
+
let rightOverFlow = rect.width + padding > relativeBoxGap.right;
|
|
117
|
+
let leftOverFlow = rect.width + padding > relativeBoxGap.left;
|
|
118
|
+
let horizontalCenterOverFlow = rect.width / 2 + padding > relativeBoxGap.center.right || rect.width / 2 + padding > relativeBoxGap.center.left;
|
|
119
|
+
let verticalCenterOverFlow = rect.height / 2 + padding > relativeBoxGap.center.top || rect.height / 2 + padding > relativeBoxGap.center.bottom;
|
|
120
|
+
let horizontalLeftToRightOverFlow = rect.width + padding > relativeBoxRect.width + relativeBoxGap.right;
|
|
121
|
+
let horizontalCenterToRightOverFlow = rect.width + padding > relativeBoxGap.center.right || arrowHorizontalBalancePx > relativeBoxGap.center.left;
|
|
122
|
+
let horizontalRightToLeft = rect.width + padding > relativeBoxRect.width + relativeBoxGap.left;
|
|
123
|
+
let horizontalCenterToLeft = rect.width + padding > relativeBoxGap.center.left || arrowHorizontalBalancePx > relativeBoxGap.center.right;
|
|
124
|
+
let verticalTopToBottomOverFlow = rect.height + padding > relativeBoxRect.height + relativeBoxGap.bottom;
|
|
125
|
+
let verticalCenterToBottomOverFlow = rect.height + padding > relativeBoxGap.center.bottom || arrowVerticalBalancePx > relativeBoxGap.center.top;
|
|
126
|
+
let verticalBottomToTopOverFlow = rect.height + padding > relativeBoxRect.height + relativeBoxGap.top;
|
|
127
|
+
let verticalCenterToTopOverFlow = rect.height + padding > relativeBoxGap.center.top || arrowVerticalBalancePx > relativeBoxGap.center.bottom;
|
|
129
128
|
let views = {
|
|
130
129
|
bottomCenter: !(bottomOverFlow || horizontalCenterOverFlow),
|
|
131
130
|
bottomLeftToRight: !(bottomOverFlow || horizontalLeftToRightOverFlow),
|
package/es/Provider/Config.js
CHANGED
|
@@ -8,7 +8,10 @@ let id = {
|
|
|
8
8
|
direction: 'ltr',
|
|
9
9
|
tooltipDebounce: 175,
|
|
10
10
|
getTooltipContainer: () => {},
|
|
11
|
-
autoComplete: false
|
|
11
|
+
autoComplete: false,
|
|
12
|
+
portalPrefix: '',
|
|
13
|
+
getRootElement: () => {},
|
|
14
|
+
getPortalContainer: () => {}
|
|
12
15
|
};
|
|
13
16
|
export function getLibraryConfig(key) {
|
|
14
17
|
return id[key];
|
|
@@ -100,9 +100,10 @@
|
|
|
100
100
|
{
|
|
101
101
|
background-color: var(--zdt_rippleeffect_secondary_bg);
|
|
102
102
|
}
|
|
103
|
-
.secondary.active {
|
|
103
|
+
.secondary.active, .hoverEffect:hover.secondary.active.bgHover {
|
|
104
104
|
background-color: var(--zdt_rippleeffect_secondary_active_bg);
|
|
105
105
|
}
|
|
106
|
-
.secondary.active.border
|
|
106
|
+
.secondary.active.border
|
|
107
|
+
.hoverEffect:hover.secondary.active.border {
|
|
107
108
|
border-color: var(--zdt_rippleeffect_secondary_active_border);
|
|
108
109
|
}
|
package/lib/DropBox/DropBox.js
CHANGED
|
@@ -11,7 +11,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
|
|
12
12
|
var _FocusScope = _interopRequireDefault(require("@zohodesk/a11y/es/FocusScope/FocusScope"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _Portal = _interopRequireDefault(require("../Modal/Portal/Portal"));
|
|
15
15
|
|
|
16
16
|
var _LibraryContextInit = _interopRequireDefault(require("../Provider/LibraryContextInit"));
|
|
17
17
|
|
|
@@ -90,13 +90,13 @@ function DropBox(props) {
|
|
|
90
90
|
}, props, {
|
|
91
91
|
zIndexStyle: zIndexStyle
|
|
92
92
|
}));
|
|
93
|
-
return isModel && isActive ? /*#__PURE__*/_react["default"].createElement(
|
|
93
|
+
return isModel && isActive ? /*#__PURE__*/_react["default"].createElement(_Portal["default"], {
|
|
94
94
|
portalId: portalId
|
|
95
95
|
}, /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
|
|
96
96
|
className: "".concat(_DropBoxModule["default"].freezeLayer, " ").concat(_DropBoxModule["default"].freeze),
|
|
97
97
|
style: zIndexStyle,
|
|
98
98
|
onClick: _Common.stopPropagation
|
|
99
|
-
}), dropBoxEle)) : !isAbsolutePositioningNeeded && isActive ? /*#__PURE__*/_react["default"].createElement(
|
|
99
|
+
}), dropBoxEle)) : !isAbsolutePositioningNeeded && isActive ? /*#__PURE__*/_react["default"].createElement(_Portal["default"], {
|
|
100
100
|
portalId: portalId
|
|
101
101
|
}, /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, isRestrictScroll ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
102
102
|
className: _DropBoxModule["default"].freezeLayer,
|
package/lib/Modal/Modal.js
CHANGED
|
@@ -9,12 +9,14 @@ exports["default"] = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
|
12
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
13
|
-
|
|
14
12
|
var _defaultProps = require("./props/defaultProps");
|
|
15
13
|
|
|
16
14
|
var _propTypes = require("./props/propTypes");
|
|
17
15
|
|
|
16
|
+
var _Portal = _interopRequireDefault(require("./Portal/Portal"));
|
|
17
|
+
|
|
18
|
+
var _Config = require("../Provider/Config");
|
|
19
|
+
|
|
18
20
|
var _AppContainerModule = _interopRequireDefault(require("../AppContainer/AppContainer.module.css"));
|
|
19
21
|
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -59,10 +61,13 @@ var Modal = /*#__PURE__*/function (_React$Component) {
|
|
|
59
61
|
_this.handleAddPortalId = _this.handleAddPortalId.bind(_assertThisInitialized(_this));
|
|
60
62
|
_this.handleRemovePortalId = _this.handleRemovePortalId.bind(_assertThisInitialized(_this));
|
|
61
63
|
_this.handleInsertPortalDiv = _this.handleInsertPortalDiv.bind(_assertThisInitialized(_this));
|
|
62
|
-
_this.
|
|
64
|
+
_this.setPortalDiv = _this.setPortalDiv.bind(_assertThisInitialized(_this));
|
|
65
|
+
_this.getRootElement = _this.getRootElement.bind(_assertThisInitialized(_this));
|
|
66
|
+
_this.getPortalPrefix = _this.getPortalPrefix.bind(_assertThisInitialized(_this));
|
|
63
67
|
_this.state = {
|
|
64
68
|
isMounted: false
|
|
65
69
|
};
|
|
70
|
+
_this.portalPrefix = _this.getPortalPrefix();
|
|
66
71
|
_this.portalId = props.portalId;
|
|
67
72
|
_this.setRef = _this.setRef.bind(_assertThisInitialized(_this));
|
|
68
73
|
_this.ref = null; // this.portalDiv = document.createDocumentFragment();
|
|
@@ -81,28 +86,46 @@ var Modal = /*#__PURE__*/function (_React$Component) {
|
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
}, {
|
|
84
|
-
key: "
|
|
85
|
-
value: function
|
|
86
|
-
|
|
89
|
+
key: "getRootElement",
|
|
90
|
+
value: function getRootElement() {
|
|
91
|
+
var getRootElement = (0, _Config.getLibraryConfig)('getRootElement');
|
|
92
|
+
|
|
93
|
+
if (getRootElement && typeof getRootElement === 'function') {
|
|
94
|
+
var parent = getRootElement();
|
|
95
|
+
|
|
96
|
+
if (parent) {
|
|
97
|
+
return parent;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "getPortalPrefix",
|
|
105
|
+
value: function getPortalPrefix() {
|
|
106
|
+
var portalPrefix = (0, _Config.getLibraryConfig)('portalPrefix');
|
|
107
|
+
return portalPrefix !== '' ? portalPrefix : '';
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "setPortalDiv",
|
|
111
|
+
value: function setPortalDiv() {
|
|
112
|
+
var modalRoot = this.props.portalId ? document.querySelector("[data-portal=".concat(this.portalPrefix).concat(this.props.portalId, "]")) : '';
|
|
87
113
|
|
|
88
|
-
if (!
|
|
114
|
+
if (!modalRoot) {
|
|
89
115
|
this.portalId = this.handleAddPortalId();
|
|
90
116
|
this.newModalRoot = document.createElement('div');
|
|
91
117
|
this.newModalRoot.className = _AppContainerModule["default"].container;
|
|
92
|
-
this.newModalRoot.setAttribute('data-portal', this.portalId);
|
|
118
|
+
this.newModalRoot.setAttribute('data-portal', "".concat(this.portalPrefix).concat(this.portalId));
|
|
93
119
|
this.containerDiv && this.containerDiv.appendChild(this.newModalRoot);
|
|
94
|
-
this.modalRoot = this.newModalRoot;
|
|
95
120
|
}
|
|
96
|
-
|
|
97
|
-
return this.modalRoot;
|
|
98
121
|
}
|
|
99
122
|
}, {
|
|
100
123
|
key: "componentDidMount",
|
|
101
124
|
value: function componentDidMount() {
|
|
102
125
|
var _this2 = this;
|
|
103
126
|
|
|
104
|
-
this.containerDiv =
|
|
105
|
-
this.
|
|
127
|
+
this.containerDiv = this.getRootElement() || document.getElementsByTagName('desk')[0] || document.getElementsByTagName('body')[0];
|
|
128
|
+
this.setPortalDiv();
|
|
106
129
|
this.setState({
|
|
107
130
|
isMounted: true
|
|
108
131
|
}, function () {
|
|
@@ -112,7 +135,6 @@ var Modal = /*#__PURE__*/function (_React$Component) {
|
|
|
112
135
|
}, {
|
|
113
136
|
key: "componentWillUnmount",
|
|
114
137
|
value: function componentWillUnmount() {
|
|
115
|
-
//this.modalRoot && this.modalRoot.removeChild(this.portalDiv);
|
|
116
138
|
if (this.newModalRoot) {
|
|
117
139
|
this.containerDiv && this.containerDiv.removeChild(this.newModalRoot);
|
|
118
140
|
this.handleRemovePortalId();
|
|
@@ -185,9 +207,11 @@ var Modal = /*#__PURE__*/function (_React$Component) {
|
|
|
185
207
|
|
|
186
208
|
if (isMounted) {
|
|
187
209
|
if (Element) {
|
|
188
|
-
return /*#__PURE__*/
|
|
210
|
+
return /*#__PURE__*/_react["default"].createElement(_Portal["default"], {
|
|
211
|
+
portalId: "".concat(this.portalPrefix).concat(this.portalId)
|
|
212
|
+
}, /*#__PURE__*/_react["default"].createElement(Element, _extends({
|
|
189
213
|
ref: this.setRef
|
|
190
|
-
}, elementProps))
|
|
214
|
+
}, elementProps)));
|
|
191
215
|
}
|
|
192
216
|
|
|
193
217
|
return null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = Portal;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _Portal = _interopRequireDefault(require("@zohodesk/dotkit/es/react/components/Portal/Portal"));
|
|
11
|
+
|
|
12
|
+
var _Config = require("../../Provider/Config");
|
|
13
|
+
|
|
14
|
+
var _defaultProps = require("./props/defaultProps");
|
|
15
|
+
|
|
16
|
+
var _propTypes = require("./props/propTypes");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
|
+
|
|
20
|
+
function Portal(_ref) {
|
|
21
|
+
var children = _ref.children,
|
|
22
|
+
portalId = _ref.portalId;
|
|
23
|
+
var portalPrefix = (0, _Config.getLibraryConfig)("portalPrefix");
|
|
24
|
+
|
|
25
|
+
var getPortalContainer = function getPortalContainer() {
|
|
26
|
+
var getPortalContainer = (0, _Config.getLibraryConfig)('getPortalContainer');
|
|
27
|
+
|
|
28
|
+
if (getPortalContainer && typeof getPortalContainer === 'function') {
|
|
29
|
+
var portal = getPortalContainer();
|
|
30
|
+
|
|
31
|
+
if (portal) {
|
|
32
|
+
return portal;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return /*#__PURE__*/_react["default"].createElement(_Portal["default"], {
|
|
40
|
+
portalId: "".concat(portalPrefix ? "".concat(portalPrefix) : '').concat(portalId),
|
|
41
|
+
getFallbackElement: getPortalContainer
|
|
42
|
+
}, children);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Portal.propTypes = _propTypes.propTypes;
|
|
46
|
+
Portal.defaultProps = _defaultProps.defaultProps;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = _interopRequireDefault(require("react"));
|
|
4
|
+
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
|
|
7
|
+
var _Portal = _interopRequireDefault(require("../Portal"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
|
|
11
|
+
beforeEach(function () {
|
|
12
|
+
(0, _react2.cleanup)();
|
|
13
|
+
});
|
|
14
|
+
describe('Portal', function () {
|
|
15
|
+
test('rendering the defult props', function () {
|
|
16
|
+
var customPortalContainer = document.createElement('div');
|
|
17
|
+
customPortalContainer.setAttribute('data-portal', 'portal1');
|
|
18
|
+
document.body.appendChild(customPortalContainer);
|
|
19
|
+
|
|
20
|
+
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Portal["default"], null, /*#__PURE__*/_react["default"].createElement("div", null, "Portal Div Check"))),
|
|
21
|
+
baseElement = _render.baseElement;
|
|
22
|
+
|
|
23
|
+
expect(baseElement).toMatchSnapshot();
|
|
24
|
+
});
|
|
25
|
+
test('renders with portalId prop', function () {
|
|
26
|
+
var customPortalContainer = document.createElement('div');
|
|
27
|
+
customPortalContainer.setAttribute('data-portal', 'customPortal');
|
|
28
|
+
document.body.appendChild(customPortalContainer);
|
|
29
|
+
|
|
30
|
+
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Portal["default"], {
|
|
31
|
+
portalId: "customPortal"
|
|
32
|
+
}, /*#__PURE__*/_react["default"].createElement("div", null, "Portal Content Check"))),
|
|
33
|
+
baseElement = _render2.baseElement;
|
|
34
|
+
|
|
35
|
+
expect(baseElement).toMatchSnapshot();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Portal rendering the defult props 1`] = `
|
|
4
|
+
<body>
|
|
5
|
+
<div
|
|
6
|
+
data-portal="portal1"
|
|
7
|
+
>
|
|
8
|
+
<div>
|
|
9
|
+
Portal Div Check
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
<div />
|
|
13
|
+
</body>
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
exports[`Portal renders with portalId prop 1`] = `
|
|
17
|
+
<body>
|
|
18
|
+
<div
|
|
19
|
+
data-portal="portal1"
|
|
20
|
+
/>
|
|
21
|
+
<div
|
|
22
|
+
data-portal="customPortal"
|
|
23
|
+
>
|
|
24
|
+
<div>
|
|
25
|
+
Portal Content Check
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
<div />
|
|
29
|
+
</body>
|
|
30
|
+
`;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.propTypes = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
12
|
+
var propTypes = {
|
|
13
|
+
children: _propTypes["default"].node,
|
|
14
|
+
portalId: _propTypes["default"].string
|
|
15
|
+
};
|
|
16
|
+
exports.propTypes = propTypes;
|
package/lib/Popup/viewPort.js
CHANGED
|
@@ -103,24 +103,23 @@ var viewPort = {
|
|
|
103
103
|
var paddingSpace = 5; // space between target and relative element
|
|
104
104
|
|
|
105
105
|
var arrowSize = needArrow ? 10 : 0;
|
|
106
|
-
|
|
107
|
-
rect.width = rect.width + (needArrow ? arrowSize : paddingSpace);
|
|
106
|
+
var padding = needArrow ? arrowSize : paddingSpace;
|
|
108
107
|
var arrowHorizontalBalancePx = !isAbsolute && needArrow ? 30 : 0;
|
|
109
108
|
var arrowVerticalBalancePx = !isAbsolute && needArrow ? 27 : 0;
|
|
110
|
-
var bottomOverFlow = rect.height > relativeBoxGap.bottom;
|
|
111
|
-
var topOverFlow = rect.height > relativeBoxGap.top;
|
|
112
|
-
var rightOverFlow = rect.width > relativeBoxGap.right;
|
|
113
|
-
var leftOverFlow = rect.width > relativeBoxGap.left;
|
|
114
|
-
var horizontalCenterOverFlow = rect.width / 2 > relativeBoxGap.center.right || rect.width / 2 > relativeBoxGap.center.left;
|
|
115
|
-
var verticalCenterOverFlow = rect.height / 2 > relativeBoxGap.center.top || rect.height / 2 > relativeBoxGap.center.bottom;
|
|
116
|
-
var horizontalLeftToRightOverFlow = rect.width > relativeBoxRect.width + relativeBoxGap.right;
|
|
117
|
-
var horizontalCenterToRightOverFlow = rect.width > relativeBoxGap.center.right || arrowHorizontalBalancePx > relativeBoxGap.center.left;
|
|
118
|
-
var horizontalRightToLeft = rect.width > relativeBoxRect.width + relativeBoxGap.left;
|
|
119
|
-
var horizontalCenterToLeft = rect.width > relativeBoxGap.center.left || arrowHorizontalBalancePx > relativeBoxGap.center.right;
|
|
120
|
-
var verticalTopToBottomOverFlow = rect.height > relativeBoxRect.height + relativeBoxGap.bottom;
|
|
121
|
-
var verticalCenterToBottomOverFlow = rect.height > relativeBoxGap.center.bottom || arrowVerticalBalancePx > relativeBoxGap.center.top;
|
|
122
|
-
var verticalBottomToTopOverFlow = rect.height > relativeBoxRect.height + relativeBoxGap.top;
|
|
123
|
-
var verticalCenterToTopOverFlow = rect.height > relativeBoxGap.center.top || arrowVerticalBalancePx > relativeBoxGap.center.bottom;
|
|
109
|
+
var bottomOverFlow = rect.height + padding > relativeBoxGap.bottom;
|
|
110
|
+
var topOverFlow = rect.height + padding > relativeBoxGap.top;
|
|
111
|
+
var rightOverFlow = rect.width + padding > relativeBoxGap.right;
|
|
112
|
+
var leftOverFlow = rect.width + padding > relativeBoxGap.left;
|
|
113
|
+
var horizontalCenterOverFlow = rect.width / 2 + padding > relativeBoxGap.center.right || rect.width / 2 + padding > relativeBoxGap.center.left;
|
|
114
|
+
var verticalCenterOverFlow = rect.height / 2 + padding > relativeBoxGap.center.top || rect.height / 2 + padding > relativeBoxGap.center.bottom;
|
|
115
|
+
var horizontalLeftToRightOverFlow = rect.width + padding > relativeBoxRect.width + relativeBoxGap.right;
|
|
116
|
+
var horizontalCenterToRightOverFlow = rect.width + padding > relativeBoxGap.center.right || arrowHorizontalBalancePx > relativeBoxGap.center.left;
|
|
117
|
+
var horizontalRightToLeft = rect.width + padding > relativeBoxRect.width + relativeBoxGap.left;
|
|
118
|
+
var horizontalCenterToLeft = rect.width + padding > relativeBoxGap.center.left || arrowHorizontalBalancePx > relativeBoxGap.center.right;
|
|
119
|
+
var verticalTopToBottomOverFlow = rect.height + padding > relativeBoxRect.height + relativeBoxGap.bottom;
|
|
120
|
+
var verticalCenterToBottomOverFlow = rect.height + padding > relativeBoxGap.center.bottom || arrowVerticalBalancePx > relativeBoxGap.center.top;
|
|
121
|
+
var verticalBottomToTopOverFlow = rect.height + padding > relativeBoxRect.height + relativeBoxGap.top;
|
|
122
|
+
var verticalCenterToTopOverFlow = rect.height + padding > relativeBoxGap.center.top || arrowVerticalBalancePx > relativeBoxGap.center.bottom;
|
|
124
123
|
var views = {
|
|
125
124
|
bottomCenter: !(bottomOverFlow || horizontalCenterOverFlow),
|
|
126
125
|
bottomLeftToRight: !(bottomOverFlow || horizontalLeftToRightOverFlow),
|