Summary
Refactor existing CSS styles in web components to use CSS custom properties (variables) instead of hardcoded values. This will enable easier theming, customization, and style overrides.
Problem
Currently, the web component use hardcoded CSS values for colors, spacing, typography, and other design tokens. This makes it difficult to:
- Create custom themes
- Allow users to customize the appearance
- Override styles without using
!important
- Maintain design consistency when making style updates
Proposed Solution
Convert hardcoded CSS values to CSS custom properties following this pattern:
Before:
.read-along-container {
background-color: #ffffff;
color: #333333;
border: 1px solid #cccccc;
padding: 16px;
border-radius: 4px;
}
After:
.read-along-container {
background-color: var(--read-along-bg-color, #ffffff);
color: var(--read-along-text-color, #333333);
border: var(--read-along-border-width, 1px) solid var(--component-border-color, #cccccc);
padding: var(--read-along-padding, 16px);
border-radius: var(--read-along-border-radius, 4px);
}
Implementation Details
1. Identify CSS Properties to Convert
Focus on converting these types of values:
- Colors (text, background, borders, shadows)
- Spacing (padding, margin, gaps)
- Typography (font sizes, line heights, font weights)
- Borders (width, radius)
- Shadows and effects
- Transitions and animations
2. Naming Convention
Use a consistent naming pattern for CSS variables:
--component-name-property-variant (e.g., --button-bg-color-primary)
--component-name-property for single values (e.g., --card-padding)
- Use semantic names where possible (e.g.,
--text-color-primary vs --color-gray-900)
3. Default Values
Always provide fallback values in the var() function to ensure components work even when variables aren't defined.
4. Documentation
Create documentation showing:
- Available CSS variables for each component
- Example of how to override variables
- Sample theme configurations
Benefits
- Easier theming: Users can override variables to create custom themes
- Better maintainability: Central control of design tokens
- Consistency: Shared variables ensure consistent styling
- Flexibility: No need for
!important to override styles
- Future-proof: Foundation for advanced theming features
Acceptance Criteria
Example Usage After Implementation
/* Custom theme */
:root {
--read-along-bg-color: #f8f9fa;
--read-along-text-color: #212529;
--read-along-border-color: #dee2e6;
--read-along-padding: 20px;
}
/* Dark theme */
[data-theme="dark"] {
--read-along-bg-color: #343a40;
--read-along-text-color: #f8f9fa;
--read-along-border-color: #495057;
}
Summary
Refactor existing CSS styles in web components to use CSS custom properties (variables) instead of hardcoded values. This will enable easier theming, customization, and style overrides.
Problem
Currently, the web component use hardcoded CSS values for colors, spacing, typography, and other design tokens. This makes it difficult to:
!importantProposed Solution
Convert hardcoded CSS values to CSS custom properties following this pattern:
Before:
After:
Implementation Details
1. Identify CSS Properties to Convert
Focus on converting these types of values:
2. Naming Convention
Use a consistent naming pattern for CSS variables:
--component-name-property-variant(e.g.,--button-bg-color-primary)--component-name-propertyfor single values (e.g.,--card-padding)--text-color-primaryvs--color-gray-900)3. Default Values
Always provide fallback values in the
var()function to ensure components work even when variables aren't defined.4. Documentation
Create documentation showing:
Benefits
!importantto override stylesAcceptance Criteria
Example Usage After Implementation