Skip to content

feat: introduce theme helpers#226

Open
mxschll wants to merge 3 commits into
mainfrom
dev-v3-schomax-themes
Open

feat: introduce theme helpers#226
mxschll wants to merge 3 commits into
mainfrom
dev-v3-schomax-themes

Conversation

@mxschll

@mxschll mxschll commented Jun 22, 2026

Copy link
Copy Markdown
Member

When the One Theme global flag is set, the toolkit now adds the awsui-one-theme class to <body>.

Changes made:

  • Replaced the per-theme detection logic with a data-driven themeDefinitions registry. Adding a future theme is now a single registry entry.
  • Added an exported initThemes() that applies the body class for every flag-activated
    theme. In the future, this can replace `useRuntimeVisualRefresh().

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@mxschll mxschll requested a review from YueyingLu June 22, 2026 13:57
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.00%. Comparing base (1454a6e) to head (6378064).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #226   +/-   ##
=======================================
  Coverage   99.00%   99.00%           
=======================================
  Files          44       44           
  Lines        1304     1307    +3     
  Branches      338      338           
=======================================
+ Hits         1291     1294    +3     
  Misses         13       13           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mxschll mxschll marked this pull request as ready for review June 22, 2026 14:04
@mxschll mxschll requested a review from a team as a code owner June 22, 2026 14:04
@mxschll mxschll removed the request for review from a team June 22, 2026 14:04

function applyThemeClassName(theme: Theme) {
if (typeof document !== 'undefined' && !hasThemeClassName(theme) && themeDefinitions[theme].isFlagActive()) {
document.body.classList.add(themeDefinitions[theme].className);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if multiple flags are active?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's ok, it will just add the class to the body no matter if there is another flag present.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If components use both classnames, the winning styles depend on stylesheet source order? It is implicit. What about having a precedence list, add only the highest-priority one?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I’m not sure that’s ideal, as it could hide the fact that other services are having multiple flags enabled instead of cleaning them up.

That said, if you feel strongly about it, I’m happy to add it, it’s a small change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe another solution is having that priority list, but show a dev warning if multiple flags are enabled.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think themes are mutually exclusive. Rather than silently applying 2 themes and rely on CSS order, I prefer to apply priority list, also console.warn if 2 themes are active.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we allow both classes to coexist, we'd need tests ensuring the CSS precedence holds.

Comment thread src/internal/visual-mode/index.ts Outdated
Comment thread src/internal/visual-mode/index.ts
Comment thread src/internal/visual-mode/index.ts Outdated
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.

2 participants