@equal-experts/kuat-react 0.2.3 → 0.2.5

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.
@@ -0,0 +1,477 @@
1
+ # Kuat Design System Spacing
2
+
3
+ A guide to using spacing in the Kuat Design System. This document helps ensure consistent, accessible, and harmonious spacing across all digital products built with shadcn/ui and shadcn-vue.
4
+
5
+ ---
6
+
7
+ ## Overview
8
+
9
+ The Kuat Design System uses **Tailwind CSS's spacing scale**, which is based on a **4px base unit** (0.25rem). This creates a consistent, predictable spacing system that promotes visual harmony and maintainability across all components.
10
+
11
+ **Key Principle:** Use Tailwind spacing utility classes consistently. Spacing is the primary tool for creating visual hierarchy and separation between elements—prefer spacing over borders when possible.
12
+
13
+ ---
14
+
15
+ ## Spacing Scale
16
+
17
+ The design system uses Tailwind's default spacing scale, where each unit represents **0.25rem (4px)**:
18
+
19
+ | Tailwind Class | Value | Pixels | Usage |
20
+ |----------------|-------|--------|-------|
21
+ | `0` | `0` | `0px` | No spacing |
22
+ | `0.5` | `0.125rem` | `2px` | Tight spacing, fine adjustments |
23
+ | `1` | `0.25rem` | `4px` | Minimal spacing, tight groups |
24
+ | `1.5` | `0.375rem` | `6px` | Small spacing |
25
+ | `2` | `0.5rem` | `8px` | Small spacing, compact layouts |
26
+ | `2.5` | `0.625rem` | `10px` | Small-medium spacing |
27
+ | `3` | `0.75rem` | `12px` | Medium spacing, form fields |
28
+ | `4` | `1rem` | `16px` | Standard spacing, default padding |
29
+ | `5` | `1.25rem` | `20px` | Medium-large spacing |
30
+ | `6` | `1.5rem` | `24px` | Large spacing, section separation |
31
+ | `8` | `2rem` | `32px` | Extra large spacing, major sections |
32
+ | `10` | `2.5rem` | `40px` | Very large spacing |
33
+ | `12` | `3rem` | `48px` | Maximum spacing, page sections |
34
+ | `16` | `4rem` | `64px` | Hero spacing, large sections |
35
+ | `20` | `5rem` | `80px` | Maximum hero spacing |
36
+ | `24` | `6rem` | `96px` | Ultra large spacing |
37
+
38
+ **Note:** The scale continues beyond these values, but these are the most commonly used in the design system.
39
+
40
+ ---
41
+
42
+ ## Spacing Utilities
43
+
44
+ Tailwind provides several spacing utility classes for different use cases:
45
+
46
+ ### Padding
47
+
48
+ Padding adds space inside an element:
49
+
50
+ - **All sides:** `p-{size}` (e.g., `p-4`)
51
+ - **Horizontal:** `px-{size}` (e.g., `px-4`)
52
+ - **Vertical:** `py-{size}` (e.g., `py-4`)
53
+ - **Top:** `pt-{size}` (e.g., `pt-4`)
54
+ - **Right:** `pr-{size}` (e.g., `pr-4`)
55
+ - **Bottom:** `pb-{size}` (e.g., `pb-4`)
56
+ - **Left:** `pl-{size}` (e.g., `pl-4`)
57
+
58
+ ### Margin
59
+
60
+ Margin adds space outside an element:
61
+
62
+ - **All sides:** `m-{size}` (e.g., `m-4`)
63
+ - **Horizontal:** `mx-{size}` (e.g., `mx-4`)
64
+ - **Vertical:** `my-{size}` (e.g., `my-4`)
65
+ - **Top:** `mt-{size}` (e.g., `mt-4`)
66
+ - **Right:** `mr-{size}` (e.g., `mr-4`)
67
+ - **Bottom:** `mb-{size}` (e.g., `mb-4`)
68
+ - **Left:** `ml-{size}` (e.g., `ml-4`)
69
+
70
+ ### Gap
71
+
72
+ Gap adds space between flex or grid children:
73
+
74
+ - **All directions:** `gap-{size}` (e.g., `gap-4`)
75
+ - **Horizontal:** `gap-x-{size}` (e.g., `gap-x-4`)
76
+ - **Vertical:** `gap-y-{size}` (e.g., `gap-y-4`)
77
+
78
+ ### Space Between
79
+
80
+ Space between adds vertical spacing between child elements:
81
+
82
+ - **Vertical:** `space-y-{size}` (e.g., `space-y-4`)
83
+ - **Horizontal:** `space-x-{size}` (e.g., `space-x-4`)
84
+
85
+ ---
86
+
87
+ ## Common Spacing Patterns
88
+
89
+ ### Component Padding
90
+
91
+ **Cards and Containers:**
92
+ - **Small cards:** `p-4` (16px) - Compact content
93
+ - **Standard cards:** `p-6` (24px) - Default card padding
94
+ - **Large cards:** `p-8` (32px) - Spacious content
95
+
96
+ ```tsx
97
+ // React - Standard card padding
98
+ <div className="bg-card border border-border rounded-lg p-6">
99
+ <h3>Card Title</h3>
100
+ <p>Card content</p>
101
+ </div>
102
+ ```
103
+
104
+ ### Form Spacing
105
+
106
+ **Form Elements:**
107
+ - **Input padding:** `px-3 py-2` (12px horizontal, 8px vertical)
108
+ - **Form group spacing:** `space-y-4` (16px between form fields)
109
+ - **Form section spacing:** `space-y-6` (24px between sections)
110
+
111
+ ```tsx
112
+ // React - Form with consistent spacing
113
+ <form className="space-y-4">
114
+ <div>
115
+ <label className="block mb-2">Label</label>
116
+ <input className="w-full px-3 py-2 border border-input rounded-[4px]" />
117
+ </div>
118
+ <div>
119
+ <label className="block mb-2">Another Label</label>
120
+ <input className="w-full px-3 py-2 border border-input rounded-[4px]" />
121
+ </div>
122
+ </form>
123
+ ```
124
+
125
+ ### Section Spacing
126
+
127
+ **Page Sections:**
128
+ - **Tight sections:** `space-y-4` (16px) - Related content
129
+ - **Standard sections:** `space-y-6` (24px) - Default section spacing
130
+ - **Large sections:** `space-y-8` (32px) - Major content blocks
131
+ - **Page sections:** `space-y-12` (48px) - Top-level page sections
132
+
133
+ ```tsx
134
+ // React - Page with section spacing
135
+ <div className="space-y-8">
136
+ <section>
137
+ <h2>Section Title</h2>
138
+ <p>Content</p>
139
+ </section>
140
+ <section>
141
+ <h2>Another Section</h2>
142
+ <p>More content</p>
143
+ </section>
144
+ </div>
145
+ ```
146
+
147
+ ### Button Spacing
148
+
149
+ **Buttons:**
150
+ - **Small buttons:** `px-3 py-1.5` (12px horizontal, 6px vertical)
151
+ - **Standard buttons:** `px-4 py-2` (16px horizontal, 8px vertical)
152
+ - **Large buttons:** `px-6 py-3` (24px horizontal, 12px vertical)
153
+
154
+ ```tsx
155
+ // React - Button with standard spacing
156
+ <button className="bg-primary text-primary-foreground px-4 py-2 rounded-[6px]">
157
+ Click me
158
+ </button>
159
+ ```
160
+
161
+ ### List Spacing
162
+
163
+ **Lists:**
164
+ - **List item spacing:** `space-y-2` (8px) - Tight lists
165
+ - **Standard list spacing:** `space-y-4` (16px) - Default lists
166
+ - **Spacious lists:** `space-y-6` (24px) - Comfortable reading
167
+
168
+ ```tsx
169
+ // React - List with spacing
170
+ <ul className="space-y-4">
171
+ <li>List item 1</li>
172
+ <li>List item 2</li>
173
+ <li>List item 3</li>
174
+ </ul>
175
+ ```
176
+
177
+ ---
178
+
179
+ ## Best Practices
180
+
181
+ ### ✅ Do's
182
+
183
+ 1. **Use consistent spacing values**
184
+ - ✅ Stick to the spacing scale (4px, 8px, 12px, 16px, 24px, etc.)
185
+ - ✅ Use common values: 4, 6, 8, 12, 16, 24, 32, 48
186
+ - ✅ Maintain visual rhythm by using related spacing values
187
+
188
+ 2. **Prefer spacing over borders**
189
+ - ✅ Use spacing to create separation before adding borders
190
+ - ✅ Let spacing create visual hierarchy
191
+ - ✅ Use borders only when spacing is insufficient
192
+
193
+ 3. **Use semantic spacing utilities**
194
+ - ✅ Use `space-y-*` for vertical spacing between children
195
+ - ✅ Use `gap-*` for flex and grid layouts
196
+ - ✅ Use `p-*` and `m-*` for component padding and margins
197
+
198
+ 4. **Maintain spacing relationships**
199
+ - ✅ Use smaller spacing (2-4) for related elements
200
+ - ✅ Use medium spacing (6-8) for component groups
201
+ - ✅ Use large spacing (12-16) for major sections
202
+
203
+ 5. **Consider responsive spacing**
204
+ - ✅ Use responsive utilities when needed (`sm:`, `md:`, `lg:`)
205
+ - ✅ Adjust spacing for mobile vs. desktop
206
+ - ✅ Maintain readability across screen sizes
207
+
208
+ ### ❌ Don'ts
209
+
210
+ 1. **Don't use arbitrary spacing values**
211
+ - ❌ Don't use arbitrary values like `p-[13px]` or `m-[7px]`
212
+ - ❌ Don't mix spacing systems
213
+ - ❌ Always use the spacing scale
214
+
215
+ 2. **Don't overuse spacing**
216
+ - ❌ Don't add excessive spacing that breaks visual flow
217
+ - ❌ Don't use spacing to fix layout issues (fix the layout instead)
218
+ - ❌ Don't create inconsistent spacing patterns
219
+
220
+ 3. **Don't ignore spacing relationships**
221
+ - ❌ Don't mix unrelated spacing values (e.g., 5px and 13px)
222
+ - ❌ Don't create spacing that doesn't follow the scale
223
+ - ❌ Don't use spacing that breaks visual rhythm
224
+
225
+ 4. **Don't hardcode spacing**
226
+ - ❌ Don't use inline styles for spacing
227
+ - ❌ Don't create custom CSS for spacing
228
+ - ❌ Always use Tailwind utility classes
229
+
230
+ 5. **Don't forget accessibility**
231
+ - ❌ Don't use spacing so tight that content is hard to read
232
+ - ❌ Don't use spacing so large that it breaks content flow
233
+ - ❌ Ensure spacing supports readability and usability
234
+
235
+ ---
236
+
237
+ ## Spacing Guidelines by Context
238
+
239
+ ### Component Internal Spacing
240
+
241
+ **Card Components:**
242
+ - Padding: `p-6` (24px) - Standard card padding
243
+ - Content spacing: `space-y-4` (16px) - Between card elements
244
+
245
+ **Form Components:**
246
+ - Input padding: `px-3 py-2` (12px/8px)
247
+ - Label spacing: `mb-2` (8px) - Between label and input
248
+ - Field spacing: `space-y-4` (16px) - Between form fields
249
+
250
+ **Button Components:**
251
+ - Standard: `px-4 py-2` (16px/8px)
252
+ - Small: `px-3 py-1.5` (12px/6px)
253
+ - Large: `px-6 py-3` (24px/12px)
254
+
255
+ ### Layout Spacing
256
+
257
+ **Page Layout:**
258
+ - Container padding: `px-4 md:px-6 lg:px-8` (responsive)
259
+ - Section spacing: `space-y-8` (32px) - Between major sections
260
+ - Content spacing: `space-y-6` (24px) - Between content blocks
261
+
262
+ **Grid Layouts:**
263
+ - Grid gap: `gap-4` (16px) - Standard grid spacing
264
+ - Large grid gap: `gap-6` (24px) - Spacious grids
265
+ - Tight grid gap: `gap-2` (8px) - Compact grids
266
+
267
+ **Flex Layouts:**
268
+ - Flex gap: `gap-4` (16px) - Standard flex spacing
269
+ - Button groups: `gap-2` (8px) - Tight button spacing
270
+ - Navigation: `gap-6` (24px) - Navigation item spacing
271
+
272
+ ### Content Spacing
273
+
274
+ **Text Content:**
275
+ - Paragraph spacing: `space-y-4` (16px) - Between paragraphs
276
+ - Heading spacing: `mb-4` (16px) - Below headings
277
+ - List spacing: `space-y-2` (8px) - Between list items
278
+
279
+ **Media Content:**
280
+ - Image spacing: `mb-6` (24px) - Below images
281
+ - Video spacing: `mb-8` (32px) - Below videos
282
+ - Media groups: `gap-4` (16px) - Between media items
283
+
284
+ ---
285
+
286
+ ## Examples
287
+
288
+ ### ✅ Good: Consistent Spacing
289
+
290
+ ```tsx
291
+ // React - Card with proper spacing
292
+ <div className="bg-card border border-border rounded-lg p-6">
293
+ <h3 className="mb-4">Card Title</h3>
294
+ <p className="mb-4">Card content with consistent spacing.</p>
295
+ <button className="px-4 py-2 bg-primary text-primary-foreground rounded-[6px]">
296
+ Action
297
+ </button>
298
+ </div>
299
+
300
+ // React - Form with consistent spacing
301
+ <form className="space-y-4">
302
+ <div>
303
+ <label className="block mb-2">Email</label>
304
+ <input className="w-full px-3 py-2 border border-input rounded-[4px]" />
305
+ </div>
306
+ <div>
307
+ <label className="block mb-2">Password</label>
308
+ <input type="password" className="w-full px-3 py-2 border border-input rounded-[4px]" />
309
+ </div>
310
+ <button className="px-4 py-2 bg-primary text-primary-foreground rounded-[6px]">
311
+ Submit
312
+ </button>
313
+ </form>
314
+ ```
315
+
316
+ ### ❌ Bad: Inconsistent Spacing
317
+
318
+ ```tsx
319
+ // Don't do this - arbitrary spacing values
320
+ <div className="bg-card p-[13px] mb-[7px]">
321
+ <h3 className="mb-[11px]">Title</h3>
322
+ <p className="mb-[9px]">Content</p>
323
+ </div>
324
+
325
+ // Don't do this - inconsistent spacing relationships
326
+ <div className="space-y-5">
327
+ <div>Item 1</div>
328
+ <div>Item 2</div>
329
+ </div>
330
+ ```
331
+
332
+ ### ✅ Good: Using Spacing for Separation
333
+
334
+ ```tsx
335
+ // React - Using spacing instead of borders
336
+ <div className="space-y-8">
337
+ <section>
338
+ <h2 className="text-2xl font-bold mb-4">Section Title</h2>
339
+ <p>Content here</p>
340
+ </section>
341
+ <section>
342
+ <h2 className="text-2xl font-bold mb-4">Another Section</h2>
343
+ <p>More content</p>
344
+ </section>
345
+ </div>
346
+ ```
347
+
348
+ ### ✅ Good: Responsive Spacing
349
+
350
+ ```tsx
351
+ // React - Responsive spacing
352
+ <div className="px-4 py-6 md:px-6 md:py-8 lg:px-8 lg:py-12">
353
+ <h1>Responsive Container</h1>
354
+ <p>Spacing adapts to screen size</p>
355
+ </div>
356
+ ```
357
+
358
+ ---
359
+
360
+ ## Vue Examples
361
+
362
+ ```vue
363
+ <!-- Card with proper spacing -->
364
+ <template>
365
+ <div class="bg-card border border-border rounded-lg p-6">
366
+ <h3 class="mb-4">Card Title</h3>
367
+ <p class="mb-4">Card content with consistent spacing.</p>
368
+ <button class="px-4 py-2 bg-primary text-primary-foreground rounded-[6px]">
369
+ Action
370
+ </button>
371
+ </div>
372
+ </template>
373
+
374
+ <!-- Form with consistent spacing -->
375
+ <template>
376
+ <form class="space-y-4">
377
+ <div>
378
+ <label class="block mb-2">Email</label>
379
+ <input class="w-full px-3 py-2 border border-input rounded-[4px]" />
380
+ </div>
381
+ <div>
382
+ <label class="block mb-2">Password</label>
383
+ <input type="password" class="w-full px-3 py-2 border border-input rounded-[4px]" />
384
+ </div>
385
+ <button class="px-4 py-2 bg-primary text-primary-foreground rounded-[6px]">
386
+ Submit
387
+ </button>
388
+ </form>
389
+ </template>
390
+
391
+ <!-- Page with section spacing -->
392
+ <template>
393
+ <div class="space-y-8">
394
+ <section>
395
+ <h2 class="text-2xl font-bold mb-4">Section Title</h2>
396
+ <p>Content here</p>
397
+ </section>
398
+ <section>
399
+ <h2 class="text-2xl font-bold mb-4">Another Section</h2>
400
+ <p>More content</p>
401
+ </section>
402
+ </div>
403
+ </template>
404
+ ```
405
+
406
+ ---
407
+
408
+ ## Spacing in shadcn/ui Components
409
+
410
+ shadcn/ui components follow consistent spacing patterns:
411
+
412
+ ### Card Component
413
+ - **Padding:** `p-6` (24px)
414
+ - **Content spacing:** `space-y-4` (16px)
415
+
416
+ ### Button Component
417
+ - **Padding:** `px-4 py-2` (16px/8px)
418
+ - **Icon spacing:** `gap-2` (8px) when icons are present
419
+
420
+ ### Input Component
421
+ - **Padding:** `px-3 py-2` (12px/8px)
422
+ - **Label spacing:** `mb-2` (8px)
423
+
424
+ ### Dialog Component
425
+ - **Padding:** `p-6` (24px)
426
+ - **Content spacing:** `space-y-4` (16px)
427
+ - **Footer spacing:** `mt-6` (24px)
428
+
429
+ ### Form Component
430
+ - **Field spacing:** `space-y-4` (16px)
431
+ - **Section spacing:** `space-y-6` (24px)
432
+
433
+ ---
434
+
435
+ ## Integration with Design System
436
+
437
+ ### Spacing Variables
438
+
439
+ The design system defines a base spacing unit in `@equal-experts/kuat-core/src/variables.css`:
440
+
441
+ ```css
442
+ --spacing: 0.25rem; /* 4px base unit */
443
+ ```
444
+
445
+ This aligns with Tailwind's spacing scale where `1` = `0.25rem` (4px).
446
+
447
+ ### Tailwind Configuration
448
+
449
+ The spacing scale is built into Tailwind CSS and doesn't require custom configuration. All spacing utilities are available by default:
450
+
451
+ - Padding: `p-*`, `px-*`, `py-*`, `pt-*`, `pr-*`, `pb-*`, `pl-*`
452
+ - Margin: `m-*`, `mx-*`, `my-*`, `mt-*`, `mr-*`, `mb-*`, `ml-*`
453
+ - Gap: `gap-*`, `gap-x-*`, `gap-y-*`
454
+ - Space: `space-y-*`, `space-x-*`
455
+
456
+ ---
457
+
458
+ ## Additional Resources
459
+
460
+ - **Design System Overview:** See [design-system.md](./design-system.md) for complete design system documentation
461
+ - **Borders Guide:** See [borders.md](./borders.md) for spacing vs. borders guidance
462
+ - **Component Guidelines:** See [../technical/component-guidelines.md](../technical/component-guidelines.md) for component spacing patterns
463
+ - **shadcn/ui Components:** [shadcn/ui Component Documentation](https://ui.shadcn.com/docs/components)
464
+ - **Tailwind Spacing:** [Tailwind CSS Spacing Documentation](https://tailwindcss.com/docs/padding)
465
+ - **8-Point Grid System:** Industry standard spacing methodology
466
+
467
+ ---
468
+
469
+ ## Notes
470
+
471
+ - **4px Base Unit:** All spacing is based on a 4px (0.25rem) unit for consistency
472
+ - **Consistency First:** Always use the spacing scale—avoid arbitrary values
473
+ - **Spacing Over Borders:** Prefer spacing to create separation before using borders
474
+ - **Visual Rhythm:** Maintain consistent spacing relationships throughout the interface
475
+ - **Responsive Design:** Adjust spacing appropriately for different screen sizes
476
+ - **Accessibility:** Ensure spacing supports readability and usability
477
+