Skip to content

Commit 494f2df

Browse files
authored
Revert "Revert "Add support for sidebar menu"" (#1135)
This reverts commit 6d59736.
1 parent d91dd4f commit 494f2df

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

web/src/routes/+layout.svelte

+37-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import { fly } from "svelte/transition";
99
export let data: PageData;
1010
11+
export let isSidebarOpen: boolean = true;
12+
1113
let models;
1214
let modelAvailable: boolean;
1315
const isLoading = false;
@@ -18,6 +20,10 @@
1820
let dataCht: Response | any = null;
1921
const unsubscribe = newChat.subscribe((value) => (dataCht = value));
2022
23+
function toggleSidebar(): void {
24+
isSidebarOpen = !isSidebarOpen;
25+
}
26+
2127
onMount(() => {
2228
theme = localStorage.getItem("data-theme") || "dark";
2329
document.documentElement.setAttribute("data-theme", theme);
@@ -110,9 +116,25 @@
110116
});
111117
</script>
112118

119+
<button on:click={toggleSidebar} class="btn btn-square z-10 fixed">
120+
<svg
121+
xmlns="http://www.w3.org/2000/svg"
122+
fill="none"
123+
viewBox="0 0 24 24"
124+
class="inline-block w-5 h-5 stroke-current"
125+
><path
126+
stroke-linecap="round"
127+
stroke-linejoin="round"
128+
stroke-width="2"
129+
d="M4 6h16M4 12h16M4 18h16"
130+
></path></svg
131+
>
132+
</button>
113133
<aside
114134
id="default-sidebar"
115-
class="border-base-content/[.2] fixed left-0 top-0 z-40 h-screen w-80 -translate-x-full border-r transition-transform overflow-hidden translate-x-0 aria-label=Sidebar"
135+
class="border-base-content/[.2] fixed left-0 top-0 z-40 h-screen -translate-x-full border-r transition-transform overflow-hidden translate-x-0 aria-label=Sidebar"
136+
class:w-75={isSidebarOpen}
137+
class:w-0={!isSidebarOpen}
116138
>
117139
<div
118140
class="bg-base-200 relative h-screen py-1 px-2 overflow-hidden flex flex-col items-center justify-between"
@@ -150,6 +172,19 @@
150172
</svg>
151173
<span>New Chat</span>
152174
</button>
175+
<button
176+
id="toggle-sidebar-btn"
177+
tabindex="0"
178+
on:click={toggleSidebar}
179+
on:keydown={(event) => {
180+
if (event.key === "Escape") {
181+
toggleSidebar();
182+
}
183+
}}
184+
aria-label="Close Sidebar"
185+
class="btn btn-ghost flex-shrink-0"
186+
>&#10005;
187+
</button>
153188
</div>
154189
<ul
155190
class="my-1 w-full h-[85%] overflow-y-auto no-scrollbar firefox-no-scrollbar ie-edge-no-scrollbar"
@@ -380,6 +415,6 @@
380415
</div>
381416
</aside>
382417

383-
<div class={"relative h-full transition-all md:ml-80"}>
418+
<div class={"h-full" + (isSidebarOpen ? " ml-64 min-w-64" : " min-w-0")}>
384419
<slot />
385420
</div>

0 commit comments

Comments
 (0)