@orsetra/shared-ui 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,9 +21,10 @@ interface LayoutContainerProps {
|
|
|
21
21
|
fetchMenus?: () => Promise<MenuApiResponse>
|
|
22
22
|
getSidebarMode?: (pathname: string, searchParams: URLSearchParams) => SidebarMode
|
|
23
23
|
getCurrentMenu?: (pathname: string, searchParams: URLSearchParams) => string
|
|
24
|
+
getCurrentMenuItem?: (pathname: string, searchParams: URLSearchParams) => string
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
function LayoutContent({ children, sidebarMenus = {}, user, onSignOut, mode = 'expanded', userMenuConfig, main_base_url, fetchMenus, getSidebarMode, getCurrentMenu }: LayoutContainerProps) {
|
|
27
|
+
function LayoutContent({ children, sidebarMenus = {}, user, onSignOut, mode = 'expanded', userMenuConfig, main_base_url, fetchMenus, getSidebarMode, getCurrentMenu, getCurrentMenuItem }: LayoutContainerProps) {
|
|
27
28
|
const pathname = usePathname()
|
|
28
29
|
const searchParams = useSearchParams()
|
|
29
30
|
const { setOpen } = useSidebar()
|
|
@@ -111,6 +112,7 @@ function LayoutContent({ children, sidebarMenus = {}, user, onSignOut, mode = 'e
|
|
|
111
112
|
sidebarMenus={effectiveSidebarMenus}
|
|
112
113
|
main_base_url={main_base_url}
|
|
113
114
|
sectionLabels={sectionLabels}
|
|
115
|
+
getCurrentMenuItem={getCurrentMenuItem}
|
|
114
116
|
/>
|
|
115
117
|
)}
|
|
116
118
|
|
|
@@ -5,7 +5,7 @@ import { Slot } from "@radix-ui/react-slot"
|
|
|
5
5
|
import { VariantProps, cva } from "class-variance-authority"
|
|
6
6
|
import { PanelLeft } from "lucide-react"
|
|
7
7
|
import Link from "next/link"
|
|
8
|
-
import { usePathname } from "next/navigation"
|
|
8
|
+
import { usePathname, useSearchParams } from "next/navigation"
|
|
9
9
|
|
|
10
10
|
import { useIsMobile } from "../../../hooks/use-mobile"
|
|
11
11
|
import { cn } from "../../../lib/utils"
|
|
@@ -172,12 +172,14 @@ interface SidebarProps {
|
|
|
172
172
|
sidebarMenus?: SidebarMenus
|
|
173
173
|
main_base_url?: string
|
|
174
174
|
sectionLabels?: Record<string, string>
|
|
175
|
+
getCurrentMenuItem?: (pathname: string, searchParams: URLSearchParams) => string
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
|
|
178
179
|
|
|
179
|
-
function Sidebar({ currentMenu, onMainMenuToggle, sidebarMenus = {}, main_base_url = "", sectionLabels = {} }: SidebarProps = {}) {
|
|
180
|
+
function Sidebar({ currentMenu, onMainMenuToggle, sidebarMenus = {}, main_base_url = "", sectionLabels = {}, getCurrentMenuItem }: SidebarProps = {}) {
|
|
180
181
|
const pathname = usePathname()
|
|
182
|
+
const searchParams = useSearchParams()
|
|
181
183
|
const { state } = useSidebar()
|
|
182
184
|
const [settingsOpen, setSettingsOpen] = React.useState(false)
|
|
183
185
|
const settingsRef = React.useRef<HTMLDivElement>(null)
|
|
@@ -229,10 +231,11 @@ function Sidebar({ currentMenu, onMainMenuToggle, sidebarMenus = {}, main_base_u
|
|
|
229
231
|
</div>
|
|
230
232
|
)}
|
|
231
233
|
|
|
232
|
-
{/* Navigation principale avec espacements ajustés */}
|
|
233
234
|
<nav className="flex-1 px-3 py-4 space-y-1 overflow-y-auto">
|
|
234
235
|
{currentNavigation.map((item) => {
|
|
235
|
-
|
|
236
|
+
// Use custom function if provided, otherwise use default pathname matching
|
|
237
|
+
const activeItemId = getCurrentMenuItem ? getCurrentMenuItem(pathname, searchParams) : null
|
|
238
|
+
const isActive = activeItemId ? item.id === activeItemId : (pathname === item.href || pathname.startsWith(`${item.href}/`))
|
|
236
239
|
|
|
237
240
|
const handleClick = (e: React.MouseEvent) => {
|
|
238
241
|
const href = item.href
|