Source:
ocean/docs/theme-system-figma-workflow.md| ✏️ Edit on GitHub
Theme System and Figma Token Workflow
Overview
Ocean uses a token-based design system that integrates seamlessly with Figma through design tokens. This allows for a single source of truth between design and development, ensuring consistency across the application.
Architecture
1. Token-Based Design System
Our design tokens are stored in design-tokens/tokens.json and include:
- Colors (light and dark themes)
- Border radius values
- Spacing (future)
- Typography (future)
2. CSS Variable Generation
The build-tokens.mjs script automatically generates CSS variables from the JSON tokens:
pnpm run build:tokens
This creates src/styles/tokens.css with all CSS variables.
3. Dark Mode Support
We've implemented a ThemeProvider component that:
- Detects system theme preferences
- Allows manual theme switching (light/dark/system)
- Persists user preference in localStorage
- Applies the appropriate class to the document root
4. ShadCN UI Integration
All ShadCN UI components use CSS variables for theming:
bg-backgroundinstead of hardcoded colorstext-foregroundfor text colors- Theme-aware hover and focus states
Figma Integration Workflow
Setting Up Figma Tokens
-
Install Tokens Studio Plugin in Figma
- Go to Figma → Plugins → Browse plugins
- Search for "Tokens Studio for Figma"
- Install the plugin
-
Import Tokens to Figma
- Open Tokens Studio plugin
- Click "Import" → "From URL" or "From File"
- Use the
design-tokens/tokens.jsonfile - Tokens will be available in Figma
-
Design with Tokens
- Use token references instead of hardcoded values
- Example: Use
color.backgroundinstead of#FFFFFF - Maintain consistency between themes
Development Workflow
-
Updating Tokens from Figma
# After exporting tokens from Figma to design-tokens/tokens.json
pnpm run build:tokens -
Adding New Token Categories
- Update
design-tokens/tokens.json - Modify
build-tokens.mjsto handle new token types - Run
pnpm run build:tokens
- Update
-
Theme-Aware Components
// Use CSS variables for all colors
<div className="bg-card text-card-foreground">Content</div>
// Dark mode is handled automatically
// No need for dark: prefixes when using CSS variables
Token Structure
Color Tokens
{
"color": {
"background": { "value": "oklch(1 0 0)" },
"foreground": { "value": "oklch(0.145 0 0)" }
// ... other light theme colors
},
"dark": {
"background": { "value": "oklch(0.145 0 0)" },
"foreground": { "value": "oklch(0.985 0 0)" }
// ... other dark theme colors
}
}
Adding New Colors
-
Add to
design-tokens/tokens.json:{
"color": {
"warning": { "value": "oklch(0.84 0.16 84)" },
"warning-foreground": { "value": "oklch(0.28 0.07 46)" }
},
"dark": {
"warning": { "value": "oklch(0.41 0.11 46)" },
"warning-foreground": { "value": "oklch(0.99 0.02 95)" }
}
} -
Run token build:
pnpm run build:tokens -
Use in components:
<div className="bg-warning text-warning-foreground">Warning message</div>
Best Practices
-
Always Use Tokens
- Never hardcode color values
- Use semantic token names (background, foreground, etc.)
- Keep token names consistent with Figma
-
Theme Testing
- Test all components in both light and dark modes
- Use the mode toggle to quickly switch themes
- Verify contrast ratios meet accessibility standards
-
Figma Sync
- Regular sync between Figma and code tokens
- Document any custom tokens added in code
- Keep token structure consistent
-
Component Development
- Use
bg-[token]andtext-[token]-foregroundpattern - Avoid
dark:prefixes when using CSS variables - Let the theme provider handle mode switching
- Use
Troubleshooting
Dropdown Transparency Issues
If dropdowns appear transparent in dark mode:
- Check
--popovervalue differs from--cardin dark theme - Ensure components use
bg-popovernot custom backgrounds - Keep ShadCN default styling unless necessary
Token Not Applying
- Verify
pnpm run build:tokenswas run - Check browser dev tools for CSS variable values
- Ensure component uses correct token name
- Clear browser cache if needed
Figma Token Mismatch
- Export latest tokens from Figma
- Compare with
design-tokens/tokens.json - Run build process after updates
- Verify token names match between systems