Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Active selected link in sidebar state #723

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions ui/admin/app/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from "@remix-run/react";
import { Link, useLocation } from "@remix-run/react";
import {
BotIcon,
BrainIcon,
Expand Down Expand Up @@ -81,6 +81,7 @@ const items = [

export function AppSidebar() {
const { state } = useSidebar();
const location = useLocation();
return (
<Sidebar collapsible="icon">
<SidebarRail />
Expand Down Expand Up @@ -108,12 +109,25 @@ export function AppSidebar() {
<SidebarMenuButton
asChild
className="w-full"
isActive={location.pathname.startsWith(
item.url
)}
variant="spill"
>
<Link
to={item.url}
className="w-full flex items-center"
>
<item.icon className="mr-2" />
<item.icon
className={cn(
"mr-2",
location.pathname.startsWith(
item.url
)
? "text-primary"
: ""
)}
/>
<span>{item.title}</span>
</Link>
</SidebarMenuButton>
Expand Down
3 changes: 2 additions & 1 deletion ui/admin/app/components/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ const SidebarContent = React.forwardRef<
ref={ref}
data-sidebar="content"
className={cn(
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
"flex min-h-0 flex-1 flex-col gap-2 overflow-hidden group-data-[collapsible=icon]:overflow-hidden",
className
)}
{...props}
Expand Down Expand Up @@ -534,6 +534,7 @@ const sidebarMenuButtonVariants = cva(
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
outline:
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
spill: "w-full group-data-[collapsible=icon]:data-[active=true]:!bg-background group-data-[collapsible=icon]:data-[active=true]:!w-[calc(100%+20px)] hover:bg-background hover:w-[calc(100%+20px)] data-[active=true]:bg-background data-[active=true]:w-[calc(100%+20px)] pr-[10px]",
},
size: {
default: "h-8 text-sm",
Expand Down