reactlite
Version:
react minimal components
124 lines (97 loc) • 5.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
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 _class, _temp; /**
* Panel 弹窗 (置于其他层之上)
* Created by vincent on 2016/11/4.
*/
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _reactDom = require("react-dom");
var _reactDom2 = _interopRequireDefault(_reactDom);
var _Layer = require("./Layer");
var _Layer2 = _interopRequireDefault(_Layer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
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 defaultStyle = {
position: 'fixed',
top: 0,
right: 0,
left: 0,
bottom: 0,
backgroundColor: 'rgba(55, 55, 55, 0.6)'
};
var zIndexGlobal = 10000; // 弹窗 z-index 从 zIndexGlobal 开始自增 后弹出的居上层
var Dialog = (_temp = _class = function (_React$Component) {
_inherits(Dialog, _React$Component);
function Dialog() {
_classCallCheck(this, Dialog);
var _this = _possibleConstructorReturn(this, (Dialog.__proto__ || Object.getPrototypeOf(Dialog)).call(this));
_this.zIndex = zIndexGlobal++;
return _this;
}
_createClass(Dialog, [{
key: "closeButton__onClick",
value: function closeButton__onClick() {
console.log(this, this.refs.dialog);
var unmount = this.props.unmount;
unmount();
}
}, {
key: "render",
value: function render() {
var _props = this.props,
children = _props.children,
title = _props.title,
showCloseButton = _props.showCloseButton,
unmount = _props.unmount,
props = _objectWithoutProperties(_props, ["children", "title", "showCloseButton", "unmount"]);
var innerStyle = Object.assign({ zIndex: this.zIndex }, defaultStyle);
console.log("??", showCloseButton, this.props);
return _react2.default.createElement(
"div",
_extends({ ref: "dialog" }, props, { style: innerStyle }),
_react2.default.createElement(
"div",
null,
_react2.default.createElement(
"div",
null,
_react2.default.createElement(
"h1",
null,
title
),
showCloseButton && _react2.default.createElement(
"button",
{ onClick: this.closeButton__onClick.bind(this) },
"X"
)
),
_react2.default.createElement(
"div",
null,
children
)
)
);
}
}]);
return Dialog;
}(_react2.default.Component), _class.defaultProps = {
showCloseButton: true
}, _temp);
exports.default = function (props) {
var internalUnmount = void 0;
var unmount = function unmount() {
return internalUnmount();
};
internalUnmount = (0, _Layer2.default)("dialog").mount(_react2.default.createElement(Dialog, _extends({}, props, { unmount: unmount })));
return internalUnmount;
};
;