A system that processes design tokens from Tokens Studio for Figma and transforms them into CSS files.
This project uses the Tokens Studio for Figma plugin as the primary method for managing design tokens. Here's why:
The Figma API, while powerful for many use cases, has several limitations when it comes to design tokens:
-
Incomplete Token Data:
- Only provides basic style information
- Missing computed values and references
- No support for token relationships
- Limited metadata and documentation
-
Missing Features:
- No token versioning
- Limited support for nested tokens
- No built-in token validation
- Missing token usage context
-
Data Structure Issues:
- Inconsistent formatting
- Partial token sets
- Missing style definitions
- No support for token aliases
Tokens Studio provides a complete solution for design token management:
-
Complete Token System:
- Full token definitions
- Computed values
- Token relationships
- Metadata and documentation
-
Consistent Output:
- Standardized formatting
- Complete token sets
- Proper value handling
- Consistent naming
-
Better Integration:
- Direct GitHub integration
- PR-based workflow
- Change tracking
- Version control
The recommended workflow is:
- Use Tokens Studio in Figma to manage tokens
- Push changes to GitHub via the plugin to the
incoming-token-changes
branch - GitHub Action processes the tokens and adds the output files to your PR
- Review and merge changes to main
This approach ensures we have complete, consistent, and well-managed design tokens.
-
Token Updates:
- Tokens Studio creates/updates the
incoming-token-changes
branch when changes are pushed - PR includes the updated
design-tokens.json
file - GitHub Action automatically triggers on PR creation/update
- Tokens Studio creates/updates the
-
Action Processing:
- Action checks out the PR branch
- Processes the token file
- Generates output files:
- CSS variables
- Processed JSON
- Commits the generated files back to the PR
-
File Management:
- Original
design-tokens.json
is preserved - Processed files are added to the PR:
output/design_tokens.json
(processed version)output/design_tokens.css
(CSS variables)
- Original
In addition to committing the processed files back to the pull request, the workflow also deploys the output/design_tokens.css
and output/design_tokens.json
files to GitHub Pages.
- Branch: The files are pushed to the
gh-pages
branch. - Folder: The files are placed in the
/docs
folder on thegh-pages
branch. - Access: This makes the latest processed tokens available via GitHub Pages, typically at a URL like
https://<your-username>.github.io/<your-repository>/docs/design_tokens.css
. Thedesign_tokens.json
file will be available at a similar URL.
-
Branch Structure:
main
: Production-ready tokensincoming-token-changes
: Dedicated branch for Tokens Studio updates- PRs are created from
incoming-token-changes
tomain
-
Naming Conventions:
- Main branch:
main
- Token updates branch:
incoming-token-changes
- PR titles:
Update Design Tokens: Description
- Commit messages:
chore: process design tokens
- Main branch:
-
Conflict Resolution:
- Always rebase on latest
main
- Resolve conflicts in Tokens Studio
- Push resolved changes to update PR
- Always rebase on latest
-
Required Secrets:
FIGMA_ACCESS_TOKEN: # For validation # SLACK_WEBHOOK_URL: # For notifications (currently disabled)
-
Permissions:
permissions: contents: write pull-requests: write
-
Triggers:
on: pull_request: types: [opened, synchronize, reopened] paths: - 'design-tokens.json'
-
PR Checklist:
- Token changes are valid
- Output files generated successfully
- No conflicts with existing tokens
- Documentation updated if needed
-
Validation Steps:
- Check token changes in
design-tokens.json
- Verify output files are generated:
output/design_tokens.css
output/design_tokens.json
- Review change comments
- Test in preview if available
- Check token changes in
-
Common Issues:
- Missing token references
- Invalid token values
- Output file generation errors
- Merge conflicts
-
Action Failures:
- Check action logs in GitHub
- Verify secrets are set
- Review token file format
- Test locally
-
PR Issues:
- Branch conflicts
- Permission errors
- Processing failures
- Validation errors
-
Debug Steps:
# Test locally pnpm run process-tokens -- --source file --input design-tokens.json --output ./output # Check output files cat output/design_tokens.json cat output/design_tokens.css
-
Common Solutions:
- Update branch from main
- Fix token references
- Check file permissions
- Clear GitHub Actions cache
- Node.js 18 or higher
- pnpm 8 or higher
- Figma account with Tokens Studio plugin
-
Clone the repository:
git clone https://github.com/eGovPDX/design-tokens.git cd design-tokens
-
Install dependencies:
pnpm install
-
Configure environment:
cp .env.example .env # Edit .env with your Figma token
-
Process Tokens:
pnpm run process-tokens -- --source file --input design-tokens.json --output ./output
-
Output Files:
output/design_tokens.css
: CSS variables for use in your applicationoutput/design_tokens.json
: Processed JSON tokens for reference
The token resolution system supports several token formats:
-
Color Tokens:
- Direct values:
#RRGGBB
orrgba(r,g,b,a)
- USWDS references:
{!-usa.color.primary.vivid}
orusa.color.base.dark
- Theme references:
{#-theme.color.primary.medium}
- Direct values:
-
Typography Tokens:
- Font sizes:
- USWDS references:
{!-usa.font-size.reading.5}
or{!-usa.font-size.display.2xl}
- Theme references:
{#-theme.font-size.body.sm}
- USWDS references:
- Font weights:
bold
,regular
,light
, etc. - Font families: References to font stacks
- Font sizes:
-
Spacing Tokens:
- Numeric values:
2px
,1rem
, etc. - USWDS references:
{usa.spacing.4}
or{!-usa.spacing.md}
- Theme references:
{#-theme.spacing.container}
- Numeric values:
The resolution system follows this precedence order:
- Direct token references (exact match)
- USWDS token resolution for known patterns
- Theme-based resolution using project/default themes
- Sensible fallbacks for all token types
- Run Tests: