Skip to content
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

[SharedUX] Modify code editor theme definition and resolution implementation to account for color modes in EUI Theme #203337

Merged
merged 13 commits into from
Jan 3, 2025

Conversation

eokoneyo
Copy link
Contributor

@eokoneyo eokoneyo commented Dec 6, 2024

Summary

Closes #202782

This PR reworks how custom themes used within the kibana code editor for the default visual look and ones specific to supported languages are defined to accomodate the upcoming visual refresh, the approach here leverages the euiTheme object value returned from the useEuiTheme hook, now a single theme declaration is all that is required such that using either the colorMode value or the euiTheme from the provided UseEUITheme value it's possible to craft a theme that's in the context of kIbana, color mode aware and the editor would be able to resolve the appropriate colors depending on the user's color mode.

This required some modification to monaco itself; now when defining languages if the CustomLanguageType specification is being followed, a function that resolves to a standard monaco theme can be provided on the property languageThemeResolver which will be passed the euiTheme when registering this theme. It's worth mentioning that this can also be done manually by leveraging the custom method registerLanguageThemeResolver added on the monaco editor object, like so

 monaco.editor.registerLanguageThemeResolver(LanguageID, languageThemeResolver);

However one should take note that when calling this method directly, the ID passed must correlate to a registered language ID, else the theme will not be available for use after Monaco is initialised, hence the theme name must equal an existing language ID if it's to be used for a specific language.

How to test

  • Enable borealis, like so;
    • in your kibana.dev.yml file include the following config;
       uiSettings.experimental.themeSwitcherEnabled: true
    • start kibana using the following command; KBN_OPTIMIZER_THEMES="borealislight,borealisdark,v8light,v8dark" yarn start --run-examples
  • Tryout all downstream of the code editor to ascertain the code editor colors are as should be for both Amsterdam and Borealis; downstreams include;
    • ES|QL editor, navigate to discover and click the "try ES|QL" button
    • Dev tools, on clicking the nav hamburger menu under the management menu group there's a menu item that links to all dev tools
    • Index Management use cases; navigate to stack management, under Index management select any existing index, then navigate to it's settings this should load up the code editor.
    • Saved Object use case; navigate to stack management, under saved objects attempt inspecting any saved object we'd be presented with the code editor etc.

@eokoneyo eokoneyo added release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) labels Dec 6, 2024
@eokoneyo eokoneyo self-assigned this Dec 6, 2024
Comment on lines -51 to -60
* Register custom themes
*/
registerTheme(ESQL_LIGHT_THEME_ID, buildESQLTheme({ darkMode: false }));
registerTheme(ESQL_DARK_THEME_ID, buildESQLTheme({ darkMode: true }));
registerTheme(CONSOLE_THEME_ID, buildConsoleTheme());
registerTheme(CODE_EDITOR_LIGHT_THEME_ID, buildLightTheme());
registerTheme(CODE_EDITOR_DARK_THEME_ID, buildDarkTheme());
registerTheme(CODE_EDITOR_LIGHT_THEME_TRANSPARENT_ID, buildLightTransparentTheme());
registerTheme(CODE_EDITOR_DARK_THEME_TRANSPARENT_ID, buildDarkTransparentTheme());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of this is now handled in the actual component implementation of the code editor, see https://github.com/elastic/kibana/pull/203337/files#diff-21b735fba0b5df628e2664a3605f8401d082a4eb32ab0b1ede5fae2db5251030R177-R193

@eokoneyo eokoneyo changed the title Rework code editor theme resolution to account for color modes [SharedUX] Rework code editor theme resolution to account for color modes in borealis Dec 6, 2024
Comment on lines -10 to -13
export const CODE_EDITOR_LIGHT_THEME_ID = 'codeEditorLightTheme';
export const CODE_EDITOR_DARK_THEME_ID = 'codeEditorDarkTheme';
export const CODE_EDITOR_LIGHT_THEME_TRANSPARENT_ID = 'codeEditorLightTransparentTheme';
export const CODE_EDITOR_DARK_THEME_TRANSPARENT_ID = 'codeEditorDarkTransparentTheme';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no need for light and dark variations of the same theme anymore, we resolve this automatically now

@eokoneyo eokoneyo force-pushed the fix/resolve-202782 branch 3 times, most recently from a4234d4 to 9c0bf5c Compare December 9, 2024 09:53
@eokoneyo eokoneyo changed the title [SharedUX] Rework code editor theme resolution to account for color modes in borealis [SharedUX] Modify code editor theme definition and resolution implementation to account for color modes in EUI Theme Dec 9, 2024
@eokoneyo eokoneyo force-pushed the fix/resolve-202782 branch 5 times, most recently from 442bd20 to 096c71b Compare December 10, 2024 12:02
@eokoneyo

This comment was marked as outdated.

@eokoneyo eokoneyo added the backport:skip This commit does not require backporting label Dec 12, 2024
@eokoneyo eokoneyo requested a review from ek-so December 18, 2024 09:52
@eokoneyo
Copy link
Contributor Author

@ek-so Could I trouble you to help review this, whilst it's been held up by #204482, I'd like to pre-emptively get feedback about the color selection, so that once the aforementioned PR gets merged in, we can pretty much we merge this one in?

Copy link
Contributor

@ek-so ek-so left a comment

Choose a reason for hiding this comment

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

Ok, it's looking good. But tbh, I was not able to figure out what some "lightestShades"/"emptyShades" etc. legacy colors do there. It's currently allowed to use them afaik, so I guess we can merge like this and figure out later.

Copy link
Contributor

Choose a reason for hiding this comment

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

CleanShot 2024-12-18 at 15 20 39@2x
This removes grey surface under tab bar

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be just unnecessary (we can have only subdued panel prop, that's all)

Copy link
Contributor

Choose a reason for hiding this comment

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

CleanShot 2024-12-18 at 15 22 26@2x

@eokoneyo eokoneyo marked this pull request as ready for review December 19, 2024 12:31
@eokoneyo eokoneyo requested a review from a team as a code owner December 19, 2024 12:31
Copy link
Contributor

@mattkime mattkime left a comment

Choose a reason for hiding this comment

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

Codeowner changes look good and appear to work well 🎉

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

This has many changes in comparison with the existing theme cc @ryankeairns

This PR
image

image

Main branch
image

image

@eokoneyo eokoneyo force-pushed the fix/resolve-202782 branch from 3db0b7a to 965dc0d Compare January 2, 2025 11:16
@eokoneyo eokoneyo force-pushed the fix/resolve-202782 branch from 965dc0d to c724ae5 Compare January 3, 2025 10:17
@eokoneyo
Copy link
Contributor Author

eokoneyo commented Jan 3, 2025

This has many changes in comparison with the existing theme cc @ryankeairns

This PR
image

image

Main branch
image

image

Hi @stratoula , I took a second look at this, it's true the previous changes made it such that identifiers were colored and not matching the overall text color, and I think with suggestions the colors were wrong, I made some adjustments in b30bc9e that I think should resolve these concerns.

See screenshot below,
Screenshot 2025-01-03 at 11 21 01

Could you help take a second look?

@stratoula
Copy link
Contributor

@eokoneyo thanx, much appreciated. Even from the screenshot I can see that the columns (new or existing) such as the order_date in your example is colored wrongly. It is kinda pinky while it should be same color as the index pattern

@eokoneyo
Copy link
Contributor Author

eokoneyo commented Jan 3, 2025

@eokoneyo thanx, much appreciated. Even from the screenshot I can see that the columns (new or existing) such as the order_date in your example is colored wrongly. It is kinda pinky while it should be same color as the index pattern

Thanks for pointing this out @stratoula. I've resolved this in 3252105, here's how it all looks now. Apologies for the noise.

Screenshot 2025-01-03 at 12 39 13

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Except for a small question, now it looks ok to me

I tested this at light dark mode for Amsterdam and Borealis themes. LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/monaco 124 134 +10

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
console 204.3KB 204.2KB -51.0B
esql 203.1KB 203.0KB -99.0B
searchIndices 164.1KB 164.0KB -71.0B
security 542.4KB 542.2KB -147.0B
serverlessSearch 352.1KB 352.1KB -71.0B
total -439.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
console 35.6KB 35.6KB -54.0B
kbnUiSharedDeps-srcJs 3.5MB 3.5MB +509.0B
painlessLab 10.0KB 10.0KB -3.0B
total +452.0B
Unknown metric groups

API count

id before after diff
@kbn/code-editor 41 40 -1
@kbn/monaco 124 134 +10
total +9

ESLint disabled line counts

id before after diff
@kbn/monaco 5 6 +1

References to deprecated APIs

id before after diff
@kbn/monaco 8 1 -7

Total ESLint disabled count

id before after diff
@kbn/monaco 13 14 +1

History

cc @eokoneyo

Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

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

Nice work! reviewed the code and smoke checked different editors in light/dark theme

@eokoneyo eokoneyo merged commit 8f01c30 into elastic:main Jan 3, 2025
8 checks passed
@eokoneyo eokoneyo deleted the fix/resolve-202782 branch January 3, 2025 14:02
kowalczyk-krzysztof pushed a commit to kowalczyk-krzysztof/kibana that referenced this pull request Jan 7, 2025
…ntation to account for color modes in EUI Theme (elastic#203337)

## Summary

<!-- ### DONT MERGE, THIS PR DEPENDS ON AN UPDATE TO EUI, THAT'S IN
FLIGHT -->

Closes elastic#202782

This PR reworks how custom themes used within the kibana code editor for
the default visual look and ones specific to supported languages are
defined to accomodate the upcoming visual refresh, the approach here
leverages the `euiTheme` object value returned from the `useEuiTheme`
hook, now a single theme declaration is all that is required such that
using either the `colorMode `value or the `euiTheme` from the provided
`UseEUITheme` value it's possible to craft a theme that's in the context
of kIbana, color mode aware and the editor would be able to resolve the
appropriate colors depending on the user's color mode.

This required some modification to monaco itself; now when defining
languages if the `CustomLanguageType` specification is being followed, a
function that resolves to a standard monaco theme can be provided on the
property `languageThemeResolver` which will be passed the `euiTheme`
when registering this theme. It's worth mentioning that this can also be
done manually by leveraging the custom method
`registerLanguageThemeResolver` added on the monaco editor object, like
so

```tsx
 monaco.editor.registerLanguageThemeResolver(LanguageID, languageThemeResolver);
``` 

However one should take note that when calling this method directly, the
ID passed must correlate to a registered language ID, else the theme
will not be available for use after Monaco is initialised, hence the
theme name must equal an existing language ID if it's to be used for a
specific language.


## How to test

- Enable borealis, like so;
	- in your `kibana.dev.yml` file include the following config;
		```yml
		uiSettings.experimental.themeSwitcherEnabled: true
		```
- start kibana using the following command;
`KBN_OPTIMIZER_THEMES="borealislight,borealisdark,v8light,v8dark" yarn
start --run-examples`
- Tryout all downstream of the code editor to ascertain the code editor
colors are as should be for both Amsterdam and Borealis; downstreams
include;
  - ES|QL editor, navigate to discover and click the "try ES|QL" button
- Dev tools, on clicking the nav hamburger menu under the management
menu group there's a menu item that links to all dev tools
- Index Management use cases; navigate to stack management, under Index
management select any existing index, then navigate to it's settings
this should load up the code editor.
- Saved Object use case; navigate to stack management, under saved
objects attempt inspecting any saved object we'd be presented with the
code editor etc.
  
<!--
### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...


-->

---------

Co-authored-by: ek-so <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Jan 13, 2025
…ntation to account for color modes in EUI Theme (elastic#203337)

## Summary

<!-- ### DONT MERGE, THIS PR DEPENDS ON AN UPDATE TO EUI, THAT'S IN
FLIGHT -->

Closes elastic#202782

This PR reworks how custom themes used within the kibana code editor for
the default visual look and ones specific to supported languages are
defined to accomodate the upcoming visual refresh, the approach here
leverages the `euiTheme` object value returned from the `useEuiTheme`
hook, now a single theme declaration is all that is required such that
using either the `colorMode `value or the `euiTheme` from the provided
`UseEUITheme` value it's possible to craft a theme that's in the context
of kIbana, color mode aware and the editor would be able to resolve the
appropriate colors depending on the user's color mode.

This required some modification to monaco itself; now when defining
languages if the `CustomLanguageType` specification is being followed, a
function that resolves to a standard monaco theme can be provided on the
property `languageThemeResolver` which will be passed the `euiTheme`
when registering this theme. It's worth mentioning that this can also be
done manually by leveraging the custom method
`registerLanguageThemeResolver` added on the monaco editor object, like
so

```tsx
 monaco.editor.registerLanguageThemeResolver(LanguageID, languageThemeResolver);
``` 

However one should take note that when calling this method directly, the
ID passed must correlate to a registered language ID, else the theme
will not be available for use after Monaco is initialised, hence the
theme name must equal an existing language ID if it's to be used for a
specific language.


## How to test

- Enable borealis, like so;
	- in your `kibana.dev.yml` file include the following config;
		```yml
		uiSettings.experimental.themeSwitcherEnabled: true
		```
- start kibana using the following command;
`KBN_OPTIMIZER_THEMES="borealislight,borealisdark,v8light,v8dark" yarn
start --run-examples`
- Tryout all downstream of the code editor to ascertain the code editor
colors are as should be for both Amsterdam and Borealis; downstreams
include;
  - ES|QL editor, navigate to discover and click the "try ES|QL" button
- Dev tools, on clicking the nav hamburger menu under the management
menu group there's a menu item that links to all dev tools
- Index Management use cases; navigate to stack management, under Index
management select any existing index, then navigate to it's settings
this should load up the code editor.
- Saved Object use case; navigate to stack management, under saved
objects attempt inspecting any saved object we'd be presented with the
code editor etc.
  
<!--
### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...


-->

---------

Co-authored-by: ek-so <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
viduni94 pushed a commit to viduni94/kibana that referenced this pull request Jan 23, 2025
…ntation to account for color modes in EUI Theme (elastic#203337)

## Summary

<!-- ### DONT MERGE, THIS PR DEPENDS ON AN UPDATE TO EUI, THAT'S IN
FLIGHT -->

Closes elastic#202782

This PR reworks how custom themes used within the kibana code editor for
the default visual look and ones specific to supported languages are
defined to accomodate the upcoming visual refresh, the approach here
leverages the `euiTheme` object value returned from the `useEuiTheme`
hook, now a single theme declaration is all that is required such that
using either the `colorMode `value or the `euiTheme` from the provided
`UseEUITheme` value it's possible to craft a theme that's in the context
of kIbana, color mode aware and the editor would be able to resolve the
appropriate colors depending on the user's color mode.

This required some modification to monaco itself; now when defining
languages if the `CustomLanguageType` specification is being followed, a
function that resolves to a standard monaco theme can be provided on the
property `languageThemeResolver` which will be passed the `euiTheme`
when registering this theme. It's worth mentioning that this can also be
done manually by leveraging the custom method
`registerLanguageThemeResolver` added on the monaco editor object, like
so

```tsx
 monaco.editor.registerLanguageThemeResolver(LanguageID, languageThemeResolver);
``` 

However one should take note that when calling this method directly, the
ID passed must correlate to a registered language ID, else the theme
will not be available for use after Monaco is initialised, hence the
theme name must equal an existing language ID if it's to be used for a
specific language.


## How to test

- Enable borealis, like so;
	- in your `kibana.dev.yml` file include the following config;
		```yml
		uiSettings.experimental.themeSwitcherEnabled: true
		```
- start kibana using the following command;
`KBN_OPTIMIZER_THEMES="borealislight,borealisdark,v8light,v8dark" yarn
start --run-examples`
- Tryout all downstream of the code editor to ascertain the code editor
colors are as should be for both Amsterdam and Borealis; downstreams
include;
  - ES|QL editor, navigate to discover and click the "try ES|QL" button
- Dev tools, on clicking the nav hamburger menu under the management
menu group there's a menu item that links to all dev tools
- Index Management use cases; navigate to stack management, under Index
management select any existing index, then navigate to it's settings
this should load up the code editor.
- Saved Object use case; navigate to stack management, under saved
objects attempt inspecting any saved object we'd be presented with the
code editor etc.
  
<!--
### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...


-->

---------

Co-authored-by: ek-so <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting EUI Visual Refresh release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SharedUX] Theming support for Monaco editor
9 participants