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

When you use ReactDOM.render inside a <div>, it does not instantly generate HTML code

I am currently working with React version 16.7 and attempting to embed React components into a third-party JavaScript library (specifically, Highcharts) that requires me to output HTML from a function. This is the approach I am taking at the moment: funct ...

Masonry List with Next.js Image Fill

I am encountering an issue where the normal HTML img tag works perfectly fine inside my Masonry List. However, when I use the Next.js Image Component with a layout of fill, it fails to render anything. Custom Styles: const ImageList = styled('ul&apos ...

Customize the appearance of disabled dates in the eonasdan-datetimepicker styling

I am seeking to customize the default styles for the "eonasdan-datetimepicker" (https://github.com/Eonasdan/bootstrap-datetimepicker) by implementing a basic hover message feature. The CSS attributes currently applied to disabled dates are as follows: .bo ...

Uncovering the media:thumbnail in an RSS feed using Scrapy's CSS selector

I am currently working on parsing an RSS feed that includes image URLs. The XML file structure is as follows: <item> <title>Item Title Goes Here</title> <link>https://www.google.com</link> <media:thumbnail url="https:/ ...

Ways to transfer large amounts of data to Amazon Web Services

After reading the node documentation on sqs.sendMessage, I noticed that it mentions the ability to send messages up to 256KB in size. However, my messages tend to exceed this limit. What is the recommended approach for handling large payloads in this scena ...

Having trouble accessing the desired API as the Next.js Dynamic API Page keeps returning "local..../undefined/api/......"

Within my React components, I have implemented a function called "statusHandler" that makes a fetch call to "api/orders/ + ID" where ID is a unique item identifier. My setup involves using Next.js and pages to access API routes. An error I encountered rea ...

React is throwing an error because it cannot access the property 'length' of an undefined value

TypeError: Cannot read property 'length' of undefined When I try to run my React app, I keep getting this error message from the compiler. What steps should I take to resolve this issue? request = (start,end) => { if(this.state.teams.lengt ...

Calculating the sum of all elements in an array

Hi, I am currently attempting to retrieve the total value from an array (such as Arr[1] + Arr[2], and so forth). Unfortunately, I am struggling to find a solution. Below is my existing function: this.hourlyTotals = function() { var custsperhour = Math ...

The surprising way Next.js disabled the production build and transformed my rgba color into hsla

I created CSS code to display grid patterns like this: background-image { repeating-linear-gradient( 0deg, rgba(255, 255, 255, 0.43) 0px 1px, transparent 1px 20px ), repeating-linear-gradient( 90deg, rgba(255, 255, 255, 0.43) 0px 1px, transparent 1px 20 ...

Increasing several array elements within a MongoDB object

I have been struggling with this problem for some time now. My goal is to update multiple array values in the same object with a single query. The data in the database appears as follows: id: 616f5aca5f60da8bb5870e36 title: "title" recommendations: ...

HTML elements generated dynamically do not possess any jQuery properties

I have implemented a draggable list of Div elements using jQuery. Here is the code: <div id="external-events"> <h4>List Of Staffs</h4> <div class="external-event" data-id="1">Name</div> //Draggab ...

The scope's attribute is present, but the variable within the scope's attribute is not

Currently, I am delving into angularJS development, but encountering a perplexing issue. I am attempting to format a JSON into a table with intricate rules. The JSON structure currently is as follows: { "id":"test", "title":"Test Sample", "de ...

What is the method to obtain the zoom level in IE5 using JavaScript/jQuery?

Currently, I am using IE11 and have enabled emulation in the developer tools to change the document mode to 5. My goal now is to determine the current zoom level, which I adjust in the settings of IE. https://i.stack.imgur.com/DYftF.png The code snippet ...

Encountering obstacles with asynchronous requests while attempting to retrieve an Excel file using ajax

I am coding JavaScript for a SharePoint project, focusing on creating a function to retrieve data from an Excel document in a library. While I have successfully implemented the basic functionality, I am facing an issue with large file sizes causing the dat ...

What is the best way to perform a callback after a redirect in expressjs?

After using res.redirect('/pageOne') to redirect to a different page, I want to call a function. However, when I tried calling the function immediately after the redirect like this: res.redirect('/pageOne'); callBack(); I noticed th ...

What could be causing the Autocomplete feature to display as undefined?

I'm encountering an issue where the Autocomplete box displays "undefined" even though it returns the expected results. How can I resolve this problem? import { Drawer, List, Typography, Switch, ListItem, ListItemText, ListItemSecondaryAction, TextFiel ...

Displaying a component after retrieving a value from AsyncStorage in a React Native application

I have developed a React Component that saves user settings in the AsyncStorage and retrieves them upon loading. The functionality of storing and retrieving data is working fine, but I am facing an issue where the component renders before the values are ...

Is there a feature in JavaScript that allows for the creation of URLs?

I created an index view displaying cards (like playing cards) in a grid using BootStrap. Each card is within its own div element, and I implemented a jQuery click handler for each div to open a details page when clicked. The redirect from the index to the ...

What is the easiest way to modify the color of a basic PNG image in a web browser?

While working on a website project, I encountered instructions for mouseover styles in the design that got me thinking: It's straightforward to achieve with javascript or css image swapping... but here's the catch. There will be multiple icon li ...

Creating Comet applications without the need for IFrames

Currently embarking on my journey to develop an AJAX application with server side push. My choice of tools includes Grizzly Comet on Glassfish V2. While exploring sample applications, I've noticed that most utilize IFrames for content updates on the c ...