UNPKG

joywok-material-components

Version:

<h1 align="center"> Joywok Material Components </h1>

157 lines (133 loc) 6.38 kB
'use strict'; 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 _react = require('react'); var _react2 = _interopRequireDefault(_react); var _styles = require('@material-ui/core/styles'); var _Button = require('@material-ui/core/Button'); var _Button2 = _interopRequireDefault(_Button); var _Dialog = require('@material-ui/core/Dialog'); var _Dialog2 = _interopRequireDefault(_Dialog); 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 styles = { root: {}, button: { display: 'inline-block', maxWidth: "120px" } }; require('./style/simpleDialog.css'); var SimpleDialog = function (_React$Component) { _inherits(SimpleDialog, _React$Component); function SimpleDialog(props) { _classCallCheck(this, SimpleDialog); var _this = _possibleConstructorReturn(this, (SimpleDialog.__proto__ || Object.getPrototypeOf(SimpleDialog)).call(this, props)); _this.handleClose = function () { console.log('触发leme'); _this.setState({ open: false }); _this.props.onClose && _this.props.onClose(); }; _this.state = { open: props.open || false, curcount: {} }; return _this; } _createClass(SimpleDialog, [{ key: 'btnClick', value: function btnClick(e, item) { var self = this; var key = item['key']; this.props[key] && this.props[key](e, item, this); if (typeof this.props.events != 'undefined') { this.props.events.emit('click', self, item); } } }, { key: 'componentDidMount', value: function componentDidMount() { var self = this; var interval = {}; if (this.props.actions && this.props.actions.length > 0) { _.each(this.props.actions, function (item, i) { if (item.countdown) { self.state.curcount[i] = item.countdown.time; self.setState({ curcount: self.state.curcount }); interval[i] = setInterval(function () { self.state.curcount[i] = self.state.curcount[i] - 1; console.log('self.state.curcount[i]', self.state.curcount); self.setState({ curcount: self.state.curcount }); if (self.state.curcount[i] <= 0) clearInterval(interval[i]); }, 1000); } }); } } }, { key: 'render', value: function render() { var self = this; var classes = this.props.classes; return _react2.default.createElement( _Dialog2.default, { onClose: this.handleClose, 'aria-labelledby': 'simple-dialog-title', open: this.state.open, className: 'simple-dialog' }, _react2.default.createElement( 'div', { className: 'simple-dialog-c' }, this.props.title ? _react2.default.createElement( 'div', { className: 'simple-dialog-title' }, this.props.title ) : '', _react2.default.createElement( 'div', { className: 'simple-dialog-content' }, this.props.content ), this.props.actions && this.props.actions.length != 0 ? _react2.default.createElement( 'div', { className: 'simple-dialog-action' }, _.map(this.props.actions, function (i, index) { if (i.countdown && self.state.curcount[index] > 0) { i.countdown.unit = i.countdown.unit ? i.countdown.unit.toUpperCase() : 'S'; return _react2.default.createElement( _Button2.default, _extends({}, i, { disabled: true, className: 'ellipsis jw-button-count-down ' + classes.button + ' ' + (typeof i['className'] != 'undefined' ? i["className"] : '') }), self.state.curcount[index] + i.countdown.unit ); } else { return _react2.default.createElement( _Button2.default, _extends({}, i, { className: 'ellipsis ' + classes.button + ' ' + (typeof i['className'] != 'undefined' ? i["className"] : ''), onClick: function onClick(e) { return self.btnClick(e, i); } }), i['value'] ); } }) ) : '' ) ); } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { this.setState(nextProps); } }]); return SimpleDialog; }(_react2.default.Component); exports.default = (0, _styles.withStyles)(styles)(SimpleDialog); ;