1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
package home
import "github.com/grindlemire/gothem-stack/web/components/page"
templ Page() {
@page.Base("home") {
<div class="flex items-center justify-center min-h-screen">
<div class="card w-94 bg-base-100 shadow-xl">
<div class="card-body">
<h2 class="card-title">Generate Random Strings using an HTMX call:</h2>
<div class="card-actions justify-center">
<button
class="btn btn-primary"
hx-get="/random-string"
hx-target="#random-string"
hx-swap="outerHTML swap:300ms"
hx-indicator="#loading-spinner"
_="on click
add .opacity-0 to #random-string
wait 150ms
set #random-string.innerHTML to ''"
>
Generate
</button>
</div>
<div class="relative">
<div
id="random-string"
class="h-8 flex items-center justify-center pt-4 whitespace-nowrap transition-opacity duration-300 ease-in-out"
></div>
<div
id="loading-spinner"
class="htmx-indicator loading loading-spinner loading-md absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 opacity-0 transition-opacity duration-300 ease-in-out"
></div>
</div>
<!-- Alpine.js Counter Example -->
<div class="mt-8 border-t pt-4" x-data="{ count: 0 }">
<h3 class="text-lg font-semibold mb-4">Alpine.js Counter:</h3>
<div class="flex flex-col items-center gap-4">
<div class="text-2xl font-bold" x-text="count"></div>
<div class="flex gap-2">
<button
class="btn btn-sm"
x-on:click="count--"
>
Decrease
</button>
<button
class="btn btn-sm btn-primary"
x-on:click="count++"
>
Increase
</button>
</div>
<!-- Theme Toggle -->
<div class="form-control">
<label class="label cursor-pointer gap-2">
<span class="label-text">Dark Mode</span>
<input
type="checkbox"
class="toggle"
x-model="isDark"
/>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
}
}
templ RandomString(s string) {
<div
id="random-string"
class="h-8 flex items-center justify-center pt-4 whitespace-nowrap text-lg transition-opacity duration-300 ease-in-out"
_="on load wait 10ms then add .opacity-100"
>
GS2-{ s }
</div>
}
|