|
| 1 | +# Design Tokens Workflow |
| 2 | + |
| 3 | +## Source of Truth |
| 4 | +The single source of truth for all design tokens is located in `packages/design-tokens/src/tokens.ts`. |
| 5 | +- **Do NOT** edit `apps/web/src/app/[locale]/tokens.css` directly - it's auto-generated. |
| 6 | +- **Do NOT** edit `apps/mobile/lib/core/theme/generated_theme.dart` directly - it's auto-generated. |
| 7 | +- **ALWAYS** make changes in `packages/design-tokens/src/tokens.ts`. |
| 8 | + |
| 9 | +## Color Space |
| 10 | +- **SSOT Format**: OKLCH (Lightness, Chroma, Hue) |
| 11 | +- **Web Output**: CSS OKLCH variables (P3 wide-gamut support) |
| 12 | +- **Mobile Output**: Flutter `Color.from(colorSpace: ColorSpace.displayP3)` for P3 colors |
| 13 | + |
| 14 | +## Token Structure |
| 15 | + |
| 16 | +```typescript |
| 17 | +// packages/design-tokens/src/tokens.ts |
| 18 | +export const tokens = { |
| 19 | + color: { |
| 20 | + light: { primary: { l: 0.85, c: 0.2, h: 130 }, ... }, |
| 21 | + dark: { primary: { l: 0.85, c: 0.2, h: 130 }, ... }, |
| 22 | + }, |
| 23 | + radius: { base: 10, sm: 6, md: 8, lg: 10, xl: 14 }, |
| 24 | + spacing: { xs: 4, sm: 8, md: 12, base: 16, lg: 20, xl: 24 }, |
| 25 | + typography: { fontFamily, fontSize, fontWeight, lineHeight }, |
| 26 | + style: { borderWidth: 1, disabledOpacity: 0.5 }, |
| 27 | +}; |
| 28 | +``` |
| 29 | + |
| 30 | +## Workflow |
| 31 | + |
| 32 | +### 1. Modify Tokens |
| 33 | +Edit `packages/design-tokens/src/tokens.ts`: |
| 34 | +- Add/update colors in `tokens.color.light` and `tokens.color.dark` |
| 35 | +- Modify radius, spacing, typography, or style values |
| 36 | + |
| 37 | +### 2. Build & Distribute |
| 38 | +Run the build command to generate platform-specific outputs: |
| 39 | + |
| 40 | +```bash |
| 41 | +pnpm --filter design-tokens build |
| 42 | +``` |
| 43 | + |
| 44 | +This generates: |
| 45 | +- **Web**: `apps/web/src/app/[locale]/tokens.css` (OKLCH CSS variables) |
| 46 | +- **Mobile**: `apps/mobile/lib/core/theme/generated_theme.dart` (ForUI FThemeData) |
| 47 | + |
| 48 | +### 3. Watch Mode (Development) |
| 49 | +For automatic rebuilds during development: |
| 50 | + |
| 51 | +```bash |
| 52 | +pnpm --filter design-tokens dev |
| 53 | +``` |
| 54 | + |
| 55 | +## Adding New Colors |
| 56 | + |
| 57 | +### Step 1: Add to tokens.ts |
| 58 | +```typescript |
| 59 | +color: { |
| 60 | + light: { |
| 61 | + // Add new color with OKLCH values |
| 62 | + success: { l: 0.65, c: 0.2, h: 145 }, |
| 63 | + successForeground: { l: 0.2, c: 0, h: 0 }, |
| 64 | + }, |
| 65 | + dark: { |
| 66 | + success: { l: 0.65, c: 0.2, h: 145 }, |
| 67 | + successForeground: { l: 0.98, c: 0, h: 0 }, |
| 68 | + }, |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +### Step 2: Update ForUI Mapping (if needed) |
| 73 | +If adding a new semantic color, update `tooling/build-forui-theme.ts`: |
| 74 | +```typescript |
| 75 | +const colorMap: Record<string, string> = { |
| 76 | + // ... existing mappings |
| 77 | + success: "success", |
| 78 | + successForeground: "successForeground", |
| 79 | +}; |
| 80 | +``` |
| 81 | + |
| 82 | +### Step 3: Build |
| 83 | +```bash |
| 84 | +pnpm --filter design-tokens build |
| 85 | +``` |
| 86 | + |
| 87 | +## OKLCH Color Guide |
| 88 | + |
| 89 | +| Component | Range | Description | |
| 90 | +|-----------|-------|-------------| |
| 91 | +| L (Lightness) | 0-1 | 0 = black, 1 = white | |
| 92 | +| C (Chroma) | 0-0.4+ | 0 = gray, higher = more vivid | |
| 93 | +| H (Hue) | 0-360 | Color wheel angle | |
| 94 | +| A (Alpha) | 0-1 | Optional, defaults to 1 | |
| 95 | + |
| 96 | +### Common Hue Values |
| 97 | +- 0: Red |
| 98 | +- 30: Orange |
| 99 | +- 60: Yellow |
| 100 | +- 130: Lime Green (primary) |
| 101 | +- 180: Cyan |
| 102 | +- 240: Blue |
| 103 | +- 300: Magenta |
| 104 | + |
| 105 | +## Testing |
| 106 | +Run tests to verify color conversion accuracy: |
| 107 | + |
| 108 | +```bash |
| 109 | +pnpm --filter design-tokens test |
| 110 | +``` |
| 111 | + |
| 112 | +Tests cover: |
| 113 | +- OKLCH to P3 conversion accuracy |
| 114 | +- CSS generation correctness |
| 115 | +- Flutter theme generation |
| 116 | +- Edge cases and boundary conditions |
0 commit comments