chowa
Version:
UI component library based on React
62 lines (61 loc) • 2.13 kB
JavaScript
/**
* @license chowa v1.1.3
*
* Copyright (c) Chowa Techonlogies Co.,Ltd.(http://www.chowa.cn).
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const PropTypes = require("prop-types");
const classnames_1 = require("classnames");
const utils_1 = require("../utils");
const steps_item_1 = require("./steps-item");
const Steps = (props) => {
const { children, className, style, mode, current, verticalCenter, onSelect } = props;
const componentClass = classnames_1.default({
[utils_1.preClass('steps')]: true,
[utils_1.preClass('steps-vertical-center')]: verticalCenter && mode === 'horizontal',
[utils_1.preClass(`steps-${mode}`)]: true,
[className]: utils_1.isExist(className)
});
return (React.createElement("section", { className: componentClass, style: style }, React.Children.map(children, (child, index) => {
if (!utils_1.isReactElement(child) || child.type !== steps_item_1.default) {
return null;
}
const mProps = {
stepNumber: index + 1,
onSelect: utils_1.isExist(onSelect) ? onSelect : null,
status: child.props.status
};
if (mProps.status === undefined) {
if (index + 1 === current) {
mProps.status = 'process';
}
else if (index + 1 < current) {
mProps.status = 'finish';
}
else {
mProps.status = 'wait';
}
}
return React.cloneElement(child, mProps);
})));
};
Steps.propTypes = {
className: PropTypes.string,
style: PropTypes.object,
current: PropTypes.number,
mode: PropTypes.oneOf(['horizontal', 'vertical']),
verticalCenter: PropTypes.bool,
onSelect: PropTypes.func
};
Steps.defaultProps = {
current: 1,
mode: 'horizontal',
verticalCenter: false
};
Steps.Item = steps_item_1.default;
exports.default = Steps;