@zohodesk/components 1.4.4 → 1.4.6
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 +25 -0
- package/es/AppContainer/AppContainer.js +1 -1
- 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/Popup.js +196 -92
- package/es/Popup/Registry.js +35 -0
- package/es/Popup/viewPort.js +15 -16
- package/es/Provider/Config.js +4 -1
- package/es/RippleEffect/RippleEffect.module.css +3 -2
- package/es/css.js +4 -4
- package/lib/AppContainer/AppContainer.js +1 -1
- 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/Popup.js +265 -147
- package/lib/Popup/Registry.js +45 -0
- package/lib/Popup/viewPort.js +15 -16
- package/lib/Provider/Config.js +4 -1
- package/lib/RippleEffect/RippleEffect.module.css +3 -2
- package/lib/css.js +4 -4
- package/package.json +11 -10
- package/result.json +1 -1
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;
|