Colors
Overview
The CivicTheme color system is a sophisticated, multi-layered approach to managing colours across components. It provides a flexible foundation for creating consistent, accessible, and themeable user interfaces that support both light and dark themes.
Quick Start
To use the CivicTheme color system:
Define brand colours in
$ct-colors-brands(optional)Override default colours in
$ct-colors(optional)Use component variables in
_variables.components.scssfor specific stylingApply themes using the
ct-component-thememixin in component SCSS files
Color System Architecture
1. Base Color Foundation (_variables.base.scss)
_variables.base.scss)The color system is built on a foundation of semantic colour tokens that are mapped to actual colour values:
// Brand colours can be extended
$ct-colors-brands: () !default;
// Default colour palette can be overridden
$ct-colors: () !default;
// Default semantic colour mapping
$ct-colors-default: (
'light': (
'heading': ct-color-shade(ct-color-constant-light('brand1'), 60),
'body': ct-color-tint(ct-color-shade(ct-color-constant-light('brand1'), 80), 20),
'background-light': ct-color-tint(ct-color-constant-light('brand2'), 90),
'background': ct-color-constant-light('brand2'),
'interaction-background': ct-color-constant-light('brand1'),
'interaction-text': ct-color-tint(ct-color-constant-light('brand2'), 80),
// ... more semantic colours
),
'dark': (
'heading': ct-color-tint(ct-color-constant-dark('brand1'), 95),
'body': ct-color-tint(ct-color-constant-dark('brand1'), 85),
'background': ct-color-constant-dark('brand2'),
'interaction-background': ct-color-constant-dark('brand1'),
'interaction-text': ct-color-constant-dark('brand2'),
// ... more semantic colours
)
);2. Component-Specific Variables (_variables.components.scss)
_variables.components.scss)Component variables map semantic colours to specific component properties:
How New Color Palettes Are Mapped
Step 1: Define Brand Colours (Optional)
To create a custom colour palette, start by defining your brand colours:
Step 2: Override Default Colours (Optional)
You can override specific semantic colours without changing the entire palette:
Step 3: Component Variables Automatically Update
Once you've defined your brand colours or overridden semantic colours, all component variables automatically use the new values because they reference the semantic colour functions:
How Light and Dark Theme Colours Are Applied
The ct-component-theme Mixin
ct-component-theme MixinThe ct-component-theme mixin is the core mechanism for applying theme-specific styles:
Component Implementation Pattern
Components use this pattern to apply theme-specific styles:
CSS Custom Properties Generation
The ct-component-property mixin generates CSS custom properties:
This generates CSS like:
Colour Function Resolution
The ct-color-light() and ct-color-dark() functions resolve to CSS custom properties:
This creates a chain: ct-color-light('interaction-background') → var(--ct-color-light-interaction-background) → actual colour value.
Variable Naming Convention
Component variables follow a strict naming pattern:
Examples:
$ct-tag-light-primary-background-color$ct-button-dark-secondary-hover-border-color$ct-navigation-light-dropdown-menu-item-active-background-color
Practical Example: Creating a Custom Tag Variant
To add a new "success" variant to the tag component:
Add component variables in
_variables.components.scss:
Add component styles in
tag.scss:
Benefits of This System
Semantic Colour Mapping: Colours are defined by purpose, not specific values
Automatic Theme Support: Light and dark themes are handled automatically
CSS Custom Properties: Enables runtime theme switching
Extensible: Easy to add new colours or override existing ones
Consistent: All components follow the same theming pattern
Maintainable: Changes to brand colours propagate throughout the system
Key Files
_variables.base.scss: Foundation colour definitions_variables.components.scss: Component-specific colour mappingsmixins/_color.scss: Colour utility functionsmixins/_component.scss: Theme application mixins
Next Steps
To implement a new colour palette:
Define your brand colours in
$ct-colors-brandsOverride any semantic colours in
$ct-colorsif neededTest components in both light and dark themes
Use the existing component variables for consistency
Add new component variables following the naming convention
Last updated
Was this helpful?