View source code
- column-layout.tsx
- common-layout.css
import { createColumnLayoutAlgorithm, DndLayout, useLayout } from "dnd-layout";
import "./common-layout.css";
export function Sample() {
const layout = useLayout(() => {
return {
algorithm: createColumnLayoutAlgorithm(),
initialItems: [
{ id: "1", column: 0, columnSpan: 1, height: 140 },
{ id: "2", column: 1, columnSpan: 1, height: 140 },
{ id: "3", column: 2, columnSpan: 1, height: 140 },
{ id: "4", column: 0, columnSpan: 1, height: 140 },
{ id: "5", column: 1, columnSpan: 1, height: 140 },
{ id: "6", column: 2, columnSpan: 1, height: 140 },
{ id: "7", column: 0, columnSpan: 1, height: 140 },
{ id: "8", column: 1, columnSpan: 1, height: 140 },
{ id: "9", column: 2, columnSpan: 1, height: 140 },
{ id: "10", column: 0, columnSpan: 2, height: 140 },
],
};
});
return (
<DndLayout
className="common-layout"
layout={layout}
itemRender={(item) => {
return (
<div
className="common-layout-item"
style={{
height: 140,
}}
>
{item.id}
</div>
);
}}
/>
);
}
.dnd-layout.common-layout {
border-radius: 4px;
border: var(--dnd-layout-item-border-color) solid 1px;
padding: 12px;
}
.dnd-layout .dnd-layout-item .common-layout-item {
border-radius: 4px;
border: var(--dnd-layout-item-border-color) solid 4px;
padding: 12px;
background-color: var(--dnd-layout-item-bg);
}
.dnd-layout .dnd-layout-item .common-layout-item:hover {
border-color: var(--dnd-layout-item-border-color-hover);
}
.dnd-layout .dnd-layout-placeholder .dnd-layout-placeholder-default-content {
border-radius: 4px;
}