UNPKG

hy-checkbox

Version:

checkbox & radio ui components for react

116 lines (96 loc) 4.74 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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); require('./sortBox.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 SortBox = function (_React$Component) { _inherits(SortBox, _React$Component); function SortBox(props) { _classCallCheck(this, SortBox); var _this = _possibleConstructorReturn(this, (SortBox.__proto__ || Object.getPrototypeOf(SortBox)).call(this, props)); _this.state = { isSort: false, isDesc: true, isAsc: false }; return _this; } _createClass(SortBox, [{ key: 'handleSort', value: function handleSort(e) { var _props = this.props, id = _props.id, handleSort = _props.handleSort; var _state = this.state, isAsc = _state.isAsc, isDesc = _state.isDesc, isSort = _state.isSort; var sortElems = document.querySelectorAll('.sort-icon-red'); sortElems.forEach(function (item) { if (item.id === id + '-icon') { return; } item.classList.remove('sort-icon-red'); }); if (isSort === false) { this.setState({ isSort: true }); handleSort(id, true); } else { if (isDesc === true) { this.setState({ isDesc: false, isAsc: true }); handleSort(id, false); } else { this.setState({ isDesc: true, isAsc: false }); handleSort(id, true); } } } }, { key: 'render', value: function render() { var me = this; var _props2 = this.props, title = _props2.title, id = _props2.id; var _state2 = this.state, isSort = _state2.isSort, isDesc = _state2.isDesc, isAsc = _state2.isAsc; return _react2.default.createElement( 'p', { className: 'mix-sortbox', id: id }, _react2.default.createElement( 'span', null, title ), _react2.default.createElement('i', { className: (0, _classnames2.default)({ 'iconfont': true, 'icon-xiangxia': isDesc, 'icon-xiangshang': isAsc, 'sort-icon-red': isSort }), onClick: this.handleSort.bind(me), id: id + '-icon' }) ); } }]); return SortBox; }(_react2.default.Component); SortBox.propTypes = { title: _react2.default.PropTypes.string, handleSort: _react2.default.PropTypes.func, id: _react2.default.PropTypes.string }; exports.default = SortBox;