您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

StepProgress.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from "react";
  2. import PropTypes from "prop-types";
  3. import { StepProgressContainer, Progress, StepBar, StepLine } from "./StepProgress.styled";
  4. import { ReactComponent as Checkmark } from "../../assets/images/svg/checkmark.svg";
  5. const StepProgress = (props) => {
  6. const steps = [];
  7. for (let i = 1; i <= props.numberOfSteps; i++) {
  8. steps.push({
  9. done: i < props.current,
  10. current: i === props.current,
  11. });
  12. }
  13. const functions = [];
  14. steps.forEach((item,index) => {
  15. if (props.functions[index]) {
  16. functions.push(props.functions[index])
  17. } else {
  18. functions.push(() => {})
  19. }
  20. })
  21. return (
  22. <StepProgressContainer done>
  23. {steps.map((item, index) =>
  24. index === 0 ? (
  25. <StepBar current={item.current} done={item.done} key={index} onClick={item.done ? props.functions[index] : () => {console.log("neuspeh")}}>
  26. {item.done ? <Checkmark /> : index+1}
  27. </StepBar>
  28. ) : (
  29. <React.Fragment key={index}>
  30. <StepLine done={item.done || item.current} >
  31. <Progress done={item.done || item.current} />
  32. </StepLine>
  33. <StepBar current={item.current} done={item.done} onClick={item.done ? props.functions[index] : () => {}} >
  34. {item.done ? <Checkmark /> : index+1}
  35. </StepBar>
  36. </React.Fragment>
  37. )
  38. )}
  39. </StepProgressContainer>
  40. );
  41. };
  42. StepProgress.propTypes = {
  43. children: PropTypes.node,
  44. handleNext: PropTypes.node,
  45. current: PropTypes.number,
  46. numberOfSteps: PropTypes.number,
  47. functions: PropTypes.array
  48. };
  49. StepProgress.defaultProps = {
  50. functions: []
  51. }
  52. export default StepProgress;