Creating Custom Brands
The Stride Design System includes a powerful dynamic brand system that allows you to create custom white-label brands at runtime without modifying the core design system code.Overview
Dynamic brands enable you to:- Create unlimited custom brands programmatically
- Override design tokens selectively (all tokens are optional)
- Use intelligent fallback for undefined tokens
- Persist brands automatically in localStorage
- Switch between brands with smooth transitions
Registering a Dynamic Brand
Use theregisterDynamicBrand() function to create a new brand. This function is available from both the main library and the useBrand hook.
Basic Registration
src/lib/brands.ts:254)
DynamicBrandConfig Interface
The complete configuration interface for dynamic brands:Token Structure
Core Tokens
Core tokens define the base color palette. All tokens are optional - define only what you need to customize.Semantic Tokens
Semantic tokens map to specific use cases (text, backgrounds, borders, etc.). They can reference core tokens using CSS variables, use hardcoded values, or use CSS color functions.Typography Tokens
Customize fonts and font weights:Layout Tokens
Customize spacing, border radius, shadows, and transitions:Custom Tokens
Define any custom CSS variables for brand-specific needs:Complete Example
Here’s a comprehensive example from the source code (src/stories/DynamicBrandSystem.stories.tsx:58):
Validating Brand Configuration
UsevalidateDynamicBrandConfig() to check if your brand configuration is valid before registering:
Function Signature (from src/lib/brands.ts:683)
Using with React Hook
TheuseBrand hook provides a convenient way to manage brands in React components:
Fallback System
The fallback system ensures your brand always has complete token coverage:How Fallback Works
- Core tokens: If a specific shade is not defined, the system looks for it in the fallback brand
- Semantic tokens: If
useSemanticFallback: true, undefined semantic tokens use the fallback brand’s semantic mapping - Default fallback: If no fallback is specified, the system uses the configured
defaultFallbackBrand(typically ‘stride’)
Configuring Fallback
Best Practices
-
Use descriptive IDs: Use kebab-case IDs that clearly identify the brand
-
Prefer CSS variable references: Reference core tokens in semantic tokens for consistency
-
Define complete color scales: When defining core tokens, provide at least 500, 600, 700 for interactive states
-
Validate before production: Always validate brand configs before deploying
-
Use semantic tokens for components: Don’t reference core tokens directly in components
Next Steps
- Design Tokens - Deep dive into the token system
- Theme Switching - Learn about runtime brand switching