1 | import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
|
3 | import _assertThisInitialized from "@babel/runtime-corejs2/helpers/esm/assertThisInitialized";
|
4 | import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
|
5 | import classNames from 'classnames';
|
6 | import events from 'dom-helpers/events';
|
7 | import ownerDocument from 'dom-helpers/ownerDocument';
|
8 | import canUseDOM from 'dom-helpers/util/inDOM';
|
9 | import getScrollbarSize from 'dom-helpers/util/scrollbarSize';
|
10 | import React from 'react';
|
11 | import PropTypes from 'prop-types';
|
12 | import ReactDOM from 'react-dom';
|
13 | import BaseModal from 'react-overlays/lib/Modal';
|
14 | import isOverflowing from 'react-overlays/lib/utils/isOverflowing';
|
15 | import elementType from 'prop-types-extra/lib/elementType';
|
16 | import Fade from './Fade';
|
17 | import Body from './ModalBody';
|
18 | import ModalDialog from './ModalDialog';
|
19 | import Footer from './ModalFooter';
|
20 | import Header from './ModalHeader';
|
21 | import Title from './ModalTitle';
|
22 | import { bsClass, bsSizes, prefix } from './utils/bootstrapUtils';
|
23 | import createChainedFunction from './utils/createChainedFunction';
|
24 | import splitComponentProps from './utils/splitComponentProps';
|
25 | import { Size } from './utils/StyleConfig';
|
26 |
|
27 | var propTypes = _extends({}, BaseModal.propTypes, ModalDialog.propTypes, {
|
28 | |
29 |
|
30 |
|
31 |
|
32 | backdrop: PropTypes.oneOf(['static', true, false]),
|
33 |
|
34 | |
35 |
|
36 |
|
37 |
|
38 | backdropClassName: PropTypes.string,
|
39 |
|
40 | |
41 |
|
42 |
|
43 | keyboard: PropTypes.bool,
|
44 |
|
45 | |
46 |
|
47 |
|
48 | animation: PropTypes.bool,
|
49 |
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 | dialogComponentClass: elementType,
|
56 |
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | autoFocus: PropTypes.bool,
|
64 |
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 | enforceFocus: PropTypes.bool,
|
71 |
|
72 | |
73 |
|
74 |
|
75 |
|
76 | restoreFocus: PropTypes.bool,
|
77 |
|
78 | |
79 |
|
80 |
|
81 | show: PropTypes.bool,
|
82 |
|
83 | |
84 |
|
85 |
|
86 |
|
87 | onHide: PropTypes.func,
|
88 |
|
89 | |
90 |
|
91 |
|
92 | onEnter: PropTypes.func,
|
93 |
|
94 | |
95 |
|
96 |
|
97 | onEntering: PropTypes.func,
|
98 |
|
99 | |
100 |
|
101 |
|
102 | onEntered: PropTypes.func,
|
103 |
|
104 | |
105 |
|
106 |
|
107 | onExit: PropTypes.func,
|
108 |
|
109 | |
110 |
|
111 |
|
112 | onExiting: PropTypes.func,
|
113 |
|
114 | |
115 |
|
116 |
|
117 | onExited: PropTypes.func,
|
118 |
|
119 | |
120 |
|
121 |
|
122 | container: BaseModal.propTypes.container
|
123 | });
|
124 |
|
125 | var defaultProps = _extends({}, BaseModal.defaultProps, {
|
126 | animation: true,
|
127 | dialogComponentClass: ModalDialog
|
128 | });
|
129 |
|
130 | var childContextTypes = {
|
131 | $bs_modal: PropTypes.shape({
|
132 | onHide: PropTypes.func
|
133 | })
|
134 | };
|
135 |
|
136 |
|
137 | function DialogTransition(props) {
|
138 | return React.createElement(Fade, _extends({}, props, {
|
139 | timeout: Modal.TRANSITION_DURATION
|
140 | }));
|
141 | }
|
142 |
|
143 | function BackdropTransition(props) {
|
144 | return React.createElement(Fade, _extends({}, props, {
|
145 | timeout: Modal.BACKDROP_TRANSITION_DURATION
|
146 | }));
|
147 | }
|
148 |
|
149 |
|
150 |
|
151 | var Modal =
|
152 |
|
153 | function (_React$Component) {
|
154 | _inheritsLoose(Modal, _React$Component);
|
155 |
|
156 | function Modal(props, context) {
|
157 | var _this;
|
158 |
|
159 | _this = _React$Component.call(this, props, context) || this;
|
160 | _this.handleEntering = _this.handleEntering.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
161 | _this.handleExited = _this.handleExited.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
162 | _this.handleWindowResize = _this.handleWindowResize.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
163 | _this.handleDialogClick = _this.handleDialogClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
164 | _this.setModalRef = _this.setModalRef.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
165 | _this.state = {
|
166 | style: {}
|
167 | };
|
168 | return _this;
|
169 | }
|
170 |
|
171 | var _proto = Modal.prototype;
|
172 |
|
173 | _proto.getChildContext = function getChildContext() {
|
174 | return {
|
175 | $bs_modal: {
|
176 | onHide: this.props.onHide
|
177 | }
|
178 | };
|
179 | };
|
180 |
|
181 | _proto.componentWillUnmount = function componentWillUnmount() {
|
182 |
|
183 | this.handleExited();
|
184 | };
|
185 |
|
186 | _proto.setModalRef = function setModalRef(ref) {
|
187 | this._modal = ref;
|
188 | };
|
189 |
|
190 | _proto.handleDialogClick = function handleDialogClick(e) {
|
191 | if (e.target !== e.currentTarget) {
|
192 | return;
|
193 | }
|
194 |
|
195 | this.props.onHide();
|
196 | };
|
197 |
|
198 | _proto.handleEntering = function handleEntering() {
|
199 |
|
200 | events.on(window, 'resize', this.handleWindowResize);
|
201 | this.updateStyle();
|
202 | };
|
203 |
|
204 | _proto.handleExited = function handleExited() {
|
205 |
|
206 | events.off(window, 'resize', this.handleWindowResize);
|
207 | };
|
208 |
|
209 | _proto.handleWindowResize = function handleWindowResize() {
|
210 | this.updateStyle();
|
211 | };
|
212 |
|
213 | _proto.updateStyle = function updateStyle() {
|
214 | if (!canUseDOM) {
|
215 | return;
|
216 | }
|
217 |
|
218 | var dialogNode = this._modal.getDialogElement();
|
219 |
|
220 | var dialogHeight = dialogNode.scrollHeight;
|
221 | var document = ownerDocument(dialogNode);
|
222 | var bodyIsOverflowing = isOverflowing(ReactDOM.findDOMNode(this.props.container || document.body));
|
223 | var modalIsOverflowing = dialogHeight > document.documentElement.clientHeight;
|
224 | this.setState({
|
225 | style: {
|
226 | paddingRight: bodyIsOverflowing && !modalIsOverflowing ? getScrollbarSize() : undefined,
|
227 | paddingLeft: !bodyIsOverflowing && modalIsOverflowing ? getScrollbarSize() : undefined
|
228 | }
|
229 | });
|
230 | };
|
231 |
|
232 | _proto.render = function render() {
|
233 | var _this$props = this.props,
|
234 | backdrop = _this$props.backdrop,
|
235 | backdropClassName = _this$props.backdropClassName,
|
236 | animation = _this$props.animation,
|
237 | show = _this$props.show,
|
238 | Dialog = _this$props.dialogComponentClass,
|
239 | className = _this$props.className,
|
240 | style = _this$props.style,
|
241 | children = _this$props.children,
|
242 | onEntering = _this$props.onEntering,
|
243 | onExited = _this$props.onExited,
|
244 | props = _objectWithoutPropertiesLoose(_this$props, ["backdrop", "backdropClassName", "animation", "show", "dialogComponentClass", "className", "style", "children", "onEntering", "onExited"]);
|
245 |
|
246 | var _splitComponentProps = splitComponentProps(props, BaseModal),
|
247 | baseModalProps = _splitComponentProps[0],
|
248 | dialogProps = _splitComponentProps[1];
|
249 |
|
250 | var inClassName = show && !animation && 'in';
|
251 | return React.createElement(BaseModal, _extends({}, baseModalProps, {
|
252 | ref: this.setModalRef,
|
253 | show: show,
|
254 | containerClassName: prefix(props, 'open'),
|
255 | transition: animation ? DialogTransition : undefined,
|
256 | backdrop: backdrop,
|
257 | backdropTransition: animation ? BackdropTransition : undefined,
|
258 | backdropClassName: classNames(prefix(props, 'backdrop'), backdropClassName, inClassName),
|
259 | onEntering: createChainedFunction(onEntering, this.handleEntering),
|
260 | onExited: createChainedFunction(onExited, this.handleExited)
|
261 | }), React.createElement(Dialog, _extends({}, dialogProps, {
|
262 | style: _extends({}, this.state.style, style),
|
263 | className: classNames(className, inClassName),
|
264 | onClick: backdrop === true ? this.handleDialogClick : null
|
265 | }), children));
|
266 | };
|
267 |
|
268 | return Modal;
|
269 | }(React.Component);
|
270 |
|
271 | Modal.propTypes = propTypes;
|
272 | Modal.defaultProps = defaultProps;
|
273 | Modal.childContextTypes = childContextTypes;
|
274 | Modal.Body = Body;
|
275 | Modal.Header = Header;
|
276 | Modal.Title = Title;
|
277 | Modal.Footer = Footer;
|
278 | Modal.Dialog = ModalDialog;
|
279 | Modal.TRANSITION_DURATION = 300;
|
280 | Modal.BACKDROP_TRANSITION_DURATION = 150;
|
281 | export default bsClass('modal', bsSizes([Size.LARGE, Size.SMALL], Modal)); |
\ | No newline at end of file |