Progressing through the Material UI LinearProgress bar in steps

How can I split a progress bar into more steps to achieve a design like this? https://i.stack.imgur.com/lRMj6.png

I attempted using this code but couldn't find an option for splitting:

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

Are there any additional options that I can add?

Answer №1

When discussing the concept of steps, I would suggest utilizing the Stepper component to implement this functionality.

Below is some code that provides a basic version of the component you are seeking:

// manage the step state
const [stepNumber, setStepNumber] = useState(1);
const stepsNumber = 6;
// generate an array with steps [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>

I have created a codesandbox demo here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to utilize jquery script within a react component

<script> $(document).ready(function() { var source; var destination; var fn = function(event, ui) { toDrop = $(ui.draggable).clone(); if ($("#droppable").find("li[uniqueIdentity=" ...

Adjust the checked state of the checkbox based on the outcome of the promise's data

Whenever the checkbox is clicked and the resolved data in a promise is false, I want the checkbox to remain unchecked. If the data is true, then the checkbox should be checked. I have set up a codesandbox for this purpose. This example utilizes react and ...

Easy ways to align sprite images and text in the center

I am trying to utilize css sprites for my website. I have a basic image and some text that I would like to display together. My goal is to center the image on the page, and then vertically center the text next to it. As a newcomer to css, I am struggling t ...

Is it possible to switch the gray background to another color when the item is selected?

[]2] <FormControl> <Select value={val} onChange={handleSelect} input={<BootstrapInput />} displayEmpty // classes={{selectMenu: { marginTop: 50 }}} MenuProps={{...menuProps ...

When transitioning from the current step to the previous step in the mat-stepper component, how can we emphasize the horizontal line that separates them?

screenshot of my progress I have progressed from A3 to A2 step, but I need to add a horizontal line between them. How can I achieve this and is it possible to do so using CSS styles? ...

How to resize and center an image within a div element as they both scale proportionally

Can someone help me figure out how to center a resized image within its container, which should also be centered? I've been struggling with this for 7 hours and can't seem to get it right. Any assistance would be greatly appreciated :-) Here is ...

Problem with ngStyle: Error indicating that the expected '}' is missing

I encountered an error in the Chrome console when trying to interpret the code below: <div [ngStyle]="{'width': '100%'; 'height': '100%'; 'background-size': 'cover'; 'background-repeat&ap ...

Tips for exporting SVGs properly in React/Next applications

I've been attempting to integrate an SVG into my upcoming project, but I can't seem to shake this persistent error message: 'Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite compo ...

What is the process by which a web browser executes a ".jsx" file while in development?

As a beginner in the world of react, I have successfully been able to execute the dev and build tests. One question that has been boggling my mind is how browsers handle ".js" files. I know that when a project is build, the browser runs the &quo ...

populating an array with objects

I am working with an array of objects var photos: Photos[] = []; The structure of Photos [] is as follows interface Photos { src: string; width: number; height: number; } I have a component that requires an array of strings export type PhotosArr ...

Utilizing the handleChange method to manage multiple input fields

It is important to me that the function handleChange only updates the input value that is being changed. Specifically, if I modify the 'firstName' input, I want only that state to be updated, and the same applies to the 'lastName' input ...

Using jest to simulate a private variable in your code

I am working on unit testing a function that looks like this: export class newClass { private service: ServiceToMock; constructor () { this.service = new ServiceToMock() } callToTest () { this.service.externalCall().then(()=& ...

Getting useSelector() to function properly: A beginner's guide

Help! I'm having trouble with a basic React Redux setup. My useSelector function is not returning any value. Here's the code snippet: store.js: import {createStore} from 'redux' const initialState = { counter: 0 } const counterRed ...

What could be the reason for the Checkbox's value not showing up after making changes?

In my React and Material UI project, I am facing an issue where I want to check all checkboxes in a list by simply checking one checkbox in a parent component. Despite passing down the correct value of the parent checkbox through props, the visual changes ...

Modify the hue of the div as soon as a button on a separate webpage is

Looking for assistance with a page called "diagnosticoST" that contains four buttons (btn-institucional, btn-economico, btn-social, btn-natural). These buttons have different background colors until the survey inside them is completed. Once the user comple ...

How can I determine whether the user is being directed to a component with state being navigated to navigate('/tsaks/updateTask', { state: {task: data})

I have a component that displays a list of tasks. When the user clicks on a task, they are redirected to /tasks/updateTask along with the task data. navigate('/tasks/updateTask', { state: {task: data}) The purpose of this setup is to prevent dir ...

Placing an icon and a title on the same baseline

I'm working on a new website design and I really like the layout shown in this image: https://i.stack.imgur.com/QuVRZ.png I've been struggling to align the icon with the title in a responsive manner. Here are some of the approaches I've att ...

Form fields in Bootstrap 4 will consistently expand downward in the select dropdown menu

When using bootstrap 4, I want my field to always expand downwards and never upwards, even when half the screen is taken up by the form's select element. How can I achieve this effect? I have tried using data-dropup-auto="false" but it didn't wo ...

Using Material-UI with @emotion/cache in SSR results in consistently empty cache

After transitioning my React SSR from pure @emotion to material-ui 5.0, I encountered an issue where the styles no longer get extracted. The ID extraction in createExtractCriticalToChunks seems to be functioning correctly, but the cache.inserted object fro ...

We're sorry, but the module you are looking for cannot be found. An error has occurred while trying

Struggling with an error while using React Material-UI to design my interface. The issue arises when using a specific component in the main layout. Seeking assistance from anyone who can help me find a solution. [287] ./src/components/RadioCustom.js 5.42 ...