UNPKG

react-drag-panel

Version:
122 lines (94 loc) โ€ข 3.01 kB
# ๐Ÿงฉ react-drag-panel - React ๊ธฐ๋ฐ˜์˜ ๋“œ๋ž˜๊ทธ & ๋“œ๋กญ์œผ๋กœ ์žฌ๋ฐฐ์น˜ ๊ฐ€๋Šฅํ•œ ๊ฒฉ์ž ๊ธฐ๋ฐ˜ ํŒจ๋„ ๋ ˆ์ด์•„์›ƒ ์ปดํฌ๋„ŒํŠธ - `react-grid-layout`๋ณด๋‹ค ๊ฐ€๋ณ๊ณ , ๋‹จ์ˆœํ•œ ๊ธฐ๋Šฅ ์œ„์ฃผ๋กœ ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค. --- ## ๐ŸŽฌ Examples - ์˜ˆ์ œ๋Š” examples/ ํด๋”์— ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค: ``` cd examples npm install npm run dev ``` ### Example1 ![Example1](https://github.com/user-attachments/assets/1ad23f43-33ab-4ed1-a59f-b8a1469b1d20) ### Example2 ![Example2](https://github.com/user-attachments/assets/e6cceafe-ee74-4a74-8449-a1b6d47be5dd) --- ## ๐Ÿ“ฆ 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).