Open In App

React MUI CircularProgress API

Last Updated : 28 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

React MUI 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. Material-UI is a user interface library that provides predefined and customizable React components for faster and easy web development, these Material-UI components are based on top of Material Design by Google.  

In this article, we are going to discuss the React MUI CircularProgressAPI. The Progress is used to indicate user task is completed or at what stage it is currently on.

Import CircularProgress API:

import CircularProgress from '@mui/material/CircularProgress'

 

Props list:

  • classes: It is to override or extend the styles applied to the component.
  • value: The value of the circular progress is shown through this.
  • size: It is used to denote the size of the component.
  • color: It is used to denote the color of the component. 
  • disableShrink: It is used to disable the shrink animation.
  • thickness: It is used to denote the thickness of the circle.
  • sx: It is used to add custom CSS styles to circular progress.
  • variant: It is used to choose different variants of circular progress.

CSS Rules:

  • root (MuiDivider-root):  It is the style applied to the root element.
  • determinate (MuiCircularProgress-determinate): It applies styles when the circular progress variant is determinate.
  • indeterminate (MuiCircularProgress-indeterminate): It applies styles when the circular progress variant is indeterminate
  • colorPrimary (MuiCircularProgress-colorPrimary):  It applies styles when circular progress color is primary.
  • colorSecondary (MuiCircularProgress-colorSecondary): It applies styles when circular progress color is secondary.
  • svg (MuiCircularProgress-svg): It applies styles to SVG. 
  • circle (MuiCircularProgress-circle): It applies styles to the ‘circle’ SVG path.
  • circleDeterminate (MuiCircularProgress-circleDeterminate): It applies styles to the ‘circle’ SVG path when the circular progress variant is determinate.
  • circleIndeterminate (MuiCircularProgress-circleIndeterminate): It applies styles to the ‘circle’ SVG path when the circular progress variant is indeterminate.

Approach: Let us create a React project and install React MUI module. Then we will create a UI that will showcase React MUI CircularProgress API.

Creating React Project:

Step 1: To create a react app, you need to install react modules through npx command. “npx” is used instead of “npm” because you will be needing this command in your app’s lifecycle only once.

npx create-react-app project_name

Step 2: After creating your react project, move into the folder to perform different operations.

cd project_name

Step 3: After creating the ReactJS application, Install the required module using the following command:

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

Project Structure: After running the commands mentioned in the above steps, if you open the project in an editor you can see a similar project structure as shown below. The new component user makes or the code changes, we will be performing will be done in the source folder.

Project Structure

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Example 1: We are creating a UI that shows React MUI CircularProgress. 

App.js




import React from 'react';
import CircularProgress from '@mui/material/CircularProgress';
  
export default function App() {
    return (
        <div className="App" style=
           {{ textAlign: "center" }}>
            <h1 style={{ color: 'green' }}>
               GeeksforGeeks
            </h1>
            <h3>
               <u>React MUI CircularProgress API</u>
            </h3>
            <span> Success   <CircularProgress 
                color="success" />
            </span>
            <span> Primary   <CircularProgress 
                color="primary" />
            </span>
            <span> Secondary   <CircularProgress 
                color="secondary" />
            </span>
            <span> Info   <CircularProgress 
                color="info" />
             </span>
            <span> Error   <CircularProgress 
                color="error" />
             </span>
            <span> Warning   <CircularProgress
                color="warning" />
             </span>
        </div>
    );
}


Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Example 2: We are creating a UI that shows React MUI CircularProgress. 

App.js




import React from 'react';
import CircularProgress from '@mui/material/CircularProgress';
  
export default function App() {
    return (
        <div className="App" style=
             {{ textAlign: "center" }}>
            <h1 style={{ color: 'green' }}>
              GeeksforGeeks
            </h1>
            <h3><u>React MUI CircularProgress API</u></h3>
            <CircularProgress variant="determinate"
               value={20} />   
            <CircularProgress variant="determinate" 
               value={50} />   
            <CircularProgress variant="determinate" 
               value={70} />   
            <CircularProgress variant="determinate"
               value={90} />   
            <CircularProgress variant="determinate"
               value={100} />
        </div>
    );
}


Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Reference: https://mui.com/material-ui/api/circular-progress/



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

Similar Reads