Skip to content

Commit 26fd428

Browse files
committed
dev: replace ids with data
1 parent 2eb353b commit 26fd428

File tree

7 files changed

+40
-65
lines changed

7 files changed

+40
-65
lines changed

docs/content/docs/formatters/_index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ golangci-lint formatters
2828
## All formatters
2929

3030
{{< golangci/items/filter >}}
31-
{{< golangci/items/clickable-badge class="gl-filter" id="new-filter" icon="fire" content="New" type="warning" >}}
32-
{{< golangci/items/clickable-badge class="gl-filter" id="deprecated-filter" icon="emoji-sad" content="Deprecated" type="info" >}}
33-
{{< golangci/items/clickable-badge class="gl-filter-reset gl-hidden" id="reset-filter" icon="trash" content="Reset" type="error" border=true >}}
31+
{{< golangci/items/filter-badge class="gl-filter" data="new" icon="fire" content="New" type="warning" >}}
32+
{{< golangci/items/filter-badge class="gl-filter" data="deprecated" icon="emoji-sad" content="Deprecated" type="info" >}}
33+
{{< golangci/items/filter-badge class="gl-filter-reset gl-hidden" icon="trash" content="Reset" type="error" border=true >}}
3434
{{< /golangci/items/filter >}}
3535

3636
{{< cards >}}

docs/content/docs/linters/_index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ golangci-lint linters
2828
## All Linters
2929

3030
{{< golangci/items/filter >}}
31-
{{< golangci/items/clickable-badge class="gl-filter" id="default-filter" icon="inbox" content="Default" type="info" >}}
32-
{{< golangci/items/clickable-badge class="gl-filter" id="new-filter" icon="fire" content="New" type="warning" >}}
33-
{{< golangci/items/clickable-badge class="gl-filter" id="autofix-filter" icon="sparkles" content="Autofix" type="info" >}}
34-
{{< golangci/items/clickable-badge class="gl-filter" id="fast-filter" icon="fast-forward" content="Fast" >}}
35-
{{< golangci/items/clickable-badge class="gl-filter" id="slow-filter" icon="play" content="Slow" >}}
36-
{{< golangci/items/clickable-badge class="gl-filter" id="deprecated-filter" icon="emoji-sad" content="Deprecated" type="info" >}}
37-
{{< golangci/items/clickable-badge class="gl-filter-reset gl-hidden" icon="trash" id="reset-filter" content="Reset" type="error" border=true >}}
31+
{{< golangci/items/filter-badge class="gl-filter" data="default" icon="inbox" content="Default" type="info" >}}
32+
{{< golangci/items/filter-badge class="gl-filter" data="new" icon="fire" content="New" type="warning" >}}
33+
{{< golangci/items/filter-badge class="gl-filter" data="autofix" icon="sparkles" content="Autofix" type="info" >}}
34+
{{< golangci/items/filter-badge class="gl-filter" data="fast" icon="fast-forward" content="Fast" >}}
35+
{{< golangci/items/filter-badge class="gl-filter" data="slow" icon="play" content="Slow" >}}
36+
{{< golangci/items/filter-badge class="gl-filter" data="deprecated" icon="emoji-sad" content="Deprecated" type="info" >}}
37+
{{< golangci/items/filter-badge class="gl-filter-reset gl-hidden" icon="trash" content="Reset" type="error" border=true >}}
3838
{{< /golangci/items/filter >}}
3939

4040
{{< cards >}}

docs/layouts/_partials/custom/head-end.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
let clean = event.currentTarget.classList.contains(borderClass)
2121

2222
document.querySelectorAll('.gl-item').forEach(element => element.classList.remove(hiddenClass));
23-
document.querySelectorAll('.gl-filter').forEach(element => element.classList.remove(borderClass));
23+
document.querySelectorAll('.gl-filter > *').forEach(element => element.classList.remove(borderClass));
2424

2525
if (clean) {
2626
resetButton.classList.add(hiddenClass);
@@ -29,26 +29,26 @@
2929

3030
document.querySelectorAll('.gl-filter').forEach(element => element.classList.remove(borderClass))
3131

32-
event.currentTarget.classList.add(borderClass);
32+
event.currentTarget.querySelector('*').classList.add(borderClass);
3333

3434
let selector = ''
35-
switch (event.currentTarget.id) {
36-
case 'default-filter':
35+
switch (event.currentTarget.dataset.badge) {
36+
case 'default':
3737
selector = '.gl-item:not(.gl-default)'
3838
break;
39-
case 'new-filter':
39+
case 'new':
4040
selector = '.gl-item:not(.gl-new)'
4141
break;
42-
case 'autofix-filter':
42+
case 'autofix':
4343
selector = '.gl-item:not(.gl-autofix)'
4444
break;
45-
case 'fast-filter':
45+
case 'fast':
4646
selector = '.gl-item:not(.gl-slow)'
4747
break;
48-
case 'slow-filter':
48+
case 'slow':
4949
selector = '.gl-item:not(.gl-fast)'
5050
break;
51-
case 'deprecated-filter':
51+
case 'deprecated':
5252
selector = '.gl-item:not(.gl-deprecated)'
5353
break;
5454
}
@@ -64,7 +64,7 @@
6464
event.currentTarget.classList.add(hiddenClass);
6565

6666
document.querySelectorAll('.gl-item').forEach(element => element.classList.remove(hiddenClass));
67-
document.querySelectorAll('.gl-filter').forEach(element => element.classList.remove(borderClass));
67+
document.querySelectorAll('.gl-filter > *').forEach(element => element.classList.remove(borderClass));
6868
});
6969
});
7070
</script>

docs/layouts/_partials/golangci/items/clickable-badge.html

Lines changed: 0 additions & 36 deletions
This file was deleted.

docs/layouts/_partials/shortcodes/badge.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{{- $class := .class | default "" -}}
77
{{- $border := .border | default false -}}
88
{{- $icon := .icon | default "" -}}
9+
{{- $data := .data | default "" -}}
910

1011
{{- $defaultClass := "hx:text-gray-600 hx:bg-gray-100 hx:dark:bg-neutral-800 hx:dark:text-neutral-200 hx:border-gray-200 hx:dark:border-neutral-700" -}}
1112

@@ -17,6 +18,7 @@
1718
{{- $borderClass := cond (eq $border true) "hx:border" "" -}}
1819
{{- $badgeClass := or ($styleClass.Get $type) $defaultClass -}}
1920

21+
{{- /* Custom section to handle icon-only badges. */ -}}
2022
{{- $iconOnly := hasPrefix $type "icon-only" -}}
2123
{{- if $iconOnly -}}
2224
{{- $icon = (strings.TrimPrefix "icon-only:" $type) -}}
@@ -25,7 +27,16 @@
2527
{{- $badgeClass = "hx:p-2" -}}
2628
{{- end -}}
2729

28-
<div class="hextra-badge {{ $class }}" {{- if $iconOnly -}}title="{{ $content }}"{{- end -}}>
30+
{{- /* Custom section to set attributes. */ -}}
31+
{{- $attributes := slice -}}
32+
{{- if $iconOnly -}}
33+
{{- $attributes = $attributes | append (printf `title="%s"` $content) -}}
34+
{{- end -}}
35+
{{- if $data -}}
36+
{{- $attributes = $attributes | append (printf `data-badge="%s"` $data) -}}
37+
{{- end -}}
38+
39+
<div class="hextra-badge {{ $class }}" {{ (delimit $attributes " ") | safeHTMLAttr }}>
2940
<div class="hx:inline-flex hx:gap-1 hx:items-center hx:rounded-full hx:px-2.5 hx:leading-6 hx:text-[.65rem] {{ $borderClass }} {{ $badgeClass }}">
3041
{{- with $icon -}}{{- partial "utils/icon" (dict "name" . "attributes" "height=12") -}}{{- end -}}
3142
{{- if not $iconOnly -}}{{- $content -}}{{- end -}}

docs/layouts/_shortcodes/golangci/items/clickable-badge.html renamed to docs/layouts/_shortcodes/golangci/items/filter-badge.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{{- /* Modified version of https://github.com/imfing/hextra/blob/v0.10.0/layouts/_shortcodes/badge.html */ -}}
22
{{- /*
3-
Creates a badge with the given id and class.
3+
Creates a badge with the given "data-filter" value.
44

55
@param {string} content The content of the badge.
66
@param {string} type The type of the badge.
7-
@param {string} id The id of the badge.
7+
@param {string} data The "data-filter" value for the badge.
88
@param {string} class The class of the badge.
99
@param {boolean} border Whether to render a border around the badge.
1010
@param {string} icon The icon of the badge.
1111

12-
@example {{< golangci/items/clickable-badge icon="inbox" id="my-id" content="Text" class="my-class" type="info" border=true >}}
12+
@example {{< golangci/items/filter-badge icon="inbox" data="my-data" content="Text" class="my-class" type="info" border=true >}}
1313
*/}}
1414

1515
{{- $content := .Get "content" -}}
1616
{{- $type := .Get "type" | default "" -}}
17-
{{- $id := .Get "id" | default "" -}}
17+
{{- $data := .Get "data" | default "" -}}
1818
{{- $class := .Get "class" | default "" -}}
1919
{{- $icon := .Get "icon" | default "" -}}
2020
{{- $border := .Get "border" | default false -}}
2121

22-
{{- partial "golangci/items/clickable-badge" (dict
23-
"id" $id
24-
"class" $class
22+
{{- partial "shortcodes/badge" (dict
23+
"data" $data
24+
"class" (printf "hx:mt-2 hx:mx-1 hx:cursor-pointer %s" $class)
2525
"content" $content
2626
"type" $type
2727
"border" $border

docs/layouts/_shortcodes/golangci/items/filter.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{- /*
22
This shortcode is used to create a filter bar.
33

4-
@example {{< golangci/items/filter >}}{{< golangci/items/clickable-badge content="Example">}}{{< golangci/items/filter >}}
4+
@example {{< golangci/items/filter >}}{{< golangci/items/filter-badge content="Example">}}{{< golangci/items/filter >}}
55
*/ -}}
66

77
<div class="hx:mt-6">

0 commit comments

Comments
 (0)