-
Notifications
You must be signed in to change notification settings - Fork 849
[Theme] Support theme level overrides #8558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Theme] Support theme level overrides #8558
Conversation
f0b75e1
to
988ed53
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look and work good. I want to take a quick look on how the computed
works in more detail and what performance implications it has before I approve this. This code is executed early and has direct impact on initial app render
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the computed
performance and the difference is insignificant.
LGTM
- ensures inherited colors are updated if the base is changed
- while ink and ghost are not defined for the theme, there is a use case for pure black and white tokens, expecially for HCM
- updates due to ink token change in HCM
- udpate after rebase
- ensures that provider level overrides apply ontop of theme level overrides
988ed53
to
95fe71d
Compare
@tkajtoch I rebased with main and additionally added another update (commit) that ensures the following override order (first item = lowest level; each following item overrides the previous):
ℹ️ HCM specific overrides in |
💚 Build Succeededcc @mgadewoll |
Preview staging links for this PR:
|
💚 Build Succeeded
History
cc @mgadewoll |
Summary
Closes https://github.com/elastic/eui-private/issues/281
This PR adds support for theme-specific overrides directly on the theme definition layer.
While we already have ways to override theme tokens (using the
modify
prop on theEuiProvider
) this way is limited to what's available to the provider (e.g. it does not have access to the primitive tokens).Note
HCM: Currently we add overrides for high contrast mode here.
This use passes overrides via the
modify
prop to the provider. Anything added there currently is applied to any theme active on the provider, it's a global override.For theme-specific overrides we instead would want to provide the overrides directly on the definition layer (e.g. here).
A use case we'll need to support this way soon: specific sets of data vis colors in high contrast mode.
The suggested change enables the current theming functionality to support an optional
overrides
key on theEuiThemeShape
and updates thegetComputed
theming function to include the required overrides (the implementation so far considersHCM
(high contrast mode) overrides. The approach follows what's already available for definingLIGHT
andDARK
variants per color mode. Theoverrides
key is part of theEuiThemeShape
(input theme) only, it will not be included on theEuiThemeComputed
(output theme).usage

Note
The code for building and updating themes is old, not that easy to follow and overall rather cumbersome. This PR only adds onto the code for now. In the future (likely once we have fully migrated off Amsterdam and finished Borealis) we might want to consider refactoring those functions in general to improve functionality and maintainability.
Changes
getComputed
to supporthighContrastMode
viaoverrides.HCM
on the theme objectcomputed
values (where possible) to ensure tokens are updated accordingly by overrides they inherit from (the alternative would be to have to override each token manually, which a) is still possible but mainly b) seems less favorable in terms of devX)@deprecated
mark onink
andghost
tokens - while those are not expected in the theme, there is a use case for having true black and white tokens (currently at least for HCM)ink
andghost
tokens (resets them to primitive black and white to ensure highest possible contrasts)QA
EuiButton
withfill={true}
here - the custom overrides (code) should apply (and be inherited by the button tokens)(code)Screen.Recording.2025-04-07.at.17.51.07.mov
General checklist
Checked in mobileChecked for accessibility including keyboard-only and screenreader modesAdded documentationProps have proper autodocs (using@default
if default values are missing) and playground togglesChecked Code Sandbox works for any docs examplesAdded or updated jest and cypress testsIf applicable, added the breaking change issue label (and filled out the breaking change checklist)If applicable, file an issue to update EUI's Figma library with any corresponding UI changes. (This is an internal repo, if you are external to Elastic, ask a maintainer to submit this request)