react-grid-layout
Version:
A draggable and resizable grid layout with responsive breakpoints, for React.
91 lines (88 loc) • 2.32 kB
JavaScript
;
var chunkF6NQPYKT_js = require('./chunk-F6NQPYKT.js');
var react = require('react');
var jsxRuntime = require('react/jsx-runtime');
function GridBackground({
width,
cols,
rowHeight,
margin = [10, 10],
containerPadding,
rows = 10,
height,
color = "#e0e0e0",
borderRadius = 4,
className,
style
}) {
const dims = react.useMemo(
() => chunkF6NQPYKT_js.calcGridCellDimensions({
width,
cols,
rowHeight,
margin,
containerPadding
}),
[width, cols, rowHeight, margin, containerPadding]
);
const rowCount = react.useMemo(() => {
if (rows !== "auto") return rows;
if (height) {
const padding = containerPadding ?? margin;
return Math.ceil(
(height - padding[1] * 2 + margin[1]) / (rowHeight + margin[1])
);
}
return 10;
}, [rows, height, rowHeight, margin, containerPadding]);
const totalHeight = react.useMemo(() => {
const padding = containerPadding ?? margin;
return padding[1] * 2 + rowCount * rowHeight + (rowCount - 1) * margin[1];
}, [rowCount, rowHeight, margin, containerPadding]);
const cells = react.useMemo(() => {
const rects = [];
const { cellWidth, cellHeight, offsetX, offsetY, gapX, gapY } = dims;
for (let row = 0; row < rowCount; row++) {
for (let col = 0; col < cols; col++) {
const x = offsetX + col * (cellWidth + gapX);
const y = offsetY + row * (cellHeight + gapY);
rects.push(
/* @__PURE__ */ jsxRuntime.jsx(
"rect",
{
x,
y,
width: cellWidth,
height: cellHeight,
rx: borderRadius,
ry: borderRadius,
fill: color
},
`${row}-${col}`
)
);
}
}
return rects;
}, [dims, rowCount, cols, borderRadius, color]);
return /* @__PURE__ */ jsxRuntime.jsx(
"svg",
{
className,
style: {
position: "absolute",
top: 0,
left: 0,
width,
height: totalHeight,
pointerEvents: "none",
...style
},
"aria-hidden": "true",
children: cells
}
);
}
exports.GridBackground = GridBackground;
//# sourceMappingURL=extras.js.map
//# sourceMappingURL=extras.js.map