hy-checkbox
Version:
checkbox & radio ui components for react
206 lines (176 loc) • 9.08 kB
JavaScript
'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);
var _stepHead = require('./stepHead');
var _stepHead2 = _interopRequireDefault(_stepHead);
var _stepBody = require('./stepBody');
var _stepBody2 = _interopRequireDefault(_stepBody);
var _stepFoot = require('./stepFoot');
var _stepFoot2 = _interopRequireDefault(_stepFoot);
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; } /*
* @Author: SiMeiyu
* @Date: 2017-07-04 09:53:50
*/
var Step = function (_React$Component) {
_inherits(Step, _React$Component);
function Step(props) {
_classCallCheck(this, Step);
var _this = _possibleConstructorReturn(this, (Step.__proto__ || Object.getPrototypeOf(Step)).call(this, props));
_this.state = {
activeIndex: 0,
// activeIndex: this.props.startIndex,
complete: false,
starting: true
};
_this.total = _this.props.children.length;
_this.handleNextStep = _this.handleNextStep.bind(_this);
_this.handlePrevStep = _this.handlePrevStep.bind(_this);
_this.handleFinish = _this.handleFinish.bind(_this);
return _this;
}
_createClass(Step, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if ('startIndex' in nextProps) {
this.setState({
activeIndex: nextProps.startIndex
});
}
}
}, {
key: 'handleFinish',
value: function handleFinish() {
var onFinished = this.props.onFinished;
if (onFinished) {
onFinished();
}
}
}, {
key: 'handlePrevStep',
value: function handlePrevStep() {
var activeIndex = this.state.activeIndex;
if (activeIndex > 0) {
this.setState({
activeIndex: activeIndex - 1,
complete: false
});
}
if (activeIndex == 1) {
this.setState({
starting: true
});
}
}
}, {
key: 'handleNextStep',
value: function handleNextStep() {
var activeIndex = this.state.activeIndex;
if (activeIndex < this.total - 1) {
this.setState({
activeIndex: activeIndex + 1,
starting: false
});
}
if (activeIndex == this.total - 2) {
this.setState({
complete: true
});
}
}
}, {
key: 'renderStepHead',
value: function renderStepHead() {
var _props = this.props,
prefixCls = _props.prefixCls,
children = _props.children,
showProgress = _props.showProgress;
return _react2.default.createElement(_stepHead2.default, {
key: 'stepHead',
prefixCls: prefixCls,
panels: children,
activeIndex: this.state.activeIndex,
showProgress: showProgress
});
}
}, {
key: 'renderStepBody',
value: function renderStepBody() {
var _props2 = this.props,
prefixCls = _props2.prefixCls,
children = _props2.children;
return _react2.default.createElement(_stepBody2.default, {
key: 'stepBody',
prefixCls: prefixCls,
activeIndex: this.state.activeIndex,
panels: children
});
}
}, {
key: 'renderStepFoot',
value: function renderStepFoot() {
var _props3 = this.props,
prefixCls = _props3.prefixCls,
previous = _props3.previous,
next = _props3.next,
finish = _props3.finish;
return _react2.default.createElement(_stepFoot2.default, {
key: 'stepFoot',
prefixCls: prefixCls,
previous: previous,
next: next,
finish: finish,
starting: this.state.starting,
complete: this.state.complete,
onNextStep: this.handleNextStep,
onPrevStep: this.handlePrevStep,
onFinish: this.handleFinish
});
}
}, {
key: 'render',
value: function render() {
var _props4 = this.props,
prefixCls = _props4.prefixCls,
className = _props4.className,
style = _props4.style;
var classes = (0, _classnames2.default)(prefixCls + '-step', {}, className);
return _react2.default.createElement(
'div',
{ className: classes, style: style },
this.renderStepHead(),
this.renderStepBody(),
this.renderStepFoot()
);
}
}]);
return Step;
}(_react2.default.Component);
Step.propTypes = {
prefixCls: _react2.default.PropTypes.string,
className: _react2.default.PropTypes.string,
style: _react2.default.PropTypes.object,
previous: _react2.default.PropTypes.string,
next: _react2.default.PropTypes.string,
finish: _react2.default.PropTypes.string,
children: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.string, _react2.default.PropTypes.element, _react2.default.PropTypes.array]),
// startIndex: React.PropTypes.number,
onFinished: _react2.default.PropTypes.func,
showProgress: _react2.default.PropTypes.bool
};
Step.defaultProps = {
prefixCls: 'ult',
previous: '上一步',
next: '下一步',
finish: '完成'
// startIndex: 0,
};
exports.default = Step;