UNPKG

8.38 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _react = _interopRequireWildcard(require("react"));
9
10var _propTypes = _interopRequireDefault(require("prop-types"));
11
12var _withStyles = require("../helpers/withStyles");
13
14var _reactWithStyles = require("react-with-styles");
15
16var _Blanket = _interopRequireDefault(require("./Blanket"));
17
18var _FlatButton = _interopRequireDefault(require("./FlatButton"));
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
23
24function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
25
26function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27
28function _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); } }
29
30function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
31
32function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
33
34function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
36function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
37
38function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
39
40function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
41
42function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
43
44function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
45
46var propTypes = _objectSpread({}, _reactWithStyles.withStylesPropTypes, {
47 children: _propTypes.default.any.isRequired,
48 flex: _propTypes.default.bool,
49 fullHeight: _propTypes.default.bool,
50 fullScreen: _propTypes.default.bool,
51 global: _propTypes.default.bool,
52 large: _propTypes.default.bool,
53 micro: _propTypes.default.bool,
54 noPadding: _propTypes.default.bool,
55 onClickBlanket: _propTypes.default.func,
56 onClose: _propTypes.default.func,
57 small: _propTypes.default.bool,
58 visible: _propTypes.default.bool,
59 xlarge: _propTypes.default.bool
60});
61
62var Modal =
63/*#__PURE__*/
64function (_Component) {
65 _inherits(Modal, _Component);
66
67 function Modal() {
68 _classCallCheck(this, Modal);
69
70 return _possibleConstructorReturn(this, _getPrototypeOf(Modal).apply(this, arguments));
71 }
72
73 _createClass(Modal, [{
74 key: "render",
75 value: function render() {
76 var _this$props = this.props,
77 css = _this$props.css,
78 children = _this$props.children,
79 flex = _this$props.flex,
80 fullHeight = _this$props.fullHeight,
81 fullScreen = _this$props.fullScreen,
82 global = _this$props.global,
83 large = _this$props.large,
84 micro = _this$props.micro,
85 noPadding = _this$props.noPadding,
86 onClickBlanket = _this$props.onClickBlanket,
87 onClose = _this$props.onClose,
88 removeCloseButton = _this$props.removeCloseButton,
89 small = _this$props.small,
90 styles = _this$props.styles,
91 visible = _this$props.visible,
92 xlarge = _this$props.xlarge;
93 return visible ? _react.default.createElement(_react.Fragment, null, _react.default.createElement("div", css(styles.container, fullScreen && styles.container_fullScreen), _react.default.createElement("div", css(styles.modal, flex && styles.modal_flex, fullHeight && styles.modal_fullHeight, !fullScreen && !small && !large && !micro && styles.modal_default, fullScreen && styles.modal_fullScreen, large && styles.modal_large, xlarge && styles.modal_xlarge, noPadding && styles.noPadding), !removeCloseButton && _react.default.createElement("div", css(styles.closeButton), _react.default.createElement(_FlatButton.default, {
94 transparent: true,
95 icon: "error",
96 onClick: function onClick() {
97 return onClose && onClose();
98 }
99 })), children)), _react.default.createElement(_Blanket.default, {
100 global: global,
101 visible: true,
102 onClick: function onClick() {
103 return onClickBlanket ? onClickBlanket() : onClose ? onClose() : null;
104 }
105 })) : null;
106 }
107 }]);
108
109 return Modal;
110}(_react.Component);
111
112var ModalWithStyles = (0, _withStyles.withStyles)(function (_ref) {
113 var breakpoint = _ref.breakpoint,
114 color = _ref.color,
115 units = _ref.units,
116 radius = _ref.radius,
117 shadow = _ref.shadow;
118 return {
119 container: {
120 position: 'absolute',
121 top: 0,
122 right: 0,
123 bottom: 0,
124 left: 0,
125 height: '100vh',
126 width: '100vw',
127 overflow: 'auto',
128 boxSizing: 'border-box'
129 },
130 container_fullScreen: {
131 padding: 0,
132 margin: 0,
133 width: '100vw'
134 },
135 modal: _objectSpread({
136 position: 'absolute',
137 zIndex: 999,
138 background: color.white,
139 left: '50%',
140 boxSizing: 'border-box',
141 transform: 'translate(-50%, 0)',
142 width: "calc(100% - ".concat(units(2), "px)"),
143 borderRadius: radius,
144 borderColor: color.gray,
145 borderWidth: 1,
146 borderStyle: 'solid',
147 padding: units(1.5),
148 marginTop: units(1.5)
149 }, shadow.level2),
150 modal_default: {
151 maxWidth: units(30)
152 },
153 modal_flex: {
154 display: 'flex',
155 flexDirection: 'column'
156 },
157 modal_large: {
158 maxWidth: units(64)
159 },
160 modal_xlarge: {
161 maxWidth: units(96)
162 },
163 modal_fullScreen: {
164 width: 'unset',
165 margin: 0,
166 top: 0,
167 right: 0,
168 bottom: 0,
169 left: 0,
170 transform: 'unset',
171 borderRadius: 0,
172 border: 0
173 },
174 modal_fullHeight: _defineProperty({
175 minHeight: "calc(100% - ".concat(units(3), "px)")
176 }, breakpoint.large, {
177 maxHeight: "calc(100% - ".concat(units(3), "px)")
178 }),
179 closeButton: {
180 position: 'absolute',
181 top: units(.5),
182 right: units(.5)
183 },
184 noPadding: {
185 padding: 0
186 }
187 };
188})(Modal);
189Modal.propTypes = propTypes;
190var _default = ModalWithStyles;
191exports.default = _default;
\No newline at end of file