This spec defines how component styles consume runtime theme tokens in @tiny-design/react. The goal is to keep existing class names and SCSS ergonomics while making every visual decision themeable through CSS custom properties.
- SCSS defines structure, state, and selector relationships only.
- Visual values must come from
var(--ty-*)tokens. - New hard-coded colors, radii, shadows, font sizes, spacing, and motion values are not allowed.
- Component tokens use dot notation with kebab-case segments in source registries, for example
button.bg.primary-hover. - CSS variables stay on the existing
--ty-*prefix for v2 compatibility.
Use this fallback chain consistently:
- Component token
- Semantic token
- Native CSS fallback only when no semantic token exists
Preferred pattern:
.ty-card {
border-radius: var(--ty-card-radius, var(--ty-border-radius));
background: var(--ty-card-bg, var(--ty-color-bg-container));
color: var(--ty-card-text, var(--ty-color-text));
}Direct semantic usage is only correct when the property should never diverge by component:
.ty-typography {
font-family: var(--ty-font-family);
}- Semantic CSS vars:
--ty-color-primary,--ty-border-radius,--ty-font-size-base - Component CSS vars:
--ty-button-bg-primary,--ty-button-bg-primary-hover,--ty-card-header-padding - Avoid aliases like
btnorpickerfor new token names. Use full component names.
Only structural values may be hard-coded when tokenizing them would not improve theming:
display,position,flex,overflow,white-space,pointer-events- Layout-only percentages like
width: 100% - Browser-specific resets such as
outline: 0orappearance: none - Rare intrinsic calculations like
inset: -1pxwhen tied to border mechanics
If a value affects brand, density, readability, affordance, or perceived motion, it must be tokenized.
Preferred:
.ty-button {
height: var(--ty-button-height-md, var(--ty-height-md));
padding-inline: var(--ty-button-padding-inline-md, var(--ty-spacing-4));
border-radius: var(--ty-button-radius, var(--ty-border-radius));
background: var(--ty-button-bg-primary, var(--ty-color-primary));
box-shadow: var(--ty-button-shadow-focus, var(--ty-shadow-focus));
}Avoid:
.ty-button {
height: 40px;
padding-inline: 16px;
border-radius: 6px;
background: #6e41bf;
}When editing an existing component style file:
- Replace visual literals with
var(--ty-...). - Prefer component token plus semantic fallback for component-specific properties.
- Keep selectors and class names stable unless a separate API change is intended.
- Do not add new theme logic to SCSS maps; add tokens to the JSON source and registry instead.
- Verify the component still renders correctly with default and dark themes.