content logo

React Accordions:

React Accordion with Expand and Collapse Buttons

Menus are so important in any website, and if you have a page, you have to apply a menu on it. In this post, you can see the performance of the r React Accordion with Expand and Collapse Buttons. This beautiful React Accordion Code has an attractive design, and you are able to use it on all websites with various themes. So, if you want to mention a lot of information in a small physical space on your page, this Collapsible Accordion Code is a great idea. You can apply it and get more users on your page.

We have located the preview of this React Expandable Accordion Code down to represent its performance to you. As you can see from this preview, the mentioned code has a blue theme, and you can use it if you have the same color on your website. The title has a larger font style in blue color, and there are two buttons with white background and blue text and border. Additionally, this Responsive Accordion Design includes three fields with a plus icon, and when you click on this item, you can see detailed information in a white field below.

#

React Accordion Code

#

Collapsible Accordion Code

#

React Expandable Accordion Code

#

Responsive Accordion Design

<!-- This script got from frontendfreecode.com -->
<div id="app"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
@import url("https://fonts.googleapis.com/css?family=PT+Sans");
html, body, #app {
	height: 100%;
}
.container {
	min-height: 100%;
	padding: 30px;
	font-family: "PT Sans";
	text-align: center;
}
.container h1 {
	text-align: center;
	color: #1569a8;
}
.container .btn {
	display: inline-block;
	margin-bottom: 20px;
	border: 1px solid #1569a8;
	background: white;
	color: #1569a8;
	padding: 5px 10px;
	border-radius: 5px;
	margin-right: 5px;
	font-size: 15px;
	cursor: pointer;
	outline: none;
}
.container .btn:hover {
	background: #1569a8;
	color: white;
	transition: 0.5s;
}
.accordion {
	margin: 0 auto;
	width: 80%;
}
.accordion .title {
	padding: 30px 30px;
	cursor: pointer;
	transform: translate3d(0, 0, 0);
	color: white;
	position: relative;
	font-size: 20px;
	background: #1569a8;
	margin-bottom: -1px;
	border-bottom: 1px solid #0e4671;
	text-align: left;
}
.accordion .title::after {
	content: "+";
	font-size: 18px;
	color: white;
	transition: transform 0.5s ease-in-out;
	position: absolute;
	right: 30px;
	font-family: monospace;
}
.accordion .title.is-expanded {
	transition: background 0.5s;
	background: #0e4671;
}
.accordion .title.is-expanded::after {
	content: "-";
	transform: rotate(-360deg);
}
.accordion .content {
	overflow: hidden;
	max-height: 0;
	transition: max-height 0.5s;
	margin: 0;
	padding: 0 30px;
	border: solid 1px #eeeeee;
	border-top: 0;
	background: #e8f4fc;
}
.accordion .content p {
	padding: 30px 0;
	margin: 0;
	opacity: 0;
	transition: 0.5s;
}
.accordion .content.is-expanded {
	max-height: 500px;
	overflow: hidden;
}
.accordion .content.is-expanded p {
	opacity: 1;
}
.accordion:after {
	width: 100%;
	height: 10px;
	display: block;
	background: #0e4671;
	content: "";
}
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } class Accordion extends React.Component {
    render() {
        const { title, expand, onClick } = this.props;
        return /*#__PURE__*/(
            React.createElement("div", null, /*#__PURE__*/
                React.createElement("dt", { className: expand ? 'title is-expanded' : 'title', onClick: onClick },
                    title), /*#__PURE__*/
                React.createElement("dd", { className: expand ? 'content is-expanded' : 'content', onClick: onClick }, /*#__PURE__*/
                    React.createElement("p", null, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu interdum diam. Donec interdum porttitor risus non bibendum. Maecenas sollicitudin eros in quam imperdiet placerat. Cras justo purus, rhoncus nec lobortis ut, iaculis vel ipsum. Donec dignissim arcu nec elit faucibus condimentum. Donec facilisis consectetur enim sit amet varius. Pellentesque justo dui, sodales quis luctus a, iaculis eget mauris. Aliquam dapibus, ante quis fringilla feugiat, mauris risus condimentum massa, at elementum libero quam ac ligula. Pellentesque at rhoncus dolor. Duis porttitor nibh ut lobortis aliquam. Nullam eu dolor venenatis mauris placerat tristique eget id dolor. Quisque blandit adipiscing erat vitae dapibus. Nulla aliquam magna nec elementum tincidunt."))));
    }
}
class Application extends React.Component {
    constructor(props) {
        super(props); _defineProperty(this, "toggle",
            index => () => {
                this.setState({ [`block${index}`]: !this.state[`block${index}`] });
            }); _defineProperty(this, "toggleExpand",
                (expand = false) => () => {
                    this.setState({
                        block1: expand,
                        block2: expand,
                        block3: expand
                    });
                }); this.state = { block1: true, block2: false, block3: false };
    }
    render() {
        const accordionList = [{ title: 'First Accordion' }, { title: 'Second Accordion' }, { title: 'Third Accordion' }];
        return /*#__PURE__*/React.createElement("div", { className: "container" }, /*#__PURE__*/
            React.createElement("h1", null, "React Accordion"), /*#__PURE__*/
            React.createElement("button", { type: "button", className: "btn", onClick: this.toggleExpand(true) }, "Expand All"), /*#__PURE__*/
            React.createElement("button", { type: "button", className: "btn", onClick: this.toggleExpand() }, "Collapse All"), /*#__PURE__*/
            React.createElement("dl", { className: "accordion" },
                accordionList.map((item, index) => /*#__PURE__*/
                    React.createElement(Accordion, { title: item.title, onClick: this.toggle(index + 1), expand: this.state[`block${index + 1}`] }))));
    }
}
React.render( /*#__PURE__*/React.createElement(Application, null), document.getElementById('app'));
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.min.js'></script>
<style>
@import url("https://fonts.googleapis.com/css?family=PT+Sans");
html, body, #app {
	height: 100%;
}
.container {
	min-height: 100%;
	padding: 30px;
	font-family: "PT Sans";
	text-align: center;
}
.container h1 {
	text-align: center;
	color: #1569a8;
}
.container .btn {
	display: inline-block;
	margin-bottom: 20px;
	border: 1px solid #1569a8;
	background: white;
	color: #1569a8;
	padding: 5px 10px;
	border-radius: 5px;
	margin-right: 5px;
	font-size: 15px;
	cursor: pointer;
	outline: none;
}
.container .btn:hover {
	background: #1569a8;
	color: white;
	transition: 0.5s;
}
.accordion {
	margin: 0 auto;
	width: 80%;
}
.accordion .title {
	padding: 30px 30px;
	cursor: pointer;
	transform: translate3d(0, 0, 0);
	color: white;
	position: relative;
	font-size: 20px;
	background: #1569a8;
	margin-bottom: -1px;
	border-bottom: 1px solid #0e4671;
	text-align: left;
}
.accordion .title::after {
	content: "+";
	font-size: 18px;
	color: white;
	transition: transform 0.5s ease-in-out;
	position: absolute;
	right: 30px;
	font-family: monospace;
}
.accordion .title.is-expanded {
	transition: background 0.5s;
	background: #0e4671;
}
.accordion .title.is-expanded::after {
	content: "-";
	transform: rotate(-360deg);
}
.accordion .content {
	overflow: hidden;
	max-height: 0;
	transition: max-height 0.5s;
	margin: 0;
	padding: 0 30px;
	border: solid 1px #eeeeee;
	border-top: 0;
	background: #e8f4fc;
}
.accordion .content p {
	padding: 30px 0;
	margin: 0;
	opacity: 0;
	transition: 0.5s;
}
.accordion .content.is-expanded {
	max-height: 500px;
	overflow: hidden;
}
.accordion .content.is-expanded p {
	opacity: 1;
}
.accordion:after {
	width: 100%;
	height: 10px;
	display: block;
	background: #0e4671;
	content: "";
}
</style>

</head>
<body>
<div id="app"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } class Accordion extends React.Component {
    render() {
        const { title, expand, onClick } = this.props;
        return /*#__PURE__*/(
            React.createElement("div", null, /*#__PURE__*/
                React.createElement("dt", { className: expand ? 'title is-expanded' : 'title', onClick: onClick },
                    title), /*#__PURE__*/
                React.createElement("dd", { className: expand ? 'content is-expanded' : 'content', onClick: onClick }, /*#__PURE__*/
                    React.createElement("p", null, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu interdum diam. Donec interdum porttitor risus non bibendum. Maecenas sollicitudin eros in quam imperdiet placerat. Cras justo purus, rhoncus nec lobortis ut, iaculis vel ipsum. Donec dignissim arcu nec elit faucibus condimentum. Donec facilisis consectetur enim sit amet varius. Pellentesque justo dui, sodales quis luctus a, iaculis eget mauris. Aliquam dapibus, ante quis fringilla feugiat, mauris risus condimentum massa, at elementum libero quam ac ligula. Pellentesque at rhoncus dolor. Duis porttitor nibh ut lobortis aliquam. Nullam eu dolor venenatis mauris placerat tristique eget id dolor. Quisque blandit adipiscing erat vitae dapibus. Nulla aliquam magna nec elementum tincidunt."))));
    }
}
class Application extends React.Component {
    constructor(props) {
        super(props); _defineProperty(this, "toggle",
            index => () => {
                this.setState({ [`block${index}`]: !this.state[`block${index}`] });
            }); _defineProperty(this, "toggleExpand",
                (expand = false) => () => {
                    this.setState({
                        block1: expand,
                        block2: expand,
                        block3: expand
                    });
                }); this.state = { block1: true, block2: false, block3: false };
    }
    render() {
        const accordionList = [{ title: 'First Accordion' }, { title: 'Second Accordion' }, { title: 'Third Accordion' }];
        return /*#__PURE__*/React.createElement("div", { className: "container" }, /*#__PURE__*/
            React.createElement("h1", null, "React Accordion"), /*#__PURE__*/
            React.createElement("button", { type: "button", className: "btn", onClick: this.toggleExpand(true) }, "Expand All"), /*#__PURE__*/
            React.createElement("button", { type: "button", className: "btn", onClick: this.toggleExpand() }, "Collapse All"), /*#__PURE__*/
            React.createElement("dl", { className: "accordion" },
                accordionList.map((item, index) => /*#__PURE__*/
                    React.createElement(Accordion, { title: item.title, onClick: this.toggle(index + 1), expand: this.state[`block${index + 1}`] }))));
    }
}
React.render( /*#__PURE__*/React.createElement(Application, null), document.getElementById('app'));
</script>

</body>
</html>
Preview