Skip to content

Dark Mode Support#516

Open
TerranceKhumalo-absa wants to merge 15 commits intomasterfrom
feature/512-dark-mode
Open

Dark Mode Support#516
TerranceKhumalo-absa wants to merge 15 commits intomasterfrom
feature/512-dark-mode

Conversation

@TerranceKhumalo-absa
Copy link
Copy Markdown
Collaborator

@TerranceKhumalo-absa TerranceKhumalo-absa commented Apr 1, 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 Files

  • projects/cps-ui-kit/src/lib/utils/colors-utils.ts

Release notes:

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Coverage report for library

St.
Category Percentage Covered / Total
🔴 Statements 30.1% 1920/6379
🔴 Branches 23.4% 668/2855
🔴 Functions 25.62% 351/1370
🔴 Lines 30.97% 1817/5867

Test suite run success

429 tests passing in 22 suites.

Report generated by 🧪jest coverage report action from fbe4121

@TerranceKhumalo-absa TerranceKhumalo-absa review requested due to automatic review settings April 1, 2026 13:33
@TerranceKhumalo-absa TerranceKhumalo-absa self-assigned this Apr 1, 2026
@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, 11 seconds
commit  fbe4121
info  For details, download the Playwright report

Copilot AI review requested due to automatic review settings April 1, 2026 16:33
… 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.
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 reintroduces dark mode support for the CPS Shared UI library by adding a theme service and dark theme token overrides, migrating multiple component styles to semantic CSS variables, and addressing the previously reported production crash on the Colors page by hardening RGB(A) parsing.

Changes:

  • Add dark theme token overrides and semantic design tokens (surfaces, text, borders, radius, motion) based on CSS variables.
  • Introduce CpsThemeService for toggling/persisting theme settings and add a Composition “appearance” toggle UI.
  • Fix Colors page production crash by updating isDark() to handle modern minified rgb(r g b / a) syntax (and add a null guard).

Reviewed changes

Copilot reviewed 40 out of 42 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; adds global scrollbar + base background/text styling + transition hook.
projects/cps-ui-kit/styles/_colors.scss Adds semantic tokens (surfaces/text/borders/radius/motion) and theme attribute variants; updates error base color.
projects/cps-ui-kit/styles/_colors-dark.scss New dark theme overrides keyed off data-theme='dark' and related attribute combinations.
projects/cps-ui-kit/src/public-api.ts Reorders exports and exposes CpsThemeService publicly.
projects/cps-ui-kit/src/lib/utils/colors-utils.ts Updates isDark() regex + null guard; restricts getCpsColors() selector filtering.
projects/cps-ui-kit/src/lib/services/cps-theme/cps-theme.service.ts New theming service using signals + DOM attributes + localStorage persistence.
projects/cps-ui-kit/src/lib/services/cps-theme/cps-theme.service.spec.ts New unit tests for theme service defaults and persistence.
projects/cps-ui-kit/src/lib/components/cps-progress-linear/cps-progress-linear.component.ts Makes default progress color theme-aware via CSS variable.
projects/cps-ui-kit/src/lib/components/cps-loader/cps-loader.component.ts Updates loader label/background defaults toward semantic tokens.
projects/cps-ui-kit/src/lib/components/cps-loader/cps-loader.component.scss Swaps loader ring colors to semantic accent variables.
projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.ts Import ordering adjustments only.
projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.scss Migrates input styling to semantic variables; adds focus ring/disabled/borderless tweaks.
projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.html Replaces ngClass with class bindings; adjusts icon color + progress opacity.
projects/cps-ui-kit/src/lib/components/cps-icon/cps-icon.component.ts Adds new icon names (sun/moon/kafka); import ordering adjustment.
projects/cps-ui-kit/src/lib/components/cps-chip/cps-chip.component.scss Migrates chip styling to semantic surface/border/text variables.
projects/cps-ui-kit/src/lib/components/cps-chip/cps-chip.component.html Switches close icon color to semantic text variable.
projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.scss Migrates autocomplete styling to semantic tokens; improves focus/hover visuals.
projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.html Improves keyboard tabbing behavior; adds aria-labels; updates disabled icon color.
projects/cps-ui-kit/assets/icons.svg Adds SVG symbols for sun, moon, and kafka icons.
projects/composition/src/variables.scss Updates Composition variables to semantic tokens.
projects/composition/src/styles.scss Migrates Composition table/page styling to semantic tokens; adds row hover styling.
projects/composition/src/app/pages/icons-page/icons-page/icons-page.component.scss Updates icon row text color for dark mode compatibility.
projects/composition/src/app/pages/icons-page/icons-page/icons-page.component.html Makes icon color theme-aware for the icons page.
projects/composition/src/app/components/theme-toggle/theme-toggle.component.ts New appearance + theme toggle UI wiring to CpsThemeService.
projects/composition/src/app/components/theme-toggle/theme-toggle.component.scss New styling for the appearance settings popover/menu.
projects/composition/src/app/components/theme-toggle/theme-toggle.component.html New template for appearance menu + dark mode toggle button.
projects/composition/src/app/components/navigation-sidebar/navigation-sidebar.component.scss Migrates sidebar styling to semantic background/highlight/text tokens.
projects/composition/src/app/components/component-docs-viewer/component-docs-viewer.component.html Updates tab group background value to a new theme token.
projects/composition/src/app/app.module.ts Registers ThemeToggleComponent in Composition app module.
projects/composition/src/app/app.component.spec.ts Updates test imports to include ThemeToggleComponent.
projects/composition/src/app/app.component.scss Migrates toolbar/body toolbar styles to semantic tokens; positions theme toggle.
projects/composition/src/app/app.component.html Adds logo alt text; inserts the theme toggle into the top toolbar.
projects/composition/src/app/api-data/types_map.json Maps new theme types into the “theme” API docs section.
projects/composition/src/app/api-data/cron-validation.service.json Normalizes description line endings in API docs JSON.
projects/composition/src/app/api-data/cps-tree-table.json Normalizes description line endings in API docs JSON.
projects/composition/src/app/api-data/cps-theme.json New API doc entry describing CpsThemeService and theme-related types.
projects/composition/src/app/api-data/cps-table.json Normalizes description line endings in API docs JSON.
projects/composition/src/app/api-data/cps-progress-linear.json Updates default prop value to match new theme-aware default.
projects/composition/src/app/api-data/cps-notification.json Normalizes description line endings in API docs JSON.
projects/composition/src/app/api-data/cps-loader.json Updates documented default for loader label color.
package.json Adds jest-preset-angular dev dependency.
package-lock.json Lockfile updates for added dependency and metadata normalization.
Comments suppressed due to low confidence (1)

projects/cps-ui-kit/src/lib/components/cps-loader/cps-loader.component.ts:47

  • backgroundColor is set to var(--cps-surface-overlay) but then overwritten in ngOnInit() with rgba(0, 0, 0, ...), so the new theme-aware token is never used (and dark mode will still get a light-mode overlay). Use the semantic token for the base color (and apply opacity separately if needed), or remove the overwrite.

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)

3 participants