Material UI 线性进度条步骤

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

Materiel ui LinearProgress bar steps

问题

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

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

<LinearProgress
  variant="determinate"
  classes={{ root: "progressBar", bar: "progressBar-bar" }}
  value={(100 / stepsNumber) * stepNumber}
  valueBuffer={40}
/>

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

英文:

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

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

Is there some options to add ?

答案1

得分: 0

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

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

// 处理步骤状态
const [stepNumber, setStepNumber] = useState(1);
const stepsNumber = 6;
// 创建步骤数组 [0,1,2,...]
const steps = Array.from({ length: stepsNumber }, (_, i) => i);

// ...

<Stepper
  activeStep={stepNumber}
  connector={null}
  style={{
    display: "flex",
    justifyContent: "center",
    width: "100%",
    maxWidth: 300,
  }}
>
  {steps.map((label) => (
    <Step
      key={label}
      style={{
        background: label < stepNumber ? "black" : "grey",
        height: 12,
        flex: 1,
        borderRadius: 12,
      }}
    />
  ))}
</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.

// handle the step state
const [stepNumber, setStepNumber] = useState(1);
const stepsNumber = 6;
// create array of steps [0,1,2,...]
const steps = Array.from({ length: stepsNumber }, (_, i) =&gt; i);

// ...

&lt;Stepper
  activeStep={stepNumber}
  connector={null}
  style={{
    display: &quot;flex&quot;,
    justifyContent: &quot;center&quot;,
    width: &quot;100%&quot;,
    maxWidth: 300,
  }}
&gt;
  {steps.map((label) =&gt; (
    &lt;Step
      key={label}
      style={{
        background: label &lt; stepNumber ? &quot;black&quot; : &quot;grey&quot;,
        height: 12,
        flex: 1,
        borderRadius: 12,
      }}
    /&gt;
  ))}
&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:

确定