-
Notifications
You must be signed in to change notification settings - Fork 324
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: add optional extra_classes
in version-switcher
#576
Conversation
Failure in CI seems unrelated. |
This is different from what I was expecting, which was that the extra classes get added to the parent node (the drop-down button, not the individual entries). It will require checking whether the version in |
I thought about the same and the reason I did it like this for now is that I was not sure if there might be other things people would want to do with this feature. You could add different markers, or shades, hide some elements based on some other context, etc. I can move the block to the active only section so that it only applies there. @larsoner @jorisvandenbossche what do you think? |
I was also assuming this was about the dropdown "button", not entries. See also my comment at scipy/scipy#15380 (comment) If we all initially thought about a class for the button, then I would propose to first tackle that. We can still later see if there is demand for classes in the dropdown entries, but I would personally wait until there are actual use cases. |
1bc50f3
to
e98bd62
Compare
I updated the PR to only apply the classes when an element is active. |
// Add extra class to the entry | ||
if ("extra_classes" in entry) { | ||
$.each(entry.extra_classes, function(index, extra_class) { | ||
node.classList.add(extra_class); |
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 is still adding the class to the entry link, I think? (although now only to the active version)
if I understand correctly, the current code will add the class in the html (as it is after being generated with the javascript, simplified a bit for explanation purposes) where I labeled it "HERE" (so in the first <a>
node):
<div class="dropdown show" id="version_switcher">
<button type="button" class="..." id="version_switcher_button" ...>
0.8.0 <span class="caret"></span>
</button>
<div id="version_switcher_menu" class="dropdown-menu ..." ...>
<a class="list-group-item ... HERE" href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.1/index.html">v0.8.0 (stable)</a>
<a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.1/index.html">v0.7.1</a>
<a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.0/index.html" >0.7.0</a >
...
</div>
</div>
While my understanding is that we want to be able to color the dropdown button, so have it instead at this location:
<div class="dropdown show" id="version_switcher">
<button type="button" class="... HERE" id="version_switcher_button" ...>
0.8.0 <span class="caret"></span>
</button>
<div id="version_switcher_menu" class="dropdown-menu ..." ...>
<a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.1/index.html">v0.8.0 (stable)</a>
<a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.1/index.html">v0.7.1</a>
<a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.0/index.html" >0.7.0</a >
...
</div>
</div>
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.
ah ok I see. I move the code to version_switcher_button
.
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 changes are in. Can you have another look @jorisvandenbossche?
8b5f2bb
to
f168b98
Compare
f168b98
to
c50de2d
Compare
+1, but wondering if we should showcase this on our site...
Related to #574 |
@damianavila do you prefer that I copy this phrasing over what I put now in the doc?
EDIT: ok understood what you meant 😅 The demo site should show this. |
Ideally yes, but I think that will require #574 to first be merged |
@jorisvandenbossche If this PR goes in first, you can showcase the behaviour in #574 |
@drammock @jorisvandenbossche @damianavila can you please take another look? |
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 - just one quick comment in there in case people give a string, but this looks good to me when that is resolved
@@ -72,6 +72,12 @@ | |||
if (entry.version == "{{ theme_switcher.get('version_match') }}") { | |||
node.classList.add("active"); | |||
$("#version_switcher_button").text(entry.name); | |||
// Add extra class to the button for the selected entry | |||
if ("extra_classes" in entry) { | |||
$.each(entry.extra_classes, function(index, extra_class) { |
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.
Personally I would not add complexity here. But I can make the change if you want.
I think the suggestion is not correct as the type check should happen before iterating on the list of classes. (But I am really a novice on JS so I could be missing something as well)
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.
OK sounds good, let me re-work this so it's a one-liner then
@@ -72,6 +72,12 @@ | |||
if (entry.version == "{{ theme_switcher.get('version_match') }}") { | |||
node.classList.add("active"); | |||
$("#version_switcher_button").text(entry.name); | |||
// Add extra class to the button for the selected entry | |||
if ("extra_classes" in entry) { | |||
$.each(entry.extra_classes, function(index, extra_class) { |
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.
Personally I would not add complexity here. But I can make the change if you want.
I think the suggestion is not correct as the type check should happen before iterating on the list of classes. (But I am really a novice on JS so I could be missing something as well)
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html
Outdated
Show resolved
Hide resolved
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.
OK I added in a quick one-liner replacement to make it simpler.
I'm OK merging this in unless anybody else objects. But I'll note that I don't feel good about merging in a PR that we cannot test in our test suite, and that we cannot demo in our demo documentation. :-/
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html
Outdated
Show resolved
Hide resolved
…ersion-switcher.html Co-authored-by: Chris Holdgraf <choldgraf@gmail.com>
Thanks for reviewing @choldgraf.
I guess you (I am not sure I would know what to do but I can try 😅) can update your PR #584 when this goes in. Also when this is in, #574 can be updated to reflect the last 2 PRs. |
I resolved the conflicts. Had a quick look at the test you added @choldgraf but I don't understand how to adjust it for this PR (if I can since you added a note about not testing the JS). |
Let's just merge this in, and add tests in the future once we figure out the right infrastructure. Maybe @jorisvandenbossche would be willing to add in some "extra classes" in #574 to test this out, and we can make a patch PR if something isn't working as expected. |
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 @tupui for the improvement!
Sounds good, thanks 😃 !! Can't wait for the next release to use this. |
Closes #566
Allow to specify additional classes per version in switcher.json.
Right now it adds the classes for all the versions. So a user might want to combine this with
"active"
if it's purely for styling otherwise it could make a Christmas tree in the dropdown. I could move the logic into the version check, but I was not sure if there was other use cases this could be used for.