ukgovdatascience / govdown

GOV.UK Design System theme for R Markdown
https://ukgovdatascience.github.io/govdown/
Other
46 stars 5 forks source link

Implement tabs #9

Closed TimTaylor closed 5 years ago

TimTaylor commented 5 years ago

In Rmarkdown I often use the .tabset attributes with headers when to break the content up (particularly when you want multiple graphs available but not all visible at once). These seem to be implemented as tabs in the Design System as an experimental feature so it would be good if they good be included here. https://design-system.service.gov.uk/components/tabs/

nacnudus commented 5 years ago

Thanks @tjtnew.

R Markdown uses a class on a header

## Quarterly Results {.tabset}

### By Product

(tab content)

### By Region

(tab content)

image

But that would be very tricky to implement because headers aren't nested, and blocks are processed breadth-first. We'd have to have some finnicky way to work out when the tabset had been escaped by a higher-level header. Also, it requires a higher-level header to close the tabset.

Fenced-divs are probably the way to go, again.

::: {.tabset}
# Header

## Tab header 1

Tab content A

## Tab header n

Tab content B
:::

Would become something like

<div class="govuk-tabs" data-module="tabs">

  <h2 class="govuk-tabs__title">
    Header
  </h2>

  <ul class="govuk-tabs__list">
    <li class="govuk-tabs__list-item">
      <a class="govuk-tabs__tab govuk-tabs__tab--selected" href="#tab-header-1">
        Tab header 1
      </a>
    </li>
    <li class="govuk-tabs__list-item">
      <a class="govuk-tabs__tab" href="#tab-header-2">
        Tab header 2
      </a>
    </li>
  </ul>

  <section class="govuk-tabs__panel" id="tab-header1">
    <h2 class="govuk-heading-l">Tab content A</h2>
  </section>

  <section class="govuk-tabs__panel" id="tab-header2">
    <h2 class="govuk-heading-l">Tab content B</h2>
  </section>

</div>

To Google: convert tab title strings to #tab-title-strings in Lua.