@jdcfe/yep-react
Version:
一套移动端的React组件库
108 lines (86 loc) • 3.84 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
/**
* Created by zhaohongyang1 on 18-4-26.
*/
import * as React from 'react';
import classNames from 'classnames';
import fixMask from './fixMask';
import { createPortal } from 'react-dom';
/**
* screen mask, use in `Dialog`, `ActionSheet`, `Popup`.
*
*/
var Mask = /*#__PURE__*/function (_React$PureComponent) {
_inherits(Mask, _React$PureComponent);
var _super = _createSuper(Mask);
function Mask() {
var _this;
_classCallCheck(this, Mask);
_this = _super.apply(this, arguments);
_this.destroy = function () {
// Use regex to prevent matching `mask-open` as part of a different class, e.g. `my-mask-opened`
var classes = document.body.className.replace(/(^| )mask-open( |$)/, ' ');
document.body.className = classNames(classes).trim();
};
_this.show = function () {
var classes = document.body.className;
document.body.className = classNames(classes, 'mask-open');
};
return _this;
}
_createClass(Mask, [{
key: "componentDidMount",
value: function componentDidMount() {
this.show();
fixMask();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.destroy();
}
}, {
key: "render",
value: function render() {
var _classNames;
var _a = this.props,
transparent = _a.transparent,
className = _a.className,
prefixCls = _a.prefixCls,
usePortal = _a.usePortal,
others = __rest(_a, ["transparent", "className", "prefixCls", "usePortal"]);
var clz = classNames((_classNames = {}, _defineProperty(_classNames, prefixCls, !transparent), _defineProperty(_classNames, "".concat(prefixCls, "_transparent"), transparent), _classNames), className);
var content = /*#__PURE__*/React.createElement("div", _extends({
className: clz
}, others));
if (usePortal) {
return /*#__PURE__*/createPortal(content, document.body);
}
return content;
}
}]);
return Mask;
}(React.PureComponent);
export { Mask as default };
Mask.defaultProps = {
prefixCls: 'Yep-mask',
transparent: false
};