@unbxd-ui/unbxd-react-components 0.2.142 → 0.2.143
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,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = exports.InlineModalBody = exports.InlineModalActivator = void 0;
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _react2 = require("motion/react");
|
|
9
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
@@ -33,7 +34,8 @@ var InlineModal = function InlineModal(props, ref) {
|
|
|
33
34
|
onModalStateChange = props.onModalStateChange,
|
|
34
35
|
_props$closeOnBodyCli = props.closeOnBodyClick,
|
|
35
36
|
closeOnBodyClick = _props$closeOnBodyCli === void 0 ? false : _props$closeOnBodyCli,
|
|
36
|
-
closeOnOutsideClick = props.closeOnOutsideClick
|
|
37
|
+
closeOnOutsideClick = props.closeOnOutsideClick,
|
|
38
|
+
animateBody = props.animateBody;
|
|
37
39
|
var _useState = (0, _react.useState)(propIsOpen),
|
|
38
40
|
_useState2 = _slicedToArray(_useState, 2),
|
|
39
41
|
isModalOpen = _useState2[0],
|
|
@@ -49,6 +51,64 @@ var InlineModal = function InlineModal(props, ref) {
|
|
|
49
51
|
var inlineModalRef = (0, _react.useRef)();
|
|
50
52
|
var inlineModalBodyRef = (0, _react.useRef)();
|
|
51
53
|
var isFirstRun = (0, _react.useRef)(true);
|
|
54
|
+
var activatorRef = (0, _react.useRef)(null);
|
|
55
|
+
var transformOriginRef = (0, _react.useRef)("top center");
|
|
56
|
+
var computeTransformOrigin = function computeTransformOrigin() {
|
|
57
|
+
if (activatorRef.current && inlineModalBodyRef.current) {
|
|
58
|
+
var activatorRect = activatorRef.current.getBoundingClientRect();
|
|
59
|
+
var modalRect = inlineModalBodyRef.current.getBoundingClientRect();
|
|
60
|
+
|
|
61
|
+
//to get the center point of the activator
|
|
62
|
+
var activatorCenterX = activatorRect.left + activatorRect.width / 2;
|
|
63
|
+
var activatorCenterY = activatorRect.top + activatorRect.height / 2;
|
|
64
|
+
var originX = (activatorCenterX - modalRect.left) / modalRect.width * 100;
|
|
65
|
+
var originY = (activatorCenterY - modalRect.top) / modalRect.height * 100;
|
|
66
|
+
|
|
67
|
+
//check originX and originY are valid numbers
|
|
68
|
+
if (isNaN(originX) || isNaN(originY)) {
|
|
69
|
+
return "top center";
|
|
70
|
+
}
|
|
71
|
+
return "".concat(originX, "% ").concat(originY, "%");
|
|
72
|
+
}
|
|
73
|
+
return "top center";
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//default animation of inline modal body
|
|
77
|
+
var fadeInScaleVariants = {
|
|
78
|
+
hidden: {
|
|
79
|
+
opacity: 0,
|
|
80
|
+
scale: 0.8,
|
|
81
|
+
transformOrigin: transformOriginRef.current,
|
|
82
|
+
transition: {
|
|
83
|
+
ease: "easeInOut",
|
|
84
|
+
duration: 0.1
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
visible: {
|
|
88
|
+
opacity: 1,
|
|
89
|
+
scale: 1,
|
|
90
|
+
transformOrigin: transformOriginRef.current,
|
|
91
|
+
transition: {
|
|
92
|
+
ease: "easeInOut",
|
|
93
|
+
duration: 0.1
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
exit: {
|
|
97
|
+
opacity: 0,
|
|
98
|
+
scale: 0.8,
|
|
99
|
+
transformOrigin: transformOriginRef.current,
|
|
100
|
+
transition: {
|
|
101
|
+
ease: "easeInOut",
|
|
102
|
+
duration: 0.1
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
(0, _react.useEffect)(function () {
|
|
107
|
+
if (showModalBody) {
|
|
108
|
+
var origin = computeTransformOrigin();
|
|
109
|
+
transformOriginRef.current = origin;
|
|
110
|
+
}
|
|
111
|
+
}, [showModalBody]);
|
|
52
112
|
(0, _react.useEffect)(function () {
|
|
53
113
|
if (isModalOpen !== undefined) setShowModalBody(isModalOpen);
|
|
54
114
|
}, [isModalOpen]);
|
|
@@ -137,11 +197,16 @@ var InlineModal = function InlineModal(props, ref) {
|
|
|
137
197
|
className: inlineModalClassName,
|
|
138
198
|
ref: inlineModalRef
|
|
139
199
|
}, modalCloseProps), /*#__PURE__*/_react["default"].createElement("div", _extends({}, activatorProps, {
|
|
140
|
-
className: "RCB-inline-modal-btn ".concat(activatorClassName)
|
|
141
|
-
|
|
200
|
+
className: "RCB-inline-modal-btn ".concat(activatorClassName),
|
|
201
|
+
ref: activatorRef
|
|
202
|
+
}), children[0]), /*#__PURE__*/_react["default"].createElement(_react2.AnimatePresence, null, showModalBody && /*#__PURE__*/_react["default"].createElement(_react2.motion.div, {
|
|
142
203
|
className: "RCB-inline-modal-body RCB-align-".concat(halign),
|
|
143
|
-
ref: inlineModalBodyRef
|
|
144
|
-
|
|
204
|
+
ref: inlineModalBodyRef,
|
|
205
|
+
variants: animateBody ? animateBody : fadeInScaleVariants,
|
|
206
|
+
initial: "hidden",
|
|
207
|
+
animate: "visible",
|
|
208
|
+
exit: "exit"
|
|
209
|
+
}, children[1])));
|
|
145
210
|
};
|
|
146
211
|
InlineModal = /*#__PURE__*/(0, _react.forwardRef)(InlineModal);
|
|
147
212
|
InlineModal.propTypes = {
|
|
@@ -8,6 +8,7 @@ exports["default"] = void 0;
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _react2 = require("motion/react");
|
|
11
12
|
var _excluded = ["isOpen", "onClose", "isConditionalHideEnabled"];
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
@@ -21,6 +22,32 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
21
22
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
22
23
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
23
24
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
25
|
+
var fadeInScaleVariants = {
|
|
26
|
+
hidden: {
|
|
27
|
+
opacity: 0,
|
|
28
|
+
scale: .9,
|
|
29
|
+
transition: {
|
|
30
|
+
ease: "easeInOut",
|
|
31
|
+
duration: 0.2
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
visible: {
|
|
35
|
+
opacity: 1,
|
|
36
|
+
scale: 1,
|
|
37
|
+
transition: {
|
|
38
|
+
ease: "easeInOut",
|
|
39
|
+
duration: 0.2
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
exit: {
|
|
43
|
+
opacity: 0,
|
|
44
|
+
scale: 0.8,
|
|
45
|
+
transition: {
|
|
46
|
+
ease: "easeInOut",
|
|
47
|
+
duration: 0.2
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
24
51
|
var ModalContent = function ModalContent(props) {
|
|
25
52
|
var className = props.className,
|
|
26
53
|
children = props.children,
|
|
@@ -28,11 +55,29 @@ var ModalContent = function ModalContent(props) {
|
|
|
28
55
|
titleComponent = props.titleComponent,
|
|
29
56
|
showClose = props.showClose,
|
|
30
57
|
showHeader = props.showHeader,
|
|
31
|
-
hideModal = props.hideModal
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
58
|
+
hideModal = props.hideModal,
|
|
59
|
+
animateBody = props.animateBody;
|
|
60
|
+
return /*#__PURE__*/_react["default"].createElement(_react2.motion.div, {
|
|
61
|
+
className: "RCB-modal ".concat(className),
|
|
62
|
+
initial: {
|
|
63
|
+
opacity: 0.6
|
|
64
|
+
},
|
|
65
|
+
animate: {
|
|
66
|
+
opacity: 1
|
|
67
|
+
},
|
|
68
|
+
exit: {
|
|
69
|
+
opacity: 0
|
|
70
|
+
},
|
|
71
|
+
transition: {
|
|
72
|
+
duration: 0.2,
|
|
73
|
+
ease: "easeInOut"
|
|
74
|
+
}
|
|
75
|
+
}, /*#__PURE__*/_react["default"].createElement(_react2.motion.div, {
|
|
76
|
+
className: "RCB-modal-body",
|
|
77
|
+
variants: animateBody ? animateBody : fadeInScaleVariants,
|
|
78
|
+
initial: "hidden",
|
|
79
|
+
animate: "visible",
|
|
80
|
+
exit: "exit"
|
|
36
81
|
}, showHeader && /*#__PURE__*/_react["default"].createElement("div", {
|
|
37
82
|
className: "RCB-modal-header"
|
|
38
83
|
}, /*#__PURE__*/_react["default"].createElement("span", {
|
|
@@ -91,9 +136,9 @@ var Modal = function Modal(props, ref) {
|
|
|
91
136
|
hideModal: hideModal
|
|
92
137
|
};
|
|
93
138
|
});
|
|
94
|
-
return
|
|
139
|
+
return /*#__PURE__*/_reactDom["default"].createPortal( /*#__PURE__*/_react["default"].createElement(_react2.AnimatePresence, null, isModalOpen ? /*#__PURE__*/_react["default"].createElement(ModalContent, _extends({}, restProps, {
|
|
95
140
|
hideModal: hideModal
|
|
96
|
-
})), bodyElement)
|
|
141
|
+
})) : null), bodyElement);
|
|
97
142
|
};
|
|
98
143
|
Modal = /*#__PURE__*/(0, _react.forwardRef)(Modal);
|
|
99
144
|
Modal.propTypes = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unbxd-ui/unbxd-react-components",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.143",
|
|
4
4
|
"description": "React components library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react components",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"bluebird": "^3.7.2",
|
|
42
42
|
"dequal": "^1.0.1",
|
|
43
43
|
"lodash.clonedeep": "^4.5.0",
|
|
44
|
+
"motion": "^12.0.6",
|
|
44
45
|
"postcss": "^8.4.28",
|
|
45
46
|
"react": "^16.14.0",
|
|
46
47
|
"react-dom": "^16.14.0",
|