|
| 1 | +--- |
| 2 | +description: "Comprehensive guide for adding, modifying, and managing color tokens in the monday-ui-style package (@style). Covers SCSS theme files, build process, naming conventions, and special handling for hacker theme." |
| 3 | +globs: "packages/style/**/*" |
| 4 | +--- |
| 5 | + |
| 6 | +# Color Token Management for monday-ui-style (@style) |
| 7 | + |
| 8 | +This rule provides a complete guide for managing color tokens in the `@style` package, which publishes as `monday-ui-style`. |
| 9 | + |
| 10 | +## Package Structure Overview |
| 11 | + |
| 12 | +The `@style` package uses a **two-layer system** for color tokens: |
| 13 | + |
| 14 | +1. **SCSS Theme Files** (source of truth) - Define CSS custom properties (`--token-name`) |
| 15 | +2. **JSON Files** (auto-generated) - Generated from compiled CSS for programmatic access |
| 16 | + |
| 17 | +### Key Files and Directories |
| 18 | + |
| 19 | +- **Theme SCSS Files**: [src/themes/](mdc:packages/style/src/themes/) |
| 20 | + |
| 21 | + - [light-theme.scss](mdc:packages/style/src/themes/light-theme.scss) - Default/light theme |
| 22 | + - [dark-theme.scss](mdc:packages/style/src/themes/dark-theme.scss) - Dark theme |
| 23 | + - [black-theme.scss](mdc:packages/style/src/themes/black-theme.scss) - Black theme |
| 24 | + - [hacker-theme.scss](mdc:packages/style/src/themes/hacker-theme.scss) - Hacker theme |
| 25 | + |
| 26 | +- **Build Script**: [scripts/generate-colors.ts](mdc:packages/style/scripts/generate-colors.ts) |
| 27 | +- **Generated Files**: |
| 28 | + - [src/files/tokens.json](mdc:packages/style/src/files/tokens.json) - Resolved token values |
| 29 | + - [src/files/colors.json](mdc:packages/style/src/files/colors.json) - Raw color values |
| 30 | + - [dist/index.css](mdc:packages/style/dist/index.css) - Compiled CSS |
| 31 | + |
| 32 | +## Step-by-Step Process for Adding/Modifying Tokens |
| 33 | + |
| 34 | +### 1. Add Token to ALL Theme SCSS Files |
| 35 | + |
| 36 | +You **must** add the new token to all four theme files to ensure consistency: |
| 37 | + |
| 38 | +```css |
| 39 | +// Example: Adding --info-color token |
| 40 | + |
| 41 | +// In light-theme.scss |
| 42 | +:root, |
| 43 | +.light-app-theme, |
| 44 | +.default-app-theme { |
| 45 | + // ... existing tokens |
| 46 | + --info-color: #0084ff; |
| 47 | + --info-color-hover: #006bd6; |
| 48 | + --info-color-selected: #b3d9ff; |
| 49 | +} |
| 50 | + |
| 51 | +// In dark-theme.scss |
| 52 | +.dark-app-theme { |
| 53 | + // ... existing tokens |
| 54 | + --info-color: #0084ff; |
| 55 | + --info-color-hover: #4da3ff; |
| 56 | + --info-color-selected: #1a3d5c; |
| 57 | +} |
| 58 | + |
| 59 | +// In black-theme.scss |
| 60 | +.black-app-theme { |
| 61 | + // ... existing tokens |
| 62 | + --info-color: #0084ff; |
| 63 | + --info-color-hover: #4da3ff; |
| 64 | + --info-color-selected: #1a3d5c; |
| 65 | +} |
| 66 | + |
| 67 | +// In hacker-theme.scss |
| 68 | +.hacker_theme-app-theme { |
| 69 | + // ... existing tokens |
| 70 | + --info-color: #8be9fd; // Hacker theme specific OR same as black theme |
| 71 | + --info-color-hover: #6be7fb; |
| 72 | + --info-color-selected: #2d4a5c; |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +### 2. Special Rule for Hacker Theme |
| 77 | + |
| 78 | +**IMPORTANT**: If no specific value is provided for the hacker theme, **always use the same value as the black theme**. Do not create arbitrary values. |
| 79 | + |
| 80 | +```css |
| 81 | +// ✅ CORRECT: When no hacker-specific value is given |
| 82 | +.black-app-theme { |
| 83 | + --ui-background-hover-color: #3b3b3b; |
| 84 | +} |
| 85 | + |
| 86 | +.hacker_theme-app-theme { |
| 87 | + --ui-background-hover-color: #3b3b3b; // Same as black theme |
| 88 | +} |
| 89 | + |
| 90 | +// ❌ INCORRECT: Don't create arbitrary values |
| 91 | +.hacker_theme-app-theme { |
| 92 | + --ui-background-hover-color: #3a3f56; // Don't make up colors |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### 3. Build and Generate JSON Files |
| 97 | + |
| 98 | +After adding tokens to SCSS files, run the build process: |
| 99 | + |
| 100 | +```bash |
| 101 | +cd packages/style |
| 102 | +yarn build |
| 103 | +``` |
| 104 | + |
| 105 | +This will: |
| 106 | + |
| 107 | +1. Compile SCSS to CSS (`dist/index.css`) |
| 108 | +2. Run [generate-colors.ts](mdc:packages/style/scripts/generate-colors.ts) |
| 109 | +3. Generate updated JSON files in `src/files/` and `dist/` |
| 110 | + |
| 111 | +### 4. Verify Implementation |
| 112 | + |
| 113 | +Check that your tokens appear correctly: |
| 114 | + |
| 115 | +```bash |
| 116 | +# Verify token exists in all themes |
| 117 | +grep "your-token-name" packages/style/src/files/tokens.json |
| 118 | + |
| 119 | +# Check CSS compilation |
| 120 | +grep "your-token-name" packages/style/dist/index.css |
| 121 | +``` |
| 122 | + |
| 123 | +## Naming Conventions (if names weren't included in human's request) |
| 124 | + |
| 125 | +### Token Naming Patterns |
| 126 | + |
| 127 | +- Use **kebab-case**: `--info-color`, `--primary-background-color` |
| 128 | +- Include **state variants**: `-hover`, `-selected`, `-selected-hover` |
| 129 | +- For branded colors: `--color-ocean-blue`, `--color-forest-green` |
| 130 | +- Add stylelint disable comments for underscores: `/* stylelint-disable-line custom-property-pattern */` |
| 131 | + |
| 132 | +### Token Categories |
| 133 | + |
| 134 | +**Semantic Tokens** (preferred for new additions): |
| 135 | + |
| 136 | +```css |
| 137 | +--primary-color, --secondary-color |
| 138 | +--positive-color, --negative-color, --warning-color |
| 139 | +--text-color-on-primary, --background-color |
| 140 | +--ui-background-color, --ui-background-hover-color |
| 141 | +``` |
| 142 | + |
| 143 | +**Branded Colors** (specific color values): |
| 144 | + |
| 145 | +```css |
| 146 | +--color-grass-green, --color-sofia-pink |
| 147 | +--color-working-orange, --color-done-green |
| 148 | +``` |
| 149 | + |
| 150 | +### Token Positioning |
| 151 | + |
| 152 | +Place new tokens **logically** near related existing tokens: |
| 153 | + |
| 154 | +```css |
| 155 | +// ✅ Good: Group related tokens together |
| 156 | +--ui-border-color: #c3c6d4; |
| 157 | +--ui-background-color: #e7e9ef; |
| 158 | +--ui-background-hover-color: #d8d9e0; // ← New token placed logically |
| 159 | +--layout-border-color: #d0d4e4; |
| 160 | +``` |
| 161 | + |
| 162 | +## Usage After Implementation |
| 163 | + |
| 164 | +```css |
| 165 | +.my-component { |
| 166 | + background-color: var(--ui-background-color); |
| 167 | + |
| 168 | + &:hover { |
| 169 | + background-color: var(--ui-background-hover-color); |
| 170 | + } |
| 171 | +} |
| 172 | +``` |
| 173 | + |
| 174 | +## Best Practices |
| 175 | + |
| 176 | +1. **Always add tokens to ALL theme files** - Never skip a theme |
| 177 | +2. **Position tokens logically** near related tokens in SCSS files |
| 178 | +3. **Use black theme values for hacker theme** when no specific value is provided by human |
| 179 | +4. **Test in all themes** to verify proper contrast and accessibility |
| 180 | +5. **Use semantic names** over specific color names when possible |
| 181 | +6. **Follow existing patterns** for state variants |
| 182 | +7. **Run build process** after making changes |
| 183 | + |
| 184 | +## Common Mistakes to Avoid |
| 185 | + |
| 186 | +- ❌ Adding tokens to only some theme files |
| 187 | +- ❌ Creating arbitrary colors for hacker theme |
| 188 | +- ❌ Forgetting to run the build process |
| 189 | +- ❌ Using inconsistent naming conventions |
| 190 | +- ❌ Not testing across all themes |
| 191 | + |
| 192 | +## Build Process Details |
| 193 | + |
| 194 | +The [generate-colors.ts](mdc:packages/style/scripts/generate-colors.ts) script: |
| 195 | + |
| 196 | +1. Reads compiled CSS from `dist/index.css` |
| 197 | +2. Extracts color tokens using PostCSS |
| 198 | +3. Resolves CSS custom property references |
| 199 | +4. Generates `tokens.json` with final hex/rgba values |
| 200 | +5. Outputs count: "✓ light-app-theme: 283 colors" etc. |
| 201 | + |
| 202 | +## Example: Complete Token Addition |
| 203 | + |
| 204 | +Here's a complete example of adding `--info-color` across all themes: |
| 205 | + |
| 206 | +```css |
| 207 | +// light-theme.scss |
| 208 | +--info-color: #0084ff; |
| 209 | +--info-color-hover: #006bd6; |
| 210 | +--info-color-selected: #b3d9ff; |
| 211 | + |
| 212 | +// dark-theme.scss |
| 213 | +--info-color: #0084ff; |
| 214 | +--info-color-hover: #4da3ff; |
| 215 | +--info-color-selected: #1a3d5c; |
| 216 | + |
| 217 | +// black-theme.scss |
| 218 | +--info-color: #0084ff; |
| 219 | +--info-color-hover: #4da3ff; |
| 220 | +--info-color-selected: #1a3d5c; |
| 221 | + |
| 222 | +// hacker-theme.scss |
| 223 | +--info-color: #0084ff; // Same as black if no specific value |
| 224 | +--info-color-hover: #4da3ff; // Same as black if no specific value |
| 225 | +--info-color-selected: #1a3d5c; // Same as black if no specific value |
| 226 | +``` |
| 227 | + |
| 228 | +After running `yarn build`, the token will be available throughout the design system! |
0 commit comments