Skip to content

Extract common CSS vars#14349

Merged
gabalafou merged 28 commits into
branch-3.8from
gabalafou/css-vars-tabs
May 5, 2025
Merged

Extract common CSS vars#14349
gabalafou merged 28 commits into
branch-3.8from
gabalafou/css-vars-tabs

Conversation

@gabalafou

@gabalafou gabalafou commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

Closes #14177

@gabalafou gabalafou added status: WIP grant: CZI R6 Funded by CZI Round 6 grant labels Feb 19, 2025
@mattpap mattpap added this to the 3.8 milestone Feb 19, 2025
@mattpap mattpap modified the milestones: 3.8, 3.9 Mar 7, 2025
@mattpap mattpap changed the base branch from branch-3.7 to branch-3.8 March 7, 2025 07:55
@gabalafou gabalafou force-pushed the gabalafou/css-vars-tabs branch from ef97781 to 1661ab5 Compare March 19, 2025 15:33
@gabalafou gabalafou marked this pull request as draft March 19, 2025 15:34
@gabalafou gabalafou changed the title Tabs CSS vars CSS vars Mar 25, 2025
// attribution is also dark. Not sure what to do about this. Any thoughts?
background-color: rgba(255, 255, 255, 0.5);
font-size: 9px;
font-size: 0.5625rem; // 9px if base font is 16px

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to configure this as a percentage of the base font?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How would I do that?

If I set this to:

font-size: 56.25%;

I believe that means 56.25% of the font size of the element's parent. And the element's parent may have a different font size than the base font, right? So we need to use rem to specify this as a percentage of the base font, unless I'm misunderstanding something.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose both approaches are valid in certain applications and as long as used consistently. However, given that we indeed define everything in terms of the base font size, then perhaps it would be better to use rem units.

Comment thread bokehjs/src/less/attribution.less Outdated
// @mattpap: So I think the 0.5 alpha value is to help this look good no
// matter what background color is used for the data viz, but this creates
// contrast issues when the background is dark, and text color of the
// attribution is also dark. Not sure what to do about this. Any thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Alpha is there to make it see through, so that the annotation doesn't obscure the underlying content too much. I'm not sure what's the best practice to improve contrast issues.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I understand why the alpha value is there. I'm just pointing out that it creates the potential for contrast issues that I'm not sure how to solve.

I wonder if there's a better way to implement attributions - specifically drawing it outside of the plot coordinates. I suppose that part of the point of having attribution happen within the plot coordinates is that it becomes more likely to be included if somebody tries to screenshot just the plot and then shares the screenshot — i.e., it's can function like a watermark for the plot.

I can also look into ways to solve this without changing the placement of attributions — maybe text-shadow will solve the contrast issues - not sure, I'll have to investigate.

Comment thread bokehjs/src/less/buttons.less Outdated
Comment on lines 17 to 19
// @mattpap - I don't really like this style of inset focus ring
// but I guess this should be tackled in a separate PR?
outline-offset: -5px;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, as we discussed in the meeting. In fact, please start an issue for this, so that we have a place to discuss possible improvements.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread bokehjs/src/less/dialogs.less Outdated
// to something with better contrast against the lightgray
// background color of the dialog header bar. Should we just
// change it now?
--bokeh-ctrl-color: var(--color);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would wait with this this for #14415.

Comment thread bokehjs/src/less/dropdown.less Outdated
// rather than use lighten/darken functions because in light
// mode we would need to darken but in dark mode we would need
// to lighten (I think)
background-color: darken(var(--background-color), 10%);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also we can mix CSS variables with Less functions:

RuntimeError: Error evaluating function `darken`: Argument cannot be evaluated to a color in /home/runner/work/bokeh/bokeh/bokehjs/src/less/dropdown.less on line 42, column 25:
41       // to lighten (I think)
42       background-color: darken(var(--background-color), 10%);
43     }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We may be able to use color-mix() CSS function to replace lighten() and darken(), but even then it would be good to define lighter/darker variants somewhere. However, it looks like #14415 provides enough shades to cover these cases.

Comment thread bokehjs/src/less/tabs.less Outdated
--block-start-border-width: 3px;

--close-icon-hover-background-color: var(--error);
// Should these dimensions be px or rem?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For now we should keep pixels, but eventually replace them with relative units. Can you start an issue for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread bokehjs/src/less/panels.less Outdated
position: absolute;
background-color: white;
background-color: var(--background-color);
// @matpapp - why are these commented out?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should have been removed. Originally Panel was meant to be one thing, but ended up being a different kind of component, for which setting default borders and padding doesn't make sense.

Comment thread bokehjs/src/less/pretty.less Outdated
Comment on lines 1 to 6
// @mattpap - these colors should probably be parameterized
// but I think this is pretty much only used by the examiner,
// so maybe not high enough priority to fix?
.bk-nullish { color: #7724c1; }
.bk-token { color: #881280; }
.bk-boolean { color: #007500; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can leave them out for now. These are specific to pretty printing models, properties and values, used primarily in examiner component for the time being.

Comment on lines -149 to +157
background-color: #5f6368;
// @mattpap - same here, we might need something like "muted color"
background-color: var(--muted-color);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That should probably be just icon color. Looking at the following lines, this may predate SVG images, so I will definitely want this to get migrated to use icons, so everything else, including relevant colors, will be inherited.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That creates low contrast with the background (2.5:1), so I'd rather not change it to match --icon-color.

Comment thread bokehjs/src/less/examiner.less Outdated
Comment on lines +145 to +149
// @mattpap - I couldn't find a good substitute for this color from the colors
// already defined in base.less. We might need something like "muted
// background color"
background-color: var(--muted-bg-color);
border-color: var(--border-color);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should use the "default" gray (like of widgets' background). The muted appearance comes from opacity: 0.6 for non-dirty properties and if dirty it reverts to 1.0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.prop > * {
  opacity: 0.6;
}
.prop.dirty > * {
  opacity: 1.0;
}

@gabalafou gabalafou left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done self-reviewing.

@mattpap, I think I addressed all of your comments and concerns, this is ready for another round of review.

// attribution is also dark. Not sure what to do about this. Any thoughts?
background-color: rgba(255, 255, 255, 0.5);
font-size: 9px;
font-size: 0.5625rem; // 9px if base font is 16px

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How would I do that?

If I set this to:

font-size: 56.25%;

I believe that means 56.25% of the font size of the element's parent. And the element's parent may have a different font size than the base font, right? So we need to use rem to specify this as a percentage of the base font, unless I'm misunderstanding something.

Comment thread bokehjs/src/less/buttons.less Outdated
Comment on lines 17 to 19
// @mattpap - I don't really like this style of inset focus ring
// but I guess this should be tackled in a separate PR?
outline-offset: -5px;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread bokehjs/src/less/tabs.less Outdated
--block-start-border-width: 3px;

--close-icon-hover-background-color: var(--error);
// Should these dimensions be px or rem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread bokehjs/src/less/attribution.less Outdated
// @mattpap: So I think the 0.5 alpha value is to help this look good no
// matter what background color is used for the data viz, but this creates
// contrast issues when the background is dark, and text color of the
// attribution is also dark. Not sure what to do about this. Any thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I understand why the alpha value is there. I'm just pointing out that it creates the potential for contrast issues that I'm not sure how to solve.

I wonder if there's a better way to implement attributions - specifically drawing it outside of the plot coordinates. I suppose that part of the point of having attribution happen within the plot coordinates is that it becomes more likely to be included if somebody tries to screenshot just the plot and then shares the screenshot — i.e., it's can function like a watermark for the plot.

I can also look into ways to solve this without changing the placement of attributions — maybe text-shadow will solve the contrast issues - not sure, I'll have to investigate.

Comment thread bokehjs/src/less/base.less Outdated

--bokeh-top-level: 10000; // used for z-index of menus, dropdowns, etc.

--color: #2f2f2f;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got this off-black color from tooltip text. Eventually, will pull in the gray-900 from #14415.

In this PR, everywhere that was using pure black for text color, I replace with this off-black via var(--color).

Comment thread bokehjs/src/less/base.less Outdated
--disabled-background-color: #eee;

--input-focus-border-color: #66afe9; // rgb(102, 175, 233)
--input-focus-halo-color: rgba(102, 175, 233, 0.6); // fade(#66afe9, 60%)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The set of variables in this file (base.less) is almost exhaustive with respect to this PR but not quite. In particular, in buttons.less and tables.less, there are a number of variables defined in those two files that I chose not to hoist up to this file for now.

The way I see it, in the next PR, I will define all of the colors from #14415 in base.less and use them in buttons.less and other places.

gap: 1em;
padding: 5px;
background-color: lightgray;
background-color: var(--border-color);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As I review my own code, I notice that it looks odd to to set background-color to var(--border-color). However, one could think of the dialog header as a very thick border. But maybe this should be hoisted up at least to the top of the file (as --bokeh-header-bg-color), maybe to base.less. What do you think?

Comment thread bokehjs/src/less/tabs.less Outdated
--block-start-border-width: 3px;

--close-icon-hover-background-color: var(--error);
// Should these dimensions be px or rem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gabalafou gabalafou marked this pull request as ready for review April 7, 2025 20:28
@mattpap

mattpap commented Apr 16, 2025

Copy link
Copy Markdown
Contributor

Baseline changes are limited in scope and trivial. There's one thing, however, that I don't like, which are inner shadows in buttons:

  • old
    image
  • new
    image
    My preference is to keep the original or closer to it.

@mattpap

mattpap commented Apr 16, 2025

Copy link
Copy Markdown
Contributor

This looks good. It doesn't seem to be breaking anything. Baseline changes are trivial (need updating).

@gabalafou gabalafou changed the title CSS vars Extract common CSS vars Apr 23, 2025
@gabalafou

gabalafou commented Apr 23, 2025

Copy link
Copy Markdown
Contributor Author

I updated all of the image snapshots and removed all of the "@mattpap" comments or replaced them with "TODO" comments.

@gabalafou gabalafou mentioned this pull request Apr 23, 2025
3 tasks
@mattpap mattpap modified the milestones: 3.9, 3.8 Apr 27, 2025

@mattpap mattpap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good as the first iteration. No major changes in baseline images.

@gabalafou

Copy link
Copy Markdown
Contributor Author

Thanks @mattpap I'll merge this into branch-3.8 after the sync on Wednesday

@mattpap

mattpap commented Apr 28, 2025

Copy link
Copy Markdown
Contributor

I'll merge this into branch-3.8 after the sync on Wednesday.

That's a good idea. I was going to suggest anyway, to not merge immediately and give other time to process this, especially given that this was marked as ready not too long ago. I would suggest to mark PRs as ready as soon as you don't intend to include any major changes (e.g. I often mark as ready before I add tests, though I state that in the PR).

@gabalafou gabalafou merged commit be6a7a7 into branch-3.8 May 5, 2025
@gabalafou gabalafou deleted the gabalafou/css-vars-tabs branch May 5, 2025 13:55
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

grant: CZI R6 Funded by CZI Round 6 grant status: accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define the initial set of common CSS variables

2 participants