UNPKG

hy-checkbox

Version:

checkbox & radio ui components for react

174 lines (144 loc) 6.26 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 _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _notice = require('./notice'); var _notice2 = _interopRequireDefault(_notice); require('./notificationRoot.less'); 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 NotificationRoot = function (_React$Component) { _inherits(NotificationRoot, _React$Component); function NotificationRoot(props) { _classCallCheck(this, NotificationRoot); var _this = _possibleConstructorReturn(this, (NotificationRoot.__proto__ || Object.getPrototypeOf(NotificationRoot)).call(this, props)); _this.addNotice = function (noticeitem) { //console.log("数组是+++++++++++++++++++++",noticeitem); var keyid = noticeitem.id; var noticeItem = _this.state.notices; _this.setState(function (previousState) { var isNotice = void 0; if (previousState.notices.length) { isNotice = previousState.notices.find(function (p) { return p.id == keyid; }); } else { isNotice = false; } if (isNotice) { return null; } else { return { notices: noticeItem.concat(noticeitem) }; } }); }; _this.remove = function (keyid) { _this.setState(function (previousState) { return { notices: previousState.notices.filter(function (notice) { return notice.id !== keyid; }) }; }); }; _this.state = { isFlag: false, notices: [] // notify:this.props.show, }; return _this; } _createClass(NotificationRoot, [{ key: 'closeNotification', value: function closeNotification() { this.setState({ isFlag: false }); } }, { key: 'NoticeInfor', value: function NoticeInfor(noticedata) { var _props = this.props, warning = _props.warning, prefixCls = _props.prefixCls, onClose = _props.onClose; var isFlag = this.state.isFlag; var me = this; var NoticeC = this.state.notices; var noticeNodes = NoticeC.map(function (notice) { console.log("点击后是否关闭", notice.id); return _react2.default.createElement( _notice2.default, _extends({ prefixCls: prefixCls, ClassName: notice.type, key: notice.id }, notice, { onClose: me.remove.bind(me, notice.id) }), notice.content ); }); return noticeNodes; } }, { key: 'render', value: function render() { var _props2 = this.props, warning = _props2.warning, prefixCls = _props2.prefixCls, isFlag = _props2.isFlag; var me = this; var NoticeC = this.state.notices; return _react2.default.createElement( 'div', { className: (0, _classnames2.default)(prefixCls + '-ui-notice') }, _react2.default.createElement( 'dl', null, NoticeC.length ? me.NoticeInfor(NoticeC) : null ) ); } }]); return NotificationRoot; }(_react2.default.Component); NotificationRoot.propTypes = { closeNotification: _react2.default.PropTypes.func, Notification: _react2.default.PropTypes.func, addNotice: _react2.default.PropTypes.func, removeNotice: _react2.default.PropTypes.func, notice: _react2.default.PropTypes.func, prefixCls: _react2.default.PropTypes.string, title: _react2.default.PropTypes.string, iconNode: _react2.default.PropTypes.string, isFlag: _react2.default.PropTypes.bool, isNotice: _react2.default.PropTypes.bool }; NotificationRoot.defaultProps = { title: '提示', warning: false, prefixCls: 'ult' }; NotificationRoot.newInstance = function Notification(noticeData) { var prefixCls = 'ult'; var props = noticeData || {}; var wrapper = document.createElement('div'); wrapper.className = prefixCls + '-ui-notice-wrap'; wrapper = document.body.appendChild(wrapper); var notification = ReactDOM.render(_react2.default.createElement(NotificationRoot, _extends({ warning: true, isFlag: true }, props)), wrapper); return { notice: function notice(noticeProps) { notification.addNotice(noticeProps); } }; }; exports.default = NotificationRoot;