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<% } %><% if (tailwind) {
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<% } %>
29
30export default function Header() {
31<% if (tailwind) {
32const menusWithChildren = addOns.filter(a => a.routes?.some(r => r.children));
33const userHeaders = integrations.filter(i => i.type === 'header-user');
34%>
35 const [isOpen, setIsOpen] = useState(false);
36 <% if (menusWithChildren.length > 0) { %>const [groupedExpanded, setGroupedExpanded] = useState<Record<string, boolean>>({});
37 <% } %>
38
39 return (
40 <>
41 <header className="p-4 flex items-center bg-gray-800 text-white shadow-lg">
42 <button
43 onClick={() => setIsOpen(true)}
44 className="p-2 hover:bg-gray-700 rounded-lg transition-colors"
45 aria-label="Open menu"
46 >
47 <Menu size={24} />
48 </button>
49 <h1 className="ml-4 text-xl font-semibold">
50 <a href="/">
51 <img
52 src={logo}
53 alt="Redwood SDK Logo"
54 className="h-10"
55 />
56 </a>
57 </h1>
58 </header>
59
60 <aside
61 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 ${
62 isOpen ? "translate-x-0" : "-translate-x-full"
63 }`}
64 >
65 <div className="flex items-center justify-between p-4 border-b border-gray-700">
66 <h2 className="text-xl font-bold">Navigation</h2>
67 <button
68 onClick={() => setIsOpen(false)}
69 className="p-2 hover:bg-gray-800 rounded-lg transition-colors"
70 aria-label="Close menu"
71 >
72 <X size={24} />
73 </button>
74 </div>
75
76 <nav className="flex-1 p-4 overflow-y-auto">
77 <a
78 href="/"
79 onClick={() => setIsOpen(false)}
80 className="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"
81 >
82 <Home size={20} />
83 <span className="font-medium">Home</span>
84 </a>
85
86 {/* Demo Links Start */}
87 <% for(const addOn of addOns) {
88 for(const route of (addOn?.routes||[])?.filter(r => r.url && r.name)) {
89 if (route.children) { %>
90 <div className="flex flex-row justify-between">
91 <a href="<%= route.url %>"
92 onClick={() => setIsOpen(false)}
93 className="flex-1 flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"
94 >
95 <<%= route.icon || "Globe" %> size={20} />
96 <span className="font-medium"><%= route.name %></span>
97 </a>
98 <button
99 className="p-2 hover:bg-gray-800 rounded-lg transition-colors"
100 onClick={() => setGroupedExpanded(prev => ({ ...prev, <%= route.jsName %>: !prev.<%= route.jsName %> }))}>
101 {groupedExpanded.<%= route.jsName %> ? <ChevronDown size={20} /> : <ChevronRight size={20} />}
102 </button>
103 </div>
104 {groupedExpanded.<%= route.jsName %> && (
105 <div className="flex flex-col ml-4">
106 <% for(const child of route.children) { %>
107 <a
108 href="<%= child.url %>"
109 onClick={() => setIsOpen(false)}
110 className="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"
111 >
112 <<%= child.icon || "Globe" %> size={20} />
113 <span className="font-medium"><%= child.name %></span>
114 </a>
115 <% } %>
116 </div>
117 )}
118 <% } else { %>
119 <a
120 href="<%= route.url %>"
121 onClick={() => setIsOpen(false)}
122 className="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"
123 activeProps={{
124 className:
125 "flex items-center gap-3 p-3 rounded-lg bg-cyan-600 hover:bg-cyan-700 transition-colors mb-2",
126 }}
127 >
128 <<%= route.icon || "Globe" %> size={20} />
129 <span className="font-medium"><%= route.name %></span>
130 </a>
131 <% } } } %>
132 {/* Demo Links End */}
133 </nav>
134
135 <% if (userHeaders.length > 0) { %>
136 <div className="p-4 border-t border-gray-700 bg-gray-800 flex flex-col gap-2">
137 <% for(const integration of userHeaders) { %>
138 <<%= integration.jsName %> />
139 <% } %>
140 </div>
141 <% } %>
142 </aside>
143 </>
144 );
145<% } else { %>
146 return (
147 <header className="p-2 flex gap-2 bg-white text-black justify-between">
148 <nav className="flex flex-row">
149 <div className="px-2 font-bold">
150 <a href="/">Home</a>
151 </div>
152<% for(const addOn of addOns) {
153 for(const route of (addOn?.routes||[])?.filter(r => r.url && r.name)) { %>
154<div className="px-2 font-bold"><a href="<%= route.url %>"><%= route.name %></a></div>
155<% } } %>
156 </nav>
157<% if (integrations.filter(i => i.type === 'header-user').length > 0) { %>
158 <div>
159<% for(const integration of integrations.filter(i => i.type === 'header-user')) { %>
160 <<%= integration.jsName %> />
161<% } %>
162 </div>
163<% } %>
164 </header>
165 )
166<% } %>
167}