Design Token System
Overview
The Design Token System has been introduced, if you want to use any colour or any dimensional values you must refer to the src/style/tokens and use tokens from there.
If the desired color or sizes are not present in the token files then you may add that in the token
file with proper naming convention, then reference it via var(--token-name).
Token Files
src/style/tokens/colors.csssrc/style/tokens/spacing.csssrc/style/tokens/typography.csssrc/style/tokens/breakpoints.css
Token files are imported in src/style/tokens/index.css.
Tokens are imported globally in src/index.tsx.
Naming Convention
- Colors:
--color-<family>-<scale>(example:--color-gray-100) or--color-<name>for base colors. - Spacing:
--space-<step>(example:--space-4). - Typography:
--font-size-<size>,--line-height-<name>,--font-weight-<name>,--letter-spacing-<name>. - Breakpoints:
--breakpoint-<size>(example:--breakpoint-md).
Follow the existing scale order and units in each file when adding new tokens.
Usage
.button {
background-color: var(--color-primary);
color: var(--color-surface);
padding: var(--space-4) var(--space-6);
font-size: var(--font-size-md);
line-height: var(--line-height-normal);
font-weight: var(--font-weight-medium);
}
<button
style={{
marginTop: 'var(--space-4)',
fontSize: 'var(--font-size-md)',
fontWeight: 'var(--font-weight-semibold)',
}}
>
Save
</button>
Validation and CI/CD Checks
Token usage is enforced by scripts/validate-tokens.ts, which scans src/ CSS/TS/TSX files (excluding token files and src/assets/css/app.css) for hardcoded values:
- Hex colors (for example:
#ffffff) pxvalues in spacing-related declarations (margin,padding,width,height,gap,top,right,bottom,left)font-sizeinpx- Numeric
font-weightvalues (for example:600)
Local checks:
lint-stagedrunsnpx tsx scripts/validate-tokens.ts --fileson staged*.ts,*.tsx,*.css,*.scss,*.sass..husky/pre-commitrunslint-staged, so violations fail the commit before it is created.
CI/CD checks:
- The PR workflow runs
pnpm exec tsx scripts/validate-tokens.ts --files $CHANGED_FILESto scan only the files changed in the PR, and the job fails if hardcoded values are found.
These guardrails catch new hardcoded values before merge and keep token usage consistent without slowing down CI with full-repo scans.
Run locally:
pnpm exec tsx scripts/validate-tokens.ts --stagedpnpm exec tsx scripts/validate-tokens.ts --files src/path/to/file.tsxpnpm exec tsx scripts/validate-tokens.ts --scan-entire-repo
Current Limitations
- Spacing detection only matches a single
pxvalue in simple CSS declarations, so shorthands likepadding: 8px 16pxmay only flag the first value. - TSX inline styles (including MUI
sx) and camelCase properties likemarginTopare not parsed by the current regex checks. - Only
pxis checked for spacing and font sizes;rem/emvalues are not detected.
Planned Follow-up Work
- Add camelCase property patterns for TSX (for example:
marginTop,paddingX,fontSize). - Detect
rem/emunits with a token allowlist to avoid false positives.
Notes
- Hex colors and raw unit values should only exist in token files.
- Use the token scales for spacing and typography instead of raw values.
- If a needed value does not exist, add it in
src/style/tokensfollowing the naming conventions above.