Design tokens
Design tokens are a system of reusable values that help maintain consistency across our design system. Instead of using hardcoded values, we use predefined tokens that ensure our UI elements stay consistent and maintainable.
Benefits of using tokens
Using tokens provides several key benefits:
- Consistency: Ensures all UI elements use the same values
- Maintainability: Makes updates easy by changing values in one place
- Organization: Keeps all design values in a single source of truth
- Themes: Enables easy switching between different design themes
The token process
Here’s how we create and use our tokens:
-
Design in Figma
- We create all our designs in Figma, a professional design tool
- In Figma, we carefully define and organize our color palettes, spacing, and typography
- We use Figma’s design tokens feature to maintain consistency across our designs
-
Export to JSON
- The Tokens Studio plugin in Figma pushes the tokens to the Click UI repository as JSON
- This JSON is our single source of truth for all design values
- It contains all our color values, spacing units, and other design properties
-
Generate CSS custom properties
- A build script turns the JSON into CSS custom properties for the light and dark themes
- The variables follow a consistent naming convention (e.g.,
--click-global-color-stroke-muted) - Every Click UI component is styled with these variables
For a deeper dive into how this system works in practice, check out our blog post on rebuilding the ClickHouse Cloud Console.
Token structure
Our tokens are organized into a hierarchical structure:
Colors
We use a palette-based system with different shades:
palette.slate: Gray color scalepalette.slate.100: Light gray (for subtle backgrounds)palette.slate.200: Medium gray (for text and borders)palette.slate.300: Dark gray (for emphasis)
Global colors
These are commonly used colors throughout our interface:
global.color.stroke.default: Standard border colorglobal.color.stroke.muted: Subtle border colorglobal.color.stroke.intense: Stronger border variant
Real-world example
Here’s how we use tokens in practice:
In CSS
/* Instead of using hardcoded values */
border-color: #e6e7e9;
/* We use our design tokens */
border-color: var(--click-global-color-stroke-muted);In your own components
Click UI is styled with CSS Modules and exposes every token as a CSS custom property, so your own styles can use the same values:
/* Instead of using hardcoded values */
.my-button {
border-radius: 4px;
background-color: #1a73e8;
}
/* We use our design tokens */
.my-button {
border-radius: var(--click-button-radii-all);
background-color: var(--click-button-basic-color-primary-background-default);
}This approach means that if we need to update our light gray color, we only need to change it in one place, and it will automatically update across the entire application. The variables work in any styling approach that can read CSS custom properties, ensuring consistent styling throughout our components.
Theme support
Click UI currently supports two themes:
- Light theme: The default theme with light backgrounds and dark text
- Dark theme: A high-contrast theme with dark backgrounds and light text
Using design tokens makes theme switching automatic - all components will update their colors and styles based on the selected theme. You don’t need to manually update any styles when switching themes; the tokens take care of everything for you.