Skip to content

feat(theming): add OS-adaptive auto themes (sap_horizon_auto, sap_horizon_hc_auto)#13300

Merged
ilhan007 merged 4 commits intomainfrom
feat/auto-theme
Mar 19, 2026
Merged

feat(theming): add OS-adaptive auto themes (sap_horizon_auto, sap_horizon_hc_auto)#13300
ilhan007 merged 4 commits intomainfrom
feat/auto-theme

Conversation

@ilhan007
Copy link
Copy Markdown
Contributor

@ilhan007 ilhan007 commented Mar 19, 2026

Summary

  • Add sap_horizon_auto theme that automatically switches between light and dark based on the user's OS preference
  • Add sap_horizon_hc_auto theme that automatically switches between high contrast white (HCW) and high contrast black (HCB)
  • Uses CSS light-dark() for color values and space toggles for non-color values — purely CSS-driven, no runtime changes
  • Browser support: Chrome 123+, Firefox 120+, Safari 17.5+

How it works

At build time, the existing light and dark theme CSS outputs are merged into a single stylesheet:

  • Identical values → kept as-is (majority of variables)
  • Different color valueslight-dark(lightVal, darkVal) (native CSS function)
  • Different non-color values → space toggle pattern using --_ui5-light-scheme / --_ui5-dark-scheme (same guaranteed-invalid trick as cozy/compact density)
  • The theming package :root output gets color-scheme: light dark and a @media (prefers-color-scheme: dark) rule to flip the toggles

The same mechanism applies to high contrast themes — HCW maps to light mode, HCB maps to dark mode.

Usage

?sap-ui-theme=sap_horizon_auto
?sap-ui-theme=sap_horizon_hc_auto
setTheme("sap_horizon_auto")
setTheme("sap_horizon_hc_auto")

Theme pairs

Auto theme Light mode Dark mode
sap_horizon_auto sap_horizon sap_horizon_dark
sap_horizon_hc_auto sap_horizon_hcw sap_horizon_hcb

Files changed

  • packages/tools/assets-meta.js — register new theme names
  • packages/tools/lib/css-processors/css-processor-themes.mjs — merge light+dark after processing, add toggle setup for theming package
  • packages/tools/lib/css-processors/merge-light-dark.mjs — new: merge two CSS strings using light-dark() and space toggles
  • 10 placeholder parameters-bundle.css files — enable theme directory discovery by the build system

Test plan

  • yarn generate && yarn start then open ?sap-ui-theme=sap_horizon_auto
  • Toggle OS dark mode → components switch instantly without page reload
  • Verify ?sap-ui-theme=sap_horizon_hc_auto switches between HCW/HCB based on OS color scheme
  • Verify switching to a regular theme (sap_horizon) removes the auto behavior

…themes

Add auto-switching themes that adapt to the user's OS light/dark preference
using CSS light-dark() for color values and space toggles for non-color values.

At build time, the light and dark theme CSS outputs are merged into a single
stylesheet. Color variables use the native CSS light-dark() function (Chrome 123+,
Firefox 120+, Safari 17.5+). Non-color variables use the space toggle pattern
with guaranteed-invalid custom properties, the same approach already used for
cozy/compact density switching.

The auto theme is self-contained: switching away from it removes the toggles.
No runtime code changes needed — it is purely CSS-driven.

Usage:
- URL: ?sap-ui-theme=sap_horizon_auto
- JS: setTheme("sap_horizon_auto")
- Config: <script data-ui5-config>{"theme":"sap_horizon_auto"}</script>
@ui5-webcomponents-bot
Copy link
Copy Markdown
Collaborator

ui5-webcomponents-bot commented Mar 19, 2026

🧹 Preview deployment cleaned up: https://pr-13300--ui5-webcomponents.netlify.app

@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview March 19, 2026 10:51 Inactive
@ilhan007 ilhan007 requested review from nnaydenow and pskelin March 19, 2026 13:59
…ptive themes

Merge HCW (light) and HCB (dark) high contrast themes using the same
light-dark() and space toggle mechanism as the existing auto themes,
enabling automatic switching based on OS prefers-color-scheme.
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview March 19, 2026 17:54 Inactive
@pskelin pskelin changed the title feat(theming): add OS-adaptive auto themes (sap_horizon_auto, sap_fiori_3_auto) feat(theming): add OS-adaptive auto themes (light/dark and high contrast) Mar 19, 2026
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview March 19, 2026 18:13 Inactive
Remove sap_fiori_3_auto and sap_fiori_3_hc_auto to reduce scope.
Only sap_horizon_auto and sap_horizon_hc_auto are generated.
@pskelin pskelin changed the title feat(theming): add OS-adaptive auto themes (light/dark and high contrast) feat(theming): add OS-adaptive auto themes (sap_horizon_auto, sap_horizon_hc_auto) Mar 19, 2026
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview March 19, 2026 18:23 Inactive
@ilhan007 ilhan007 merged commit f6ae2b5 into main Mar 19, 2026
14 checks passed
@ilhan007 ilhan007 deleted the feat/auto-theme branch March 19, 2026 18:49
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview March 19, 2026 18:49 Inactive
@ui5-webcomponents-bot
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version v2.21.0-rc.2 🎉

The release is available on v2.21.0-rc.2

Your semantic-release bot 📦🚀

@ui5-webcomponents-bot
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version v2.21.0 🎉

The release is available on v2.21.0

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants