Open In App

React MUI IconButton API

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 IconButtonAPI. IconButton allows the user to add icons to your application. Icons are commonly used in every application for UI purposes.

Import IconButton API:

import IconButton from '@mui/material/IconButton'

 

Props list:

  • children: It is used to denote the icon.
  • classes: It is to override or extend the styles applied to the component.
  • color: It is used to denote the color of the component. 
  • disabled: It is used to disable the component.
  • disableFocusRipple: It is used to disable the keyboard focus ripple.
  • disableRipple: It is used to disable the ripple effect.
  • edge: It is used for aligning the content along with the icon.
  • size: It is used to denote the size of the component.
  • sx: It is used to add custom CSS styles to the icon button.

CSS Rules:

  • root (MuiDivider-root):  It is the style applied to the root element.
  • edgeStart (MuiIconButton-edgeStart): It applies styles to the root when the edge is started.
  • edgeEnd (MuiIconButton-edgeEnd): It applies styles to the root when the edge ends.
  • colorInherit (MuiIconButton-colorInherit): It applies styles to the root when color is inherent.
  • colorPrimary (MuiIconButton-colorPrimary): It applies styles to the root when color is primary.
  • colorSecondary (MuiIconButton-colorSecondary): It applies styles to the root when color is secondary.
  • disabled (Mui-disabled): It applies styles to root when disabled is true.
  • sizeSmall (MuiIconButton-sizeSmall): It applies styles to the root when the size is small.
  • sizeMedium (MuiIconButton-sizeMedium): It applies styles to root when size is medium.
  • sizeLarge (MuiIconButton-sizeLarge): It applies styles to root when size is large.

Approach: Let us create a React project and install React MUI module. Then we will create a UI that will showcase React MUI IconButton 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/icons-material

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 IconButton API.

App.js




import * as React from 'react';
import IconButton from '@mui/material/IconButton';
import WifiIcon from '@mui/icons-material/Wifi';
import CreateIcon from '@mui/icons-material/Create';
import BuildIcon from '@mui/icons-material/Build';
  
export default function Demo() {
    return (
        <div style={{ margin: 100, textAlign: "center" }}>
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3><u>React MUI IconButton API</u></h3>
            <br />
            <IconButton color="error" size="large">
               <WifiIcon />
            </IconButton>
            <IconButton color="success" size="large">
              <CreateIcon />
            </IconButton>
            <IconButton color="primary" size="large">
               <BuildIcon />
            </IconButton>
        </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 IconButton API.

App.js




import * as React from 'react';
import IconButton from '@mui/material/IconButton';
import TvIcon from '@mui/icons-material/LiveTv';
import BoltIcon from '@mui/icons-material/Bolt';
import BluetoothIcon from '@mui/icons-material/BluetoothSearching';
import WbCloudy from '@mui/icons-material/WbCloudy';
export default function Demo() {
    return (
        <div style={{ margin: 100, textAlign: "center" }}>
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3><u>React MUI IconButton API</u></h3>
            <br />
            <IconButton color="secondary" size="small">
               <WbCloudy />
            </IconButton>
            <IconButton color="secondary" size="small"
               ><BluetoothIcon />
            </IconButton>
            <IconButton color="success" size="large">
               <TvIcon />
            </IconButton>
            <IconButton color="success" size="large">
               <BoltIcon />
            </IconButton>
        </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/icon-button/



Last Updated : 28 Sep, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads