FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

support for tabs in BS4 by maelle · Pull Request #1694 · r-lib/pkgdown · GitHub

/ pkgdown Public

support for tabs in BS4 - #1694

Merged
maelle merged 29 commits into
masterfrom
taaabs
Jun 18, 2021
Merged

support for tabs in BS4#1694
maelle merged 29 commits into
masterfrom
taaabs

Conversation

maelle commented May 18, 2021

Copy link
Copy Markdown
Collaborator

Fix #1667

maelle commented May 18, 2021

Copy link
Copy Markdown
Collaborator Author

I wonder whether there'd be a way to make each tabset height fixed at the height of the highest tab.

Comment thread R/html-tweak.R
tablist_item <- function(tab, html, parent_id) {
id <- xml2::xml_attr(tab, "id")
text <- xml_text1(xml2::xml_child(tab))
ul_nav <- xml2::xml_find_first(html, sprintf("//ul[@id='%s']", parent_id))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I didn't think this would be needed as HTML here is supposed to be the tabset, but if I didn't use the ID, all tabs ended up in the first tabset when there were two tabsets.

maelle marked this pull request as ready for review May 19, 2021 11:25
maelle requested a review from hadley May 19, 2021 11:25
margin-top: -.5rem;
}

/* tabsets */

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Another tweak that might make sense would be more padding/margin at the top of tab content.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is there normally some styling around the content of the tabs? For the pills example in particular, it's hard to tell how the tab names are related to the content.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I added left and bottom borders for the pills example. Its color won't be hard-coded forever, since the blslib variables PR will prevent this kind of hard-coding.

Comment thread R/html-tweak.R Outdated
Comment thread R/html-tweak.R Outdated
Comment thread R/html-tweak.R Outdated
Comment thread R/html-tweak.R
Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
Comment thread R/html-tweak.R
xml2::xml_remove(container)
}

# Tabsets tweaking: find Markdown recommended in https://bookdown.org/yihui/rmarkdown-cookbook/html-tabs.html

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@cderv is this transformation something that you might consider hosting in an Rmd-adjacent package at some point in the future? Or do you think the xml2 based transformation is too foreign for the Rmd ecosystem?

cderv Jun 2, 2021
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We are currently discussing a bit tabset feature because of rstudio/rmarkdown#2054. We got input from @cpsievert that bslib will offer functions for creating navs / tabs UI (https://rstudio.github.io/bslib/reference/index.html#section-create-navs-and-navbars) and that we may be able to leverage that in some way in the future for rmarkdown.

Until now our direction for reworking tabset feature would be to use Lua filters rather than R directly. Also because Quarto has already a Lua filter for this (but using a fenced div syntax). But nothing is planned and started on this.

I think Lua filter would not help at all pkgdown usage currently, am I right ?

If we don't go the Lua filter road, then yes regarding xml2, I think it could be included in the Rmd ecosystem. it has no dependency and I feel we should use it more for some html post processing. But it is not already in the package tree for rmarkdown.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If users use bslib for creating navs, then the resulting divs should be protected i.e. not treated by pkgdown. The code in this PR recognizes future tabsets via the XPath query .//div[contains(@class, 'tabset')] which if I follow correctly would not pick up navs created by bslib. 🤔

maelle commented May 24, 2021
edited
Loading

Copy link
Copy Markdown
Collaborator Author

maelle requested a review from hadley May 24, 2021 08:30

maelle commented Jun 1, 2021

Copy link
Copy Markdown
Collaborator Author

I think tweaking HTML with xml2 is easier than using https://rstudio.github.io/bslib/reference/index.html#section-create-navs-and-navbars, given what we start from. (but still wanted to make a note of the existence of those functions)

Comment thread R/html-tweak.R
xml2::xml_remove(container)
}

# Tabsets tweaking: find Markdown recommended in https://bookdown.org/yihui/rmarkdown-cookbook/html-tabs.html

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@cderv is this transformation something that you might consider hosting in an Rmd-adjacent package at some point in the future? Or do you think the xml2 based transformation is too foreign for the Rmd ecosystem?

Comment thread R/html-tweak.R Outdated
Comment thread R/html-tweak.R Outdated
Comment thread R/html-tweak.R Outdated
margin-top: -.5rem;
}

/* tabsets */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is there normally some styling around the content of the tabs? For the pills example in particular, it's hard to tell how the tab names are related to the content.

maelle commented Jun 3, 2021

Copy link
Copy Markdown
Collaborator Author

Note from the PR linked by @cderv: in R Markdown you can have nav dropdowns but it's not documented, therefore I won't support it in this PR. 😇

cderv commented Jun 3, 2021

Copy link
Copy Markdown
Contributor

in R Markdown you can have nav dropdowns but it's not documented

Correct. This is a special feature to turn tabs in a dropdown menu instead. And there is suggestion to make it more like Bootstrap dropdowns with tabs / navs: rstudio/rmarkdown#2054

maelle commented Jun 3, 2021

Copy link
Copy Markdown
Collaborator Author

Regarding the fading effect: if I remove the dependencies created by bslib and add Bootstrap via a CDN instead, I can see the fading effect. It's as if something were missing from the bslib JS? When I click on the tabs, the "fade" class disappears (and the "show" class isn't added).

Comment thread NEWS.md
maelle requested a review from hadley June 3, 2021 12:26
maelle marked this pull request as draft June 3, 2021 16:53
maelle marked this pull request as ready for review June 4, 2021 06:15

maelle commented Jun 4, 2021

Copy link
Copy Markdown
Collaborator Author

As a side-note, because the Netlify preview isn't a direct Netlify-GitHub integration, we don't get to use the fancy new Netlify preview tools. 😭 (How nice would screenshots be!)

<h3 class="hasAnchor">
<a href="#tab-1" class="anchor" aria-hidden="true"></a>Tab 1</h3>
<p>blablablabla</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is it important to have source code in here? Otherwise it would be better to keep the test as short and simple as possible.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I can't find of another solution right now #1725 (comment)

Comment thread R/html-tweak.R
Comment thread R/html-tweak.R
# no matter the heading level -- the headings one level down are the tabs
# and transform to tabsets HTML a la Bootstrap

tweak_tabsets <- function(html) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I wonder if it's time to start breaking this file up into smaller pieces?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Oh no, it was my favorite R script in pkgdown 😢 More seriously: #1725

maelle changed the title work on tabs support for tabs in BS4 Jun 18, 2021
maelle merged commit 51268b0 into master Jun 18, 2021
maelle deleted the taaabs branch June 18, 2021 12:31
jonkeane mentioned this pull request Nov 9, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to put content in tabs?

3 participants


Back | FazBrowse Home | New Git URL