This repository was archived by the owner on Aug 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbutton.templ
More file actions
88 lines (79 loc) · 1.5 KB
/
button.templ
File metadata and controls
88 lines (79 loc) · 1.5 KB
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
83
84
85
86
87
88
package templdais
type ButtonAttrs struct {
Type string
Brand string
Figure string
Size string
Class string
Outline bool
Active bool
Link templ.SafeURL
Click templ.ComponentScript
}
func (btn ButtonAttrs) GetClassName() string {
var class = "btn " + getClassName(btn.Brand, btn.Figure, btn.Size, "btn")
if btn.Outline {
class += " btn-outline"
}
if btn.Active {
class += " btn-active"
}
if btn.Class != "" {
class += " " + btn.Class
}
return trimSpaces(class)
}
func (btn ButtonAttrs) SetActive() ButtonAttrs {
newBtn := ButtonAttrs{
Type: btn.Type,
Brand: btn.Brand,
Figure: btn.Figure,
Size: btn.Size,
Outline: btn.Outline,
Active: true,
Link: btn.Link,
}
return newBtn
}
func (btn ButtonAttrs) SetLink(link templ.SafeURL) ButtonAttrs {
newBtn := ButtonAttrs{
Type: btn.Type,
Brand: btn.Brand,
Figure: btn.Figure,
Size: btn.Size,
Outline: btn.Outline,
Active: btn.Active,
Link: link,
}
return newBtn
}
templ Button(btn ButtonAttrs, attrs templ.Attributes) {
switch btn.Type {
case "button":
<button
{ attrs... }
type="button"
class={ btn.GetClassName() }
onclick={ btn.Click }
>
{ children... }
</button>
case "anchor":
<a
{ attrs... }
href={ btn.Link }
class={ btn.GetClassName() }
>
{ children... }
</a>
default:
<button
{ attrs... }
type="button"
class={ btn.GetClassName() }
onclick={ btn.Click }
>
{ children... }
</button>
}
}