This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.templ
71 lines (58 loc) · 1.44 KB
/
button.templ
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
package franken
import "fmt"
type ButtonType string
const (
ButtonTypeDefault ButtonType = "button"
ButtonTypeSubmit ButtonType = "submit"
)
type ButtonData struct {
Text string
Type ButtonType
Color FrankenColor
Disabled bool
Link string
Class []string
}
templ Button(data ButtonData) {
if data.Link != "" {
<a href={ templ.URL(data.Link) }>
<button disabled?={ data.Disabled } type={ string(data.Type) } class={ templ.Classes("uk-button", fmt.Sprint("uk-button-"+data.Color), data.Class) }>{ data.Text }</button>
</a>
} else {
<button disabled?={ data.Disabled } type={ string(data.Type) } class={ templ.Classes("uk-button", fmt.Sprint("uk-button-"+data.Color), data.Class) }>{ data.Text }</button>
}
}
func ButtonBuilder() *ButtonData {
return &ButtonData{
Text: "Button",
Type: ButtonTypeDefault,
Disabled: false,
}
}
func (b *ButtonData) SetText(text string) *ButtonData {
b.Text = text
return b
}
func (b *ButtonData) SetType(bType ButtonType) *ButtonData {
b.Type = bType
return b
}
func (b *ButtonData) SetColor(bColor FrankenColor) *ButtonData {
b.Color = bColor
return b
}
func (b *ButtonData) SetDisabled(disabled bool) *ButtonData {
b.Disabled = disabled
return b
}
func (b *ButtonData) SetLink(link string) *ButtonData {
b.Link = link
return b
}
func (b *ButtonData) SetClass(class ...string) *ButtonData {
b.Class = class
return b
}
templ (b ButtonData) Finish() {
@Button(b)
}