Module tokens

Source
Expand description

§Design Tokens

Design tokens are the atomic building blocks of the Fern design system. They encode visual design decisions (colors, spacing, radii) as type-safe Rust values.

§What Are Design Tokens?

Design tokens are named values that store visual design attributes. Instead of scattering magic values throughout code:

ⓘ
// ❌ Bad: Magic values everywhere
button.background = "#313244";
button.padding = 8;
button.radius = 4;

We use semantic tokens:

ⓘ
// ✅ Good: Semantic tokens
button.background = theme.surface;      // ColorToken<Surface>
button.padding = SpacingSm::pixels();   // 8px from scale
button.radius = theme.radius.button();  // Semantic radius

§Token Categories

CategoryModuleDescription
ColorcolorRGBA colors with semantic roles
SpacingspacingScale-based spacing values
RadiusradiusBorder radius with semantic names
TypographytypographyFont families and size scales

§Type Safety

Tokens use Rust’s type system to prevent misuse:

  • Color roles: Can’t use a foreground color as a background
  • Spacing scale: Can’t use arbitrary pixel values
  • Radius semantics: Components can only use valid radii

See each submodule for detailed examples.

Re-exports§

pub use color::*;
pub use radius::*;
pub use spacing::*;
pub use typography::*;

Modules§

color
Type-Safe Color Tokens
radius
Semantic Border Radius Tokens
spacing
Scale-Based Spacing Tokens
typography
Typography Tokens