Skip to content

Commit 857d4df

Browse files
committed
Playground: Fix theme toggle UI when sidebar is collapsed (#7853)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refining the sidebar component in the application by adjusting styles, modifying the theme toggle functionality, and enhancing the UI elements for better user experience. ### Detailed summary - Updated `SIDEBAR_WIDTH` and `SIDEBAR_WIDTH_MOBILE` from `"19rem"` to `"18rem"`. - Removed `ChevronDownIcon` and replaced it with `ChevronRightIcon` in `RenderSidebarSubmenu`. - Added `<SidebarSeparator />` in `FullWidthSidebarLayoutInner`. - Replaced `Button` with `SidebarMenu`, `SidebarMenuButton`, and `SidebarMenuItem` in `ThemeToggle`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Theme toggle now appears as a sidebar menu item with improved loading placeholders for icon and label. - UI/UX - Sidebar width reduced from 19rem to 18rem for a more compact layout. - Chevron indicators updated: right-chevron rotates 90° when open for clearer state. - Added a visual separator in the sidebar footer for better grouping. - Bug Fixes - Prevented rendering of empty sidebar menus/submenus. - Refactor - Streamlined imports and removed unused variants; maintained existing toggle behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 22aad59 commit 857d4df

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { ChevronDownIcon, ChevronRightIcon } from "lucide-react";
3+
import { ChevronRightIcon } from "lucide-react";
44
import Link from "next/link";
55
import { useMemo, useState } from "react";
66
import {
@@ -126,6 +126,7 @@ function FullWidthSidebarLayoutInner(props: FullWidthSidebarLayoutProps) {
126126
links={footerSidebarLinks}
127127
fullPath={props.fullPath}
128128
/>
129+
<SidebarSeparator />
129130
<ThemeToggle />
130131
</SidebarFooter>
131132
)}
@@ -289,7 +290,7 @@ function RenderSidebarSubmenu(props: {
289290
<DynamicHeight transition="height 200ms ease">
290291
<SidebarMenuItem>
291292
<Collapsible
292-
className="group/collapsible [&[data-state=open]>button>svg[data-chevron]]:rotate-180"
293+
className="group/collapsible [&[data-state=open]>button>svg[data-chevron]]:rotate-90"
293294
defaultOpen={open}
294295
open={open}
295296
onOpenChange={setOpen}
@@ -307,9 +308,9 @@ function RenderSidebarSubmenu(props: {
307308
<span>{props.subMenu.label}</span>
308309

309310
{sidebar.open && (
310-
<ChevronDownIcon
311+
<ChevronRightIcon
311312
data-chevron
312-
className="transition-transform ml-auto"
313+
className="transition-transform ml-auto text-foreground"
313314
/>
314315
)}
315316
</SidebarMenuButton>

apps/playground-web/src/components/ui/sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import { cn } from "@/lib/utils";
2727

2828
const SIDEBAR_COOKIE_NAME = "sidebar_state";
2929
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
30-
const SIDEBAR_WIDTH = "19rem";
31-
const SIDEBAR_WIDTH_MOBILE = "19rem";
30+
const SIDEBAR_WIDTH = "18rem";
31+
const SIDEBAR_WIDTH_MOBILE = "18rem";
3232
const SIDEBAR_WIDTH_ICON = "3rem";
3333
const SIDEBAR_KEYBOARD_SHORTCUT = "b";
3434

0 commit comments

Comments
 (0)