content logo

React Accordions:

Simple Tree Accordion using React JS

This post represents the Simple Tree Accordion using React JS and its attractive design. If you have a web page and want to change its appearance as soon as possible, this React Tree Accordion is a great idea. With the help of this beautiful HTML Accordion Code, you are able to structure and categorize all items on your website better. As a result, your audiences can access information easily. So, if you use these kinds of JS Accordion using React codes and your page, you can gain more followers in a short time.

If you want to realize the performance of this code, you can look at its preview below. As you see, this Simple Accordion Code can be suitable for different kinds of websites. It has a white background and a plus icon on the corner of the page. This icon and all texts are black. When you click on the plus icon, some subcategories will be displayed with a hover effect below this icon. These items are presented in a field with white background, and they have a gray thin border. If you use this code on your website, you are able to write various information in a small space.

#

React Tree Accordion

#

Simple Accordion Code

#

HTML Accordion Code

#

JS Accordion using React

<!-- This script got from frontendfreecode.com -->
<div id="menuContainer"></div>
<div>
    <p>Body Text</p>
    <p>Body Text</p>
    <p>Body Text</p>
</div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
.menu-enter {
	max-height: 0px;
	-webkit-transition: max-height 1s ease;
	overflow: hidden;
}
.menu-enter.menu-enter-active {
	height: auto;
	max-height: 100px;
}
.menu-leave {
	max-height: 100px;
	-webkit-transition: max-height 1s ease;
}
.menu-leave.menu-leave-active {
	overflow: hidden;
	max-height: 0px;
}
ul {
	border: #ababab solid 1px;
	width: 70%;
}
let ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
class DropDown extends React.Component {
    constructor(props) {
        super(props);
        this.toggleMenu = this.toggleMenu.bind(this);
        this.state = {
            menuActive: false
        };
    }
    toggleMenu() {
        let menuState = !this.state.menuActive;
        this.setState({
            menuActive: menuState
        });
    }
    render() {
        let menu;
        if (this.state.menuActive) {
            menu = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/
                React.createElement("ul", null, /*#__PURE__*/
                    React.createElement("li", null, "First Item "), /*#__PURE__*/
                    React.createElement("li", null, "Second Item "), /*#__PURE__*/
                    React.createElement("li", null, "Third Item ")));
        } else {
            menu = "";
        }
        return /*#__PURE__*/(
            React.createElement("div", { id: "menu" }, /*#__PURE__*/
                React.createElement("i", { className: "fa fa-plus", onClick: this.toggleMenu }), /*#__PURE__*/
                React.createElement(ReactCSSTransitionGroup, { transitionName: "menu", transitionEnterTimeout: 1000, transitionLeaveTimeout: 1000 },
                    menu)));
    }
}
ReactDOM.render( /*#__PURE__*/
    React.createElement(DropDown, null),
    document.getElementById('menuContainer'));
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.5/react-with-addons.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.5/react-dom.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.5/react-with-addons.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.5/react-dom.js'></script>
<style>
.menu-enter {
	max-height: 0px;
	-webkit-transition: max-height 1s ease;
	overflow: hidden;
}
.menu-enter.menu-enter-active {
	height: auto;
	max-height: 100px;
}
.menu-leave {
	max-height: 100px;
	-webkit-transition: max-height 1s ease;
}
.menu-leave.menu-leave-active {
	overflow: hidden;
	max-height: 0px;
}
ul {
	border: #ababab solid 1px;
	width: 70%;
}
</style>

</head>
<body>
<div id="menuContainer"></div>
<div>
    <p>Body Text</p>
    <p>Body Text</p>
    <p>Body Text</p>
</div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
let ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
class DropDown extends React.Component {
    constructor(props) {
        super(props);
        this.toggleMenu = this.toggleMenu.bind(this);
        this.state = {
            menuActive: false
        };
    }
    toggleMenu() {
        let menuState = !this.state.menuActive;
        this.setState({
            menuActive: menuState
        });
    }
    render() {
        let menu;
        if (this.state.menuActive) {
            menu = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/
                React.createElement("ul", null, /*#__PURE__*/
                    React.createElement("li", null, "First Item "), /*#__PURE__*/
                    React.createElement("li", null, "Second Item "), /*#__PURE__*/
                    React.createElement("li", null, "Third Item ")));
        } else {
            menu = "";
        }
        return /*#__PURE__*/(
            React.createElement("div", { id: "menu" }, /*#__PURE__*/
                React.createElement("i", { className: "fa fa-plus", onClick: this.toggleMenu }), /*#__PURE__*/
                React.createElement(ReactCSSTransitionGroup, { transitionName: "menu", transitionEnterTimeout: 1000, transitionLeaveTimeout: 1000 },
                    menu)));
    }
}
ReactDOM.render( /*#__PURE__*/
    React.createElement(DropDown, null),
    document.getElementById('menuContainer'));
</script>

</body>
</html>
Preview