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