Skip to content

Commit 47d755c

Browse files
committed
Playground: Fix theme toggle UI when sidebar is collapsed
1 parent a3b2f8f commit 47d755c

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

apps/playground-web/src/components/ThemeToggle.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,39 @@
33
import { MoonIcon, SunIcon } from "lucide-react";
44
import { useTheme } from "next-themes";
55
import { ClientOnly } from "@/components/ClientOnly";
6-
import { Button } from "@/components/ui/button";
6+
import {
7+
SidebarMenu,
8+
SidebarMenuButton,
9+
SidebarMenuItem,
10+
} from "@/components/ui/sidebar";
711
import { Skeleton } from "@/components/ui/skeleton";
812

913
export function ThemeToggle() {
1014
const { setTheme, theme } = useTheme();
1115

1216
return (
13-
<div className="border-t pt-2">
14-
<ClientOnly
15-
ssr={<Skeleton className="size-[34px] rounded-full border bg-accent" />}
16-
>
17-
<Button
17+
<SidebarMenu>
18+
<SidebarMenuItem>
19+
<SidebarMenuButton
1820
aria-label="Toggle theme"
1921
className="w-full text-muted-foreground hover:text-foreground px-2 py-1.5 text-left justify-start gap-2 capitalize h-auto font-normal"
2022
onClick={() => {
2123
setTheme(theme === "dark" ? "light" : "dark");
2224
}}
23-
size="sm"
24-
variant="ghost"
2525
>
26-
{theme === "light" ? (
27-
<SunIcon className="size-4" />
28-
) : (
29-
<MoonIcon className="size-4" />
30-
)}
26+
<ClientOnly ssr={<Skeleton className="size-4" />}>
27+
{theme === "light" ? (
28+
<SunIcon className="size-4" />
29+
) : (
30+
<MoonIcon className="size-4" />
31+
)}
32+
</ClientOnly>
3133

32-
{theme}
33-
</Button>
34-
</ClientOnly>
35-
</div>
34+
<ClientOnly ssr={<Skeleton className="w-16 h-4" />}>
35+
<span>{theme}</span>
36+
</ClientOnly>
37+
</SidebarMenuButton>
38+
</SidebarMenuItem>
39+
</SidebarMenu>
3640
);
3741
}

apps/playground-web/src/components/blocks/full-width-sidebar-layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function FullWidthSidebarLayoutInner(props: FullWidthSidebarLayoutProps) {
126126
links={footerSidebarLinks}
127127
fullPath={props.fullPath}
128128
/>
129+
<SidebarSeparator />
129130
<ThemeToggle />
130131
</SidebarFooter>
131132
)}

0 commit comments

Comments
 (0)