Material UI 线性进度条步骤

huangapple go评论96阅读模式
英文:

Materiel ui LinearProgress bar steps

问题

如何将进度条分成更多的步骤以获得类似的效果?

我尝试了这段代码,但找不到拆分选项:

  1. <LinearProgress
  2. variant="determinate"
  3. classes={{ root: "progressBar", bar: "progressBar-bar" }}
  4. value={(100 / stepsNumber) * stepNumber}
  5. valueBuffer={40}
  6. />

是否有一些选项可以添加?

英文:

how to split a progress bar to more steps to get something like that?
Material UI 线性进度条步骤

I try this code but I can't find the option of splitting

  1. &lt;LinearProgress
  2. variant=&quot;determinate&quot;
  3. classes={{ root: &quot;progressBar&quot;, bar: &quot;progressBar-bar&quot; }}
  4. value={(100 / stepsNumber) * stepNumber}
  5. valueBuffer={40}
  6. /&gt;

Is there some options to add ?

答案1

得分: 0

由于您提到了“steps”,我建议使用Stepper组件来实现这种功能。

以下是一个包含基本版本的代码,您需要获取您要查找的组件。

  1. // 处理步骤状态
  2. const [stepNumber, setStepNumber] = useState(1);
  3. const stepsNumber = 6;
  4. // 创建步骤数组 [0,1,2,...]
  5. const steps = Array.from({ length: stepsNumber }, (_, i) => i);
  6. // ...
  7. <Stepper
  8. activeStep={stepNumber}
  9. connector={null}
  10. style={{
  11. display: "flex",
  12. justifyContent: "center",
  13. width: "100%",
  14. maxWidth: 300,
  15. }}
  16. >
  17. {steps.map((label) => (
  18. <Step
  19. key={label}
  20. style={{
  21. background: label < stepNumber ? "black" : "grey",
  22. height: 12,
  23. flex: 1,
  24. borderRadius: 12,
  25. }}
  26. />
  27. ))}
  28. </Stepper>

我在这里创建了一个codesandbox

英文:

Since you mention steps, I would recommend using the Stepper component for this kind of feature.

The following code has a basic version you'll need to get component you're looking for.

  1. // handle the step state
  2. const [stepNumber, setStepNumber] = useState(1);
  3. const stepsNumber = 6;
  4. // create array of steps [0,1,2,...]
  5. const steps = Array.from({ length: stepsNumber }, (_, i) =&gt; i);
  6. // ...
  7. &lt;Stepper
  8. activeStep={stepNumber}
  9. connector={null}
  10. style={{
  11. display: &quot;flex&quot;,
  12. justifyContent: &quot;center&quot;,
  13. width: &quot;100%&quot;,
  14. maxWidth: 300,
  15. }}
  16. &gt;
  17. {steps.map((label) =&gt; (
  18. &lt;Step
  19. key={label}
  20. style={{
  21. background: label &lt; stepNumber ? &quot;black&quot; : &quot;grey&quot;,
  22. height: 12,
  23. flex: 1,
  24. borderRadius: 12,
  25. }}
  26. /&gt;
  27. ))}
  28. &lt;/Stepper&gt;

I've made a codesandbox here

huangapple
  • 本文由 发表于 2023年7月24日 17:18:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753018.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定