Design Tokens
Token Architecture
Section titled “Token Architecture”Sparkle’s design token system follows the Design Tokens Community Group specification and provides a unified approach to design decisions across web and mobile platforms.
Token Categories
Section titled “Token Categories”Colors
Section titled “Colors”Color tokens use a numeric scale from 50 (lightest) to 950 (darkest) for consistent color progression:
// Primary brand colorstokens.colors.primary[500] // Main brand color: '#3b82f6'tokens.colors.primary[600] // Darker variant: '#2563eb'tokens.colors.primary[400] // Lighter variant: '#60a5fa'
// Secondary colorstokens.colors.secondary[500] // Main secondary: '#64748b'tokens.colors.secondary[600] // Darker variant: '#475569'
// Semantic colorstokens.colors.success[500] // Success green: '#22c55e'tokens.colors.warning[500] // Warning amber: '#f59e0b'tokens.colors.error[500] // Error red: '#ef4444'tokens.colors.info[500] // Info blue: '#06b6d4'Spacing
Section titled “Spacing”Consistent spacing scale for layouts and components:
// Spacing tokenstokens.spacing.xs // 0.25rem (4px)tokens.spacing.sm // 0.5rem (8px)tokens.spacing.md // 1rem (16px)tokens.spacing.lg // 1.5rem (24px)tokens.spacing.xl // 2rem (32px)tokens.spacing['2xl'] // 2.5rem (40px)tokens.spacing['3xl'] // 3rem (48px)Typography
Section titled “Typography”Font families, sizes, weights, and line heights:
// Font familiestokens.typography.fontFamily.sans // Inter, system-ui, sans-seriftokens.typography.fontFamily.mono // Menlo, Monaco, monospace
// Font sizestokens.typography.fontSize.xs // 0.75remtokens.typography.fontSize.sm // 0.875remtokens.typography.fontSize.base // 1remtokens.typography.fontSize.lg // 1.125remtokens.typography.fontSize.xl // 1.25rem
// Font weightstokens.typography.fontWeight.normal // 400tokens.typography.fontWeight.medium // 500tokens.typography.fontWeight.semibold // 600tokens.typography.fontWeight.bold // 700Border Radius
Section titled “Border Radius”Consistent border radius values for rounded corners:
// Border radius tokenstokens.borderRadius.none // 0tokens.borderRadius.sm // 0.125rem (2px)tokens.borderRadius.md // 0.375rem (6px)tokens.borderRadius.lg // 0.5rem (8px)tokens.borderRadius.xl // 0.75rem (12px)tokens.borderRadius.full // 9999px (circular)Shadows
Section titled “Shadows”Elevation and depth with consistent shadow system:
// Shadow tokenstokens.shadow.sm // Subtle shadow for cardstokens.shadow.md // Standard component shadowtokens.shadow.lg // Elevated elementstokens.shadow.xl // High elevation (modals, dropdowns)Cross-Platform Usage
Section titled “Cross-Platform Usage”Web Implementation
Section titled “Web Implementation”On web platforms, tokens are automatically converted to CSS custom properties:
/* Generated CSS custom properties */:root { --colors-primary-500: #3b82f6; --colors-secondary-500: #64748b; --spacing-md: 1rem; --typography-fontSize-base: 1rem;}
/* Usage in CSS */.button { background-color: var(--colors-primary-500); padding: var(--spacing-md); font-size: var(--typography-fontSize-base);}React Native Implementation
Section titled “React Native Implementation”For React Native, tokens are converted to StyleSheet-compatible values:
import { useThemeTokens } from '@sparkle/theme'
function MyComponent() { const tokens = useThemeTokens()
const styles = StyleSheet.create({ button: { backgroundColor: tokens.colors.primary[500], // '#3b82f6' padding: tokens.spacing.md, // 16 fontSize: tokens.typography.fontSize.base, // 16 } })
return <View style={styles.button} />}Theme Variants
Section titled “Theme Variants”Light and Dark Themes
Section titled “Light and Dark Themes”Sparkle provides built-in light and dark theme variants:
// Light theme valueslightTheme.colors.background.primary // '#ffffff'lightTheme.colors.text.primary // '#1f2937'
// Dark theme valuesdarkTheme.colors.background.primary // '#1f2937'darkTheme.colors.text.primary // '#f9fafb'Custom Theme Creation
Section titled “Custom Theme Creation”Create custom themes by extending base tokens:
import { baseTokens } from '@sparkle/theme'
const customTheme = { ...baseTokens, colors: { ...baseTokens.colors, primary: { ...baseTokens.colors.primary, 500: '#8b5cf6', // Custom purple primary } }}Token Usage Patterns
Section titled “Token Usage Patterns”Component Styling
Section titled “Component Styling”Use tokens consistently in component styling:
// ✅ Good: Using tokensconst buttonStyles = { backgroundColor: tokens.colors.primary[500], padding: `${tokens.spacing.sm} ${tokens.spacing.md}`, borderRadius: tokens.borderRadius.md, fontSize: tokens.typography.fontSize.base,}
// ❌ Avoid: Hard-coded valuesconst buttonStyles = { backgroundColor: '#3b82f6', padding: '8px 16px', borderRadius: '6px', fontSize: '16px',}Responsive Design
Section titled “Responsive Design”Use spacing tokens for consistent responsive breakpoints:
.container { padding: var(--spacing-sm);}
@media (min-width: 768px) { .container { padding: var(--spacing-md); }}
@media (min-width: 1024px) { .container { padding: var(--spacing-lg); }}Color Accessibility
Section titled “Color Accessibility”Follow accessibility guidelines when using color tokens:
// ✅ Good: Sufficient contrastconst styles = { backgroundColor: tokens.colors.primary[500], // #3b82f6 color: tokens.colors.white, // #ffffff (4.5:1 contrast)}
// ✅ Good: Semantic color usageconst errorStyles = { backgroundColor: tokens.colors.error[50], // Light red background color: tokens.colors.error[800], // Dark red text borderColor: tokens.colors.error[500], // Medium red border}Token Naming Conventions
Section titled “Token Naming Conventions”Structure
Section titled “Structure”Tokens follow a hierarchical naming structure:
{category}.{property}.{variant}
Examples:- colors.primary.500- spacing.md- typography.fontSize.lg- borderRadius.xlCategories
Section titled “Categories”- colors: Color values (brand, semantic, neutral)
- spacing: Layout spacing and padding values
- typography: Font-related properties
- borderRadius: Corner radius values
- shadow: Elevation and depth effects
- animation: Timing and easing functions
Variants
Section titled “Variants”- Numeric scale: 50-950 for colors, xs-3xl for sizes
- Semantic names: primary, secondary, success, warning, error
- Descriptive names: base, large, small, none, full
Best Practices
Section titled “Best Practices”Token Selection
Section titled “Token Selection”- Use semantic tokens when the meaning is more important than the specific value
- Use scale tokens when you need specific design control
- Prefer design system tokens over component-specific values
- Consider accessibility when choosing color combinations
Performance
Section titled “Performance”- Use CSS custom properties for dynamic theming on web
- Pre-compute values for React Native StyleSheet objects
- Minimize token transformations at runtime
- Cache compiled theme objects when possible
Maintenance
Section titled “Maintenance”- Update tokens centrally rather than in individual components
- Use semantic naming that survives design changes
- Document token relationships and dependencies
- Version token changes using semantic versioning
Migration Guide
Section titled “Migration Guide”From Hard-coded Values
Section titled “From Hard-coded Values”// Before: Hard-coded stylesconst oldStyles = { color: '#1f2937', fontSize: '16px', padding: '12px 16px', borderRadius: '8px',}
// After: Token-based stylesconst newStyles = { color: tokens.colors.text.primary, fontSize: tokens.typography.fontSize.base, padding: `${tokens.spacing.sm} ${tokens.spacing.md}`, borderRadius: tokens.borderRadius.lg,}From CSS Variables
Section titled “From CSS Variables”/* Before: Custom CSS variables */.component { background: var(--blue-500); padding: var(--space-4);}
/* After: Sparkle tokens */.component { background: var(--colors-primary-500); padding: var(--spacing-md);}