Semantic Tokens
Semantic tokens express intent rather than raw values. They reference primitive tokens via var(), so theming only requires redefining this layer — not touching component code.
Import in your stylesheet:
@import '@latty-ds/tokens/semantic.css';
Or generate them at runtime with your own color palette:
import { configure } from '@latty-ds/tokens/configure';
configure({ colors: { primary: '#6366f1' } });
Naming convention
Semantic tokens follow the pattern {role}-{variant}[-{state}]:
- Role:
text,bg,border, orinteractive - Variant:
default,primary,success, etc. - State (optional):
subtle,strong,muted,hover,active
Contrast resolution
Tokens like bg-primary and text-on-primary are paired to meet WCAG AA contrast (4.5:1 for text). The token pipeline uses resolveVariantColors to pick fill and foreground steps that pass programmatically — you don't need to verify contrast yourself when using semantic token pairs.
For higher-contrast borders, configure border.contrast:
configure({
border: { contrast: 'high' } // shifts border tokens to higher-contrast steps
});
Light mode
Dark mode
In dark mode, semantic tokens remap to different primitive steps — lighter foregrounds on darker backgrounds. The same token names apply; only the references change.