Monorepo for Tangled
tangled.org
1{{ define "repo/fragments/diffOpts" }}
2 {{ $active := "unified" }}
3 {{ if .Split }}
4 {{ $active = "split" }}
5 {{ end }}
6
7 {{ $usePost := ne .RefreshUrl "" }}
8 {{ $target := .Target }}
9 {{ if eq $target "" }}{{ $target = "#diff-files" }}{{ end }}
10 {{ $field := .Field }}
11 {{ if eq $field "" }}{{ $field = "diff" }}{{ end }}
12
13 <div class="btn-group"
14 hx-on::before-request="const t=event.target.closest('button');if(!t||t.classList.contains('active'))return event.preventDefault();this.querySelectorAll('button').forEach(b=>b.classList.toggle('active',b===t))">
15 <button
16 {{ if $usePost }}
17 hx-post="{{ .RefreshUrl }}"
18 hx-vals='{"{{ $field }}":"unified"}'
19 hx-include="closest form"
20 {{ else }}
21 hx-get="?{{ $field }}=unified"
22 hx-push-url="true"
23 {{ end }}
24 hx-target="{{ $target }}"
25 hx-select="{{ $target }}"
26 hx-swap="outerHTML"
27 hx-indicator="this"
28 class="group btn-group-item {{ if eq $active "unified" }}active{{ end }}">
29 {{ i "square-split-vertical" "size-4 inline group-[.htmx-request]:hidden" }}
30 {{ i "loader-circle" "size-4 animate-spin hidden group-[.htmx-request]:inline" }}
31 Unified
32 </button>
33 <button
34 {{ if $usePost }}
35 hx-post="{{ .RefreshUrl }}"
36 hx-vals='{"{{ $field }}":"split"}'
37 hx-include="closest form"
38 {{ else }}
39 hx-get="?{{ $field }}=split"
40 hx-push-url="true"
41 {{ end }}
42 hx-target="{{ $target }}"
43 hx-select="{{ $target }}"
44 hx-swap="outerHTML"
45 hx-indicator="this"
46 class="group btn-group-item {{ if eq $active "split" }}active{{ end }}">
47 {{ i "square-split-horizontal" "size-4 inline group-[.htmx-request]:hidden" }}
48 {{ i "loader-circle" "size-4 animate-spin hidden group-[.htmx-request]:inline" }}
49 Split
50 </button>
51 </div>
52{{ end }}