Timeline Component in React.js
Timelines are often used in user interfaces to illustrate a step-by-step procedure. It can describe to the user which stage of the process they currently are and what the further tasks are. Material UI labs module provide a Timeline component along with some other utility components to make this very easy to include in our React app.
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app gfg
Step 2: After creating your project folder i.e. gfg, move to it using the following command:
Step 3: After creating the ReactJS application, Install the material-ui modules using the following command:
npm install @material-ui/core npm install @material-ui/lab
As an example, we’ll create a Stages component that illustrates the different stages an Article at GeeksforGeeks goes through in form of a Timeline. Create a file stages.js in the src folder where we’ll define this component.
Project Structure: It will look like the following.
Timeline component in Material-UI
The Timeline component in Material UI labs displays items in chronological order and gives the developers freedom to alter how it’s displayed up to some extent. It has some useful props:
- align: The textual content can be posted at the left, right, or alternating to the timeline.
- color: Used to denote the color of the timeline dot at that stage. It’s the prop of the TimelineDot component which we use inside the Timeline component.
Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
Step to Run Application: Run the application using the following command from the root directory of the project:
Output: Now open your browser and go to http://localhost:3000/, you will see the following output: