Open In App

React MUI TimelineItem API

Last Updated : 01 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Material-UI is a UI library providing predefined robust and customizable components for React for easier web development. The MUI design is based on top of Material Design by Google. 

In this article, we are going to discuss the React MUI TimelineItem API. The Timeline item is the component placed inside the Timeline component. The API provides a lot of functionality and we are going to learn to implement them.

Import TimeLineItem API

import TimelineItem from '@mui/lab/TimelineItem';
// or
import { TimelineItem } from '@mui/lab';

Props List: Here is the list of different props used with this component. We can access them and modify them according to our needs.

  • children (node): It is a component similar to the table row.
  • classes (object): This overrides the existing styles or adds new styles to the component.
  • sx (Array<func/object/bool> func/object): The system prop allows defining system overrides as well as additional CSS styles. 
  • position (left/right): It can be left/right and it sets where the timeline’s item should appear.

CSS Rules:

  • root (.MuiTimelineItem-root): It is the style applied to the root element.
  • positionLeft (.MuiTimelineItem-positionLeft): It is the style applied to the root element if the position is set to left.
  • positionRight (.MuiTimelineItem-positionRight): It is the style applied to the root element if the position is set to right.
  • positionAlternate (.MuiTimelineItem-positionAlternate): It is the style applied to the root element if the position is set to alternate.
  • missingOppositeContent(.MuiTimelineItem-missingOppositeContent): It is the style applied to the root element if TimelineOppositeContent isn’t provided.

Syntax: Create the timeline item as follows:

<TimelineItem>
    <TimelineSeparator>
        <TimelineDot />
        <TimelineConnector />
    </TimelineSeparator>
    <TimelineContent>HTML</TimelineContent>
</TimelineItem>

Installing and Creating React app, and adding the MUI dependencies:

Step 1: Create a react project using the following command.

npx create-react-app gfg_tutorial

Step 2: Get into the project directory

cd gfg_tutorial

Step 3: Install the MUI dependencies as follows:

npm install @mui/material @emotion/react @emotion/styled @mui/lab

Step 4: Run the project as follows:

npm start

Example 1: In the following example, we have a timeline tree with timeline items.

App.js




import "./App.css";
import Timeline from "@mui/lab/Timeline";
import TimelineItem from "@mui/lab/TimelineItem";
import TimelineSeparator from "@mui/lab/TimelineSeparator";
import TimelineConnector from "@mui/lab/TimelineConnector";
import TimelineContent from "@mui/lab/TimelineContent";
import TimelineDot from "@mui/lab/TimelineDot";
function App() {
    return (
        <div className="App">
            <div
                className="head"
                style={{
                    width: "fit-content",
                    margin: "auto",
                }}
            >
                <h1
                    style={{
                        color: "green",
                    }}
                >
                    GeeksforGeeks
                </h1>
                <strong>React MUI TimelineItem API</strong>
            </div>
  
            <Timeline>
                <TimelineItem position="left">
                    <TimelineSeparator>
                        <TimelineDot />
                        <TimelineConnector />
                    </TimelineSeparator>
                    <TimelineContent>
                        Frontend Learning Path
                    </TimelineContent>
                </TimelineItem>
                <TimelineItem>
                    <TimelineSeparator>
                        <TimelineDot />
                        <TimelineConnector />
                    </TimelineSeparator>
                    <TimelineContent>HTML</TimelineContent>
                </TimelineItem>
                <TimelineItem>
                    <TimelineSeparator>
                        <TimelineDot />
                        <TimelineConnector />
                    </TimelineSeparator>
                    <TimelineContent>CSS</TimelineContent>
                </TimelineItem>
                <TimelineItem>
                    <TimelineSeparator>
                        <TimelineDot />
                    </TimelineSeparator>
                    <TimelineContent>Javascript</TimelineContent>
                </TimelineItem>
            </Timeline>
        </div>
    );
}
  
export default App;


Output:

 

Example 2: In the following example, we have used the sx to override the default CSS and then applied new CSS on the first timeline item.

App.js




import "./App.css";
import Timeline from "@mui/lab/Timeline";
import TimelineItem from "@mui/lab/TimelineItem";
import TimelineSeparator from "@mui/lab/TimelineSeparator";
import TimelineConnector from "@mui/lab/TimelineConnector";
import TimelineContent from "@mui/lab/TimelineContent";
import TimelineDot from "@mui/lab/TimelineDot";
function App() {
    return (
        <div className="App">
            <div
                className="head"
                style={{
                    width: "fit-content",
                    margin: "auto",
                }}
            >
                <h1
                    style={{
                        color: "green",
                    }}
                >
                    GeeksforGeeks
                </h1>
                <strong>React MUI TimelineItem API</strong>
            </div>
  
            <Timeline>
                <TimelineItem
                    sx={{
                        color: "darkblue",
                        textDecoration: "underline",
                    }}
                    position="left"
                >
                    <TimelineSeparator>
                        <TimelineDot />
                        <TimelineConnector />
                    </TimelineSeparator>
                    <TimelineContent>
                        Frontend Learning Path
                    </TimelineContent>
                </TimelineItem>
                <TimelineItem>
                    <TimelineSeparator>
                        <TimelineDot />
                        <TimelineConnector />
                    </TimelineSeparator>
                    <TimelineContent>HTML</TimelineContent>
                </TimelineItem>
                <TimelineItem>
                    <TimelineSeparator>
                        <TimelineDot />
                        <TimelineConnector />
                    </TimelineSeparator>
                    <TimelineContent>CSS</TimelineContent>
                </TimelineItem>
                <TimelineItem>
                    <TimelineSeparator>
                        <TimelineDot />
                    </TimelineSeparator>
                    <TimelineContent>Javascript</TimelineContent>
                </TimelineItem>
            </Timeline>
        </div>
    );
}
  
export default App;


Output:

 

Reference: https://mui.com/material-ui/api/timeline-item/



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads