-
Notifications
You must be signed in to change notification settings - Fork 297
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
ENH: Simplify theme variable code and support Sphinx Design #746
Conversation
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.
This looks good in general! I have a quick comments in there about how to structure the implementation etc, but the end-result looks very nice!
|
||
html[data-theme="light"], | ||
html[data-theme="dark"] { | ||
@each $name in $sd-semantic-color-names { |
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 SCSS magic is strong with you ✨
Can you add a link to the SCSS docs that explain how @each
works? I think many developers won't be familiar with it so it will be helpful to have breadcrumbs to help them learn quickly if they hit this code
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.
Can you add a link to the SCSS docs that explain how
@each
works?
done
--pst-color-#{$name}-text: #{text-color($value)}; | ||
--pst-color-#{$name}-highlight: #{mix(#000, $value, 15%)}; | ||
} | ||
/* ↓↓↓ these are not sphinx-design overrides ↓↓↓ */ |
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.
Hmm, I am worried about intermixing "special casing" CSS with "default CSS" in one place, I feel like this could be confusing given that Sphinx Design is not bundled with the theme.
Is there a way that we can cleanly separate the two so that one section is entirely "just this theme" and another section is clearly "sphinx design", or even better if we can put the sphinx design stuff just in the extensions/
folder?
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 am worried about intermixing "special casing" CSS with "default CSS"
I tried and failed to keep them separate yesterday. Today I did better; this is now fixed.
--pst-color-text-base: rgb(201, 209, 217); | ||
--pst-color-text-muted: rgb(192, 192, 192); | ||
--pst-color-border: rgb(192, 192, 192); | ||
$pst-semantic-colors: ( |
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.
Could we somehow make this a dictionary-like object at the top of the file, with [light]
and [dark]
keys? Then we can access the colors via those keys in our SCSS logic below? Might make it easier to keep everything in one place.
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.
Could we somehow make this a dictionary-like object at the top of the file, with
[light]
and[dark]
keys?
done
* main colors | ||
* main colors. the $pst-semantic-colors follow the naming convention in | ||
* sphinx-design, to allow for color overrides in | ||
* ../extensions/_sphinx_design.scss. NOTE: some of these colors (most notably |
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.
See my other point about intermixing sphinx-design and theme-specific colors, but if we're going to do it this way, can we be remove the uncertainty here? E.g., not "some of these colors", but instead list the specific colors this statement applies to. And remove the "probably", we should be precise and explicit because others without context will have a hard time reasoning what is a sphinx-design thing and what's a theme thing, as well as the implications of using those variables in the theme in general.
Sorry for being a stickler on this, but we recently spent a lot of effort trying to reduce our surface area of variables that are exposed to devs and to users, so just trying to make sure we stick with those goals :-)
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.
can we remove the uncertainty here?
This point is now moot; all colors needed for sphinx-design overrides are now only in extensions/_sphinx_design.scss
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 think I've addressed all your comments @choldgraf, and the local nox -s docs-live
looks good to me. See what you think!
--pst-color-text-base: rgb(201, 209, 217); | ||
--pst-color-text-muted: rgb(192, 192, 192); | ||
--pst-color-border: rgb(192, 192, 192); | ||
$pst-semantic-colors: ( |
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.
Could we somehow make this a dictionary-like object at the top of the file, with
[light]
and[dark]
keys?
done
--pst-color-#{$name}-text: #{text-color($value)}; | ||
--pst-color-#{$name}-highlight: #{mix(#000, $value, 15%)}; | ||
} | ||
/* ↓↓↓ these are not sphinx-design overrides ↓↓↓ */ |
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 am worried about intermixing "special casing" CSS with "default CSS"
I tried and failed to keep them separate yesterday. Today I did better; this is now fixed.
* main colors | ||
* main colors. the $pst-semantic-colors follow the naming convention in | ||
* sphinx-design, to allow for color overrides in | ||
* ../extensions/_sphinx_design.scss. NOTE: some of these colors (most notably |
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.
can we remove the uncertainty here?
This point is now moot; all colors needed for sphinx-design overrides are now only in extensions/_sphinx_design.scss
|
||
html[data-theme="light"], | ||
html[data-theme="dark"] { | ||
@each $name in $sd-semantic-color-names { |
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.
Can you add a link to the SCSS docs that explain how
@each
works?
done
…n.scss Co-authored-by: Chris Holdgraf <choldgraf@gmail.com>
9996d6e
to
47bb4eb
Compare
The failing test is "no unexpected sphinx warnings", and it's complaining because sphinx/pygments can't lex the SCSS file. This is apparently a known bug I pasted the content of |
One easy solution is to not embed the entire |
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 had no idea that SCSS could do all of this stuff, it is basically like python! :-)
The implementation looks good to me (a few quick comments in there). The tests seem to be failing because Sphinx doesn't know how to parse the SCSS, I think in the docs here:
Those docs are actually probably out of date now anyway, because the color variables are structured differently than they used to be...can you think of a way to have the same effect with this new structure? Doesn't need to be the exact same, but should be useful at helping others understand the variable structure and how to change them.
Here's the rendered page:
https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/customizing.html#color-variables
src/pydata_sphinx_theme/assets/styles/extensions/_sphinx_design.scss
Outdated
Show resolved
Hide resolved
oops just saw your extra comments - I'd be +1 on:
|
done
I think this is pretty clear now because we point them to
done. |
Ahh I bet what's going on with sphinx design is that our variables are defined first, and later the sphinx design variables are defined, effectively overriding them. Can we think of a quick way to make our variable definitions load after all the extensions, but before the user supplied custom CSS file? If that'd be complicated i agree we should just go with the current implementation |
I'm not certain but I think it's the opposite: sphinx-design's style sheet is evaluated first, in a context in which our re-definition of their variables hasn't happened yet, and the value of those variables gets "frozen" into the rules. I think this SO answer backs that up, though the use case is a little different: https://stackoverflow.com/a/52015817 it's a really long answer, so I'll excerpt here two things that sum it up:
If that's applicable here, I think there is actually no way to override CSS variables in I would love to be wrong about this, but I'm really bumping up against the limits of my understanding of the CSS cascade. Maybe someone else will recognize what I've done as an anti-pattern an fix it in a later PR :) |
...aaand, I'm totally wrong. Pushing a fix that eliminates the rule-rewriting, and everything seems to still look correct. 🤷🏻 |
CI failure looks like a fluke:
can someone with permissions re-run that one job? |
ok, all green except for the macOS job which was cancelled (?) so I think this one is ready! |
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.
Thanks @drammock for this PR!
I didn't had the time to check it but that was nice reading your exchange. Appart from the few comments I made I'm very satisfied with this final version. it works as expected and ensure that the theme remains a nice neighbour.
@choldgraf I started to play with sass in the PR on sidebar display and I think there's a lot of refactoring to make in our files (but that will be for another PR)
@12rambau I think I've addressed your comments. It helped catch something I had missed, which was that previously downstream users overriding Here's the doc section, still looking good: and CIs are all green. |
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.
LGTM
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.
This looks good to me as well, I really like the conciseness of the SCSS rules, many thanks for stepping through all this work @drammock 🚀
closes #733
@12rambau note that even though these override rules ought to be "more specific" because they're nested inside html data themes, I still needed to add
!important
to get them to actually override the sphinx-design rules.LMK if anything looks weird / anything got missed.