-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.templ
69 lines (57 loc) · 1.03 KB
/
menu.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
package templdais
type MenuAttrs struct {
Size string
Responsive bool
Vertical bool
Items []MenuItem
Class string
}
func (m MenuAttrs) GetClass() string {
class := "menu"
if m.Size != "" {
class += " menu-" + m.Size
}
if m.Responsive {
class += " menu-vertical lg:menu-horizontal"
}
if m.Vertical {
class += " menu-vertical flex flex-nowrap flex-col"
} else {
class += " menu-horizontal"
}
if m.Class != "" {
class += " " + m.Class
}
return trimSpaces(class)
}
type MenuItem struct {
Text string
Link templ.SafeURL
Class string
Disabled bool
}
func (m MenuItem) GetClass() string {
class := ""
if m.Disabled {
class = "disabled"
}
if m.Class != "" {
class += " " + m.Class
}
return trimSpaces(class)
}
templ Menu(m MenuAttrs) {
<ul class={ m.GetClass() }>
for _, item := range m.Items {
<li class={ item.GetClass() }>
if item.Disabled {
<span>{ item.Text }</span>
} else {
<a
href={ item.Link }
>{ item.Text }</a>
}
</li>
}
</ul>
}