Skip to content

Debt - use CSS variables over registerThemingParticipant #165169

Closed

Description

When running VS Code (or the Monaco editor) all theme colors are exposed as CSS variables. That means components don’t need to use JavaScript to read and set colors but can simply rely on CSS. When a theme changes, the variable values automatically update. Also, with CSS variables you have less code and everything in one place.

The (long) list below is all users of registerThemingParticipant. Those that only set/update colors are candidates for adopting CSS variables The names of the CSS variables can be "derived" with the following logic

  1. prefix --vscode-
  2. take the theme color id and replace dots with slashes

For instance the color id editorSuggestWidget.background is exposed as CSS variables --vscode-editorSuggestWidget-background. Find a sample adoption in this commit: 3a787a8.


Activity

  1. 121 remaining items

  2. Tyriar commented on Feb 27, 2023

    @Tyriar
    Contributor

    Andrea Mah (@andreamah) you could have another rule with higher specificity that re-applies the link color?

  3. aeschli commented on Feb 28, 2023

    @aeschli
    Contributor

    Daniel Imms (@Tyriar) For

    registerThemingParticipant((theme, collector) => {
    let editorHoverHighlightColor = theme.getColor(editorHoverHighlight);
    if (editorHoverHighlightColor) {
    if (editorHoverHighlightColor.isOpaque()) {
    editorHoverHighlightColor = editorHoverHighlightColor.transparent(0.5);
    }
    collector.addRule(`.integrated-terminal .hoverHighlight { background-color: ${editorHoverHighlightColor}; }`);
    }
    });

    you could define a new (terminal hover specific) color. The default value of the color can express that it is a function of editorHoverHighlightColor

    let successColor: string | Color | undefined;
    let errorColor: string | Color | undefined;
    let defaultColor: string | Color | undefined;
    registerThemingParticipant((theme: IColorTheme) => {
    successColor = theme.getColor(TERMINAL_COMMAND_DECORATION_SUCCESS_BACKGROUND_COLOR);
    errorColor = theme.getColor(TERMINAL_COMMAND_DECORATION_ERROR_BACKGROUND_COLOR);
    defaultColor = theme.getColor(TERMINAL_COMMAND_DECORATION_DEFAULT_BACKGROUND_COLOR);
    });

    To access a color value use IThemeService.getColorTheme().getColor(...)

  4. bpasero commented on Feb 28, 2023

    @bpasero
    Contributor

    As discussed in standup, tabs have quite an involved CSS ruling that involves not only colors but also other properties. I would like to keep it this way via registerThemingParticipant and not invent various class names to get a similar effect to make maintenance easier there.

  5. removed their assignment
    on Mar 1, 2023
  6. removed their assignment
    on Mar 1, 2023
  7. jrieken commented on May 9, 2023

    @jrieken
    ContributorAuthor

    Closing this as I believe we are done here

  8. locked and limited conversation to collaborators on Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debtperf-bloat

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions