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] Theming support for Monaco editor #202782

Closed
tsullivan opened this issue Dec 3, 2024 · 1 comment · Fixed by #203337
Closed

[SharedUX] Theming support for Monaco editor #202782

tsullivan opened this issue Dec 3, 2024 · 1 comment · Fixed by #203337
Assignees
Labels
Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience)

Comments

@tsullivan
Copy link
Member

tsullivan commented Dec 3, 2024

Part of https://github.com/elastic/kibana-team/issues/1082
Split from #200620

  1. The file packages/kbn-monaco/src/console/theme.ts has a considerable amount of usage of hardcoded color constants and deprecated imports of color variables. This file needs special attention for the EUI Visual Refresh.
  2. Also impacted is packages/shared-ux/code_editor/impl/index.tsx.
@botelastic botelastic bot added the needs-team Issues missing a team label label Dec 3, 2024
@eokoneyo eokoneyo added Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) and removed needs-team Issues missing a team label labels Dec 4, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

kowalczyk-krzysztof pushed a commit to kowalczyk-krzysztof/kibana that referenced this issue 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 issue 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience)
Projects
None yet
3 participants