tailwind-grid-layout 0.0.1-beta.20250620111548
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.ko.md +411 -0
- package/README.md +411 -0
- package/dist/components/DroppableGridContainer.d.ts +7 -0
- package/dist/components/DroppableGridContainer.d.ts.map +1 -0
- package/dist/components/GridContainer.d.ts +4 -0
- package/dist/components/GridContainer.d.ts.map +1 -0
- package/dist/components/GridItem.d.ts +23 -0
- package/dist/components/GridItem.d.ts.map +1 -0
- package/dist/components/ResizeHandle.d.ts +10 -0
- package/dist/components/ResizeHandle.d.ts.map +1 -0
- package/dist/components/ResponsiveGridContainer.d.ts +18 -0
- package/dist/components/ResponsiveGridContainer.d.ts.map +1 -0
- package/dist/components/WidthProvider.d.ts +8 -0
- package/dist/components/WidthProvider.d.ts.map +1 -0
- package/dist/components/ui/card.d.ts +9 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3442 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/test/setup.d.ts +1 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/dist/types/index.d.ts +109 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/cn.d.ts +3 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/grid.d.ts +17 -0
- package/dist/utils/grid.d.ts.map +1 -0
- package/dist/utils/layouts.d.ts +15 -0
- package/dist/utils/layouts.d.ts.map +1 -0
- package/package.json +127 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Seungwoo, Lee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ko.md
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
# Tailwind Grid Layout
|
|
2
|
+
|
|
3
|
+
React용 현대적이고 가벼운 그리드 레이아웃 시스템으로, Tailwind CSS로 구축되었습니다. react-grid-layout의 강력한 대안으로 모든 기능을 제공하면서도 더 작은 번들 크기를 자랑합니다.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/tailwind-grid-layout)
|
|
6
|
+
[](https://github.com/Seungwoo321/tailwind-grid-layout/blob/main/LICENSE)
|
|
7
|
+
[](https://bundlephobia.com/package/tailwind-grid-layout)
|
|
8
|
+
|
|
9
|
+
> [English](./README.md) | 한국어
|
|
10
|
+
|
|
11
|
+
## 특징
|
|
12
|
+
|
|
13
|
+
- 🎯 **react-grid-layout과 완벽한 기능 호환성**
|
|
14
|
+
- 🪶 **경량화** - Tailwind CSS를 사용한 더 작은 번들 크기
|
|
15
|
+
- 🎨 **Tailwind 네이티브** - Tailwind CSS 유틸리티로 구축
|
|
16
|
+
- 📱 **반응형** - 모든 화면 크기에서 작동
|
|
17
|
+
- 🔧 **TypeScript** - 완전한 TypeScript 지원
|
|
18
|
+
- ⚡ **고성능** - 최적화된 렌더링과 애니메이션
|
|
19
|
+
- 🧪 **철저한 테스트** - 100% 테스트 커버리지
|
|
20
|
+
|
|
21
|
+
## 설치
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install tailwind-grid-layout
|
|
25
|
+
# 또는
|
|
26
|
+
yarn add tailwind-grid-layout
|
|
27
|
+
# 또는
|
|
28
|
+
pnpm add tailwind-grid-layout
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 필수 요구사항
|
|
32
|
+
|
|
33
|
+
- React 19.1.0
|
|
34
|
+
- Tailwind CSS 4.1.8+ (v4 전용 - CSS 우선 구성)
|
|
35
|
+
- Node.js 20.0.0+
|
|
36
|
+
- pnpm 10.11.0+
|
|
37
|
+
|
|
38
|
+
## Tailwind CSS v4 설정
|
|
39
|
+
|
|
40
|
+
이 라이브러리는 새로운 CSS 우선 구성 방식을 사용하는 Tailwind CSS v4가 필요합니다. JavaScript 구성 파일은 필요하지 않습니다.
|
|
41
|
+
|
|
42
|
+
```css
|
|
43
|
+
/* 메인 CSS 파일에서 */
|
|
44
|
+
@import "tailwindcss";
|
|
45
|
+
|
|
46
|
+
/* 선택사항: 커스텀 테마 구성 추가 */
|
|
47
|
+
@theme {
|
|
48
|
+
--color-grid-placeholder: oklch(0.7 0.15 210);
|
|
49
|
+
--color-grid-handle: oklch(0.3 0.05 210);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 빠른 시작
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { GridContainer } from 'tailwind-grid-layout'
|
|
57
|
+
|
|
58
|
+
const items = [
|
|
59
|
+
{ id: '1', x: 0, y: 0, w: 2, h: 2 },
|
|
60
|
+
{ id: '2', x: 2, y: 0, w: 2, h: 2 },
|
|
61
|
+
{ id: '3', x: 0, y: 2, w: 4, h: 2 }
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
function App() {
|
|
65
|
+
return (
|
|
66
|
+
<GridContainer
|
|
67
|
+
items={items}
|
|
68
|
+
cols={12}
|
|
69
|
+
rowHeight={60}
|
|
70
|
+
onLayoutChange={(newLayout) => console.log(newLayout)}
|
|
71
|
+
>
|
|
72
|
+
{(item) => (
|
|
73
|
+
<div className="bg-blue-500 text-white p-4 rounded">
|
|
74
|
+
Item {item.id}
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
</GridContainer>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Props 참조
|
|
83
|
+
|
|
84
|
+
### GridContainer Props
|
|
85
|
+
|
|
86
|
+
| Prop | 타입 | 기본값 | 설명 |
|
|
87
|
+
|------|------|---------|-------------|
|
|
88
|
+
| **items** | `GridItem[]` | 필수 | 위치와 크기 정보를 포함한 그리드 아이템 배열 |
|
|
89
|
+
| **children** | `(item: GridItem) => ReactNode` | 필수 | 그리드 아이템을 위한 렌더 함수 |
|
|
90
|
+
| **cols** | `number` | `12` | 그리드의 열 개수 |
|
|
91
|
+
| **rowHeight** | `number` | `60` | 각 행의 높이 (픽셀) |
|
|
92
|
+
| **gap** | `number` | `16` | 그리드 아이템 간 간격 (픽셀) |
|
|
93
|
+
| **margin** | `[number, number]` | `[gap, gap]` | 아이템 간 여백 [수평, 수직] |
|
|
94
|
+
| **containerPadding** | `[number, number]` | `[16, 16]` | 그리드 컨테이너 내부 패딩 [수평, 수직] |
|
|
95
|
+
| **maxRows** | `number` | - | 최대 행 개수 |
|
|
96
|
+
| **isDraggable** | `boolean` | `true` | 드래그 활성화/비활성화 |
|
|
97
|
+
| **isResizable** | `boolean` | `true` | 크기 조정 활성화/비활성화 |
|
|
98
|
+
| **preventCollision** | `boolean` | `false` | 아이템 충돌 방지 |
|
|
99
|
+
| **allowOverlap** | `boolean` | `false` | 아이템 겹침 허용 |
|
|
100
|
+
| **isBounded** | `boolean` | `true` | 컨테이너 경계 내 아이템 유지 |
|
|
101
|
+
| **compactType** | `'vertical' \| 'horizontal' \| null` | `'vertical'` | 압축 타입 |
|
|
102
|
+
| **resizeHandles** | `Array<'s' \| 'w' \| 'e' \| 'n' \| 'sw' \| 'nw' \| 'se' \| 'ne'>` | `['se']` | 크기 조정 핸들 위치 |
|
|
103
|
+
| **draggableCancel** | `string` | - | 드래그를 트리거하지 않을 요소의 CSS 선택자 |
|
|
104
|
+
| **draggableHandle** | `string` | - | 드래그 핸들용 CSS 선택자 |
|
|
105
|
+
| **autoSize** | `boolean` | `true` | 모든 아이템에 맞게 컨테이너 높이 자동 조정 |
|
|
106
|
+
| **verticalCompact** | `boolean` | `true` | 더 이상 사용되지 않음: compactType 사용 |
|
|
107
|
+
| **transformScale** | `number` | `1` | 확대/축소 시 드래그/크기 조정을 위한 스케일 팩터 |
|
|
108
|
+
| **droppingItem** | `Partial<GridItem>` | - | 외부에서 드래그 중 미리보기 아이템 |
|
|
109
|
+
| **className** | `string` | - | 컨테이너에 추가할 CSS 클래스 |
|
|
110
|
+
| **style** | `React.CSSProperties` | - | 컨테이너용 인라인 스타일 |
|
|
111
|
+
| **onLayoutChange** | `(layout: GridItem[]) => void` | - | 레이아웃 변경 시 콜백 |
|
|
112
|
+
| **onDragStart** | `(layout, oldItem, newItem, placeholder, e, element) => void` | - | 드래그 시작 콜백 |
|
|
113
|
+
| **onDrag** | `(layout, oldItem, newItem, placeholder, e, element) => void` | - | 드래그 중 콜백 |
|
|
114
|
+
| **onDragStop** | `(layout, oldItem, newItem, placeholder, e, element) => void` | - | 드래그 종료 콜백 |
|
|
115
|
+
| **onResizeStart** | `(layout, oldItem, newItem, placeholder, e, element) => void` | - | 크기 조정 시작 콜백 |
|
|
116
|
+
| **onResize** | `(layout, oldItem, newItem, placeholder, e, element) => void` | - | 크기 조정 중 콜백 |
|
|
117
|
+
| **onResizeStop** | `(layout, oldItem, newItem, placeholder, e, element) => void` | - | 크기 조정 종료 콜백 |
|
|
118
|
+
|
|
119
|
+
### GridItem 속성
|
|
120
|
+
|
|
121
|
+
| 속성 | 타입 | 필수 | 설명 |
|
|
122
|
+
|----------|------|----------|-------------|
|
|
123
|
+
| **id** | `string` | ✓ | 아이템의 고유 식별자 |
|
|
124
|
+
| **x** | `number` | ✓ | 그리드 단위의 X 위치 |
|
|
125
|
+
| **y** | `number` | ✓ | 그리드 단위의 Y 위치 |
|
|
126
|
+
| **w** | `number` | ✓ | 그리드 단위의 너비 |
|
|
127
|
+
| **h** | `number` | ✓ | 그리드 단위의 높이 |
|
|
128
|
+
| **minW** | `number` | - | 최소 너비 |
|
|
129
|
+
| **minH** | `number` | - | 최소 높이 |
|
|
130
|
+
| **maxW** | `number` | - | 최대 너비 |
|
|
131
|
+
| **maxH** | `number` | - | 최대 높이 |
|
|
132
|
+
| **isDraggable** | `boolean` | - | 컨테이너의 isDraggable 재정의 |
|
|
133
|
+
| **isResizable** | `boolean` | - | 컨테이너의 isResizable 재정의 |
|
|
134
|
+
| **static** | `boolean` | - | 아이템을 정적으로 만들기 (이동/크기조정 불가) |
|
|
135
|
+
| **className** | `string` | - | 아이템에 추가할 CSS 클래스 |
|
|
136
|
+
|
|
137
|
+
## react-grid-layout과의 비교
|
|
138
|
+
|
|
139
|
+
| 기능 | react-grid-layout | tailwind-grid-layout | 비고 |
|
|
140
|
+
|---------|-------------------|---------------------|--------|
|
|
141
|
+
| **핵심 기능** |
|
|
142
|
+
| 드래그 & 드롭 | ✅ | ✅ | 완전 지원 |
|
|
143
|
+
| 크기 조정 | ✅ | ✅ | 8방향 크기 조정 |
|
|
144
|
+
| 충돌 감지 | ✅ | ✅ | 50% 겹침 규칙 |
|
|
145
|
+
| 자동 압축 | ✅ | ✅ | 수직, 수평 또는 없음 |
|
|
146
|
+
| 정적 아이템 | ✅ | ✅ | 완전 지원 |
|
|
147
|
+
| 경계 내 이동 | ✅ | ✅ | 아이템을 경계 내에 유지 |
|
|
148
|
+
| **레이아웃 옵션** |
|
|
149
|
+
| 반응형 브레이크포인트 | ✅ | ✅ | ResponsiveGridContainer로 완전 지원 |
|
|
150
|
+
| 레이아웃 유지 | ✅ | ✅ | onLayoutChange를 통해 |
|
|
151
|
+
| 최소/최대 크기 | ✅ | ✅ | 완전 지원 |
|
|
152
|
+
| 충돌 방지 | ✅ | ✅ | 완전 지원 |
|
|
153
|
+
| 겹침 허용 | ✅ | ✅ | 완전 지원 |
|
|
154
|
+
| **이벤트** |
|
|
155
|
+
| 레이아웃 변경 | ✅ | ✅ | 완전 지원 |
|
|
156
|
+
| 드래그 이벤트 | ✅ | ✅ | 시작, 이동, 종료 |
|
|
157
|
+
| 크기 조정 이벤트 | ✅ | ✅ | 시작, 조정, 종료 |
|
|
158
|
+
| 외부에서 드롭 | ✅ | ✅ | DroppableGridContainer로 완전 지원 |
|
|
159
|
+
| **스타일링** |
|
|
160
|
+
| CSS-in-JS | ✅ | ❌ | Tailwind 사용 |
|
|
161
|
+
| 커스텀 클래스 | ✅ | ✅ | 완전 지원 |
|
|
162
|
+
| 애니메이션 | ✅ | ✅ | Tailwind 트랜지션 |
|
|
163
|
+
| **성능** |
|
|
164
|
+
| 번들 크기 | ~30KB | ~15KB | 50% 작음 |
|
|
165
|
+
| 의존성 | React만 | React + Tailwind | |
|
|
166
|
+
| Tree-shaking | ✅ | ✅ | 완전 지원 |
|
|
167
|
+
|
|
168
|
+
## 고급 예제
|
|
169
|
+
|
|
170
|
+
### 커스텀 드래그 핸들
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
<GridContainer items={items}>
|
|
174
|
+
{(item) => (
|
|
175
|
+
<div className="bg-white rounded-lg shadow p-4">
|
|
176
|
+
<div className="grid-drag-handle cursor-move p-2 bg-gray-100 rounded">
|
|
177
|
+
<GripIcon className="w-4 h-4" />
|
|
178
|
+
</div>
|
|
179
|
+
<div className="p-4">
|
|
180
|
+
{item.id}의 콘텐츠
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
)}
|
|
184
|
+
</GridContainer>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 정적 아이템
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
const items = [
|
|
191
|
+
{ id: '1', x: 0, y: 0, w: 4, h: 2, static: true }, // 이 아이템은 이동할 수 없음
|
|
192
|
+
{ id: '2', x: 4, y: 0, w: 4, h: 2 },
|
|
193
|
+
]
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 반응형 브레이크포인트
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
import { ResponsiveGridContainer } from 'tailwind-grid-layout'
|
|
200
|
+
|
|
201
|
+
const layouts = {
|
|
202
|
+
lg: [{ id: '1', x: 0, y: 0, w: 3, h: 2 }],
|
|
203
|
+
md: [{ id: '1', x: 0, y: 0, w: 6, h: 2 }],
|
|
204
|
+
sm: [{ id: '1', x: 0, y: 0, w: 12, h: 2 }],
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
<ResponsiveGridContainer
|
|
208
|
+
layouts={layouts}
|
|
209
|
+
breakpoints={{ lg: 1200, md: 768, sm: 480 }}
|
|
210
|
+
cols={{ lg: 12, md: 8, sm: 4 }}
|
|
211
|
+
>
|
|
212
|
+
{(item) => <div>반응형 아이템 {item.id}</div>}
|
|
213
|
+
</ResponsiveGridContainer>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### 외부에서 드래그 앤 드롭
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
import { DroppableGridContainer } from 'tailwind-grid-layout'
|
|
220
|
+
|
|
221
|
+
<DroppableGridContainer
|
|
222
|
+
items={items}
|
|
223
|
+
onDrop={(newItem) => setItems([...items, newItem])}
|
|
224
|
+
droppingItem={{ w: 2, h: 2 }} // 드롭된 아이템의 기본 크기
|
|
225
|
+
>
|
|
226
|
+
{(item) => <div>드롭된 아이템 {item.id}</div>}
|
|
227
|
+
</DroppableGridContainer>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 커스텀 크기 조정 핸들
|
|
231
|
+
|
|
232
|
+
```tsx
|
|
233
|
+
<GridContainer
|
|
234
|
+
items={items}
|
|
235
|
+
resizeHandles={['se', 'sw', 'ne', 'nw']} // 모서리 핸들만 활성화
|
|
236
|
+
>
|
|
237
|
+
{(item) => <div>아이템 {item.id}</div>}
|
|
238
|
+
</GridContainer>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### 충돌 방지
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
<GridContainer
|
|
245
|
+
items={items}
|
|
246
|
+
preventCollision={true} // 아이템이 겹칠 수 없음
|
|
247
|
+
allowOverlap={false}
|
|
248
|
+
>
|
|
249
|
+
{(item) => <div>아이템 {item.id}</div>}
|
|
250
|
+
</GridContainer>
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### 최대 행 수를 가진 경계 그리드
|
|
254
|
+
|
|
255
|
+
```tsx
|
|
256
|
+
<GridContainer
|
|
257
|
+
items={items}
|
|
258
|
+
isBounded={true}
|
|
259
|
+
maxRows={10} // 그리드를 10행으로 제한
|
|
260
|
+
>
|
|
261
|
+
{(item) => <div>아이템 {item.id}</div>}
|
|
262
|
+
</GridContainer>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### AutoSize 컨테이너
|
|
266
|
+
|
|
267
|
+
```tsx
|
|
268
|
+
<GridContainer
|
|
269
|
+
items={items}
|
|
270
|
+
autoSize={true} // 컨테이너 높이가 자동으로 조정됨
|
|
271
|
+
>
|
|
272
|
+
{(item) => <div>아이템 {item.id}</div>}
|
|
273
|
+
</GridContainer>
|
|
274
|
+
|
|
275
|
+
// 고정 높이
|
|
276
|
+
<div style={{ height: 400, overflow: 'auto' }}>
|
|
277
|
+
<GridContainer
|
|
278
|
+
items={items}
|
|
279
|
+
autoSize={false}
|
|
280
|
+
style={{ height: '100%' }}
|
|
281
|
+
>
|
|
282
|
+
{(item) => <div>아이템 {item.id}</div>}
|
|
283
|
+
</GridContainer>
|
|
284
|
+
</div>
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### DroppingItem 미리보기
|
|
288
|
+
|
|
289
|
+
```tsx
|
|
290
|
+
<DroppableGridContainer
|
|
291
|
+
items={items}
|
|
292
|
+
droppingItem={{ w: 4, h: 2 }} // 드래그 중 미리보기 표시
|
|
293
|
+
onDrop={(newItem) => setItems([...items, newItem])}
|
|
294
|
+
>
|
|
295
|
+
{(item) => <div>아이템 {item.id}</div>}
|
|
296
|
+
</DroppableGridContainer>
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## 레이아웃 유틸리티
|
|
300
|
+
|
|
301
|
+
### generateLayouts
|
|
302
|
+
|
|
303
|
+
단일 레이아웃 정의에서 모든 브레이크포인트에 대한 동일한 레이아웃을 생성합니다.
|
|
304
|
+
|
|
305
|
+
```tsx
|
|
306
|
+
import { generateLayouts } from 'tailwind-grid-layout'
|
|
307
|
+
|
|
308
|
+
const items = [
|
|
309
|
+
{ id: '1', x: 0, y: 0, w: 4, h: 2 },
|
|
310
|
+
{ id: '2', x: 4, y: 0, w: 4, h: 2 }
|
|
311
|
+
]
|
|
312
|
+
|
|
313
|
+
// lg, md, sm, xs, xxs에 대해 동일한 위치로 레이아웃 생성
|
|
314
|
+
const layouts = generateLayouts(items)
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### generateResponsiveLayouts
|
|
318
|
+
|
|
319
|
+
브레이크포인트별 다른 컬럼 수에 맞게 레이아웃을 자동으로 조정합니다.
|
|
320
|
+
|
|
321
|
+
```tsx
|
|
322
|
+
import { generateResponsiveLayouts } from 'tailwind-grid-layout'
|
|
323
|
+
|
|
324
|
+
const items = [
|
|
325
|
+
{ id: '1', x: 0, y: 0, w: 12, h: 2 },
|
|
326
|
+
{ id: '2', x: 0, y: 2, w: 6, h: 2 }
|
|
327
|
+
]
|
|
328
|
+
|
|
329
|
+
// 컬럼 제약에 맞게 아이템 너비와 위치를 조정
|
|
330
|
+
const layouts = generateResponsiveLayouts(items, {
|
|
331
|
+
lg: 12,
|
|
332
|
+
md: 10,
|
|
333
|
+
sm: 6,
|
|
334
|
+
xs: 4,
|
|
335
|
+
xxs: 2
|
|
336
|
+
})
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### WidthProvider HOC
|
|
340
|
+
|
|
341
|
+
ResponsiveGridContainer에 컨테이너 너비를 자동으로 제공합니다.
|
|
342
|
+
|
|
343
|
+
```tsx
|
|
344
|
+
import { ResponsiveGridContainer, WidthProvider } from 'tailwind-grid-layout'
|
|
345
|
+
|
|
346
|
+
const ResponsiveGridWithWidth = WidthProvider(ResponsiveGridContainer)
|
|
347
|
+
|
|
348
|
+
// 컨테이너 너비를 수동으로 추적할 필요 없음
|
|
349
|
+
<ResponsiveGridWithWidth
|
|
350
|
+
layouts={layouts}
|
|
351
|
+
measureBeforeMount={true} // 선택사항: 레이아웃 변경 방지
|
|
352
|
+
>
|
|
353
|
+
{(item) => <div>아이템 {item.id}</div>}
|
|
354
|
+
</ResponsiveGridWithWidth>
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
## 스타일링 가이드
|
|
359
|
+
|
|
360
|
+
### Tailwind CSS와 함께 사용하기
|
|
361
|
+
|
|
362
|
+
이 라이브러리는 Tailwind CSS와 원활하게 작동하도록 제작되었습니다:
|
|
363
|
+
|
|
364
|
+
```tsx
|
|
365
|
+
<GridContainer items={items} className="bg-gray-50 rounded-lg">
|
|
366
|
+
{(item) => (
|
|
367
|
+
<div className="bg-white rounded-lg shadow-md hover:shadow-lg transition-shadow">
|
|
368
|
+
<div className="p-4">
|
|
369
|
+
<h3 className="text-lg font-semibold">아이템 {item.id}</h3>
|
|
370
|
+
</div>
|
|
371
|
+
</div>
|
|
372
|
+
)}
|
|
373
|
+
</GridContainer>
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### 커스텀 플레이스홀더
|
|
377
|
+
|
|
378
|
+
드래그 및 크기 조정 플레이스홀더는 CSS를 통해 스타일링할 수 있습니다:
|
|
379
|
+
|
|
380
|
+
```css
|
|
381
|
+
/* 드래그 플레이스홀더 */
|
|
382
|
+
.tailwind-grid-layout .drag-placeholder {
|
|
383
|
+
background: rgba(59, 130, 246, 0.15);
|
|
384
|
+
border: 2px dashed rgb(59, 130, 246);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/* 크기 조정 플레이스홀더 */
|
|
388
|
+
.tailwind-grid-layout .resize-placeholder {
|
|
389
|
+
background: rgba(59, 130, 246, 0.1);
|
|
390
|
+
border: 2px dashed rgb(59, 130, 246);
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## 브라우저 지원
|
|
395
|
+
|
|
396
|
+
- Chrome (최신)
|
|
397
|
+
- Firefox (최신)
|
|
398
|
+
- Safari (최신)
|
|
399
|
+
- Edge (최신)
|
|
400
|
+
|
|
401
|
+
## 기여하기
|
|
402
|
+
|
|
403
|
+
기여를 환영합니다! 자세한 내용은 [기여 가이드](CONTRIBUTING.md)를 참조하세요.
|
|
404
|
+
|
|
405
|
+
## 라이선스
|
|
406
|
+
|
|
407
|
+
MIT © [Seungwoo, Lee](./LICENSE)
|
|
408
|
+
|
|
409
|
+
## 감사의 글
|
|
410
|
+
|
|
411
|
+
이 라이브러리는 [react-grid-layout](https://github.com/react-grid-layout/react-grid-layout)에서 영감을 받았으며, 현대적이고 Tailwind 우선의 대안을 제공하는 것을 목표로 합니다.
|