Open In App

React Suite Container Sidebar Layout

Last Updated : 25 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

React Suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application.

In this article, we’ll learn about React Suite Container Sidebar Layout. The container layout can define the main frame of the page using header, content, sidebar, and footer components. The sidebar is used to provide side navigation functionality to the users.

Syntax:

<Container>
    <Sidebar>...</Sidebar>
     <Header>Header</Header>
     <Content>Content</Content>
     <Footer>Footer</Footer>
</Container>

Creating React Application And Installing Module:

Step 1: Create a React application using the given command:

npm create-react-app projectname

Step 2: After creating your project, move to it using the given command:

cd projectname

Step 3: Now Install the rsuite node package using the given command:

npm install rsuite

Project Structure: Now your project structure should look like the following:

 

Example 1: Below example demonstrates the basic sidebar layout.

App.js




import {
    Container,
    Header,
    Footer,
    Content,
    Sidebar,
    Sidenav,
    Nav,
} from "rsuite";
import "rsuite/dist/rsuite.min.css";
  
export default function App() {
    return (
        <center>
            <div>
                <h2>GeeksforGeeks</h2>
                <h4 style={{ color: "green" }}>
                    React Suite Sidebar Layout
                </h4>
                <div style={{ marginTop: 20, width: 800 }}>
                    <Container>
                        <Sidebar 
                            style={{ 
                                backgroundColor: "#172F50"
                                padding: 30 
                            }}
                        >
                            <h4 style={{ color: "white" }}>
                                GeeksforGeeks
                            </h4>
                            <ul
                                style={{
                                    listStyleType: "none",
                                    padding: 10,
                                    fontSize: 20,
                                    color: "white",
                                }}
                            >
                                <li>Tutorials</li>
                                <li>Courses</li>
                                <li>Jobs</li>
                                <li>Practice</li>
                                <li>Contact</li>
                            </ul>
                        </Sidebar>
                        <Container>
                            <Header
                                style={{
                                    backgroundColor: "green",
                                    padding: 20,
                                    color: "white",
                                }}
                            >
                                <h2>GeeksforGeeks</h2>
                            </Header>
                            <Content
                                style={{
                                    backgroundColor: "lightgreen",
                                    padding: 40,
                                    color: "white",
                                }}
                            >
                                GeeksforGeeks is a portal for geeks. 
                                It is a collection of well-written, 
                                well-thought, and well-responsive articles.
                            </Content>
                            <Footer
                                style={{
                                    backgroundColor: "lightgray",
                                    padding: 20,
                                    color: "white",
                                }}
                            >
                                © GeeksforGeeks.org
                            </Footer>
                        </Container>
                    </Container>
                </div>
            </div>
        </center>
    );
}


Step to Run Application: Run the application using the following command from the project’s root directory.

npm start

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

 

Example 2: Below example demonstrates the sidebar layout with side navigation.

App.js




import { useState } from "react";
import {
    Container,
    Header,
    Content,
    Sidebar,
    Sidenav,
    Nav,
    Navbar,
} from "rsuite";
  
import "rsuite/dist/rsuite.min.css";
import Cog from "@rsuite/icons/legacy/Cog";
import AngleLeft from "@rsuite/icons/legacy/AngleLeft";
import AngleRight from "@rsuite/icons/legacy/AngleRight";
  
const ToggleButton = ({ expand, onChange }) => {
    return (
        <Navbar appearance="subtle" className="nav-toggle">
            <Navbar.Body>
                <Nav>
                    <Nav.Menu
                        placement="topStart"
                        trigger="click"
                        renderTitle={(children) => {
                            return (
                                <Cog
                                    style={{
                                        width: 56,
                                        height: 56,
                                        padding: 18,
                                        lineHeight: "56px",
                                        textAlign: "center",
                                    }}
                                />
                            );
                        }}
                    >
                        <Nav.Item>Help</Nav.Item>
                        <Nav.Item>Settings</Nav.Item>
                        <Nav.Item>Sign out</Nav.Item>
                    </Nav.Menu>
                </Nav>
  
                <Nav pullRight>
                    <Nav.Item
                        onClick={onChange}
                        style={{ width: 56, textAlign: "center" }}
                    >
                        {expand ? <AngleLeft /> : <AngleRight />}
                    </Nav.Item>
                </Nav>
            </Navbar.Body>
        </Navbar>
    );
};
  
export default function App() {
    const [expand, setExpand] = useState(true);
  
    return (
        <div>
            <Container>
                <Sidebar
                    style={{ 
                        display: "flex"
                        flexDirection: "column" 
                    }}
                    width={expand ? 260 : 56}
                    collapsible
                >
                    <Sidenav.Header>
                        <div
                            style={{
                                padding: 18,
                                fontSize: 20,
                                height: 56,
                                color: " #fff",
                                background: "green",
                            }}
                        >
                            <span style={{ marginLeft: 12 }}>
                                GeeksforGeeks
                            </span>
                        </div>
                    </Sidenav.Header>
                    <Sidenav expanded={expand} defaultOpenKeys={["2"]}>
                        <Sidenav.Body>
                            <Nav>
                                <Nav.Item eventKey="1" active>
                                    My Dashboard
                                </Nav.Item>
                                <Nav.Item eventKey="2">
                                    Posts
                                </Nav.Item>
                                <Nav.Menu
                                    eventKey="3"
                                    trigger="hover"
                                    title="Courses"
                                    placement="rightStart"
                                >
                                    <Nav.Item eventKey="3-1">
                                        Full Stack Dev
                                    </Nav.Item>
                                    <Nav.Item eventKey="3-2">
                                        DSA
                                    </Nav.Item>
                                    <Nav.Item eventKey="3-3">
                                        C++
                                    </Nav.Item>
                                    <Nav.Item eventKey="3-4">
                                        Java
                                    </Nav.Item>
                                    <Nav.Item eventKey="3-5">
                                        Python
                                    </Nav.Item>
                                </Nav.Menu>
                                <Nav.Menu
                                    eventKey="4"
                                    trigger="hover"
                                    title="Tutorials"
                                    placement="rightStart"
                                >
                                    <Nav.Item eventKey="4-1">
                                        Data Structures
                                    </Nav.Item>
                                    <Nav.Item eventKey="4-2">
                                        Algorithms
                                    </Nav.Item>
                                    <Nav.Item eventKey="4-3">
                                        Web Dev
                                    </Nav.Item>
                                    <Nav.Item eventKey="4-4">
                                        Android Dev
                                    </Nav.Item>
                                </Nav.Menu>
                            </Nav>
                        </Sidenav.Body>
                    </Sidenav>
                    <ToggleButton 
                        expand={expand} 
                        onChange={() => setExpand(!expand)} 
                    />
                </Sidebar>
  
                <Container>
                    <Header style={{ padding: 20 }}>
                        <h2>Welcome to GeeksforGeeks</h2>
                    </Header>
                    <Content style={{ padding: 20 }}>
                        <h3>Dashboard</h3>
                        <p>
                            GeeksforGeeks is a portal for the 
                            community of geeks. It is a place 
                            for you to share your knowledge, share 
                            your experience, and connect with other geeks.
                        </p>
                    </Content>
                </Container>
            </Container>
        </div>
    );
}


Output:

 

Reference: https://rsuitejs.com/components/container/#sidebar-layout



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads