index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as React from 'react';
  2. import SliderContext from "../context";
  3. import Dot from "./Dot";
  4. var Steps = function Steps(props) {
  5. var prefixCls = props.prefixCls,
  6. marks = props.marks,
  7. dots = props.dots,
  8. style = props.style,
  9. activeStyle = props.activeStyle;
  10. var _React$useContext = React.useContext(SliderContext),
  11. min = _React$useContext.min,
  12. max = _React$useContext.max,
  13. step = _React$useContext.step;
  14. var stepDots = React.useMemo(function () {
  15. var dotSet = new Set();
  16. // Add marks
  17. marks.forEach(function (mark) {
  18. dotSet.add(mark.value);
  19. });
  20. // Fill dots
  21. if (dots && step !== null) {
  22. var current = min;
  23. while (current <= max) {
  24. dotSet.add(current);
  25. current += step;
  26. }
  27. }
  28. return Array.from(dotSet);
  29. }, [min, max, step, dots, marks]);
  30. return /*#__PURE__*/React.createElement("div", {
  31. className: "".concat(prefixCls, "-step")
  32. }, stepDots.map(function (dotValue) {
  33. return /*#__PURE__*/React.createElement(Dot, {
  34. prefixCls: prefixCls,
  35. key: dotValue,
  36. value: dotValue,
  37. style: style,
  38. activeStyle: activeStyle
  39. });
  40. }));
  41. };
  42. export default Steps;