Skip to content

Commit

Permalink
feat: overhaul sidebar
Browse files Browse the repository at this point in the history
The sidebar now uses the ShadCN component. This
reduces code complexity by a lot. Throughout the
applications the various components for this are
used and overall styling has changed quite a bit.

As such, the old sidebar components are no longer
needed and are deleted.

Signed-off-by: tylerslaton <[email protected]>
  • Loading branch information
tylerslaton committed Oct 22, 2024
1 parent 9e05bbe commit 86f375e
Show file tree
Hide file tree
Showing 17 changed files with 972 additions and 221 deletions.
42 changes: 5 additions & 37 deletions ui/admin/app/components/header/HeaderNav.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link, useLocation, useParams } from "@remix-run/react";
import { ArrowLeftIcon, MenuIcon } from "lucide-react";
import { ArrowLeftIcon } from "lucide-react";
import { $params, $path } from "remix-routes";
import useSWR from "swr";

Expand All @@ -10,19 +10,11 @@ import { cn, parseQueryParams } from "~/lib/utils";

import { DarkModeToggle } from "~/components/DarkModeToggle";
import { TypographyH4, TypographySmall } from "~/components/Typography";
import { OttoLogo } from "~/components/branding/OttoLogo";
import { useLayout } from "~/components/layout/LayoutProvider";
import { Button } from "~/components/ui/button";
import { UserMenu } from "~/components/user/UserMenu";

export function HeaderNav() {
const {
isExpanded,
onExpandedChange,
smallSidebarWidth,
fullSidebarWidth,
} = useLayout();
import { SidebarTrigger } from "../ui/sidebar";

export function HeaderNav() {
const { pathname } = useLocation();
const headerHeight = "h-[60px]";

Expand All @@ -34,39 +26,15 @@ export function HeaderNav() {
)}
>
<div className="h-full flex-auto flex">
<div
className={cn(
"relative h-full flex items-center justify-center p-4 border-b",
fullSidebarWidth,
{ "border-r": isExpanded }
)}
>
<Button
className={cn(
"absolute z-30 top-0 left-0 rounded-none",
headerHeight,
smallSidebarWidth
)}
variant="ghost"
size="icon"
onClick={() => onExpandedChange()}
>
<MenuIcon className="h-6 w-6" />
<span className="sr-only">Collapse sidebar</span>
</Button>

<OttoLogo />
</div>

<div className="flex flex-grow border-b">
<div className="flex-grow flex justify-start items-center p-4">
<div className="flex-grow flex justify-start items-center p-4 gap-2">
<SidebarTrigger />
<TypographyH4 className="text-muted-foreground font-normal w-full">
{getHeaderContent(pathname)}
</TypographyH4>
</div>

<div className="flex items-center justify-center p-4 mr-4">
<UserMenu className="pr-4 border-r mr-4" />
<DarkModeToggle />
</div>
</div>
Expand Down
118 changes: 83 additions & 35 deletions ui/admin/app/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,97 @@
import React from "react";
import { Link } from "@remix-run/react";
import { BotIcon, MessageSquare, User } from "lucide-react";
import { $path } from "remix-routes";

import { cn } from "~/lib/utils";

import { SidebarFull } from "~/components/sidebar/SidebarFull";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarRail,
useSidebar,
} from "~/components/ui/sidebar";

import { useLayout } from "../layout/LayoutProvider";
import { SidebarCollapsed } from "./SidebarCollapsed";
import { OttoLogo } from "../branding/OttoLogo";
import { UserMenu } from "../user/UserMenu";

type SidebarProps = React.HTMLAttributes<HTMLDivElement>;

export function Sidebar({ className, ...props }: SidebarProps) {
const { isExpanded, sidebarWidth } = useLayout();
// Menu items.
const items = [
{
title: "Agents",
url: $path("/agents"),
icon: BotIcon,
},
{
title: "Threads",
url: $path("/threads"),
icon: MessageSquare,
},
{
title: "Users",
url: $path("/users"),
icon: User,
},
];

export function AppSidebar() {
const { state } = useSidebar();
return (
<div
className={cn("h-full overflow-hidden", sidebarWidth, className)}
{...props}
>
<div className="relative h-full">
<div
className={cn(
"absolute inset-y-0 left-0 w-64 transition-transform duration-300 ease-in-out",
isExpanded
? "translate-x-0 z-20"
: "-translate-x-48 z-10"
)}
>
<div className="h-full border-r">
<SidebarFull />
</div>
</div>

<Sidebar className="" collapsible="icon">
<SidebarRail />
<SidebarHeader
className={cn("pt-4", state === "collapsed" ? "" : "px-4")}
>
<div
className={cn(
"absolute inset-y-0 left-0 w-16 transition-opacity duration-300 ease-in-out",
isExpanded
? "opacity-0 pointer-events-none"
: "opacity-100 z-20"
"flex justify-start",
state === "collapsed" ? "pl-1" : "pl-3"
)}
>
<div className="h-full flex flex-col items-center border-r">
<SidebarCollapsed />
</div>
<OttoLogo
classNames={{
image:
state === "collapsed" ? "w-6 h-6" : "w-8 h-8",
root: "text-foreground",
}}
hideText={state === "collapsed"}
/>
</div>
</div>
</div>
</SidebarHeader>
<SidebarContent className={cn(state === "collapsed" ? "" : "px-4")}>
<SidebarGroup>
<SidebarGroupContent>
<SidebarMenu>
{items.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton asChild>
<Link to={item.url}>
<item.icon />
<span>{item.title}</span>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter
className={cn("pb-4", state === "collapsed" ? "" : "")}
>
<UserMenu
className={cn({
"p-2 rounded-lg border border-muted-foreground/20":
state === "expanded",
})}
/>
</SidebarFooter>
</Sidebar>
);
}
35 changes: 0 additions & 35 deletions ui/admin/app/components/sidebar/SidebarCollapsed.tsx

This file was deleted.

40 changes: 0 additions & 40 deletions ui/admin/app/components/sidebar/SidebarFull.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions ui/admin/app/components/sidebar/SidebarSection.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion ui/admin/app/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Sidebar } from "~/components/sidebar/Sidebar";
export { AppSidebar as Sidebar } from "~/components/sidebar/Sidebar";
17 changes: 6 additions & 11 deletions ui/admin/app/components/ui/sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,23 @@ const sheetVariants = cva(

interface SheetContentProps
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
VariantProps<typeof sheetVariants> {
hideClose?: boolean;
}
VariantProps<typeof sheetVariants> {}

const SheetContent = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Content>,
SheetContentProps
>(({ side = "right", className, children, hideClose, ...props }, ref) => (
>(({ side = "right", className, children, ...props }, ref) => (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
ref={ref}
className={cn(sheetVariants({ side }), className)}
{...props}
>
{!hideClose && (
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<Cross2Icon className="h-4 w-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
)}

<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<Cross2Icon className="h-4 w-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
{children}
</SheetPrimitive.Content>
</SheetPortal>
Expand Down
Loading

0 comments on commit 86f375e

Please sign in to comment.