Open History to see the last commit
1<% if (addOns.length === 0 && integrations.length === 0 && routes.length === 0) { ignoreFile() } %>import { Link } from '@tanstack/solid-router'
2<% for(const integration of integrations.filter(i => i.type === 'header-user')) { %>
3import <%= integration.jsName %> from "<%= relativePath(integration.path) %>";
4<% } %><% if (tailwind) {
5const icons = new Set([
6 "Menu",
7 "X",
8 "House",
9 "Home",
10 "Globe",
11 "ChevronDown",
12 "ChevronRight",
13 "Layers",
14])
15
16for(const addOn of addOns) {
17 for(const route of (addOn?.routes||[])?.filter(r => r.url && r.name)) {
18 icons.add( route.icon || "Globe");
19 }
20}
21%>
22import { createSignal } from 'solid-js';
23import {
24 <%= Array.from(icons).sort().join(", ") %>
25} from "lucide-solid";
26<% } %>
27
28export default function Header() {
29<% if (tailwind) {
30const menusWithChildren = addOns.filter(a => a.routes?.some(r => r.children));
31const userHeaders = integrations.filter(i => i.type === 'header-user');
32%>
33 const [isOpen, setIsOpen] = createSignal(false);
34 const [groupedExpanded, setGroupedExpanded] = createSignal<Record<string, boolean>>({});
35
36 return (
37 <>
38 <header class="p-4 flex items-center bg-gray-800 text-white shadow-lg">
39 <button
40 onClick={() => setIsOpen(true)}
41 class="p-2 hover:bg-gray-700 rounded-lg transition-colors"
42 aria-label="Open menu"
43 >
44 <Menu size={24} />
45 </button>
46 <h1 class="ml-4 text-xl font-semibold">
47 <Link to="/">
48 <img
49 src="/tanstack-word-logo-white.svg"
50 alt="TanStack Logo"
51 class="h-10"
52 />
53 </Link>
54 </h1>
55 </header>
56
57 <aside
58 class={`fixed top-0 left-0 h-full w-80 bg-gray-900 text-white shadow-2xl z-50 transform transition-transform duration-300 ease-in-out flex flex-col ${
59 isOpen() ? "translate-x-0" : "-translate-x-full"
60 }`}
61 >
62 <div class="flex items-center justify-between p-4 border-b border-gray-700">
63 <h2 class="text-xl font-bold">Navigation</h2>
64 <button
65 onClick={() => setIsOpen(false)}
66 class="p-2 hover:bg-gray-800 rounded-lg transition-colors"
67 aria-label="Close menu"
68 >
69 <X size={24} />
70 </button>
71 </div>
72
73 <nav class="flex-1 p-4 overflow-y-auto">
74 <Link
75 to="/"
76 onClick={() => setIsOpen(false)}
77 class="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"
78 activeProps={{
79 class:
80 "flex items-center gap-3 p-3 rounded-lg bg-cyan-600 hover:bg-cyan-700 transition-colors mb-2",
81 }}
82 >
83 <Home size={20} />
84 <span class="font-medium">Home</span>
85 </Link>
86
87 {/* Demo Links Start */}
88 <% for(const addOn of addOns) {
89 for(const route of (addOn?.routes||[])?.filter(r => r.url && r.name)) {
90 if (route.children) { %>
91 <div class="flex flex-row justify-between">
92 <Link to="<%= route.url %>"
93 onClick={() => setIsOpen(false)}
94 class="flex-1 flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"
95 activeProps={{
96 class:
97 "flex-1 flex items-center gap-3 p-3 rounded-lg bg-cyan-600 hover:bg-cyan-700 transition-colors mb-2",
98 }}
99 >
100 <<%= route.icon || "Globe" %> size={20} />
101 <span class="font-medium"><%= route.name %></span>
102 </Link>
103 <button
104 class="p-2 hover:bg-gray-800 rounded-lg transition-colors"
105 onClick={() => setGroupedExpanded(prev => ({ ...prev, <%= route.jsName %>: !prev.<%= route.jsName %> }))}>
106 {groupedExpanded().<%= route.jsName %> ? <ChevronDown size={20} /> : <ChevronRight size={20} />}
107 </button>
108 </div>
109 {groupedExpanded().<%= route.jsName %> && (
110 <div class="flex flex-col ml-4">
111 <% for(const child of route.children) { %>
112 <Link
113 to="<%= child.url %>"
114 onClick={() => setIsOpen(false)}
115 class="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"
116 activeProps={{
117 class:
118 "flex items-center gap-3 p-3 rounded-lg bg-cyan-600 hover:bg-cyan-700 transition-colors mb-2",
119 }}
120 >
121 <<%= child.icon || "Globe" %> size={20} />
122 <span class="font-medium"><%= child.name %></span>
123 </Link>
124 <% } %>
125 </div>
126 )}
127 <% } else { %>
128 <Link
129 to="<%= route.url %>"
130 onClick={() => setIsOpen(false)}
131 class="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"
132 activeProps={{
133 class:
134 "flex items-center gap-3 p-3 rounded-lg bg-cyan-600 hover:bg-cyan-700 transition-colors mb-2",
135 }}
136 >
137 <<%= route.icon || "Globe" %> size={20} />
138 <span class="font-medium"><%= route.name %></span>
139 </Link>
140 <% } } } %>
141 {/* Demo Links End */}
142 </nav>
143
144 <% if (userHeaders.length > 0) { %>
145 <div class="p-4 border-t border-gray-700 bg-gray-800 flex flex-col gap-2">
146 <% for(const integration of userHeaders) { %>
147 <<%= integration.jsName %> />
148 <% } %>
149 </div>
150 <% } %>
151 </aside>
152 </>
153 );
154<% } else { %>
155 return (
156 <header class="p-2 flex gap-2 bg-white text-black justify-between">
157 <nav class="flex flex-row">
158 <div class="px-2 font-bold">
159 <Link to="/">Home</Link>
160 </div>
161<% for(const addOn of addOns) {
162 for(const route of (addOn?.routes||[])?.filter(r => r.url && r.name)) { %>
163<div class="px-2 font-bold"><Link to="<%= route.url %>"><%= route.name %></Link></div>
164<% } } %>
165 </nav>
166<% if (integrations.filter(i => i.type === 'header-user').length > 0) { %>
167 <div>
168<% for(const integration of integrations.filter(i => i.type === 'header-user')) { %>
169 <<%= integration.jsName %> />
170<% } %>
171 </div>
172<% } %>
173 </header>
174 )
175<% } %>
176}