react-drag-panel
Version:
Drag & drop panel grid layout for React
122 lines (94 loc) โข 3.01 kB
Markdown
# ๐งฉ react-drag-panel
- React ๊ธฐ๋ฐ์ ๋๋๊ทธ & ๋๋กญ์ผ๋ก ์ฌ๋ฐฐ์น ๊ฐ๋ฅํ ๊ฒฉ์ ๊ธฐ๋ฐ ํจ๋ ๋ ์ด์์ ์ปดํฌ๋ํธ
- `react-grid-layout`๋ณด๋ค ๊ฐ๋ณ๊ณ , ๋จ์ํ ๊ธฐ๋ฅ ์์ฃผ๋ก ์ค๊ณ๋์์ต๋๋ค.
## ๐ฌ Examples
- ์์ ๋ examples/ ํด๋์ ํฌํจ๋์ด ์์ต๋๋ค:
```
cd examples
npm install
npm run dev
```
### Example1

### Example2

## ๐ฆ Install
```bash
npm install react-drag-panel
# ๋๋
yarn add react-drag-panel
```
## ๐งฑ Panel layout
`panel` prop์ ๋ค์๊ณผ ๊ฐ์ ๊ตฌ์กฐ์ ๋ฐฐ์ด์
๋๋ค.
```
type Panel = {
id: string;
x: number;
y: number;
w: number;
h: number;
content?: React.ReactNode;
}
```
| ํ๋ | ์ค๋ช
|
| --- | --- |
| `id` | ํจ๋์ ๊ณ ์ ID (`string`) |
| `x` | ๊ทธ๋ฆฌ๋ ๋ด ๊ฐ๋ก ์์น (์ด ์ธ๋ฑ์ค) |
| `y` | ๊ทธ๋ฆฌ๋ ๋ด ์ธ๋ก ์์น (ํ ์ธ๋ฑ์ค) |
| `w` | ๊ฐ๋ก ๋๋น (๋ช ์นธ ์ฐจ์งํ๋์ง) |
| `h` | ์ธ๋ก ๋์ด (๋ช ์ค ์ฐจ์งํ๋์ง) |
| `content` | ๋ ๋๋งํ ๋ด์ฉ (์ ํ) |
## ๐งฐ Usage
```tsx
<PanelGrid
panels={panels}
cols={24}
rowHeight={40}
width={1200}
margin={[10, 10]}
isDraggable={true}
preventCollision={true}
onLayoutChange={(newLayout) => {
console.log('Layout changed:', newLayout);
}}
>
{panels.map((panel) => (
<div
key={panel.id}
className="h-full w-full bg-[#1b1b3a] border border-[#3f3f7f] rounded-lg shadow-md flex items-center justify-center text-lg font-semibold"
>
{panel.content}
</div>
))}
</PanelGrid>
```
## โจ Features
- ๋๋๊ทธ & ๋๋กญ์ผ๋ก ์์น ์ฌ๋ฐฐ์น
- ์ถฉ๋ ๋ฐฉ์ง ์ฌ๋ถ ์ค์ (preventCollision)
- ๋๋๊ทธ ๊ฐ๋ฅ ์ฌ๋ถ ์ค์ (isDraggable)
- ๋ ์ด์์ ๋ณ๊ฒฝ ๊ฐ์ง ์ฝ๋ฐฑ (onLayoutChange)
- ์ ์ฐํ ๊ฒฉ์ ๊ตฌ์ฑ: cols, rowHeight, width, margin, padding
- ๊ฐ ํจ๋์ ๋ด๋ถ UI๋ ์์ ๋กญ๊ฒ ๊ตฌ์ฑ ๊ฐ๋ฅ
## ๐ง Props
| Prop | Type | ์ค๋ช
| ๊ธฐ๋ณธ๊ฐ
| --- | --- | --- | --- |
| panels | Panel[] | ๋ ๋๋งํ ํจ๋ ๋ฐฐ์ด | []
| cols | number | ํ ์ค์ ๋ฐฐ์นํ ๊ทธ๋ฆฌ๋ ์ | 12
| rowHeight | number | ํ ํ์ ๋์ด (px) | 50
| width | number | ์ ์ฒด ๊ทธ๋ฆฌ๋์ ๋๋น (px) | 1200
| margin | [number, number] | ํจ๋ ๊ฐ ๊ฐ๊ฒฉ (์ํ, ์์ง) | [0, 0]
| padding | [number, number] | ๊ทธ๋ฆฌ๋ ์ปจํ
์ด๋์ ์์ชฝ ์ฌ๋ฐฑ (์ํ, ์์ง) | [0, 0]
| isDraggable | boolean | ๋๋๊ทธ ๊ฐ๋ฅ ์ฌ๋ถ | true
| preventCollision | boolean | ๊ฒน์นจ ๋ฐฉ์ง ์ฌ๋ถ | true
| onLayoutChange | (layout: Panel[]) => void | ๋ ์ด์์ ๋ณ๊ฒฝ ์ ํธ์ถ๋๋ ์ฝ๋ฐฑ ํจ์ | undefined
| children | React.ReactNode | ๊ฐ ํจ๋์ ๋์๋๋ ์ปดํฌ๋ํธ | -
## ๐งช Test
```
npm run test
```
## License
This project is licensed under the [MIT License](https://github.com/sanholl/react-drag-panel/blob/feature/grid-layout-basic/LICENSE).