Skip to content

Commit b9ef802

Browse files
committed
Expand README with features and usage examples. Fixes #277
Added detailed documentation to the README, including a comprehensive features list, quick start guide, common layout patterns, TypeScript integration, best practices, visual references, and accessibility considerations for the unit.gl toolkit.
1 parent 21bf73a commit b9ef802

1 file changed

Lines changed: 326 additions & 0 deletions

File tree

README.md

Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,40 @@
3333

3434
`unit.gl` is a comprehensive design toolkit focused on fluid typography, responsive design, and advanced SCSS functions. It's crafted to empower designers and developers to create harmonious, scalable, and accessible web experiences efficiently.
3535

36+
---
37+
38+
## Features
39+
40+
`unit.gl` provides a robust set of features for building dynamic, responsive layouts with precision and flexibility:
41+
42+
### Core Layout System
43+
44+
- **Kyū Unit System** – A base-16 measurement system (`1q = 1/16rem = 1px`) for precise, consistent spacing and sizing across all screen sizes
45+
- **Fluid Typography** – Dynamic font scaling with `fluid_type()` mixin that smoothly interpolates between min/max sizes across viewport breakpoints
46+
- **Modular Scale** – Musical interval-based typographic scales (minor second, golden ratio, perfect fifth, etc.) for harmonious type hierarchies
47+
- **Baseline Grid** – Visual rhythm system with configurable baseline increments for vertical alignment
48+
49+
### Responsive Design Tools
50+
51+
- **Viewport Breakpoints** – Predefined breakpoint system (xs, sm, md, lg, xl, sl) with `view()` mixin for mobile-first media queries
52+
- **Device Profiles** – Pre-configured device-specific media queries for iPhone, iPad, Samsung Galaxy, and more
53+
- **Aspect Ratio Utilities** – Maintain proportions with `display_ratio()` mixin supporting common ratios (16:9, 4:3, golden ratio)
54+
- **Orientation Helpers** – Landscape/portrait-specific styling with `display_orientation_*` mixins
55+
56+
### Advanced SCSS Functions
57+
58+
- **Unit Conversion** – Seamless conversion between px, rem, em with `px_to_rem()`, `rem_to_px()`, `em_to_px()` functions
59+
- **Math Operations**`add()`, `subtract()` with intelligent unit handling; `modular_scale()` for ratio-based scaling
60+
- **Layer Management** – z-index token system via `$layers` map and `z()` function for consistent stacking order
61+
- **Paper Sizes** – ISO (A-series, B-series), ANSI, and custom Q-series paper dimensions for print layouts
62+
63+
### Developer Experience
64+
65+
- **Modern Sass** – Uses `sass:math`, `sass:map`, `sass:color` modules; no deprecated syntax
66+
- **TypeScript Support** – Grid utilities and layout helpers with full type definitions
67+
- **Visual Guides** – Built-in overlay system for baseline grids, margins, and alignment verification during development
68+
- **Customizable Variables** – Override defaults for base units, breakpoints, scales, and colors via Sass variables
69+
3670
## Installation
3771

3872
### HTML Script Tag
@@ -49,6 +83,298 @@ npm i unit.gl
4983

5084
---
5185

86+
## Quick Start
87+
88+
### Basic Usage (SCSS)
89+
90+
Import `unit.gl` into your Sass/SCSS files:
91+
92+
```scss
93+
@use "unit.gl" as *;
94+
95+
// Use the Kyū unit system
96+
.container {
97+
padding: q(4); // 4q = 4 × (1/16rem) = 0.25rem = 4px
98+
margin-bottom: q(8); // 8q = 0.5rem = 8px
99+
}
100+
101+
// Apply fluid typography
102+
.heading {
103+
@include fluid_type(
104+
$min-size: 16px,
105+
$max-size: 48px,
106+
$min-vw: 320px,
107+
$max-vw: 1280px
108+
);
109+
}
110+
111+
// Responsive breakpoints
112+
.grid {
113+
display: grid;
114+
grid-template-columns: 1fr;
115+
gap: q(4);
116+
117+
@include view(md) {
118+
grid-template-columns: repeat(2, 1fr);
119+
}
120+
121+
@include view(lg) {
122+
grid-template-columns: repeat(3, 1fr);
123+
}
124+
}
125+
```
126+
127+
### Common Layout Patterns
128+
129+
#### Fluid Card Grid with Consistent Spacing
130+
131+
```scss
132+
@use "unit.gl" as *;
133+
134+
.card-grid {
135+
display: grid;
136+
gap: q(8); // 0.5rem spacing
137+
padding: q(8);
138+
139+
// Mobile: 1 column
140+
grid-template-columns: 1fr;
141+
142+
// Tablet: 2 columns
143+
@include view(sm) {
144+
grid-template-columns: repeat(2, 1fr);
145+
gap: q(12); // 0.75rem
146+
}
147+
148+
// Desktop: 3 columns
149+
@include view(md) {
150+
grid-template-columns: repeat(3, 1fr);
151+
gap: q(16); // 1rem
152+
}
153+
}
154+
155+
.card {
156+
padding: q(12);
157+
border-radius: q(2);
158+
background: #fff;
159+
box-shadow: 0 q(1) q(4) rgba(0, 0, 0, 0.1);
160+
}
161+
```
162+
163+
#### Typography Scale with Modular Rhythm
164+
165+
```scss
166+
@use "unit.gl" as *;
167+
168+
// Use golden ratio (1.618) for harmonious type scale
169+
$scale-ratio: map.get($ratio_map, golden);
170+
171+
h1 {
172+
font-size: modular_scale(4, 1rem, $scale-ratio); // ~6.85rem
173+
line-height: baseline(6); // 6 baseline units
174+
margin-bottom: baseline(2);
175+
}
176+
177+
h2 {
178+
font-size: modular_scale(3, 1rem, $scale-ratio); // ~4.236rem
179+
line-height: baseline(5);
180+
margin-bottom: baseline(2);
181+
}
182+
183+
h3 {
184+
font-size: modular_scale(2, 1rem, $scale-ratio); // ~2.618rem
185+
line-height: baseline(4);
186+
margin-bottom: baseline(1);
187+
}
188+
189+
p {
190+
font-size: modular_scale(0, 1rem, $scale-ratio); // 1rem
191+
line-height: baseline(3); // Vertical rhythm
192+
margin-bottom: baseline(2);
193+
}
194+
```
195+
196+
#### Aspect Ratio Container (e.g., Video Embed)
197+
198+
```scss
199+
@use "unit.gl" as *;
200+
201+
.video-wrapper {
202+
width: 100%;
203+
max-width: 800px;
204+
margin: 0 auto;
205+
206+
// Maintain 16:9 aspect ratio
207+
@include display_ratio(16, 9);
208+
209+
iframe {
210+
position: absolute;
211+
top: 0;
212+
left: 0;
213+
width: 100%;
214+
height: 100%;
215+
}
216+
}
217+
```
218+
219+
#### Device-Specific Styling
220+
221+
```scss
222+
@use "unit.gl" as *;
223+
224+
.app-header {
225+
height: q(80); // 5rem = 80px
226+
227+
// iPhone-specific adjustments
228+
@include device-media-query('iphone_x') {
229+
padding-top: env(safe-area-inset-top); // Notch support
230+
}
231+
232+
// Tablet landscape
233+
@include display_orientation_landscape {
234+
@include view(sm) {
235+
height: q(64); // Shorter header in landscape
236+
}
237+
}
238+
}
239+
```
240+
241+
### TypeScript Integration
242+
243+
```typescript
244+
import { GridManager } from 'unit.gl';
245+
246+
// Initialize grid overlay for development
247+
const grid = new GridManager({
248+
columns: 12,
249+
gutter: 16, // 16px gutter
250+
baseline: 8, // 8px baseline grid
251+
color: 'rgba(255, 0, 0, 0.1)'
252+
});
253+
254+
// Toggle grid visibility
255+
grid.toggle();
256+
257+
// Update grid configuration
258+
grid.updateConfig({ columns: 16 });
259+
```
260+
261+
---
262+
263+
## Usage Guidelines & Best Practices
264+
265+
### Performance Optimization
266+
267+
1. **Minimize Media Query Complexity**
268+
- Use the `view()` mixin for standard breakpoints instead of custom media queries
269+
- Consolidate similar breakpoint rules to reduce CSS output
270+
271+
2. **Leverage Sass Variables**
272+
- Override defaults at the top of your main stylesheet:
273+
```scss
274+
@use "unit.gl" with (
275+
$q: 0.0625rem, // Customize base unit if needed
276+
$base_screen_unit: 16px // Adjust breakpoint base
277+
);
278+
```
279+
280+
3. **Selective Imports**
281+
- Import only the modules you need to reduce compilation time:
282+
```scss
283+
@use "unit.gl/scss/functions" as fn;
284+
@use "unit.gl/scss/mixins/view" as view;
285+
```
286+
287+
### Design System Integration
288+
289+
- **Consistent Spacing**: Use Kyū multiples (4q, 8q, 12q, 16q) as your spacing scale
290+
- **Type Hierarchy**: Choose one modular scale ratio and stick with it across all typographic elements
291+
- **Z-Index Management**: Define your layer stack in `$layers` map at project start
292+
- **Breakpoint Strategy**: Use mobile-first approach with `view()` mixins; avoid `max-width` queries
293+
294+
### Accessibility Considerations
295+
296+
- **Relative Units**: `unit.gl` uses `rem` internally, respecting user font-size preferences
297+
- **Viewport Scaling**: `fluid_type()` ensures readable text across all devices
298+
- **Visual Guides**: Enable baseline grid during development to verify vertical rhythm alignment
299+
300+
### Common Pitfalls to Avoid
301+
302+
**Don't mix unit systems**
303+
```scss
304+
.bad {
305+
padding: 10px; // Hardcoded px
306+
margin: q(8); // Kyū unit
307+
}
308+
```
309+
310+
**Use consistent units**
311+
```scss
312+
.good {
313+
padding: q(10); // All Kyū
314+
margin: q(8);
315+
}
316+
```
317+
318+
**Don't nest too many breakpoints**
319+
```scss
320+
.bad {
321+
@include view(md) {
322+
@include view(lg) { // Nested breakpoint = bad specificity
323+
// ...
324+
}
325+
}
326+
}
327+
```
328+
329+
**Keep breakpoints flat**
330+
```scss
331+
.good {
332+
@include view(md) { /* md styles */ }
333+
@include view(lg) { /* lg styles */ }
334+
}
335+
```
336+
337+
---
338+
339+
## Visual Reference
340+
341+
### Kyū Unit System Diagram
342+
343+
```
344+
┌─────────────────────────────────────────────────────────┐
345+
│ 1rem = 16q = 16px (default browser font size) │
346+
├─────────────────────────────────────────────────────────┤
347+
│ 1q = 0.0625rem = 1px │ Base unit │
348+
│ 4q = 0.25rem = 4px │ Small spacing │
349+
│ 8q = 0.5rem = 8px │ Medium spacing │
350+
│ 16q = 1rem = 16px │ Large spacing │
351+
│ 32q = 2rem = 32px │ Extra-large spacing │
352+
└─────────────────────────────────────────────────────────┘
353+
```
354+
355+
### Modular Scale Visualization (Golden Ratio 1.618)
356+
357+
```
358+
h1 ████████████████ (6.854rem) ← modular_scale(4)
359+
h2 ██████████ (4.236rem) ← modular_scale(3)
360+
h3 ██████ (2.618rem) ← modular_scale(2)
361+
h4 ████ (1.618rem) ← modular_scale(1)
362+
p ██ (1.000rem) ← modular_scale(0)
363+
```
364+
365+
### Breakpoint Reference
366+
367+
| Name | Min Width | Device Target |
368+
|------|-----------|------------------------|
369+
| xs | 320px | Mobile (portrait) |
370+
| sm | 480px | Mobile (landscape) |
371+
| md | 768px | Tablet |
372+
| lg | 1024px | Desktop |
373+
| xl | 1280px | Large Desktop |
374+
| sl | 1920px | Extra Large Display |
375+
376+
---
377+
52378
## Colophon
53379

54380
### Authors

0 commit comments

Comments
 (0)