baseline-kit 2.0.1 → 2.1.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/README.md +126 -102
- package/dist/README.md +126 -102
- package/dist/components/Baseline/Baseline.d.ts +27 -5
- package/dist/components/Box/Box.d.ts +26 -5
- package/dist/components/Config/Config.d.ts +51 -8
- package/dist/components/Guide/Guide.d.ts +35 -12
- package/dist/components/Layout/Layout.d.ts +20 -6
- package/dist/components/Padder/Padder.d.ts +24 -7
- package/dist/components/Spacer/Spacer.d.ts +44 -11
- package/dist/components/Stack/Stack.d.ts +24 -8
- package/dist/components/types.d.ts +1 -1
- package/dist/hooks/useBaseline.d.ts +13 -18
- package/dist/hooks/useConfig.d.ts +0 -5
- package/dist/hooks/useDebug.d.ts +1 -6
- package/dist/hooks/useGuide.d.ts +2 -7
- package/dist/hooks/useVirtual.d.ts +0 -5
- package/dist/index.cjs +11 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1447 -1038
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme.css +140 -0
- package/dist/utils/convert.d.ts +0 -5
- package/dist/utils/grid.d.ts +22 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/math.d.ts +26 -5
- package/dist/utils/merge.d.ts +54 -5
- package/dist/utils/parse.d.ts +0 -5
- package/dist/utils/snapping.d.ts +0 -5
- package/dist/utils/ssr.d.ts +33 -0
- package/dist/utils/timing.d.ts +0 -5
- package/package.json +43 -32
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Baseline Kit
|
|
2
2
|
|
|
3
|
-
Baseline Kit is a lightweight development tool for visualizing and debugging grid systems and spacing in React
|
|
3
|
+
Baseline Kit is a lightweight development tool for visualizing and debugging grid systems and spacing in React 19
|
|
4
4
|
applications. It provides configurable overlays for both column-based and baseline grids, flexible layout components,
|
|
5
5
|
and theme-aware configuration—all optimized for performance and built with TypeScript.
|
|
6
6
|
|
|
7
|
-

|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
@@ -15,6 +15,11 @@ and theme-aware configuration—all optimized for performance and built with Typ
|
|
|
15
15
|
- 📐 **Stack Component:** Flex-based container that maintains consistent spacing and baseline alignment
|
|
16
16
|
- 🎨 **Theme System:** Customizable colors and debug visuals through a centralized configuration
|
|
17
17
|
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
- **React 19**: Baseline Kit is built for React 19 and uses the latest React features like the `use` hook
|
|
21
|
+
- **Modern Browsers**: Supporting the latest CSS features
|
|
22
|
+
|
|
18
23
|
## Installation
|
|
19
24
|
|
|
20
25
|
```shell
|
|
@@ -28,18 +33,21 @@ yarn add baseline-kit
|
|
|
28
33
|
pnpm add baseline-kit
|
|
29
34
|
```
|
|
30
35
|
|
|
31
|
-
|
|
36
|
+
After installation, import both the styles and theme in your application:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
// Import in your main entry file (e.g., index.js, App.js)
|
|
40
|
+
import 'baseline-kit/styles'; // Required core styles
|
|
41
|
+
import 'baseline-kit/theme'; // Recommended theme (or use your own)
|
|
42
|
+
```
|
|
32
43
|
|
|
33
|
-
Baseline Kit is written in TypeScript and includes built-in type definitions
|
|
44
|
+
Baseline Kit is written in TypeScript and includes built-in type definitions—no additional packages required.
|
|
34
45
|
|
|
35
46
|
## Quick Start
|
|
36
47
|
|
|
37
|
-
Basic setup with debugging enabled during development:
|
|
38
|
-
|
|
39
48
|
```tsx
|
|
40
49
|
import React from 'react'
|
|
41
50
|
import { Config, Guide, Baseline, Box } from 'baseline-kit'
|
|
42
|
-
import 'baseline-kit/styles.css'
|
|
43
51
|
|
|
44
52
|
function App() {
|
|
45
53
|
const isDev = process.env.NODE_ENV === 'development'
|
|
@@ -97,13 +105,6 @@ unit:
|
|
|
97
105
|
>
|
|
98
106
|
{/* Content automatically aligned to the 8px grid */}
|
|
99
107
|
</Layout>
|
|
100
|
-
|
|
101
|
-
<Stack
|
|
102
|
-
block={[17, 25]} // Top: 16px, Bottom: 24px
|
|
103
|
-
inline={22} // Left/Right: 24px
|
|
104
|
-
>
|
|
105
|
-
{/* Padding automatically adjusted to base unit multiples */}
|
|
106
|
-
</Stack>
|
|
107
108
|
</Config>
|
|
108
109
|
```
|
|
109
110
|
|
|
@@ -113,7 +114,7 @@ Spacing props (`block`, `inline`, `gap`) accept values in three formats:
|
|
|
113
114
|
|
|
114
115
|
```
|
|
115
116
|
// Single number (applies to both sides)
|
|
116
|
-
block={
|
|
117
|
+
block={16} // 16px top and bottom
|
|
117
118
|
|
|
118
119
|
// Array [start, end]
|
|
119
120
|
block={[2, 3]} // 2px top, 3px bottom
|
|
@@ -159,128 +160,172 @@ debugging = "none" // Removes debug elements entirely
|
|
|
159
160
|
#### 3. Configuration
|
|
160
161
|
|
|
161
162
|
- **`Config`** Theme and settings provider
|
|
162
|
-
- **`Padder`** Internal spacing utility
|
|
163
163
|
|
|
164
|
-
###
|
|
164
|
+
### Key Components
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
#### Config
|
|
167
167
|
|
|
168
168
|
```tsx
|
|
169
169
|
<Config
|
|
170
170
|
base={8} // Base unit for calculations
|
|
171
171
|
baseline={{ debugging }} // Baseline grid visibility
|
|
172
|
-
guide={{
|
|
173
|
-
debugging,
|
|
174
|
-
colors: {
|
|
175
|
-
line: 'rgba(0,0,255,0.1)'
|
|
176
|
-
}
|
|
177
|
-
}}
|
|
172
|
+
guide={{ debugging }} // Guide customization
|
|
178
173
|
>
|
|
179
174
|
{children}
|
|
180
175
|
</Config>
|
|
181
176
|
```
|
|
182
177
|
|
|
183
|
-
|
|
178
|
+
#### Baseline
|
|
184
179
|
|
|
185
180
|
```tsx
|
|
186
181
|
<Baseline
|
|
187
|
-
base={8} // Base unit (defaults to Config value)
|
|
188
182
|
height="100vh" // Overlay height
|
|
189
183
|
variant="line" // "line" or "flat"
|
|
190
184
|
debugging="visible" // Show the grid overlay
|
|
191
185
|
/>
|
|
192
186
|
```
|
|
193
187
|
|
|
194
|
-
|
|
188
|
+
#### Guide
|
|
195
189
|
|
|
196
190
|
```tsx
|
|
197
191
|
<Guide
|
|
198
|
-
variant="pattern"
|
|
199
|
-
columns={['100px', '1fr', '100px']}
|
|
200
|
-
gap={8}
|
|
201
|
-
|
|
202
|
-
width="1200px" // Container width
|
|
203
|
-
debugging="visible" // Show grid overlay
|
|
192
|
+
variant="pattern" // "line", "pattern", "fixed", or "auto"
|
|
193
|
+
columns={['100px', '1fr', '100px']} // Column definition
|
|
194
|
+
gap={8} // Gap value
|
|
195
|
+
width="1200px" // Container width
|
|
204
196
|
/>
|
|
205
197
|
```
|
|
206
198
|
|
|
207
|
-
|
|
199
|
+
#### Box
|
|
208
200
|
|
|
209
201
|
```tsx
|
|
210
202
|
<Box
|
|
211
|
-
block={[2, 5]} // Vertical padding in base units
|
|
203
|
+
block={[2, 5]} // Vertical padding in base units
|
|
212
204
|
span={2} // Grid column span when used in Layout
|
|
213
205
|
snapping="height" // "none", "height", or "clamp"
|
|
214
|
-
debugging="visible" // Show alignment guides
|
|
215
206
|
>
|
|
216
207
|
<p>Content aligned to baseline grid</p>
|
|
217
208
|
</Box>
|
|
218
209
|
```
|
|
219
210
|
|
|
220
|
-
|
|
211
|
+
## Theme System
|
|
212
|
+
|
|
213
|
+
Baseline Kit comes with two CSS files:
|
|
214
|
+
|
|
215
|
+
1. `styles.css` - Contains the core component styles required for functionality
|
|
216
|
+
2. `theme.css` - Contains color variables and theming (optional but recommended)
|
|
217
|
+
|
|
218
|
+
### Theme Options
|
|
219
|
+
|
|
220
|
+
You have three options for using the theme system:
|
|
221
|
+
|
|
222
|
+
#### 1. Use the Built-in Theme
|
|
221
223
|
|
|
222
224
|
```tsx
|
|
223
|
-
|
|
224
|
-
direction="column" // "row" or "column"
|
|
225
|
-
block={[8, 24]} // Vertical padding (auto-snapping)
|
|
226
|
-
inline={16} // Horizontal padding (auto-snapping)
|
|
227
|
-
gap={16} // Gap value
|
|
228
|
-
justify="center" // Flex justify-content
|
|
229
|
-
align="center" // Flex align-items
|
|
230
|
-
debugging="visible" // Show alignment guides
|
|
231
|
-
>
|
|
232
|
-
<Box>Item 1</Box>
|
|
233
|
-
<Box>Item 2</Box>
|
|
234
|
-
</Stack>
|
|
225
|
+
import 'baseline-kit/theme'; // Default theme with light/dark mode support
|
|
235
226
|
```
|
|
236
227
|
|
|
237
|
-
|
|
228
|
+
#### 2. Create a Custom Theme
|
|
238
229
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
230
|
+
Create your own theme.css file:
|
|
231
|
+
|
|
232
|
+
```css
|
|
233
|
+
/* yourCustomTheme.css */
|
|
234
|
+
:root {
|
|
235
|
+
/* Component-specific colors */
|
|
236
|
+
--bk-baseline-color-line-theme: hsla(210, 100%, 50%, 0.15);
|
|
237
|
+
--bk-baseline-color-flat-theme: hsla(270, 100%, 60%, 0.2);
|
|
238
|
+
/* Add other component colors as needed */
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* Optional dark mode support */
|
|
242
|
+
@media (prefers-color-scheme: dark) {
|
|
243
|
+
:root {
|
|
244
|
+
--bk-baseline-color-line-theme: hsla(210, 100%, 50%, 0.2);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
250
247
|
```
|
|
251
248
|
|
|
252
|
-
|
|
249
|
+
Then import your custom theme:
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
import 'baseline-kit/styles'; // Required core styles
|
|
253
|
+
import './path/to/yourCustomTheme.css'; // Your custom theme
|
|
254
|
+
```
|
|
253
255
|
|
|
254
|
-
|
|
256
|
+
#### 3. Override via Config
|
|
255
257
|
|
|
256
|
-
|
|
258
|
+
For minor adjustments, use the Config component:
|
|
257
259
|
|
|
258
260
|
```tsx
|
|
259
261
|
<Config
|
|
260
|
-
base={8}
|
|
261
|
-
guide={{
|
|
262
|
-
colors: {
|
|
263
|
-
line: 'rgba(0,0,255,0.1)',
|
|
264
|
-
pattern: 'rgba(0,0,255,0.05)',
|
|
265
|
-
auto: 'rgba(0,0,255,0.05)',
|
|
266
|
-
fixed: 'rgba(0,0,255,0.05)'
|
|
267
|
-
}
|
|
268
|
-
}}
|
|
269
262
|
baseline={{
|
|
270
263
|
colors: {
|
|
271
|
-
line: 'rgba(255,0,0,0.1)',
|
|
272
|
-
flat: 'rgba(255,0,0,0.05)'
|
|
264
|
+
line: 'rgba(255,0,0,0.1)', // Custom red baseline lines
|
|
265
|
+
flat: 'rgba(255,0,0,0.05)', // Custom red baseline backgrounds
|
|
273
266
|
}
|
|
274
267
|
}}
|
|
275
268
|
>
|
|
276
|
-
{
|
|
269
|
+
{/* Your components here */}
|
|
277
270
|
</Config>
|
|
278
271
|
```
|
|
279
272
|
|
|
280
|
-
|
|
281
|
-
through CSS media queries. No additional configuration is required.
|
|
273
|
+
### Theme Variables Reference
|
|
282
274
|
|
|
283
|
-
|
|
275
|
+
| Component | Variable Pattern | Purpose |
|
|
276
|
+
|-----------|-----------------|---------|
|
|
277
|
+
| Baseline | `--bk-baseline-color-[line/flat]-theme` | Colors for lines and backgrounds |
|
|
278
|
+
| Guide | `--bk-guide-color-[line/pattern/auto/fixed]-theme` | Colors for different guide variants |
|
|
279
|
+
| Box | `--bk-box-color-[line/flat/text]-theme` | Colors for borders, backgrounds and text |
|
|
280
|
+
| Stack | `--bk-stack-color-[line/flat/text]-theme` | Colors for borders, backgrounds and text |
|
|
281
|
+
| Layout | `--bk-layout-color-[line/flat/text]-theme` | Colors for borders, backgrounds and text |
|
|
282
|
+
| Spacer | `--bk-spacer-color-[line/flat/text]-theme` | Colors for borders, backgrounds and text |
|
|
283
|
+
|
|
284
|
+
See the [default theme file](https://github.com/dnvt/baseline-kit/blob/main/dist/theme.css) for a complete example.
|
|
285
|
+
|
|
286
|
+
## Browser Support
|
|
287
|
+
|
|
288
|
+
- Modern browsers (Chrome, Firefox, Safari, Edge)
|
|
289
|
+
- Requires CSS Grid Layout support and CSS Custom Properties
|
|
290
|
+
- Falls back gracefully in unsupported browsers
|
|
291
|
+
|
|
292
|
+
## React 19 Features
|
|
293
|
+
|
|
294
|
+
Baseline Kit leverages React 19's latest features:
|
|
295
|
+
|
|
296
|
+
- **`use` Hook**: Replaces `useContext` for better performance and cleaner code
|
|
297
|
+
- **Streamlined Context API**: Uses the simplified Context Provider syntax
|
|
298
|
+
- **JSX Transform**: Takes advantage of the mandatory JSX transform in React 19
|
|
299
|
+
|
|
300
|
+
These modern features allow for cleaner code and better performance, but require React 19.
|
|
301
|
+
|
|
302
|
+
## Server-Side Rendering (SSR)
|
|
303
|
+
|
|
304
|
+
Baseline Kit is fully compatible with React's Server-Side Rendering in frameworks like Next.js, Remix, and other React Router-based applications.
|
|
305
|
+
|
|
306
|
+
### SSR-Friendly Design
|
|
307
|
+
|
|
308
|
+
Components are designed to:
|
|
309
|
+
- Provide consistent rendering between server and client
|
|
310
|
+
- Avoid hydration mismatches by using deterministic initial values
|
|
311
|
+
- Progressively enhance with client-side measurements after hydration
|
|
312
|
+
- Work with frameworks that use streaming SSR
|
|
313
|
+
|
|
314
|
+
### SSR Mode Prop
|
|
315
|
+
|
|
316
|
+
Components accept an `ssrMode` prop to explicitly optimize for server rendering:
|
|
317
|
+
|
|
318
|
+
```tsx
|
|
319
|
+
<Baseline
|
|
320
|
+
height="100vh"
|
|
321
|
+
ssrMode={true}
|
|
322
|
+
debugging="visible"
|
|
323
|
+
/>
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
With `ssrMode` enabled, components use simplified rendering during SSR and initial hydration, then enhance with full features after client-side hydration completes.
|
|
327
|
+
|
|
328
|
+
## Development
|
|
284
329
|
|
|
285
330
|
```shell
|
|
286
331
|
# Clone the repository
|
|
@@ -294,38 +339,17 @@ bun run dev
|
|
|
294
339
|
|
|
295
340
|
# Run tests
|
|
296
341
|
bun run test
|
|
297
|
-
|
|
298
|
-
# Build package
|
|
299
|
-
bun run build
|
|
300
342
|
```
|
|
301
343
|
|
|
302
|
-
##
|
|
344
|
+
## Performance Features
|
|
303
345
|
|
|
304
|
-
Baseline Kit is compatible with SSR frameworks like Next.js and Gatsby. The overlay components automatically handle
|
|
305
|
-
hydration mismatches.
|
|
306
|
-
|
|
307
|
-
## Browser Support
|
|
308
|
-
|
|
309
|
-
- Modern browsers (Chrome, Firefox, Safari, Edge)
|
|
310
|
-
- Requires CSS Grid Layout support
|
|
311
|
-
- Requires CSS Custom Properties (CSS Variables)
|
|
312
|
-
- Falls back gracefully in unsupported browsers
|
|
313
|
-
|
|
314
|
-
## Performance Considerations
|
|
315
|
-
|
|
316
|
-
- Uses requestAnimationFrame for smooth animations
|
|
317
346
|
- Virtualizes large grid overlays
|
|
318
347
|
- Optimizes re-renders using React.memo
|
|
319
348
|
- Supports tree-shaking for minimal bundle size
|
|
320
349
|
|
|
321
350
|
## Contributing
|
|
322
351
|
|
|
323
|
-
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for detailed guidelines
|
|
324
|
-
|
|
325
|
-
- Development setup
|
|
326
|
-
- Code style
|
|
327
|
-
- Testing requirements
|
|
328
|
-
- Pull request process
|
|
352
|
+
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for detailed guidelines.
|
|
329
353
|
|
|
330
354
|
## License
|
|
331
355
|
|