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

Enhancing User Input in React with Material Design Components

I am currently working on implementing an input field that completes a link and directs the user to it. However, when I click on the button, the page opens but there is an 'undefined' displayed at the end, as if the input field was not properly u ...

Issue retrieving nested object in NextJS

view-component.js const ViewComponent = () => { const route = useRoute(); //All good here const data = fetchData(); console.log(data); //Issue arises with this line const profileData = data.profile; console.log(profileData) ...

How can I dynamically replace a specific element inside a .map() function with a custom component when the state updates, without replacing all elements at once?

I'm currently developing a task management application and I need to enhance the user experience by implementing a feature that allows users to update specific tasks. When a user clicks on the update button for a particular task, it should replace tha ...

Encountered an issue while attempting npm install, with the error message "Error: Undefined variable standalone_static_library in binding.gyp" and node-sass chokidar error

I've been working on updating a Ruby on Rails and React project from 3 years ago. However, I encountered an issue while trying to npm install. $ npm install gyp: Undefined variable standalone_static_library in binding.gyp while trying to load binding ...

The width:auto attribute for images in ie6 is not functioning as expected

I am facing a challenge with dynamically changing and resizing an image element to fit its container. My current approach involves: Resetting the image: // Ensuring the 'load' event is re-triggered img.src = ""; // Resetting dimensions img. ...

Guide assistance: Imported name does not match component name, but functionality is unaffected

I've been keeping up with the project on GitHub and making some personal tweaks. Although I could probably find the answer on Google or in the documentation, I just can't seem to come up with the right keywords. But one day, I will figure it out ...

The code "transform: rotate(' ')" does not seem to be functioning properly in Javascript

I set out to create a simple spin wheel exercise, but it quickly became more challenging than I anticipated. After researching how to make one online, I found code similar to mine that worked on a JSFiddle Example, yet my own code still didn't work. ...

Experimenting with combining a CSS class alongside the Nth-child selector

Hello, I've been researching various sources including Stackoverflow on how to effectively use an Nth child selector and a Class together but have not had much success so far. In essence, my menu consists of Main categories (class = cat) and subcateg ...

Variety of formatting options for menu items when the menu is in its collapsed state

I am working with a Bootstrap nav-bar that collapses into a button by default. Within my nav-bar, I have opted for images instead of text links. However, when the nav-bar is collapsed, I would like these images to be smaller in size. Is there a way to cu ...

Trouble arises with padding in MUI 5 DialogContent

After upgrading to mui v5, I'm facing an issue with DialogContent. How can I customize this style using MuiDialogContent -> styleOverrides? Is there a way to combine class names? You can find the source code where the style is applied here: https: ...

React application experiencing incorrect hexadecimal hash value output in crypto function

In my Reactjs app rendered by Nextjs, I am confused about why I am receiving different hash values in the web browser when using this code: crypto.createHash('sha256').update("12345678").digest("hex"); The expected hash value from the sha256 on ...

GAE does not have access to background images

Having trouble loading background pictures in my GAE front-end app. "Failed to load resource: the server responded with a status of 404 (Not Found)". My app is a simple website, no GAE backend. Using Eclipse with Google AppEngine Plugin. Background pict ...

What is the best way to trigger a function once all asynchronous calls within a loop have been completed?

The function addData is called asynchronously within a loop every time reader.onloadend is triggered. const uploadFiles = () => { console.log(acceptedFiles) setLoading(true) console.log(loading) let i = 0 let l = acceptedFiles.length ...

Ways to connect images located outside of the Next.js project directory

Currently, I am working on a project that utilizes node.js and express for the back-end, as well as next js for the front-end. One of the features of this project is a form where users have the ability to create new products, each accompanied by an image. ...

Issue with JQuery event handlers becoming unresponsive upon resizing the window

JSBin link: http://jsbin.com/4QLDC/6 Here is the JS code snippet that I have written: var toggleContent = function (event) { $(event.target).siblings().toggle(); }; var showOrHidePanels = function () { var windowHeight = $(window).height(); v ...

Flutter DataTable: issue with missing columns and rows properties

My journey with Flutter development involving tables has hit a roadblock. The issue revolves around using DataTable to present data in a tabular format. The error message I encounter is regarding the 'columns' named parameter being undefined. Des ...

The React Bootstrap modal refuses to fully close no matter how many times I click away or even on the close button

I am facing an issue with a modal in my React component. When I open the modal, it does not completely close when I try to click away or hit the close button. The backdrop disappears but the modal itself remains on the screen. (Screenshots attached for r ...

Tips for creating a unique design for a form that includes a non-binary mask, inspired by bitmasks

Currently, I am in the process of creating an app using Reactjs and Material-UI. The main requirement is for users to input a mask of specific length containing various letters such as I, V, and C. In search of a suitable design pattern or solution for thi ...

Styling with CSS in a React component

I am trying to display a row of buttons instead of columns on my webpage. I have used display:flex but it is still showing as a column. What I want is for each button to display the first character of its name underneath it, with all buttons lined up next ...

The one-click button is functional on larger screens, while on mobile devices, only a double click will register

I am facing an issue in angular where a button works perfectly fine with one click on larger screens, such as Macbook. However, on iPhone, it requires a double click to function properly (it works fine on Android too). The alert triggers with a single cl ...