This repository has been archived by the owner on Oct 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Modal.js
158 lines (137 loc) · 6.78 KB
/
Modal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _reactModal = require("react-modal");
var _reactModal2 = _interopRequireDefault(_reactModal);
var _reactCustomScrollbars = require("react-custom-scrollbars");
var _dnnSvgIcons = require("dnn-svg-icons");
require("./style.less");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Modal = function (_Component) {
_inherits(Modal, _Component);
function Modal() {
_classCallCheck(this, Modal);
return _possibleConstructorReturn(this, (Modal.__proto__ || Object.getPrototypeOf(Modal)).apply(this, arguments));
}
_createClass(Modal, [{
key: "getScrollbarStyle",
value: function getScrollbarStyle(props) {
return {
width: "100%",
height: props.header ? "calc(100% - 55px)" : "100%",
boxSizing: "border-box",
padding: "25px 30px"
};
}
}, {
key: "getModalStyles",
value: function getModalStyles(props) {
var modalWidth = props.modalWidth;
var modalTopMargin = props.modalTopMargin;
if (document.getElementsByClassName("socialpanel") && document.getElementsByClassName("socialpanel").length > 0 && !props.modalWidth) {
modalWidth = document.getElementsByClassName("socialpanel")[0].offsetWidth;
}
if (document.getElementsByClassName("dnn-persona-bar-page-header") && document.getElementsByClassName("dnn-persona-bar-page-header").length > 0 && !props.modalHeight) {
modalTopMargin = document.getElementsByClassName("dnn-persona-bar-page-header")[0].offsetHeight;
}
return props.style || {
overlay: {
zIndex: "99999",
backgroundColor: "rgba(0,0,0,0.6)"
},
content: {
top: modalTopMargin + props.dialogVerticalMargin,
left: props.dialogHorizontalMargin + 85,
padding: 0,
borderRadius: 0,
border: "none",
width: modalWidth - props.dialogHorizontalMargin * 2,
height: props.modalHeight || "60%",
backgroundColor: "#FFFFFF",
position: "absolute",
userSelect: "none",
WebkitUserSelect: "none",
MozUserSelect: "none",
MsUserSelect: "none",
boxSizing: "border-box"
}
};
}
/*eslint-disable react/no-danger*/
}, {
key: "render",
value: function render() {
var props = this.props;
var modalStyles = this.getModalStyles(props);
var scrollBarStyle = this.getScrollbarStyle(props);
return _react2.default.createElement(
_reactModal2.default,
{
isOpen: props.isOpen,
onRequestClose: props.onRequestClose,
onAfterOpen: props.onAfterOpen,
closeTimeoutMS: props.closeTimeoutMS,
shouldCloseOnOverlayClick: props.shouldCloseOnOverlayClick,
style: modalStyles },
props.header && _react2.default.createElement(
"div",
{ className: "modal-header" },
_react2.default.createElement(
"h3",
null,
props.header
),
props.headerChildren,
_react2.default.createElement("div", {
className: "close-modal-button",
dangerouslySetInnerHTML: { __html: _dnnSvgIcons.XThinIcon },
onClick: props.onRequestClose })
),
_react2.default.createElement(
_reactCustomScrollbars.Scrollbars,
{ style: scrollBarStyle },
_react2.default.createElement(
"div",
{ style: props.contentStyle },
props.children
)
)
);
}
}]);
return Modal;
}(_react.Component);
Modal.propTypes = {
isOpen: _react.PropTypes.bool,
style: _react.PropTypes.object,
onRequestClose: _react.PropTypes.func,
children: _react.PropTypes.node,
dialogVerticalMargin: _react.PropTypes.number,
dialogHorizontalMargin: _react.PropTypes.number,
modalWidth: _react.PropTypes.number,
modalHeight: _react.PropTypes.number,
modalTopMargin: _react.PropTypes.number,
header: _react.PropTypes.string,
headerChildren: _react.PropTypes.node,
contentStyle: _react.PropTypes.object,
onAfterOpen: _react.PropTypes.func,
closeTimeoutMS: _react.PropTypes.number,
shouldCloseOnOverlayClick: _react.PropTypes.bool
};
Modal.defaultProps = {
modalWidth: 861,
modalTopMargin: 100,
dialogVerticalMargin: 25,
dialogHorizontalMargin: 30,
contentStyle: { padding: "25px 30px" },
shouldCloseOnOverlayClick: true
};
exports.default = Modal;
//# sourceMappingURL=Modal.js.map