Adjust item size and move them into the panel

I am looking to create a panel that arranges items in a specific layout shown here:

https://i.stack.imgur.com/qw3lS.png

Below is the code I have attempted so far:

import React, { useCallback, useEffect } from "react";
import { Box, Grid, Tab, Tabs, Typography } from "@material-ui/core";
import { makeStyles, Theme } from "@material-ui/core/styles";
import { sizing } from "@material-ui/system";

const useStyles1 = makeStyles((theme: Theme) => ({
    color: {
        backgroundColor: "green",
        border: "1px solid black"
    }
}));

const useStyles2 = makeStyles((theme: Theme) => ({
    color: {
        backgroundColor: "mediumvioletred",
        border: "1px solid black"
    }
}));

const useStyles3 = makeStyles((theme: Theme) => ({
    color: {
        backgroundColor: "orange",
        border: "1px solid black"
    }
}));

export default function Hello() {
    const classes1 = useStyles1();
    const classes2 = useStyles2();
    const classes3 = useStyles3();

    return (
        <>
            <Grid
                spacing={0}
                container
                direction="row"
                justifyContent="flex-start"
                xs={12}
                alignItems={"stretch"}
                style={{ height: "100vh", overflow: "auto", flexGrow: 1 }}
            >
                <Grid
                    // spacing={0}
                    // container
                    // direction="row"
                    // xs={3}
                    //  style={{ height: "100%", overflow: "auto" }}
                >
                    <Grid item xs={12}>
                        <Grid
                            className={classes1.color}
                            container
                            direction="column"
                            justifyContent="flex-start"
                            alignItems="center"
                        >
                            <Grid item xs={12}>
                                <Box m={2}>item link 1</Box>
                            </Grid>
                            <Grid item xs={12}>
                                <Box m={2}>item link 2</Box>
                            </Grid>
                            <Grid item xs={12}>
                                <Box m={2}>item link 3</Box>
                            </Grid>
                            <Grid item xs={12}>
                                <Box m={2}>item link 4</Box>
                            </Grid>
                        </Grid>
                    </Grid>
                </Grid>

                <Grid
                    spacing={0}
                    container
                    direction="row"
                    xs={2}
                    className={classes2.color}
                    style={{ height: "100%", overflow: "auto" }}
                >
                    <Grid item xs={12}>
                        <Box m={10}>item 11</Box>
                    </Grid>
                    <Grid item xs={12}>
                        <Box m={10}>item 11</Box>
                    </Grid>
                    <Grid item xs={12}>
                        <Box m={10}>item 13</Box>
                    </Grid>
                    <Grid item xs={12}>
                        <Box m={10}>item 14</Box>
                    </Grid>
                    <Grid item xs={12}>
                        <Box m={10}>item 15</Box>
                    </Grid>
                    <Grid item xs={12}>
                        <Box m={10}>item 16</Box>
                    </Grid>
                </Grid>
                <Grid
                    container
                    direction="row"
                    xs={4}
                    alignItems={"stretch"}
                    style={{ height: "100%", overflow: "auto" }}
                >
                    <Grid item xs={12}>
                        <Grid
                            className={classes3.color}
                            container
                            direction="row"
                            justifyContent="space-around"
                            alignItems="center"
                            style={{ width: "100%", overflow: "auto" }}
                        >
                            <Grid item xs={12}>
                                <Box m={2}>item area 1</Box>
                            </Grid>
                            <Grid item xs={12}>
                                <Box m={2}>item area 2</Box>
                            </Grid>
                        </Grid>
                    </Grid>
                </Grid>
            </Grid>
        </>
    );
}

You can view the full code here.

Any suggestions on how I can add drag functionality to the borders and enhance the layout using TypeScript?

Answer №1

Check out this demonstration that utilizes Material UI and the react-beautiful-dnd library

This example showcases a drag-and-drop functionality inspired by ticket-based systems like Jira

Within the App.js file:

import React, { useState } from "react";
import makeStyles from "@material-ui/core/styles/makeStyles";
import Grid from "@material-ui/core/Grid";
import { DragDropContext } from "react-beautiful-dnd";
import Column from "./Column";

const App = () => {
  // Logic for generating initial columns
  const initialColumns = {
    links: {
      id: "links",
      list: [
        { id: "1", text: "text1" },
        { id: "2", text: "text2" },
        { id: "3", text: "text3" }
      ]
    },
    items: {
      id: "items",
      list: []
    },
    area1: {
      id: "area1",
      list: []
    },
    area2: {
      id: "area2",
      list: [
        { id: "7", text: "text7" },
        { id: "8", text: "text8" },
        { id: "9", text: "text9" }
      ]
    }
  };

  // Populating lists in columns dynamically
  // Set up drag and drop logic using onDragEnd function

  return (
    <DragDropContext onDragEnd={onDragEnd}>
      {/* Displaying columns using Material UI grid layout */}
    </DragDropContext>
  );
};

export default App;

const useStyles = makeStyles((theme) => ({}));

Further elaboration can be found within the Column.js and ListItemCustom.js files - offering components for rendering draggable elements

Updates including enhanced scrolling and improved layout spacing have been introduced to refine user experience

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

Please be patient for the PayPal script to load on the nextjs page

I've encountered an issue with my code that is meant to display PayPal buttons <Head> <script src="https://www.paypal.com/sdk/js?client-id=KEY"></script> </Head> The PayPal buttons are loaded within the ...

ReactJS - Continuous Loop invoking Encapsulated Function

I keep encountering the same issue with an infinite loop in my code, but I can't figure out why. Currently, I am working with reactJS version 16.5.2 The infinite loops tend to occur when you try to use SetState where it is not allowed (such as in th ...

Performance issues with jquery addClass and removeClass functions observed in Internet Explorer 11

I am currently working on an application that monitors nodes within a cluster, and I have created a visual state example to demonstrate this. Each small box in the grid represents a node, and when hovering over a node, the rest of the nodes in that particu ...

How can you line up various form elements, like pickers, in a row using Material UI?

As someone new to material ui, I haven't come across a solution for my specific issue yet. While there are similar questions, none seem to address the problem of aligning different form field types. My observation is that the material ui date picker ...

Error message occurs: "Unable to perform state update on unmounted component" despite the absence of Set State or Async

I feel like I'm hitting a wall with this. No matter what I try, I can't seem to get my component to function properly. I've scoured through all the error posts here and on Google, but nothing seems to work. The error message I keep encounter ...

ReferenceError: 'document' is not defined in React's server-side rendering

One potential issue is with the library react-modal, but similar problems could arise with other libraries. How should this be handled? server.js import express from 'express'; import React from 'react'; import { match, RoutingCont ...

What is the best way to condense a repetitive method declaration and make it more concise?

I'm facing a situation where I have declared similar const values. Here's my current setup... import React from 'react' function Component_a() { const x = 5; const y = 10; const image_a = [...Array(x)].map((e, i) => ...

Using Flickity to select cells in React

I have a dropdown menu where each option is linked to an image ID. The goal is to display the corresponding image when an option is selected. Here's the code snippet I'm using: const myCustomNext = () => { flkty.selectCell(somevar) }; ...

When representing audio as sound bars on a canvas, the previous drawing is retained if canvas height is not specified

After obtaining an audioBuffer containing an audio clip, I proceed to create a visualization by drawing a series of sound bars in the shape of a circle: const { audioContext, analyser } = this.getAudioContext(); const source = audioContext.createBufferSou ...

Popper.js enhances the appearance of the input field label

When the placement of a tooltip created by Popper.js and overlaying a material-ui input field flips to the top, how can we prevent this overlay? Here is an example of the Popper code: <Popper id={id} open={open} anchorEl={this.state.anchorEl} ...

Adding padding to the navbar when collapsed causes extra space between the brand name and the hamburger icon button in Bootstrap

I am in the process of creating a fixed-top navigation bar for my webpage. However, I have encountered an issue where there is excessive space between the "Brand" name and the collapsed menu icon when viewed on smaller screens. Here is a visual representa ...

What steps can I take to stop the MUI Dialog from closing when I perform an action?

Is there a way to stop the MUI Dialog from closing when any action is performed inside it? Currently, it closes if I click on any input within the dialog box or anywhere else, except for clicking on the backdrop. How can I prevent this behavior? In my JSX ...

What's the best way to integrate redux-persist into a TypeScript project?

Having some difficulty adding redux-persist to my React project (in typescript). The compilation is failing with the following error message: Could not find a declaration file for module 'redux-persist/lib/storage'. '.../WebstormProjects/c ...

Include a basic downward-pointing arrow graphic to enhance the drop-down navigation menus

I am working on a website that has drop-down menu headings styled with CSS. I am looking to enhance these certain menu headers by adding small down-facing arrows indicating they are clickable. Does anyone have any suggestions on how I can achieve this? ...

Ways to adjust Safari printing margins using CSS to achieve borderless printing

I am struggling to eliminate margins when printing a webpage to PDF in Safari. Despite setting the page size to 'A4 borderless' in the print dialogue, Safari on OSX continues to add extra margins around my HTML. Enabling 'print backgrounds&a ...

Calculator screen filled with numbers overflowing beyond its boundaries

I'm encountering an issue with my calculator created in create-react-app where the numbers are overflowing off the screen. Specifically, when inputting very large numbers like 11111111111111111111111111111111, they exceed the output container. I am lo ...

When the page loads, an Open Modal function is triggered, resulting in the error message

As I attempt to launch a modal upon page load, I encounter an issue stating: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updat ...

Is there a way to insert images into a table cell?

Currently, I am working on a project where I have set up a sandbox specifically for a table. My goal is to incorporate a unique image for each row. Does anyone know the best approach to achieve this? If you are interested in helping out or taking a look, ...

Horizontal Alignment of DIV Tags

I'm currently working on aligning some div tags to serve as contact links on my website. My goal is for them to be positioned on the right-hand side and aligned in a single line. Here's how they look at the moment: Here's the preferred ali ...

Using the React JS useState hook to toggle the state of a JSON object containing an array when a checkbox is clicked

When I submit my state as a stringified variable from a form to a POST request via a lamda server, it gets parsed and sent to sendgrid for templating. To loop over specific parts (multiple checkboxes) in JSON format, each with the same key but different va ...