1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
|
4 | import classNames from 'classnames';
|
5 | import events from 'dom-helpers/events';
|
6 | import ownerDocument from 'dom-helpers/ownerDocument';
|
7 | import canUseDOM from 'dom-helpers/util/inDOM';
|
8 | import getScrollbarSize from 'dom-helpers/util/scrollbarSize';
|
9 | import React from 'react';
|
10 | import BaseModal from 'react-overlays/Modal';
|
11 | import Fade from './Fade';
|
12 | import Body from './ModalBody';
|
13 | import ModalDialog from './ModalDialog';
|
14 | import Footer from './ModalFooter';
|
15 | import Header from './ModalHeader';
|
16 | import Title from './ModalTitle';
|
17 | import BootstrapModalManager from './utils/BootstrapModalManager';
|
18 | import { createBootstrapComponent } from './ThemeProvider';
|
19 | import ModalContext from './ModalContext';
|
20 | var defaultProps = {
|
21 | show: false,
|
22 | backdrop: true,
|
23 | keyboard: true,
|
24 | autoFocus: true,
|
25 | enforceFocus: true,
|
26 | restoreFocus: true,
|
27 | animation: true,
|
28 | dialogAs: ModalDialog,
|
29 | manager: new BootstrapModalManager()
|
30 | };
|
31 |
|
32 |
|
33 | function DialogTransition(props) {
|
34 | return React.createElement(Fade, props);
|
35 | }
|
36 |
|
37 | function BackdropTransition(props) {
|
38 | return React.createElement(Fade, props);
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 | var Modal =
|
44 |
|
45 | function (_React$Component) {
|
46 | _inheritsLoose(Modal, _React$Component);
|
47 |
|
48 | function Modal() {
|
49 | var _this;
|
50 |
|
51 | for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
|
52 | _args[_key] = arguments[_key];
|
53 | }
|
54 |
|
55 | _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
|
56 | _this.state = {
|
57 | style: {}
|
58 | };
|
59 | _this.modalContext = {
|
60 | onHide: function onHide() {
|
61 | return _this.props.onHide();
|
62 | }
|
63 | };
|
64 |
|
65 | _this.setModalRef = function (ref) {
|
66 | _this._modal = ref;
|
67 | };
|
68 |
|
69 | _this.handleDialogMouseDown = function () {
|
70 | _this._waitingForMouseUp = true;
|
71 | };
|
72 |
|
73 | _this.handleMouseUp = function (e) {
|
74 | if (_this._waitingForMouseUp && e.target === _this._modal.dialog) {
|
75 | _this._ignoreBackdropClick = true;
|
76 | }
|
77 |
|
78 | _this._waitingForMouseUp = false;
|
79 | };
|
80 |
|
81 | _this.handleClick = function (e) {
|
82 | if (_this._ignoreBackdropClick || e.target !== e.currentTarget) {
|
83 | _this._ignoreBackdropClick = false;
|
84 | return;
|
85 | }
|
86 |
|
87 | _this.props.onHide();
|
88 | };
|
89 |
|
90 | _this.handleEnter = function (node) {
|
91 | var _this$props;
|
92 |
|
93 | if (node) {
|
94 | node.style.display = 'block';
|
95 |
|
96 | _this.updateDialogStyle(node);
|
97 | }
|
98 |
|
99 | for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
100 | args[_key2 - 1] = arguments[_key2];
|
101 | }
|
102 |
|
103 | if (_this.props.onEnter) (_this$props = _this.props).onEnter.apply(_this$props, [node].concat(args));
|
104 | };
|
105 |
|
106 | _this.handleEntering = function (node) {
|
107 | var _this$props2;
|
108 |
|
109 | for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
110 | args[_key3 - 1] = arguments[_key3];
|
111 | }
|
112 |
|
113 | if (_this.props.onEntering) (_this$props2 = _this.props).onEntering.apply(_this$props2, [node].concat(args));
|
114 |
|
115 | events.on(window, 'resize', _this.handleWindowResize);
|
116 | };
|
117 |
|
118 | _this.handleExited = function (node) {
|
119 | var _this$props3;
|
120 |
|
121 | if (node) node.style.display = '';
|
122 |
|
123 | for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
124 | args[_key4 - 1] = arguments[_key4];
|
125 | }
|
126 |
|
127 | if (_this.props.onExited) (_this$props3 = _this.props).onExited.apply(_this$props3, args);
|
128 |
|
129 | events.off(window, 'resize', _this.handleWindowResize);
|
130 | };
|
131 |
|
132 | _this.handleWindowResize = function () {
|
133 | _this.updateDialogStyle(_this._modal.dialog);
|
134 | };
|
135 |
|
136 | _this.renderBackdrop = function (props) {
|
137 | var _this$props4 = _this.props,
|
138 | bsPrefix = _this$props4.bsPrefix,
|
139 | backdropClassName = _this$props4.backdropClassName,
|
140 | animation = _this$props4.animation;
|
141 | return React.createElement("div", _extends({}, props, {
|
142 | className: classNames(bsPrefix + "-backdrop", backdropClassName, !animation && 'show')
|
143 | }));
|
144 | };
|
145 |
|
146 | return _this;
|
147 | }
|
148 |
|
149 | var _proto = Modal.prototype;
|
150 |
|
151 | _proto.componentWillUnmount = function componentWillUnmount() {
|
152 |
|
153 | events.off(window, 'resize', this.handleWindowResize);
|
154 | };
|
155 |
|
156 | _proto.updateDialogStyle = function updateDialogStyle(node) {
|
157 | if (!canUseDOM) return;
|
158 | var manager = this.props.manager;
|
159 | var containerIsOverflowing = manager.isContainerOverflowing(this._modal);
|
160 | var modalIsOverflowing = node.scrollHeight > ownerDocument(node).documentElement.clientHeight;
|
161 | this.setState({
|
162 | style: {
|
163 | paddingRight: containerIsOverflowing && !modalIsOverflowing ? getScrollbarSize() : undefined,
|
164 | paddingLeft: !containerIsOverflowing && modalIsOverflowing ? getScrollbarSize() : undefined
|
165 | }
|
166 | });
|
167 | };
|
168 |
|
169 | _proto.render = function render() {
|
170 | var _this$props5 = this.props,
|
171 | bsPrefix = _this$props5.bsPrefix,
|
172 | className = _this$props5.className,
|
173 | style = _this$props5.style,
|
174 | dialogClassName = _this$props5.dialogClassName,
|
175 | children = _this$props5.children,
|
176 | Dialog = _this$props5.dialogAs,
|
177 | show = _this$props5.show,
|
178 | animation = _this$props5.animation,
|
179 | backdrop = _this$props5.backdrop,
|
180 | keyboard = _this$props5.keyboard,
|
181 | manager = _this$props5.manager,
|
182 | onEscapeKeyDown = _this$props5.onEscapeKeyDown,
|
183 | onShow = _this$props5.onShow,
|
184 | onHide = _this$props5.onHide,
|
185 | container = _this$props5.container,
|
186 | autoFocus = _this$props5.autoFocus,
|
187 | enforceFocus = _this$props5.enforceFocus,
|
188 | restoreFocus = _this$props5.restoreFocus,
|
189 | onEntered = _this$props5.onEntered,
|
190 | onExit = _this$props5.onExit,
|
191 | onExiting = _this$props5.onExiting,
|
192 | _ = _this$props5.onExited,
|
193 | _1 = _this$props5.onEntering,
|
194 | _6 = _this$props5.onEnter,
|
195 | _4 = _this$props5.onEntering,
|
196 | _2 = _this$props5.backdropClassName,
|
197 | props = _objectWithoutPropertiesLoose(_this$props5, ["bsPrefix", "className", "style", "dialogClassName", "children", "dialogAs", "show", "animation", "backdrop", "keyboard", "manager", "onEscapeKeyDown", "onShow", "onHide", "container", "autoFocus", "enforceFocus", "restoreFocus", "onEntered", "onExit", "onExiting", "onExited", "onEntering", "onEnter", "onEntering", "backdropClassName"]);
|
198 |
|
199 | var clickHandler = backdrop === true ? this.handleClick : null;
|
200 |
|
201 | var baseModalStyle = _extends({}, style, {}, this.state.style);
|
202 |
|
203 |
|
204 | if (!animation) baseModalStyle.display = 'block';
|
205 | return React.createElement(ModalContext.Provider, {
|
206 | value: this.modalContext
|
207 | }, React.createElement(BaseModal, {
|
208 | show: show,
|
209 | backdrop: backdrop,
|
210 | container: container,
|
211 | keyboard: keyboard,
|
212 | autoFocus: autoFocus,
|
213 | enforceFocus: enforceFocus,
|
214 | restoreFocus: restoreFocus,
|
215 | onEscapeKeyDown: onEscapeKeyDown,
|
216 | onShow: onShow,
|
217 | onHide: onHide,
|
218 | onEntered: onEntered,
|
219 | onExit: onExit,
|
220 | onExiting: onExiting,
|
221 | manager: manager,
|
222 | ref: this.setModalRef,
|
223 | style: baseModalStyle,
|
224 | className: classNames(className, bsPrefix),
|
225 | containerClassName: bsPrefix + "-open",
|
226 | transition: animation ? DialogTransition : undefined,
|
227 | backdropTransition: animation ? BackdropTransition : undefined,
|
228 | renderBackdrop: this.renderBackdrop,
|
229 | onClick: clickHandler,
|
230 | onMouseUp: this.handleMouseUp,
|
231 | onEnter: this.handleEnter,
|
232 | onEntering: this.handleEntering,
|
233 | onExited: this.handleExited
|
234 | }, React.createElement(Dialog, _extends({}, props, {
|
235 | onMouseDown: this.handleDialogMouseDown,
|
236 | className: dialogClassName
|
237 | }), children)));
|
238 | };
|
239 |
|
240 | return Modal;
|
241 | }(React.Component);
|
242 |
|
243 | Modal.defaultProps = defaultProps;
|
244 | var DecoratedModal = createBootstrapComponent(Modal, 'modal');
|
245 | DecoratedModal.Body = Body;
|
246 | DecoratedModal.Header = Header;
|
247 | DecoratedModal.Title = Title;
|
248 | DecoratedModal.Footer = Footer;
|
249 | DecoratedModal.Dialog = ModalDialog;
|
250 | DecoratedModal.TRANSITION_DURATION = 300;
|
251 | DecoratedModal.BACKDROP_TRANSITION_DURATION = 150;
|
252 | export default DecoratedModal; |
\ | No newline at end of file |