UNPKG

1.26 kBJavaScriptView Raw
1import React from 'react';
2import classNames from 'classnames';
3import { mergeProps } from '../../utils/with-default-props';
4import { withNativeProps } from '../../utils/native-props';
5const classPrefix = `adm-steps`;
6const stepClassPrefix = `adm-step`;
7const defaultIcon = React.createElement("span", {
8 className: `${stepClassPrefix}-icon-dot`
9});
10const defaultProps = {
11 current: 0,
12 direction: 'horizontal'
13};
14export const Steps = p => {
15 const props = mergeProps(defaultProps, p);
16 const {
17 direction,
18 current
19 } = props;
20 const classString = classNames(classPrefix, `${classPrefix}-${direction}`);
21 return withNativeProps(props, React.createElement("div", {
22 className: classString
23 }, React.Children.map(props.children, (child, index) => {
24 var _a;
25 if (!React.isValidElement(child)) {
26 return child;
27 }
28 const childProps = child.props;
29 let status = childProps.status || 'wait';
30 if (index < current) {
31 status = childProps.status || 'finish';
32 } else if (index === current) {
33 status = childProps.status || 'process';
34 }
35 const icon = (_a = childProps.icon) !== null && _a !== void 0 ? _a : defaultIcon;
36 return React.cloneElement(child, {
37 status,
38 icon
39 });
40 })));
41};
\No newline at end of file