UNPKG

mp-colorui

Version:

MP ColorUI 是一款基于 Taro 框架并且联合 Color-UI CSS 库开发的多端 UI 组件库(支持小程序端和H5端)

344 lines (280 loc) 20.3 kB
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([["components/message/index"],{ /***/ "./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js?!./src/components/message/index.tsx?taro&type=script&parse=COMPONENT&": /*!*************************************************************************************************************************************************************!*\ !*** ./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js??ref--4-0!./src/components/message/index.tsx?taro&type=script&parse=COMPONENT& ***! \*************************************************************************************************************************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); 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 _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; var _taroWeapp = __webpack_require__(/*! @tarojs/taro-weapp */ "./node_modules/@tarojs/taro-weapp/index.js"); var _taroWeapp2 = _interopRequireDefault(_taroWeapp); __webpack_require__(/*! ./index.scss */ "./src/components/message/index.scss"); var _index = __webpack_require__(/*! ../../lib/index */ "./src/lib/index.ts"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 timer = void 0; var ClMessage = function (_Taro$Component) { _inherits(ClMessage, _Taro$Component); function ClMessage() { var _ref; var _temp, _this, _ret; _classCallCheck(this, ClMessage); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ClMessage.__proto__ || Object.getPrototypeOf(ClMessage)).call.apply(_ref, [this].concat(args))), _this), _this.$usedState = ["anonymousState__temp", "anonymousState__temp2", "$compid__853", "$compid__854", "$compid__855", "$compid__856"], _this.customComponents = ["ClCard", "ClFlex", "ClText", "ClIcon"], _temp), _possibleConstructorReturn(_this, _ret); } _createClass(ClMessage, [{ key: "_constructor", value: function _constructor(props) { _get(ClMessage.prototype.__proto__ || Object.getPrototypeOf(ClMessage.prototype), "_constructor", this).call(this, props); this.$$refs = new _taroWeapp2.default.RefsArray(); } }, { key: "_createData", value: function _createData() { var _this2 = this; this.__state = arguments[0] || this.state || {}; this.__props = arguments[1] || this.props || {}; var __isRunloopRef = arguments[2]; var __prefix = this.$prefix; ; var _genCompid = (0, _taroWeapp.genCompid)(__prefix + "$compid__853"), _genCompid2 = _slicedToArray(_genCompid, 2), $prevCompid__853 = _genCompid2[0], $compid__853 = _genCompid2[1]; var _genCompid3 = (0, _taroWeapp.genCompid)(__prefix + "$compid__854"), _genCompid4 = _slicedToArray(_genCompid3, 2), $prevCompid__854 = _genCompid4[0], $compid__854 = _genCompid4[1]; var _genCompid5 = (0, _taroWeapp.genCompid)(__prefix + "$compid__855"), _genCompid6 = _slicedToArray(_genCompid5, 2), $prevCompid__855 = _genCompid6[0], $compid__855 = _genCompid6[1]; var _genCompid7 = (0, _taroWeapp.genCompid)(__prefix + "$compid__856"), _genCompid8 = _slicedToArray(_genCompid7, 2), $prevCompid__856 = _genCompid8[0], $compid__856 = _genCompid8[1]; var props = this.__props; var tempHeight = 500; var bgColor = props.bgColor, type = props.type, onClose = props.onClose, message = props.message, show = props.show, duration = props.duration; var _useState = (0, _taroWeapp.useState)(show), _useState2 = _slicedToArray(_useState, 2), showMessage = _useState2[0], setShowMessage = _useState2[1]; var _useState3 = (0, _taroWeapp.useState)(tempHeight), _useState4 = _slicedToArray(_useState3, 2), contentHeight = _useState4[0], setContentHeight = _useState4[1]; var _useState5 = (0, _taroWeapp.useState)(""), _useState6 = _slicedToArray(_useState5, 2), tempMessage = _useState6[0], setTempMessage = _useState6[1]; var _useState7 = (0, _taroWeapp.useState)(), _useState8 = _slicedToArray(_useState7, 2), tempType = _useState8[0], setTempType = _useState8[1]; var durationTime = duration || 3; var mapColor = { success: "light-green", error: "light-red", warn: "light-yellow", info: "light-grey", custom: bgColor }; var calculateHeight = function calculateHeight() { var view = _taroWeapp2.default.createSelectorQuery().in(_this2.$scope); var query = view.select("#content"); return new Promise(function (resolve) { query.boundingClientRect().exec(function (res) { var data = res[0]; resolve(data.height); }); }); }; var clickClose = function clickClose() { new Promise(function (resolve) { resolve(calculateHeight()); }).then(function (res) { var height = res; clearTimeout(timer); timer = null; setContentHeight(height); setShowMessage(false); onClose && onClose(); }); }; (0, _taroWeapp.useEffect)(function () { (function () { if (!showMessage) { new Promise(function (resolve) { resolve(calculateHeight()); }).then(function (res) { var height = res; tempHeight = height; setContentHeight(tempHeight); setShowMessage(false); }); } else { tempHeight = 0; setTempType(type); setTempMessage(message || ""); if (duration !== 0) { if (timer) { clickClose(); clearTimeout(timer); timer = null; return; } timer = setTimeout(function () { clickClose(); clearTimeout(timer); timer = null; props.message = ""; }, durationTime * 1000); } setContentHeight(tempHeight); setShowMessage(true); } })(); }, [showMessage]); (0, _taroWeapp.useEffect)(function () { show && setShowMessage(!!show); props.show = false; }, [show]); (0, _taroWeapp.useEffect)(function () { if (show) { clearTimeout(timer); timer = null; clickClose(); setTimeout(function () { setShowMessage(true); setTempMessage(message || ""); setTempType(type); }, 300); } }, [message, show]); var anonymousState__temp = (0, _index.classNames)("cu-cl-message", props.className); var anonymousState__temp2 = (0, _taroWeapp.internal_inline_style)(Object.assign({ transition: "all 0.2s linear", top: "" + (showMessage ? "0" : "-" + contentHeight + "px") }, props.style)); this.anonymousFunc0 = function () { clickClose(); }; _taroWeapp.propsManager.set({ "bgColor": mapColor[tempType] || "light-grey", "shadow": false }, $compid__853, $prevCompid__853); _taroWeapp.propsManager.set({ "justify": "between", "align": "center" }, $compid__854, $prevCompid__854); _taroWeapp.propsManager.set({ "text": tempMessage }, $compid__855, $prevCompid__855); _taroWeapp.propsManager.set({ "iconName": "close", "size": "xsmall" }, $compid__856, $prevCompid__856); Object.assign(this.__state, { anonymousState__temp: anonymousState__temp, anonymousState__temp2: anonymousState__temp2, $compid__853: $compid__853, $compid__854: $compid__854, $compid__855: $compid__855, $compid__856: $compid__856 }); return this.__state; } }, { key: "anonymousFunc0", value: function anonymousFunc0(e) { ; } }]); return ClMessage; }(_taroWeapp2.default.Component); ClMessage.$$events = ["anonymousFunc0"]; ClMessage.$$componentPath = "components/message/index"; ClMessage.options = { addGlobalClass: true }; ClMessage.defaultProps = { bgColor: "light-grey", type: "info", onClose: function onClose() {}, message: "", show: false, duration: 3 }; exports.default = ClMessage; Component(__webpack_require__(/*! @tarojs/taro-weapp */ "./node_modules/@tarojs/taro-weapp/index.js").default.createComponent(ClMessage)); /***/ }), /***/ "./node_modules/file-loader/dist/cjs.js?name=[path][name].wxml&context=/Users/jinbai/Documents/develop/github/mp-colorui-old/mp-colorui/src!./node_modules/@tarojs/mini-runner/dist/loaders/miniTemplateLoader.js!./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js?!./src/components/message/index.tsx?taro&type=template&parse=COMPONENT&": /*!********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\ !*** ./node_modules/file-loader/dist/cjs.js?name=[path][name].wxml&context=/Users/jinbai/Documents/develop/github/mp-colorui-old/mp-colorui/src!./node_modules/@tarojs/mini-runner/dist/loaders/miniTemplateLoader.js!./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js??ref--4-0!./src/components/message/index.tsx?taro&type=template&parse=COMPONENT& ***! \********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__.p + "components/message/index.wxml"; /***/ }), /***/ "./src/components/message/index.scss": /*!*******************************************!*\ !*** ./src/components/message/index.scss ***! \*******************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { // extracted by mini-css-extract-plugin /***/ }), /***/ "./src/components/message/index.tsx": /*!******************************************!*\ !*** ./src/components/message/index.tsx ***! \******************************************/ /*! no static exports found */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */ var _index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index.tsx?taro&type=template&parse=COMPONENT& */ "./src/components/message/index.tsx?taro&type=template&parse=COMPONENT&"); /* harmony import */ var _index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./index.tsx?taro&type=script&parse=COMPONENT& */ "./src/components/message/index.tsx?taro&type=script&parse=COMPONENT&"); /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_1__) if(__WEBPACK_IMPORT_KEY__ !== 'default') (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_1__[key]; }) }(__WEBPACK_IMPORT_KEY__)); /***/ }), /***/ "./src/components/message/index.tsx?taro&type=script&parse=COMPONENT&": /*!****************************************************************************!*\ !*** ./src/components/message/index.tsx?taro&type=script&parse=COMPONENT& ***! \****************************************************************************/ /*! no static exports found */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */ var _node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../../../node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js??ref--4-0!./index.tsx?taro&type=script&parse=COMPONENT& */ "./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js?!./src/components/message/index.tsx?taro&type=script&parse=COMPONENT&"); /* harmony import */ var _node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__); /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== 'default') (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__[key]; }) }(__WEBPACK_IMPORT_KEY__)); /* harmony default export */ __webpack_exports__["default"] = (_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_script_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0___default.a); /***/ }), /***/ "./src/components/message/index.tsx?taro&type=template&parse=COMPONENT&": /*!******************************************************************************!*\ !*** ./src/components/message/index.tsx?taro&type=template&parse=COMPONENT& ***! \******************************************************************************/ /*! no static exports found */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */ var _node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../../../node_modules/file-loader/dist/cjs.js?name=[path][name].wxml&context=/Users/jinbai/Documents/develop/github/mp-colorui-old/mp-colorui/src!../../../node_modules/@tarojs/mini-runner/dist/loaders/miniTemplateLoader.js!../../../node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js??ref--4-0!./index.tsx?taro&type=template&parse=COMPONENT& */ "./node_modules/file-loader/dist/cjs.js?name=[path][name].wxml&context=/Users/jinbai/Documents/develop/github/mp-colorui-old/mp-colorui/src!./node_modules/@tarojs/mini-runner/dist/loaders/miniTemplateLoader.js!./node_modules/@tarojs/mini-runner/dist/loaders/wxTransformerLoader.js?!./src/components/message/index.tsx?taro&type=template&parse=COMPONENT&"); /* harmony import */ var _node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__); /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== 'default') (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _node_modules_file_loader_dist_cjs_js_name_path_name_wxml_context_Users_jinbai_Documents_develop_github_mp_colorui_old_mp_colorui_src_node_modules_tarojs_mini_runner_dist_loaders_miniTemplateLoader_js_node_modules_tarojs_mini_runner_dist_loaders_wxTransformerLoader_js_ref_4_0_index_tsx_taro_type_template_parse_COMPONENT___WEBPACK_IMPORTED_MODULE_0__[key]; }) }(__WEBPACK_IMPORT_KEY__)); /***/ }) },[["./src/components/message/index.tsx","runtime","taro","vendors","common"]]]);