feat: global platform update
This commit is contained in:
@@ -26,9 +26,16 @@ import {
|
||||
import { usePathname } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import * as React from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export type NavGuideState = {
|
||||
highlightedItem?: string;
|
||||
expandedItems?: string[];
|
||||
};
|
||||
|
||||
export function NavMain({
|
||||
items,
|
||||
guideState,
|
||||
}: {
|
||||
items: {
|
||||
title: string;
|
||||
@@ -40,10 +47,12 @@ export function NavMain({
|
||||
url: string;
|
||||
}[];
|
||||
}[];
|
||||
guideState?: NavGuideState;
|
||||
}) {
|
||||
const pathname = usePathname();
|
||||
const { state } = useSidebar();
|
||||
const isCollapsed = state === "collapsed";
|
||||
const highlightedItem = guideState?.highlightedItem;
|
||||
|
||||
return (
|
||||
<SidebarGroup>
|
||||
@@ -53,6 +62,11 @@ export function NavMain({
|
||||
const isActive = pathname === item.url;
|
||||
const hasActiveSubmenu =
|
||||
hasSubmenu && item.items!.some((sub) => pathname === sub.url);
|
||||
const shouldForceOpen = guideState?.expandedItems?.includes(item.title);
|
||||
const isGuideHighlight = highlightedItem === item.title;
|
||||
const highlightedButtonClass = isGuideHighlight
|
||||
? "ring-2 ring-primary/70"
|
||||
: undefined;
|
||||
|
||||
// В свернутом состоянии показываем DropdownMenu для элементов с подменю
|
||||
if (isCollapsed && hasSubmenu) {
|
||||
@@ -63,6 +77,7 @@ export function NavMain({
|
||||
<SidebarMenuButton
|
||||
tooltip={item.title}
|
||||
isActive={isActive || hasActiveSubmenu}
|
||||
className={cn(highlightedButtonClass)}
|
||||
>
|
||||
{item.icon && <item.icon />}
|
||||
<span>{item.title}</span>
|
||||
@@ -99,9 +114,11 @@ export function NavMain({
|
||||
// Обычное отображение для развернутого состояния
|
||||
return (
|
||||
<Collapsible
|
||||
key={item.title}
|
||||
key={`${item.title}-${shouldForceOpen ? "guide" : "default"}`}
|
||||
asChild
|
||||
defaultOpen={isActive || hasActiveSubmenu}
|
||||
defaultOpen={
|
||||
shouldForceOpen || isActive || hasActiveSubmenu
|
||||
}
|
||||
className="group/collapsible"
|
||||
>
|
||||
<SidebarMenuItem>
|
||||
@@ -111,6 +128,7 @@ export function NavMain({
|
||||
<SidebarMenuButton
|
||||
tooltip={item.title}
|
||||
isActive={isActive || hasActiveSubmenu}
|
||||
className={cn(highlightedButtonClass)}
|
||||
>
|
||||
{item.icon && <item.icon />}
|
||||
<span>{item.title}</span>
|
||||
@@ -142,6 +160,7 @@ export function NavMain({
|
||||
asChild
|
||||
tooltip={item.title}
|
||||
isActive={isActive}
|
||||
className={cn(highlightedButtonClass)}
|
||||
>
|
||||
<Link href={item.url}>
|
||||
{item.icon && <item.icon />}
|
||||
|
||||
Reference in New Issue
Block a user