Comments (4)
I would say if you want to have more fresh version, of this library wit same functionality try to look at gridstack
from react-grid-layout.
Yeh I was wondering about the same thing because I would like to implement DnD feature in my project like Grafana
I checked the examples for react-grid-layout but they are implemented using class-based components which React.js itself doesn't recommend. I would like to use functional components and hooks. I tried to convert one of the examples into a functional component but what I'm not able to do is make the items maintain their sizes and positions when I change the screen size from large to small and back to large screen.
Currently, this is how the code looks
"use client";
import React, { useMemo, useState, ReactNode } from "react";
import ReactGridLayout, { WidthProvider, Responsive } from "react-grid-layout";
import MyResponsiveLine from "@/grid-test/Chart";
import CloseOutlinedIcon from "@mui/icons-material/CloseOutlined";
import "../../grid-test/styles.css";
import { Box, Button, IconButton } from "@mui/material";
type Item = {
i: string;
x: number;
y: number;
w: number;
h: number;
component?: ReactNode;
};
type AddRemoveProps = {
cols: { lg: number; md: number; sm: number; xs: number; xxs: number };
rowHeight?: number;
};
const AddRemoveLayout = () => {
const ResponsiveReactGridLayout = useMemo(
() => WidthProvider(Responsive),
[]
);
const defaultAddRemoveValues: AddRemoveProps = {
cols: { lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 },
rowHeight: 100,
};
const [items, setItems] = useState<Item[]>([]);
const [newCounter, setNewCounter] = useState(0);
const cols = defaultAddRemoveValues.cols;
const rowHeight = defaultAddRemoveValues.rowHeight;
console.log("cols", cols);
console.log("rowHeight", rowHeight);
const onAddItem = () => {
console.log("adding", "n" + newCounter);
const newItem = {
i: "n" + newCounter,
x: (items.length * 2) % (cols ? cols.lg : 12),
y: Infinity,
w: 2,
h: 2,
// add: false
component: <MyResponsiveLine key={"n" + newCounter} />,
};
setItems([...items, newItem]);
setNewCounter(newCounter + 1);
};
const onRemoveItem = (i: string) => {
console.log("removing", i);
setItems(items.filter((item) => item.i !== i));
};
const onLayoutChange = (layout: any) => {
// setNewLayout(layout);
console.log("the layout just changed ", layout);
};
const onBreakpointChange = (breakpoint: any, cols: any) => {
console.log("the layout just changed ", breakpoint, cols);
};
return (
<Box>
<Button variant="outlined" onClick={onAddItem} style={{ color: "black" }}>
Add Item
</Button>
<ResponsiveReactGridLayout
onLayoutChange={onLayoutChange}
onBreakpointChange={onBreakpointChange}
cols={cols}
rowHeight={rowHeight}
>
{items.map((item, index) => (
<Box key={index} data-grid={item} className="react-grid-item">
{item.component}
<IconButton
onClick={() => onRemoveItem(item.i)}
sx={{
position: "absolute",
top: 0,
right: "2px",
}}
>
<CloseOutlinedIcon />
</IconButton>
</Box>
))}
</ResponsiveReactGridLayout>
</Box>
);
};
export default AddRemoveLayout;
I tried to lookin to Grafana's code but I couldnt make any sense of it
from react-grid-layout.
Still doesn't technically fit my needs.
from react-grid-layout.
@sikhaman I just the website and it looks promising. I will let you know how it works out for me
Thank You.
from react-grid-layout.
Related Issues (20)
- Using with Nextjs 14 HOT 3
- [rtl resize] In RTL resize, when I try to shrink it, it gets bigger instead
- Race condition on React 18 setState causes mouse to "skip" when dragging / resizing. HOT 7
- Positioning and Resizing does not work as intended in production mode HOT 2
- The performance of the grid layout is adversely affected when dealing with large SVG grid elements (size ≥ 1MB). HOT 5
- dragging working not correct HOT 10
- Setting item height based on rowHeight in OnResize is buggy HOT 1
- The x,y coordinate of the item is incorrect
- When columns are thin and column spacing is set, items move from their grid position when clicked HOT 3
- Issue with Red Color Popover on Item Click in Versions 1.4.3 and Above HOT 7
- [feature request] Drop onto another widget
- Dynamic static changes on children do not change children rendering HOT 3
- Grid item shifts leftward unexpectedly when dragging leftward resize handle.
- Responsive Grid Layout not working.. HOT 2
- React-grid-layout, antd dynamic form list HOT 1
- Upgrading dependencies causes react-grid-layout Responsive to crash with babel-loader error HOT 3
- Have errors in utils.js && ReactGridLayout.js HOT 3
- I have maxRows, but still its allow me to add more rows
- React 19 - Each child in a list should have a unique "key" prop. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-grid-layout.