What is the best way to position the left sidebar on top of the other components and shift them to the

Currently, I am working on a project to display NBA data fetched from an API.
I am aiming to recreate the design showcased here: Dribbble Design
My main challenge lies in overlaying the left sidebar onto the main box and shifting the components slightly to the right. Any tips or suggestions on how to achieve this?
The API I am utilizing can be found at: Ball Don't Lie
For the GitHub repository of my project with numerous components, visit: Project Repository
To create the design and showcase the chart, I have used ChakraUI and recharts.

// App.js - My Application File

import { Box, ChakraProvider } from "@chakra-ui/react";
import Sidebar from "./components/sidebar";
import RecentMatches from "./components/recent";
import SearchBar from "./components/topbar";
import RenderLineChart from "./components/chart";
import HighestPoints from "./components/table";
import PlayerCard from "./components/cardcomponents";

function App() {
  return (
    <ChakraProvider>
      <Sidebar />
      <Box display='flex' flexDir='column' justifyContent='center'>
        <Box
          w={[700, 800, 900]}
          border='1px'
          boxShadow='md'
          p={5}
          borderRadius={20}
          bg='white'
          borderColor='gray.400'
          mx='auto'
        >
          <SearchBar />
          <PlayerCard />
          <Box
            display='flex'
            justifyContent='space-between'
            alignItems='center'
          >
            <Box>
              <RenderLineChart />
              <RecentMatches />
            </Box>
            <Box>
              <HighestPoints />
            </Box>
          </Box>
        </Box>
      </Box>
    </ChakraProvider>
  );
}

export default App;

//sidebar.js file

import React from "react";
import {
  ProSidebar,
  SidebarHeader,
  SidebarFooter,
  SidebarContent,
} from "react-pro-sidebar";
import "react-pro-sidebar/dist/css/styles.css";

function Sidebar() {
  return (
    <ProSidebar>
      <SidebarHeader>My NBA Profile</SidebarHeader>
      <SidebarContent>Dashboard</SidebarContent>
      <SidebarContent>Dashboard</SidebarContent>
      <SidebarContent>Dashboard</SidebarContent>
      <SidebarFooter>
        {/**
         *  You can add a footer for the sidebar ex: copyright
         */}
      </SidebarFooter>
    </ProSidebar>
  );
}

export default Sidebar;

Answer №1

This is my approach to managing sidebars, which are responsive, RTL compatible, and support multiple languages using the chakra-ui library.

The layout:

import {
    Box,
    Drawer,
    DrawerBody,
    DrawerCloseButton,
    DrawerContent,
    DrawerFooter,
    DrawerHeader,
    DrawerOverlay,
    Grid,
    GridItem,
    useBreakpointValue,
} from "@chakra-ui/react";
import { ReactElement, useContext, useEffect } from "react";
import { SideBarSizeContext } from "../../contexts";
import Sidebar from "./Components/Sidebar";
import { useTheme } from "@chakra-ui/system";

export default function ProjectLayout({ children }: any): ReactElement {
    const { direction } = useTheme();
    const { sidebarSize, setSidebarSize } = useContext(SideBarSizeContext);
    const isMobile = useBreakpointValue({ base: true, md: false });
    useEffect(() => {
        isMobile && setSidebarSize("hide");
    }, [isMobile, setSidebarSize]);
    return (
        <Grid
            templateColumns={{ base: "auto", md: "min-content auto" }}
            css={{ transition: "2s" }}
        >
            {!isMobile ? (
                <GridItem minH="100vh" bg="facebook.500" color="white">
                    {sidebarSize !== "hide" && (
                        <Box paddingBlockStart="1.5">
                            {/* <Flex h="3rem">Logo</Flex> */}
                            <Sidebar sidbarWidth={sidebarSize} />
                        </Box>
                    )}
                </GridItem>
            ) : (
                <Drawer
                    isOpen={sidebarSize !== "hide"}
                    onClose={() => setSidebarSize("hide")}
                    colorScheme="facebook"
                    size="xs"
                    placement={direction === "ltr" ? "left" : "right"}
                >
                    <DrawerOverlay />
                    <DrawerContent width="2.5" dir={direction}>
                        <DrawerCloseButton onClick={() => setSidebarSize("hide")} />
                        <DrawerHeader>Drawer heading text</DrawerHeader>
                        <DrawerBody p="0">
                            <Sidebar sidbarWidth="open-wide" />
                        </DrawerBody>
                        <DrawerFooter></DrawerFooter>
                    </DrawerContent>
                </Drawer>
            )}
            <GridItem>
                <Box bg="gray.100" h="100%">
                    {children}
                </Box>
            </GridItem>
        </Grid>
    );
}

The context:

import { createContext } from "react";

interface LangCTX {
    locale: string;
    changeLocale: React.Dispatch<React.SetStateAction<string>>;
}
export const LanguageContext = createContext({} as LangCTX);

interface SideBarSizeCTX {
    sidebarSize: "compact" | "open-wide" | "hide";
    setSidebarSize: React.Dispatch<
        React.SetStateAction<"compact" | "open-wide" | "hide">
    >;
}
export const SideBarSizeContext = createContext({} as SideBarSizeCTX);

The sidebar:

import { Flex, List, ListIcon, ListItem, Text } from "@chakra-ui/react";
import React, { ReactElement } from "react";
import { HiOutlineCube, HiOutlineServer } from "react-icons/hi";
import { RiScales3Line, RiKeyLine } from "react-icons/ri";
import { GiFirewall } from "react-icons/gi";
import { FaNetworkWired } from "react-icons/fa";
import { BiNetworkChart } from "react-icons/bi";
import { Link as ReactRouterLink, useParams } from "react-router-dom";
import { FormattedMessage } from "react-intl";

interface Props {
    sidbarWidth: "compact" | "open-wide" | "hide";
}

export default function Sidebar({ sidbarWidth }: Props): ReactElement {
    const { id }: any = useParams();
    return (
        <Flex w="100%" justifyContent="flex-start" alignItems="center">
            <List spacing={3} colorScheme="facebook">
                <ListItem
                    as={ReactRouterLink}
                    to={`/project/${id}/servers`}
                    justifyContent="flex-start"
                    alignItems="center"
                    display="flex"
                    flexDirection={sidbarWidth === "open-wide" ? "row" : "column"}
                    gridGap={2}
                    title="servers"
                    p="2.5"
                >
                    <ListIcon m={0} p={0} as={HiOutlineServer} w={6} h={6} />
                    {sidbarWidth === "open-wide" && (
                        <Text fontSize="xs" textAlign="center" whiteSpace="nowrap">
                            <FormattedMessage id="Sidebar.Servers" defaultMessage="Servers" />
                        </Text>
                    )}
                </ListItem>
                <ListItem
                    as={ReactRouterLink}
                    to={`/project/${id}/volumes`}
                    justifyContent="flex-start"
                    alignItems="center"
                    display="flex"
                    flexDirection={sidbarWidth === "open-wide" ? "row" : "column"}
                    gridGap={2}
                    title="volumes"
                    p="2.5"
                >
                    <ListIcon m={0} p={0} as={HiOutlineCube} w={6} h={6} />
                    {sidbarWidth === "open-wide" && (
                        <Text fontSize="xs" textAlign="center" whiteSpace="nowrap">
                            <FormattedMessage id="Sidebar.Volumes" defaultMessage="Volumes" />
                        </Text>
                    )}
                </ListItem>
                <!-- More sidebar items -->
            </List>
        </Flex>
    );
}

The language provider for App.js:

import { ChakraProvider, extendTheme } from "@chakra-ui/react";
import { ReactElement, useEffect, useState } from "react";
import { IntlProvider } from "react-intl";
import { LanguageContext } from "../contexts";
<!-- Code omitted for brevity -->

AppBar > Toggle SideBar size button: (hide, compact, open-wide):

import { Flex, IconButton, useBreakpointValue } from "@chakra-ui/react";
import { ReactElement } from "react";
import { MdExitToApp, MdMenu } from "react-icons/md";
import { useHistory } from "react-router-dom";
import LanguageSwitcher from "./LanguageSwitcher";

interface Props {
    setSideBarSize: Function;
}

export default function AppBar({ setSideBarSize }: Props): ReactElement {
    const history = useHistory();
    const variant = useBreakpointValue({
        base: () =>
            setSideBarSize((prev: "compact" | "open-wide" | "hide") => {
                return prev === "hide" ? "open-wide" : "hide";
            }),
        md: () =>
            setSideBarSize((prev: "compact" | "open-wide" | "hide") => {
                if (prev === "hide") return "open-wide";
                if (prev === "compact") return "hide";
                return "compact";
            }),
    });
    return (
        <Flex
            bg="facebook.400"
            color="white"
            w="100%"
            h="3rem"
            alignItems="center"
            paddingInline="0.3rem"
            justifyContent="space-between"
        >
            <Flex alignItems="center">
                <IconButton
                    variant="unstyled"
                    aria-label="Menu"
                    icon={<MdMenu />}
                    display="flex"
                    alignItems="center"
                    fontSize={24}
                    cursor="pointer"
                    onClick={variant}
                />
                My Panel
            </Flex>
            <Flex>
                <LanguageSwitcher />
                <IconButton
                    variant="unstyled"
                    icon={<MdExitToApp />}
                    fontSize={24}
                    aria-label="Logout"
                    display="flex"
                    alignItems="center"
                    onClick={() => {
                        
                    }}
                />
            </Flex>
        </Flex>
    );
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty retrieving data despite providing the correct URL

I am encountering an issue with a fetch function designed to retrieve a JSON web token. Despite verifying the correctness of the URL, the function is not functioning as expected. Below is the front-end function: const handleSubmit = async (e) => { ...

Creating a dynamic image slider that smoothly glides across a webpage

I've been working on a carousel (image slider) for my website and I need some help. Specifically, I want to reposition the entire slider slightly to the left on the webpage. You can see the slider in action on this site: and I also created a jsfiddle ...

Can someone please guide me on how to transfer information from a material ui datagrid Row to a form input?

I need assistance. I have a table that holds user data and I want to create a functionality where clicking on the edit button opens a dialogue box with a form pre-filled with the user's initial data. However, I'm currently only able to pass the u ...

Dealing with AJAX error in pure JavaScript

I have been attempting to address AJAX errors using the code below, but unfortunately, it does not seem to be effective. function ajaxPost(url, data, success, error) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () ...

Learn how to implement AuthContext and createDataContext in React Native Expo development using TypeScript

AuthContext.tsx import createDataContext from './createDataContext'; import serverApi from '../api/server'; const authReducer = ({state, action}: any) => { switch(action.type){ default: return state; } } ...

Incorporating an SVG with CSS styling from a stylesheet

After exploring various articles and questions on the topic, I am yet to find a definitive solution. I have an external file named icon.svg, and my objective is to utilize it across multiple HTML files with different fill colors and sizes for each instanc ...

Personalizing the predefined title bar outline of the input text field

The outline color of the title in the input textbox appears differently in Google Chrome, and the bottom border line looks different as well. <input type="text" title="Please fill out this field."> https://i.stack.imgur.com/iJwPp.png To address th ...

Compiling this HTML template in dev mode with Vue is agonizingly slow

I've been working with a template app setup that was bootstrapped using vue CLI. Within one of my components, I have 20 nested div tags. During development mode, it's taking roughly 10 seconds to compile this component. The more deeply I nest HTM ...

Pass RGBA color code from JavaScript to Laravel controller

I have an exciting project where users need to select a color value in hex format. Once I retrieve this value in JavaScript, I convert it to Rgba format. Now, my challenge is figuring out how to send this converted value to the controller for database stor ...

Is it possible to create clickable strings in React?

I am currently working on displaying strings using material-ui and react, but I have encountered an interesting challenge: <Typography paragraph variant="body1"> {text1} <strong>{text2}</strong> </Typograp ...

Dynamic controller in TypeScript with React Hook Form

Is there a way to ensure that the fieldName is always inside the control? Passing a field name that doesn't exist in the form causes issues for me, so I'm looking for a solution. Can anyone help? import { Control, Controller } from 'react-ho ...

Scroll to the top of a new page with Material UI's table component

Feeling a little stuck here. I've tested various settings with scrollTop, but haven't had much luck. To clarify, I'm working with Material UI and their pagination features in conjunction with a table (you can find the documentation here). W ...

Creating an array of options for a jQuery plugin by parsing and populating

I am currently in the process of developing my very first jQuery plugin. The main function of this plugin involves taking JSON data and loading it into a table. Although most of the logic has been implemented successfully, I am facing challenges when it co ...

Is it conceivable that Jquery is failing to load for an Ajax request?

I have been experiencing an issue with my jQuery code not working within Ajax requests. The jQuery plugin I am using is FancyBox which can be found at . When calling the FancyBox plugin directly, everything works perfectly and multiple links load the plugi ...

The behavior of JavaScript replace varies between Chrome and IE

This JavaScript code successfully replaces a string in Chrome: myUrl = someUrl.replace('%2C%7B%22itn%22%3A%5B%22%20guidelines%20%22%5D%7D', ''); However, when tested in Internet Explorer, it does not replace the string as expected. T ...

React - The Suspense boundary was still updating when it received a new update

I'm encountering these errors on my local environment but not on the production site: Unhandled Runtime Error Error: I'm facing issues with a Suspense boundary that switched to client rendering before finishing hydration. The typical solution is ...

Align your content in the center of any browser

My CSS code is currently only centering on a certain type of screen, but I want it to be centered on any screen. Here is the CSS code: @import url(http://fonts.googleapis.com/css?family=Roboto+Condensed); html{ font-family: "HelveticaNeue-Light" ...

Using JS regular expressions to only select anchor (a) tags with specific attributes

When trying to select a link tag (a) with a specific data-attr, I encountered an issue. I currently use the following regex pattern: /<a.*?data-extra-url=".*?<\/a>/g. However, I noticed that this selection goes wrong when there are no line br ...

javascript to retrieve data by reducing

Here is the code snippet I am working with: var points = 4; var yModifier = []; for (var i = 0; i <= points; i++) { yModifier.push([]); }; yModifier.forEach( (a, j) => { var start = j; var end = start + points; fo ...

Is there a way to enable code completion for Firebase on VS Code?

After successfully setting up Typescript for code completion following the guidelines provided in this resource, I now want to enable code completion for Firebase in VS Code. However, I am unsure of the steps to achieve this. How can I activate code compl ...