jss-react-material
Version:
Google Material Components for React
111 lines (83 loc) • 5.02 kB
JavaScript
;
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 _class, _temp;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _getClasses = require('./addons/get-classes');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
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 Stepper = (_temp = _class = function (_React$Component) {
_inherits(Stepper, _React$Component);
function Stepper(props, context) {
_classCallCheck(this, Stepper);
var _this = _possibleConstructorReturn(this, (Stepper.__proto__ || Object.getPrototypeOf(Stepper)).call(this, props, context));
_this.state = { openStep: 0, stepCount: props.children.length };
_this.handleStep = _this.handleStep.bind(_this);
return _this;
}
_createClass(Stepper, [{
key: 'handleStep',
value: function handleStep(type, props, event) {
var _state = this.state,
openStep = _state.openStep,
stepCount = _state.stepCount;
if (type === 'open') {
if (props.stepNumber < openStep) {
return this.setState({ openStep: props.stepNumber });
}
return;
}
if (type === 'submit') {
if (openStep < stepCount) {
this.setState({ openStep: openStep + 1 });
}
return this.props.onStep(props, event);
}
return this.props.cancelStep(props, event);
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var _props = this.props,
children = _props.children,
continueLabel = _props.continueLabel,
cancelLabel = _props.cancelLabel,
others = _objectWithoutProperties(_props, ['children', 'continueLabel', 'cancelLabel']);
var openStep = this.state.openStep;
return _react2.default.createElement(
'div',
{ className: (0, _getClasses.getClassesStatic)('stepper', others) },
children.map(function (child, key) {
var avatar = key < openStep ? { icon: { icon: '0xE5CA' } } : { letter: { character: String(key + 1) } };
return _react2.default.cloneElement(child, {
stepProps: _this2.state.stepProps,
avatar: avatar,
continueLabel: continueLabel,
cancelLabel: cancelLabel,
handleStep: _this2.handleStep,
open: openStep === key,
stepNumber: key,
key: key
});
})
);
}
}]);
return Stepper;
}(_react2.default.Component), _class.propTypes = {
children: _propTypes2.default.arrayOf(_propTypes2.default.element),
continueLabel: _propTypes2.default.string,
cancelLabel: _propTypes2.default.string,
onStep: _propTypes2.default.func.isRequired,
cancelStep: _propTypes2.default.func.isRequired
}, _temp);
exports.default = Stepper;