Skip to content

Dark Mode Support#513

Closed
TerranceKhumalo-absa wants to merge 13 commits intomasterfrom
fix/512-colors-page-crashes
Closed

Dark Mode Support#513
TerranceKhumalo-absa wants to merge 13 commits intomasterfrom
fix/512-colors-page-crashes

Conversation

@TerranceKhumalo-absa
Copy link
Copy Markdown
Collaborator

@TerranceKhumalo-absa TerranceKhumalo-absa commented Mar 31, 2026

Dark Mode Support

This pull request introduces dark mode theming support for the CPS Shared UI library, including a theme toggle component, CSS variable-based styling, and updated API documentation.

Note: This feature was originally shipped as part of the v20.5.0 release but was rolled back in v20.5.1 due to a production bug on the Colors page (see Bug Fix below). This PR resubmits the dark mode feature with the bug resolved.


Theming & UI Enhancements

  • Added ThemeToggleComponent to the top toolbar, allowing users to switch between light and dark modes.
  • Updated styles in app.component.scss and navigation-sidebar.component.scss to use CSS variables (e.g., --cps-surface-body, --cps-text-primary) for backgrounds, borders, and text, ensuring theme consistency across both modes.
  • Changed tab group background in component-docs-viewer.component.html to use the new theme variable.
  • Added alt text to the logo image for accessibility.

Theming API Documentation

  • Added cps-theme.json API doc describing CpsThemeService and new types: CpsTheme, CpsColorTheme, CpsBaseTheme, and CpsRadiusTheme.
  • Updated types_map.json to map the new theme types to the "theme" section.

Component Updates

  • Updated default color values for cps-loader and cps-progress-linear to use theme-aware CSS variables.
  • Fixed line endings in several API doc descriptions for better formatting (cps-notification.json, cps-table.json, cps-tree-table.json, cron-validation.service.json).

Bug Fix

The original dark mode release (v20.5.0) introduced a production-only crash on the Colors page:

TypeError: Cannot read properties of null (reading '1')
    at isDark (colors-utils.ts)

Root cause:

The isDark() function used a regex that only matched the legacy comma-separated CSS color format (rgba(73, 185, 255, 0.16)). In production builds, the CSS minifier converts these to the modern space-separated syntax (rgb(73 185 255 / .16)), causing the regex to return null. This was not an issue before dark mode because the light theme's --cps-color-* variables are all hex values. The dark theme (_colors-dark.scss) introduced rgba() values for info-bg, success-bg, warn-bg, error-bg, and highlight colors.

Fix: Updated the regex in isDark() from:

/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/

to:

/^rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/

This matches both legacy and modern CSS color syntax. A null guard was also added to prevent crashes on any other unrecognized format.

Affected file: projects/cps-ui-kit/src/lib/utils/colors-utils.ts


Release notes:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class theming (light/dark + semantic tokens) to the CPS UI Kit and Composition app, and fixes the production-only Colors page crash caused by CSS-minified rgb(r g b / a) color syntax.

Changes:

  • Introduces dark theme tokens (_colors-dark.scss) and broad adoption of semantic CSS variables across components and Composition styles.
  • Adds CpsThemeService (signals-based) + a Composition ThemeToggleComponent to switch theme options at runtime.
  • Fixes colors-utils.ts parsing to support both legacy and modern rgb/rgba formats and updates API docs/type mappings.

Reviewed changes

Copilot reviewed 39 out of 41 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
projects/cps-ui-kit/styles/styles.scss Imports dark theme tokens and adds global theme-dependent base styles + transition hook.
projects/cps-ui-kit/styles/_colors.scss Adds semantic design tokens and theme/radius overrides via CSS variables.
projects/cps-ui-kit/styles/_colors-dark.scss New dark-theme palette and semantic token overrides keyed off data-theme='dark'.
projects/cps-ui-kit/src/public-api.ts Reorders exports and exposes the new CpsThemeService.
projects/cps-ui-kit/src/lib/utils/colors-utils.ts Fixes rgb/rgba parsing to prevent production crash on minified CSS formats.
projects/cps-ui-kit/src/lib/services/cps-theme/cps-theme.service.ts New root service managing theme attributes, persistence, and system preference watching.
projects/cps-ui-kit/src/lib/services/cps-theme/cps-theme.service.spec.ts Adds unit tests for the new theme service.
projects/cps-ui-kit/src/lib/components/cps-progress-linear/cps-progress-linear.component.ts Updates default progress color to a semantic theme variable.
projects/cps-ui-kit/src/lib/components/cps-loader/cps-loader.component.ts Updates loader defaults toward theme tokens.
projects/cps-ui-kit/src/lib/components/cps-loader/cps-loader.component.scss Updates loader circle colors to semantic accent tokens.
projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.ts Import reordering (no functional change).
projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.scss Replaces hard-coded/light-theme styles with semantic theme variables and focus ring styling.
projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.html Adds error label styling, updates disabled icon color, and tweaks progress opacity.
projects/cps-ui-kit/src/lib/components/cps-icon/cps-icon.component.ts Adds new icons (sun, moon, kafka) to the icon name whitelist.
projects/cps-ui-kit/src/lib/components/cps-chip/cps-chip.component.scss Updates chip styling to semantic surfaces/borders/text.
projects/cps-ui-kit/src/lib/components/cps-chip/cps-chip.component.html Updates close icon default color token.
projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.scss Migrates autocomplete styling to semantic tokens, adds focus ring, and updates popover styling.
projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.html Improves keyboard/accessibility (tabindex + aria-label) and updates disabled icon color.
projects/cps-ui-kit/assets/icons.svg Adds sun, moon, and kafka SVG symbols.
projects/composition/src/variables.scss Switches Composition variables to semantic theme tokens.
projects/composition/src/styles.scss Updates table/code block styling to semantic surfaces and adds row hover highlight.
projects/composition/src/app/pages/icons-page/icons-page/icons-page.component.scss Updates icon list text color to semantic token.
projects/composition/src/app/pages/icons-page/icons-page/icons-page.component.html Updates icon color usage to semantic theme variable.
projects/composition/src/app/components/theme-toggle/theme-toggle.component.ts New UI for selecting theme/radius/base and toggling dark mode via CpsThemeService.
projects/composition/src/app/components/theme-toggle/theme-toggle.component.scss Styling for the new theme toggle controls and popover menu.
projects/composition/src/app/components/theme-toggle/theme-toggle.component.html Adds appearance popover + dark mode toggle button with new icons.
projects/composition/src/app/components/navigation-sidebar/navigation-sidebar.component.scss Applies semantic tokens to sidebar surfaces/text/hover states.
projects/composition/src/app/components/component-docs-viewer/component-docs-viewer.component.html Updates tab background token to a semantic surface.
projects/composition/src/app/app.module.ts Registers ThemeToggleComponent in the app module.
projects/composition/src/app/app.component.spec.ts Updates AppComponent test imports to include ThemeToggleComponent.
projects/composition/src/app/app.component.scss Updates toolbar and layout styling to semantic surfaces/borders/text.
projects/composition/src/app/app.component.html Adds logo alt text and inserts the new theme toggle in the toolbar.
projects/composition/src/app/api-data/types_map.json Maps new theme-related types to a dedicated “theme” docs section.
projects/composition/src/app/api-data/cron-validation.service.json Normalizes doc line endings/formatting.
projects/composition/src/app/api-data/cps-tree-table.json Normalizes doc line endings/formatting.
projects/composition/src/app/api-data/cps-theme.json Adds new API documentation entry for CpsThemeService and theme types.
projects/composition/src/app/api-data/cps-table.json Normalizes doc line endings/formatting.
projects/composition/src/app/api-data/cps-progress-linear.json Updates documented default color to semantic variable.
projects/composition/src/app/api-data/cps-notification.json Normalizes doc line endings/formatting.
projects/composition/src/app/api-data/cps-loader.json Updates documented default label color.
package-lock.json Updates lockfile metadata (adds/removes peer flags across entries).

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

Coverage report for library

St.
Category Percentage Covered / Total
🔴 Statements 30.13% 1920/6372
🔴 Branches 23.45% 668/2849
🔴 Functions 25.71% 352/1369
🔴 Lines 31% 1817/5862

Test suite run success

429 tests passing in 22 suites.

Report generated by 🧪jest coverage report action from 9657371

… navigation sidebar styles for better theming consistency
…default values, and improve descriptions for clarity
- Added a new "kafka" icon to the icons.svg file.
- Updated the iconNames array in cps-icon.component.ts to include "kafka".
- Improved regex matching for RGB color parsing in colors-utils.ts to support modern syntax.
@TerranceKhumalo-absa TerranceKhumalo-absa force-pushed the fix/512-colors-page-crashes branch from 9be6232 to 9657371 Compare April 1, 2026 09:36
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Playwright test results

passed  34 passed

Details

stats  34 tests across 3 suites
duration  1 minute, 8 seconds
commit  9657371
info  For details, download the Playwright report

@TerranceKhumalo-absa TerranceKhumalo-absa changed the title Fix/512 colors page crashes Dark Mode Support Apr 1, 2026
@TerranceKhumalo-absa TerranceKhumalo-absa deleted the fix/512-colors-page-crashes branch April 1, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Colors page crashes in production after dark mode feature (v20.5.0)

2 participants