Skip to content

Commit 86eba41

Browse files
Copilothenryiiipre-commit-ci[bot]
authored
fix: support named tab groups for independent tab switching (#698)
* Initial plan * Implement named tab groups for independent tab functionality Co-authored-by: henryiii <[email protected]> * Remove vendor and .bundle from git, add to .gitignore Co-authored-by: henryiii <[email protected]> * style: pre-commit fixes --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: henryiii <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f0fe886 commit 86eba41

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ _readthedocs
161161

162162
# UV output
163163
/uv.lock
164+
165+
# Jekyll build artifacts
166+
vendor/
167+
.bundle/

docs/_plugins/tabs.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
module SP
44
# Sets up a tabs with top switcher bar
55
class Tabs < Liquid::Block
6+
def initialize(tag_name, markup, tokens)
7+
super
8+
@group = markup.strip.empty? ? 'default' : markup.strip
9+
end
10+
611
def render(context)
712
tab_bar_content = ''
813
context['tabs'] = []
14+
context['tab_group'] = @group
915
result = super
1016

1117
context['tabs'].each_with_index do |(label, title), index|
1218
res = index.zero? ? ' btn-purple' : ''
1319
tab_bar_content += <<~CONTENT
14-
<button class="skhep-bar-item #{label}-btn btn m-2#{res}" onclick="openTab('#{label}')">#{title}</button>
20+
<button class="skhep-bar-item #{@group}-#{label}-btn btn m-2#{res}" onclick="openTab('#{label}', '#{@group}')">#{title}</button>
1521
CONTENT
1622
end
1723

@@ -26,8 +32,14 @@ def render(context)
2632

2733
# Sets up tabs without the top switcher bar
2834
class TabBodies < Liquid::Block
35+
def initialize(tag_name, markup, tokens)
36+
super
37+
@group = markup.strip.empty? ? 'default' : markup.strip
38+
end
39+
2940
def render(context)
3041
context['tabs'] = []
42+
context['tab_group'] = @group
3143
super
3244
end
3345
end
@@ -42,10 +54,11 @@ def initialize(tag_name, markup, tokens)
4254
def render(context)
4355
raise SyntaxError, "'tab' be in 'tabs' or 'tabbodies'" unless context.key?('tabs')
4456

57+
group = context['tab_group'] || 'default'
4558
res = context['tabs'].empty? ? '' : ' style="display:none;"'
4659
context['tabs'] << [@label, @title]
4760
<<~RETURN
48-
<div class="skhep-tab #{@label}-tab" markdown="1"#{res}>
61+
<div class="skhep-tab #{group}-#{@label}-tab" markdown="1"#{res}>
4962
#{super}
5063
</div>
5164
RETURN

docs/assets/js/tabs.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
function openTab(tabName) {
1+
function openTab(tabName, groupName = "default") {
22
var tab = document.getElementsByClassName("skhep-tab");
33
for (const t of tab) {
4-
t.style.display = t.classList.contains(`${tabName}-tab`) ? "block" : "none";
4+
if (t.classList.contains(`${groupName}-${tabName}-tab`)) {
5+
t.style.display = "block";
6+
} else if (
7+
Array.from(t.classList).some(
8+
(c) => c.startsWith(`${groupName}-`) && c.endsWith("-tab"),
9+
)
10+
) {
11+
t.style.display = "none";
12+
}
513
}
614
var btn = document.getElementsByClassName("skhep-bar-item");
715
for (const b of btn) {
8-
if (b.classList.contains(`${tabName}-btn`)) b.classList.add("btn-purple");
9-
else b.classList.remove("btn-purple");
16+
if (b.classList.contains(`${groupName}-${tabName}-btn`)) {
17+
b.classList.add("btn-purple");
18+
} else if (
19+
Array.from(b.classList).some(
20+
(c) => c.startsWith(`${groupName}-`) && c.endsWith("-btn"),
21+
)
22+
) {
23+
b.classList.remove("btn-purple");
24+
}
1025
}
1126
}
1227
function ready() {

docs/pages/guides/style.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ There are a _few_ options, mostly to enable/disable certain files, remove string
102102
normalization, and to change the line length, and those go in your
103103
`pyproject.toml` file.
104104

105-
{% tabs %} {% tab ruff Ruff-format %}
105+
{% tabs formatters %} {% tab ruff Ruff-format %}
106106

107107
Ruff, the powerful Rust-based linter, has a formatter that is designed with the
108108
help of some of the Black authors to look 99.9% like Black, but run 30x faster.
@@ -214,7 +214,7 @@ won't tell you what or why it fixed things.
214214

215215
{% rr RF001 %} Ruff is configured in your `pyproject.toml`. Here's an example:
216216

217-
{% tabs %} {% tab ruff-simple Simple config %}
217+
{% tabs ruff-config %} {% tab ruff-simple Simple config %}
218218

219219
```toml
220220
[tool.ruff.lint]

0 commit comments

Comments
 (0)