-
Notifications
You must be signed in to change notification settings - Fork 1
/
dropdown.templ
45 lines (39 loc) · 988 Bytes
/
dropdown.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
package templdais
type DropdownAttrs struct {
Position string
Items []Links
End bool
Hover bool
Class string
BtnBrand string
BtnSize string
}
func (attrs *DropdownAttrs) GetClassName() string {
if attrs.Position == "" {
attrs.Position = "bottom"
}
var class = `dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52 dropdown-` + attrs.Position
if attrs.End {
class += ` dropdown-end`
}
if attrs.Hover {
class += ` dropdown-hover`
}
if attrs.Class != "" {
class += ` ` + attrs.Class
}
return trimSpaces(class)
}
templ DropdownMenu(attrs DropdownAttrs) {
<div class="dropdown">
<div tabindex="0" role="button" class={"btn m-1 " + getClassName(attrs.BtnBrand, "", attrs.BtnSize, "btn")}>{children...}</div> <!-- Dropdown button, srry, safari issues -->
<ul
tabindex="0"
class={ attrs.GetClassName() }
>
for _, item := range attrs.Items {
<li><a href={ item.Href }>{ item.Text } </a> </li>
}
</ul>
</div>
}