Sunday, November 17, 2024
Google search engine
HomeLanguagesReact MUI AccordionActions API

React MUI AccordionActions API

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 AccordionActions API. The Accordion component allows users to organize content in different sections in a single container. Users can show and hide the different sections. 

Import AccordionActions API:

import Accordion from '@mui/material/Accordion';
import AccordionActions from '@mui/material/AccordionActions';

 

Props list:

  • children: It is used to denote the content of the Accordion.
  • classes: It is to override or extend the styles applied to the component.
  • disableSpacing: It takes a boolean value to remove an additional margin.
  • sx: It is used to add custom CSS styles to the Accordion.

CSS Rules:

  • root (MuiAccordionActions-root): The style applied to the root element.
  • spacing (MuiAccordionActions-spacing): It applies styles when the disableSpacing is true.

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

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

  • Filename: App.js

Javascript




import * as React from 'react';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import {
    Accordion, AccordionSummary, AccordionDetails
    , AccordionActions, Button, Typography
} from '@mui/material';
  
export default function Demo() {
    return (
        <div style={{ margin: 100 }}>
            <h1 style={{ color: 'green' }}>neveropen</h1>
            <h3><u>React MUI AccordionActions API</u></h3>
            <Accordion>
                <AccordionSummary expandIcon={<ExpandMoreIcon />}>
                    <Typography>Accordion 1</Typography>
                </AccordionSummary>
                <AccordionDetails>
                    <h3>Disabled Spacing</h3>
                </AccordionDetails>
                <AccordionActions disableSpacing={true}>
                    <Button color="success" variant="contained">
                       Button 1
                    </Button>
                    <Button color="success" variant="contained">
                       Button 2
                     </Button>
                    <Button color="success" variant="contained">
                       Button 3
                     </Button>
                    <Button color="success" variant="contained">
                       Button 4
                    </Button>
                </AccordionActions>
            </Accordion>
        </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 AccordionActions API.

  • Filename: App.js

Javascript




import * as React from 'react';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import {
    Accordion, AccordionSummary, AccordionDetails
    , AccordionActions, Button, Typography
} from '@mui/material';
  
export default function Demo() {
    return (
        <div style={{ margin: 100 }}>
            <h1 style={{ color: 'green' }}>neveropen</h1>
            <h3><u>React MUI AccordionActions API</u></h3>
            <Accordion>
                <AccordionSummary expandIcon={<ExpandMoreIcon />}>
                    <Typography>DSA Self Paced</Typography>
                </AccordionSummary>
                <AccordionDetails>
                    <p>Course Description</p>
                    <p>
                        Most popular course on DSA trusted by
                        over 75,000 students! Built with years
                        of experience by industry experts. Start
                        Today!
                    </p>
                </AccordionDetails>
                <AccordionActions sx={{ bgcolor: "green" }}>
                    <Button color="warning" variant="contained">
                      Enroll Now
                    </Button>
                </AccordionActions>
            </Accordion>
        </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/accordion-actions/

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments