-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnavbar.templ
121 lines (116 loc) · 3.81 KB
/
navbar.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package templdais
type NavbarAttrs struct {
Brand string
Items []Links
Title string
TitleOnly bool
Submenu bool
SubmenuItems map[string][]Links
Search bool
Responsive bool
Centered bool
Class string
BodyClass string
}
func (nb NavbarAttrs) GetClassName() string {
var class = "navbar bg-base-100 " + getClassName(nb.Brand, "", "", "bg")
if nb.Class != "" {
class += " " + nb.Class
}
return trimSpaces(class)
}
templ RenderLinks(items []Links, submenuItems map[string][]Links) {
for _, item := range items {
if submenuItems[item.Text] != nil {
<li>
<details>
<summary>
Parent
</summary>
<ul class="p-2 bg-base-100 rounded-t-none">
<li><a>Link 1</a></li>
<li><a>Link 2</a></li>
</ul>
</details>
</li>
} else {
<li><a href={ item.Href }>{ item.Text }</a></li>
}
}
}
templ Navbar(nb NavbarAttrs) {
if nb.TitleOnly {
<nav class={ nb.GetClassName() }>
<a class="btn btn-ghost text-xl">{ nb.Title }</a>
</nav>
}
if nb.Submenu {
<nav class={ nb.GetClassName() }>
<section class="flex-1">
<a class="btn btn-ghost text-xl">{ nb.Title }</a>
</section>
<section class="flex-none">
<ul class={ "menu menu-horizontal px-1 " + nb.BodyClass }>
@RenderLinks(nb.Items, nb.SubmenuItems)
</ul>
</section>
</nav>
}
if nb.Search {
<nav class={ nb.GetClassName() }>
<section class="flex-1">
<a class="btn btn-ghost text-xl">{ nb.Title }</a>
</section>
<section class="flex-none gap-2">
<a class="form-control">
<input type="text" placeholder="Search" class="input input-bordered w-24 md:w-auto"/>
</a>
@DropdownMenu(DropdownAttrs{Position: "end", Items: nb.Items}){
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h8m-8 6h16"></path></svg>
}
</section>
</nav>
}
if nb.Centered {
<div class={ nb.GetClassName() }>
<div class="navbar-start">
@DropdownMenu(DropdownAttrs{Position: "start", Items: nb.Items}){
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h8m-8 6h16"></path></svg>
}
</div>
<div class="navbar-center">
<a class="btn btn-ghost text-xl">{ nb.Title }</a>
</div>
<div class="navbar-end">
@Button(ButtonAttrs{Type: "btn", Brand: "ghost", Size: "xs", Figure: "circle"}, templ.Attributes{}) {
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
}
</div>
</div>
}
if nb.Responsive {
<div class={ nb.GetClassName() }>
<div class="navbar-start lg:hidden">
<div class="dropdown">
<div tabindex="0" role="button" class="btn btn-ghost lg:hidden">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h8m-8 6h16"></path></svg>
</div>
<ul tabindex="0" class={ "menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52 " + nb.BodyClass }>
@RenderLinks(nb.Items, nb.SubmenuItems)
</ul>
</div>
</div>
<div class="navbar-start hidden lg:flex">
<ul class={ "menu menu-horizontal px-1 " + nb.BodyClass }>
@RenderLinks(nb.Items, nb.SubmenuItems)
</ul>
</div>
<div class="navbar-center">
<a href="/" class="btn btn-ghost text-xl">{ nb.Title }</a>
</div>
<div class="navbar-end">
{ children... }
</div>
</div>
}
}