baseline-kit 2.0.0
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.md +334 -0
- package/dist/README.md +334 -0
- package/dist/components/Baseline/Baseline.d.ts +48 -0
- package/dist/components/Baseline/index.d.ts +6 -0
- package/dist/components/Box/Box.d.ts +62 -0
- package/dist/components/Box/index.d.ts +6 -0
- package/dist/components/Config/Config.d.ts +136 -0
- package/dist/components/Config/defaults.d.ts +25 -0
- package/dist/components/Config/index.d.ts +11 -0
- package/dist/components/Guide/Guide.d.ts +60 -0
- package/dist/components/Guide/index.d.ts +12 -0
- package/dist/components/Guide/types.d.ts +144 -0
- package/dist/components/Guide/validation.d.ts +82 -0
- package/dist/components/Layout/Layout.d.ts +69 -0
- package/dist/components/Layout/index.d.ts +10 -0
- package/dist/components/Padder/Padder.d.ts +61 -0
- package/dist/components/Padder/index.d.ts +10 -0
- package/dist/components/Spacer/Spacer.d.ts +55 -0
- package/dist/components/Spacer/index.d.ts +10 -0
- package/dist/components/Stack/Stack.d.ts +77 -0
- package/dist/components/Stack/index.d.ts +10 -0
- package/dist/components/index.d.ts +15 -0
- package/dist/components/types.d.ts +102 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/useBaseline.d.ts +72 -0
- package/dist/hooks/useConfig.d.ts +46 -0
- package/dist/hooks/useDebug.d.ts +54 -0
- package/dist/hooks/useGuide.d.ts +66 -0
- package/dist/hooks/useMeasure.d.ts +49 -0
- package/dist/hooks/useVirtual.d.ts +65 -0
- package/dist/index.cjs +32 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.mjs +1592 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/utils/convert.d.ts +46 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/math.d.ts +64 -0
- package/dist/utils/merge.d.ts +68 -0
- package/dist/utils/normalize.d.ts +65 -0
- package/dist/utils/padding.d.ts +11 -0
- package/dist/utils/parse.d.ts +52 -0
- package/dist/utils/snapping.d.ts +33 -0
- package/dist/utils/timing.d.ts +50 -0
- package/package.json +113 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 François Denavaut
|
|
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.md
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# Baseline Kit
|
|
2
|
+
|
|
3
|
+
Baseline Kit is a lightweight development tool for visualizing and debugging grid systems and spacing in React
|
|
4
|
+
applications. It provides configurable overlays for both column-based and baseline grids, flexible layout components,
|
|
5
|
+
and theme-aware configuration—all optimized for performance and built with TypeScript.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 📏 **Baseline Grid:** Core system for maintaining vertical rhythm and consistent spacing across your layouts
|
|
12
|
+
- 🎯 **Column Grid Guide:** Customizable overlay system for visualizing column-based layouts and alignment
|
|
13
|
+
- 📦 **Box Component:** Basic container with configurable spacing that snaps to the baseline grid
|
|
14
|
+
- 🧩 **Layout Component:** CSS Grid-based container with automatic column calculations and baseline alignment
|
|
15
|
+
- 📐 **Stack Component:** Flex-based container that maintains consistent spacing and baseline alignment
|
|
16
|
+
- 🎨 **Theme System:** Customizable colors and debug visuals through a centralized configuration
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```shell
|
|
21
|
+
# Using npm
|
|
22
|
+
npm install baseline-kit
|
|
23
|
+
|
|
24
|
+
# Using yarn
|
|
25
|
+
yarn add baseline-kit
|
|
26
|
+
|
|
27
|
+
# Using pnpm
|
|
28
|
+
pnpm add baseline-kit
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### TypeScript Support
|
|
32
|
+
|
|
33
|
+
Baseline Kit is written in TypeScript and includes built-in type definitions. No additional packages are required.
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
Basic setup with debugging enabled during development:
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import React from 'react'
|
|
41
|
+
import { Config, Guide, Baseline, Box } from 'baseline-kit'
|
|
42
|
+
import 'baseline-kit/styles.css'
|
|
43
|
+
|
|
44
|
+
function App() {
|
|
45
|
+
const isDev = process.env.NODE_ENV === 'development'
|
|
46
|
+
const debugging = isDev ? 'visible' : 'hidden'
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Config
|
|
50
|
+
base={8}
|
|
51
|
+
baseline={{ debugging }}
|
|
52
|
+
box={{ debugging }}
|
|
53
|
+
guide={{ debugging }}
|
|
54
|
+
spacer={{ debugging }}
|
|
55
|
+
>
|
|
56
|
+
{/* Baseline Grid for typography alignment */}
|
|
57
|
+
<Baseline
|
|
58
|
+
height="100vh"
|
|
59
|
+
debugging="visible"
|
|
60
|
+
/>
|
|
61
|
+
|
|
62
|
+
{/* Column Grid Guide */}
|
|
63
|
+
<Guide
|
|
64
|
+
variant="pattern"
|
|
65
|
+
columns={['100px', '200px', '100px']}
|
|
66
|
+
gap={16}
|
|
67
|
+
align="center"
|
|
68
|
+
width="1200px"
|
|
69
|
+
/>
|
|
70
|
+
|
|
71
|
+
{/* Box with baseline alignment */}
|
|
72
|
+
<Box
|
|
73
|
+
block={[2, 5]}
|
|
74
|
+
inline={1}
|
|
75
|
+
debugging="visible"
|
|
76
|
+
>
|
|
77
|
+
<h1>Content Aligned to the Grid</h1>
|
|
78
|
+
</Box>
|
|
79
|
+
|
|
80
|
+
<main>Your main content goes here...</main>
|
|
81
|
+
</Config>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Core Concepts
|
|
87
|
+
|
|
88
|
+
### Base Unit
|
|
89
|
+
|
|
90
|
+
The base unit is the foundation of Baseline Kit's spacing system. All measurements are calculated as multiples of this
|
|
91
|
+
unit:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
<Config base={8}> // Sets 8px as the base unit
|
|
95
|
+
<Layout
|
|
96
|
+
block={17} // Will be rounded to 16px (2 * base)
|
|
97
|
+
inline={22} // Will be rounded to 24px (3 * base)
|
|
98
|
+
>
|
|
99
|
+
{/* Content automatically aligned to the 8px grid */}
|
|
100
|
+
</Layout>
|
|
101
|
+
|
|
102
|
+
<Stack
|
|
103
|
+
block={[17, 25]} // Top: 16px, Bottom: 24px
|
|
104
|
+
inline={22} // Left/Right: 24px
|
|
105
|
+
>
|
|
106
|
+
{/* Padding automatically adjusted to base unit multiples */}
|
|
107
|
+
</Stack>
|
|
108
|
+
</Config>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Spacing Values
|
|
112
|
+
|
|
113
|
+
Spacing props (`block`, `inline`, `gap`) accept values in three formats:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
// Single number (applies to both sides)
|
|
117
|
+
block={16px} // 16px top and bottom
|
|
118
|
+
|
|
119
|
+
// Array [start, end]
|
|
120
|
+
block={[2, 3]} // 2px top, 3px bottom
|
|
121
|
+
|
|
122
|
+
// Object with explicit values
|
|
123
|
+
block={{ start: 2, end: 3 }} // Same as above
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Grid Snapping
|
|
127
|
+
|
|
128
|
+
Components automatically adjust their spacing to maintain baseline grid alignment:
|
|
129
|
+
|
|
130
|
+
- **Box**: Adjusts bottom padding to ensure total height aligns with base unit
|
|
131
|
+
- **Stack**: Maintains baseline alignment in flex layouts
|
|
132
|
+
- **Layout**: Ensures grid cells align with baseline
|
|
133
|
+
|
|
134
|
+
### Debugging Modes
|
|
135
|
+
|
|
136
|
+
Three modes are available for development and testing:
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
debugging = "visible" // Shows all grid lines and measurements
|
|
140
|
+
debugging = "hidden" // Elements exist but are invisible
|
|
141
|
+
debugging = "none" // Removes debug elements entirely
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Components
|
|
145
|
+
|
|
146
|
+
### Component Hierarchy
|
|
147
|
+
|
|
148
|
+
#### 1. Core Components
|
|
149
|
+
|
|
150
|
+
- **`Box`** Basic container for text alignment
|
|
151
|
+
- **`Stack`** Flex-based layouts (one-dimensional)
|
|
152
|
+
- **`Layout`** Grid-based layouts (two-dimensional)
|
|
153
|
+
|
|
154
|
+
#### 2. Development Tools
|
|
155
|
+
|
|
156
|
+
- **`Baseline`** Horizontal grid overlay
|
|
157
|
+
- **`Guide`** Vertical grid overlay
|
|
158
|
+
- **`Spacer`** Precise spacing measurement
|
|
159
|
+
|
|
160
|
+
#### 3. Configuration
|
|
161
|
+
|
|
162
|
+
- **`Config`** Theme and settings provider
|
|
163
|
+
- **`Padder`** Internal spacing utility
|
|
164
|
+
|
|
165
|
+
### Config
|
|
166
|
+
|
|
167
|
+
The Config component provides theme and debugging settings to all child components.
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
<Config
|
|
171
|
+
base={8} // Base unit for calculations
|
|
172
|
+
baseline={{ debugging }} // Baseline grid visibility
|
|
173
|
+
guide={{ // Guide customization
|
|
174
|
+
debugging,
|
|
175
|
+
colors: {
|
|
176
|
+
line: 'rgba(0,0,255,0.1)'
|
|
177
|
+
}
|
|
178
|
+
}}
|
|
179
|
+
>
|
|
180
|
+
{children}
|
|
181
|
+
</Config>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Baseline
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
<Baseline
|
|
188
|
+
base={8} // Base unit (defaults to Config value)
|
|
189
|
+
height="100vh" // Overlay height
|
|
190
|
+
variant="line" // "line" or "flat"
|
|
191
|
+
debugging="visible" // Show the grid overlay
|
|
192
|
+
/>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Guide
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
<Guide
|
|
199
|
+
variant="pattern" // "line", "pattern", "fixed", or "auto"
|
|
200
|
+
columns={['100px', '1fr', '100px']} // Column definition
|
|
201
|
+
gap={8} // Gap value
|
|
202
|
+
align="center" // "start", "center", or "end"
|
|
203
|
+
width="1200px" // Container width
|
|
204
|
+
debugging="visible" // Show grid overlay
|
|
205
|
+
/>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Box
|
|
209
|
+
|
|
210
|
+
```tsx
|
|
211
|
+
<Box
|
|
212
|
+
block={[2, 5]} // Vertical padding in base units (auto-adjusted for baseline)
|
|
213
|
+
inline={1} // Horizontal padding in base units
|
|
214
|
+
span={2} // Grid column span when used in Layout
|
|
215
|
+
snapping="height" // "none", "height", or "clamp"
|
|
216
|
+
debugging="visible" // Show alignment guides
|
|
217
|
+
>
|
|
218
|
+
<p>Content aligned to baseline grid</p>
|
|
219
|
+
</Box>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Stack
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
<Stack
|
|
226
|
+
direction="column" // "row" or "column"
|
|
227
|
+
block={[8, 24]} // Vertical padding (auto-snapping)
|
|
228
|
+
inline={16} // Horizontal padding (auto-snapping)
|
|
229
|
+
gap={16} // Gap value
|
|
230
|
+
justify="center" // Flex justify-content
|
|
231
|
+
align="center" // Flex align-items
|
|
232
|
+
debugging="visible" // Show alignment guides
|
|
233
|
+
>
|
|
234
|
+
<Box>Item 1</Box>
|
|
235
|
+
<Box>Item 2</Box>
|
|
236
|
+
</Stack>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Layout
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
<Layout
|
|
243
|
+
columns={3} // Number of columns or pattern array
|
|
244
|
+
gap={16} // Gap value
|
|
245
|
+
block={16} // Vertical padding (auto-snapping)
|
|
246
|
+
inline={8} // Horizontal padding (auto-snapping)
|
|
247
|
+
debugging="visible" // Show grid guides
|
|
248
|
+
>
|
|
249
|
+
<Box span={2}>Wide content</Box>
|
|
250
|
+
<Box>Regular content</Box>
|
|
251
|
+
</Layout>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Theme System
|
|
255
|
+
|
|
256
|
+
### Color Customization
|
|
257
|
+
|
|
258
|
+
The theme system allows customization of debugging visuals through the Config component:
|
|
259
|
+
|
|
260
|
+
```tsx
|
|
261
|
+
<Config
|
|
262
|
+
base={8}
|
|
263
|
+
guide={{
|
|
264
|
+
colors: {
|
|
265
|
+
line: 'rgba(0,0,255,0.1)',
|
|
266
|
+
pattern: 'rgba(0,0,255,0.05)',
|
|
267
|
+
auto: 'rgba(0,0,255,0.05)',
|
|
268
|
+
fixed: 'rgba(0,0,255,0.05)'
|
|
269
|
+
}
|
|
270
|
+
}}
|
|
271
|
+
baseline={{
|
|
272
|
+
colors: {
|
|
273
|
+
line: 'rgba(255,0,0,0.1)',
|
|
274
|
+
flat: 'rgba(255,0,0,0.05)'
|
|
275
|
+
}
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
{children}
|
|
279
|
+
</Config>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
The library uses CSS custom properties for colors, which automatically respect the user's system dark mode preferences
|
|
283
|
+
through CSS media queries. No additional configuration is required.
|
|
284
|
+
|
|
285
|
+
## Development Setup
|
|
286
|
+
|
|
287
|
+
```shell
|
|
288
|
+
# Clone the repository
|
|
289
|
+
git clone https://github.com/dnvt/baseline-kit.git
|
|
290
|
+
|
|
291
|
+
# Install dependencies
|
|
292
|
+
bun install
|
|
293
|
+
|
|
294
|
+
# Start development server
|
|
295
|
+
bun run dev
|
|
296
|
+
|
|
297
|
+
# Run tests
|
|
298
|
+
bun run test
|
|
299
|
+
|
|
300
|
+
# Build package
|
|
301
|
+
bun run build
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Server-Side Rendering
|
|
305
|
+
|
|
306
|
+
Baseline Kit is compatible with SSR frameworks like Next.js and Gatsby. The overlay components automatically handle
|
|
307
|
+
hydration mismatches.
|
|
308
|
+
|
|
309
|
+
## Browser Support
|
|
310
|
+
|
|
311
|
+
- Modern browsers (Chrome, Firefox, Safari, Edge)
|
|
312
|
+
- Requires CSS Grid Layout support
|
|
313
|
+
- Requires CSS Custom Properties (CSS Variables)
|
|
314
|
+
- Falls back gracefully in unsupported browsers
|
|
315
|
+
|
|
316
|
+
## Performance Considerations
|
|
317
|
+
|
|
318
|
+
- Uses requestAnimationFrame for smooth animations
|
|
319
|
+
- Virtualizes large grid overlays
|
|
320
|
+
- Optimizes re-renders using React.memo
|
|
321
|
+
- Supports tree-shaking for minimal bundle size
|
|
322
|
+
|
|
323
|
+
## Contributing
|
|
324
|
+
|
|
325
|
+
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for detailed guidelines on:
|
|
326
|
+
|
|
327
|
+
- Development setup
|
|
328
|
+
- Code style
|
|
329
|
+
- Testing requirements
|
|
330
|
+
- Pull request process
|
|
331
|
+
|
|
332
|
+
## License
|
|
333
|
+
|
|
334
|
+
MIT © [François Denavaut](https://github.com/dnvt)
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# Baseline Kit
|
|
2
|
+
|
|
3
|
+
Baseline Kit is a lightweight development tool for visualizing and debugging grid systems and spacing in React
|
|
4
|
+
applications. It provides configurable overlays for both column-based and baseline grids, flexible layout components,
|
|
5
|
+
and theme-aware configuration—all optimized for performance and built with TypeScript.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 📏 **Baseline Grid:** Core system for maintaining vertical rhythm and consistent spacing across your layouts
|
|
12
|
+
- 🎯 **Column Grid Guide:** Customizable overlay system for visualizing column-based layouts and alignment
|
|
13
|
+
- 📦 **Box Component:** Basic container with configurable spacing that snaps to the baseline grid
|
|
14
|
+
- 🧩 **Layout Component:** CSS Grid-based container with automatic column calculations and baseline alignment
|
|
15
|
+
- 📐 **Stack Component:** Flex-based container that maintains consistent spacing and baseline alignment
|
|
16
|
+
- 🎨 **Theme System:** Customizable colors and debug visuals through a centralized configuration
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```shell
|
|
21
|
+
# Using npm
|
|
22
|
+
npm install baseline-kit
|
|
23
|
+
|
|
24
|
+
# Using yarn
|
|
25
|
+
yarn add baseline-kit
|
|
26
|
+
|
|
27
|
+
# Using pnpm
|
|
28
|
+
pnpm add baseline-kit
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### TypeScript Support
|
|
32
|
+
|
|
33
|
+
Baseline Kit is written in TypeScript and includes built-in type definitions. No additional packages are required.
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
Basic setup with debugging enabled during development:
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import React from 'react'
|
|
41
|
+
import { Config, Guide, Baseline, Box } from 'baseline-kit'
|
|
42
|
+
import 'baseline-kit/styles.css'
|
|
43
|
+
|
|
44
|
+
function App() {
|
|
45
|
+
const isDev = process.env.NODE_ENV === 'development'
|
|
46
|
+
const debugging = isDev ? 'visible' : 'hidden'
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Config
|
|
50
|
+
base={8}
|
|
51
|
+
baseline={{ debugging }}
|
|
52
|
+
box={{ debugging }}
|
|
53
|
+
guide={{ debugging }}
|
|
54
|
+
spacer={{ debugging }}
|
|
55
|
+
>
|
|
56
|
+
{/* Baseline Grid for typography alignment */}
|
|
57
|
+
<Baseline
|
|
58
|
+
height="100vh"
|
|
59
|
+
debugging="visible"
|
|
60
|
+
/>
|
|
61
|
+
|
|
62
|
+
{/* Column Grid Guide */}
|
|
63
|
+
<Guide
|
|
64
|
+
variant="pattern"
|
|
65
|
+
columns={['100px', '200px', '100px']}
|
|
66
|
+
gap={16}
|
|
67
|
+
align="center"
|
|
68
|
+
width="1200px"
|
|
69
|
+
/>
|
|
70
|
+
|
|
71
|
+
{/* Box with baseline alignment */}
|
|
72
|
+
<Box
|
|
73
|
+
block={[2, 5]}
|
|
74
|
+
inline={1}
|
|
75
|
+
debugging="visible"
|
|
76
|
+
>
|
|
77
|
+
<h1>Content Aligned to the Grid</h1>
|
|
78
|
+
</Box>
|
|
79
|
+
|
|
80
|
+
<main>Your main content goes here...</main>
|
|
81
|
+
</Config>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Core Concepts
|
|
87
|
+
|
|
88
|
+
### Base Unit
|
|
89
|
+
|
|
90
|
+
The base unit is the foundation of Baseline Kit's spacing system. All measurements are calculated as multiples of this
|
|
91
|
+
unit:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
<Config base={8}> // Sets 8px as the base unit
|
|
95
|
+
<Layout
|
|
96
|
+
block={17} // Will be rounded to 16px (2 * base)
|
|
97
|
+
inline={22} // Will be rounded to 24px (3 * base)
|
|
98
|
+
>
|
|
99
|
+
{/* Content automatically aligned to the 8px grid */}
|
|
100
|
+
</Layout>
|
|
101
|
+
|
|
102
|
+
<Stack
|
|
103
|
+
block={[17, 25]} // Top: 16px, Bottom: 24px
|
|
104
|
+
inline={22} // Left/Right: 24px
|
|
105
|
+
>
|
|
106
|
+
{/* Padding automatically adjusted to base unit multiples */}
|
|
107
|
+
</Stack>
|
|
108
|
+
</Config>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Spacing Values
|
|
112
|
+
|
|
113
|
+
Spacing props (`block`, `inline`, `gap`) accept values in three formats:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
// Single number (applies to both sides)
|
|
117
|
+
block={16px} // 16px top and bottom
|
|
118
|
+
|
|
119
|
+
// Array [start, end]
|
|
120
|
+
block={[2, 3]} // 2px top, 3px bottom
|
|
121
|
+
|
|
122
|
+
// Object with explicit values
|
|
123
|
+
block={{ start: 2, end: 3 }} // Same as above
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Grid Snapping
|
|
127
|
+
|
|
128
|
+
Components automatically adjust their spacing to maintain baseline grid alignment:
|
|
129
|
+
|
|
130
|
+
- **Box**: Adjusts bottom padding to ensure total height aligns with base unit
|
|
131
|
+
- **Stack**: Maintains baseline alignment in flex layouts
|
|
132
|
+
- **Layout**: Ensures grid cells align with baseline
|
|
133
|
+
|
|
134
|
+
### Debugging Modes
|
|
135
|
+
|
|
136
|
+
Three modes are available for development and testing:
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
debugging = "visible" // Shows all grid lines and measurements
|
|
140
|
+
debugging = "hidden" // Elements exist but are invisible
|
|
141
|
+
debugging = "none" // Removes debug elements entirely
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Components
|
|
145
|
+
|
|
146
|
+
### Component Hierarchy
|
|
147
|
+
|
|
148
|
+
#### 1. Core Components
|
|
149
|
+
|
|
150
|
+
- **`Box`** Basic container for text alignment
|
|
151
|
+
- **`Stack`** Flex-based layouts (one-dimensional)
|
|
152
|
+
- **`Layout`** Grid-based layouts (two-dimensional)
|
|
153
|
+
|
|
154
|
+
#### 2. Development Tools
|
|
155
|
+
|
|
156
|
+
- **`Baseline`** Horizontal grid overlay
|
|
157
|
+
- **`Guide`** Vertical grid overlay
|
|
158
|
+
- **`Spacer`** Precise spacing measurement
|
|
159
|
+
|
|
160
|
+
#### 3. Configuration
|
|
161
|
+
|
|
162
|
+
- **`Config`** Theme and settings provider
|
|
163
|
+
- **`Padder`** Internal spacing utility
|
|
164
|
+
|
|
165
|
+
### Config
|
|
166
|
+
|
|
167
|
+
The Config component provides theme and debugging settings to all child components.
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
<Config
|
|
171
|
+
base={8} // Base unit for calculations
|
|
172
|
+
baseline={{ debugging }} // Baseline grid visibility
|
|
173
|
+
guide={{ // Guide customization
|
|
174
|
+
debugging,
|
|
175
|
+
colors: {
|
|
176
|
+
line: 'rgba(0,0,255,0.1)'
|
|
177
|
+
}
|
|
178
|
+
}}
|
|
179
|
+
>
|
|
180
|
+
{children}
|
|
181
|
+
</Config>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Baseline
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
<Baseline
|
|
188
|
+
base={8} // Base unit (defaults to Config value)
|
|
189
|
+
height="100vh" // Overlay height
|
|
190
|
+
variant="line" // "line" or "flat"
|
|
191
|
+
debugging="visible" // Show the grid overlay
|
|
192
|
+
/>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Guide
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
<Guide
|
|
199
|
+
variant="pattern" // "line", "pattern", "fixed", or "auto"
|
|
200
|
+
columns={['100px', '1fr', '100px']} // Column definition
|
|
201
|
+
gap={8} // Gap value
|
|
202
|
+
align="center" // "start", "center", or "end"
|
|
203
|
+
width="1200px" // Container width
|
|
204
|
+
debugging="visible" // Show grid overlay
|
|
205
|
+
/>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Box
|
|
209
|
+
|
|
210
|
+
```tsx
|
|
211
|
+
<Box
|
|
212
|
+
block={[2, 5]} // Vertical padding in base units (auto-adjusted for baseline)
|
|
213
|
+
inline={1} // Horizontal padding in base units
|
|
214
|
+
span={2} // Grid column span when used in Layout
|
|
215
|
+
snapping="height" // "none", "height", or "clamp"
|
|
216
|
+
debugging="visible" // Show alignment guides
|
|
217
|
+
>
|
|
218
|
+
<p>Content aligned to baseline grid</p>
|
|
219
|
+
</Box>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Stack
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
<Stack
|
|
226
|
+
direction="column" // "row" or "column"
|
|
227
|
+
block={[8, 24]} // Vertical padding (auto-snapping)
|
|
228
|
+
inline={16} // Horizontal padding (auto-snapping)
|
|
229
|
+
gap={16} // Gap value
|
|
230
|
+
justify="center" // Flex justify-content
|
|
231
|
+
align="center" // Flex align-items
|
|
232
|
+
debugging="visible" // Show alignment guides
|
|
233
|
+
>
|
|
234
|
+
<Box>Item 1</Box>
|
|
235
|
+
<Box>Item 2</Box>
|
|
236
|
+
</Stack>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Layout
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
<Layout
|
|
243
|
+
columns={3} // Number of columns or pattern array
|
|
244
|
+
gap={16} // Gap value
|
|
245
|
+
block={16} // Vertical padding (auto-snapping)
|
|
246
|
+
inline={8} // Horizontal padding (auto-snapping)
|
|
247
|
+
debugging="visible" // Show grid guides
|
|
248
|
+
>
|
|
249
|
+
<Box span={2}>Wide content</Box>
|
|
250
|
+
<Box>Regular content</Box>
|
|
251
|
+
</Layout>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Theme System
|
|
255
|
+
|
|
256
|
+
### Color Customization
|
|
257
|
+
|
|
258
|
+
The theme system allows customization of debugging visuals through the Config component:
|
|
259
|
+
|
|
260
|
+
```tsx
|
|
261
|
+
<Config
|
|
262
|
+
base={8}
|
|
263
|
+
guide={{
|
|
264
|
+
colors: {
|
|
265
|
+
line: 'rgba(0,0,255,0.1)',
|
|
266
|
+
pattern: 'rgba(0,0,255,0.05)',
|
|
267
|
+
auto: 'rgba(0,0,255,0.05)',
|
|
268
|
+
fixed: 'rgba(0,0,255,0.05)'
|
|
269
|
+
}
|
|
270
|
+
}}
|
|
271
|
+
baseline={{
|
|
272
|
+
colors: {
|
|
273
|
+
line: 'rgba(255,0,0,0.1)',
|
|
274
|
+
flat: 'rgba(255,0,0,0.05)'
|
|
275
|
+
}
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
{children}
|
|
279
|
+
</Config>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
The library uses CSS custom properties for colors, which automatically respect the user's system dark mode preferences
|
|
283
|
+
through CSS media queries. No additional configuration is required.
|
|
284
|
+
|
|
285
|
+
## Development Setup
|
|
286
|
+
|
|
287
|
+
```shell
|
|
288
|
+
# Clone the repository
|
|
289
|
+
git clone https://github.com/dnvt/baseline-kit.git
|
|
290
|
+
|
|
291
|
+
# Install dependencies
|
|
292
|
+
bun install
|
|
293
|
+
|
|
294
|
+
# Start development server
|
|
295
|
+
bun run dev
|
|
296
|
+
|
|
297
|
+
# Run tests
|
|
298
|
+
bun run test
|
|
299
|
+
|
|
300
|
+
# Build package
|
|
301
|
+
bun run build
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Server-Side Rendering
|
|
305
|
+
|
|
306
|
+
Baseline Kit is compatible with SSR frameworks like Next.js and Gatsby. The overlay components automatically handle
|
|
307
|
+
hydration mismatches.
|
|
308
|
+
|
|
309
|
+
## Browser Support
|
|
310
|
+
|
|
311
|
+
- Modern browsers (Chrome, Firefox, Safari, Edge)
|
|
312
|
+
- Requires CSS Grid Layout support
|
|
313
|
+
- Requires CSS Custom Properties (CSS Variables)
|
|
314
|
+
- Falls back gracefully in unsupported browsers
|
|
315
|
+
|
|
316
|
+
## Performance Considerations
|
|
317
|
+
|
|
318
|
+
- Uses requestAnimationFrame for smooth animations
|
|
319
|
+
- Virtualizes large grid overlays
|
|
320
|
+
- Optimizes re-renders using React.memo
|
|
321
|
+
- Supports tree-shaking for minimal bundle size
|
|
322
|
+
|
|
323
|
+
## Contributing
|
|
324
|
+
|
|
325
|
+
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for detailed guidelines on:
|
|
326
|
+
|
|
327
|
+
- Development setup
|
|
328
|
+
- Code style
|
|
329
|
+
- Testing requirements
|
|
330
|
+
- Pull request process
|
|
331
|
+
|
|
332
|
+
## License
|
|
333
|
+
|
|
334
|
+
MIT © [François Denavaut](https://github.com/dnvt)
|