@orsetra/shared-ui 1.1.3 → 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.
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
 
3
3
  import { useState, useEffect } from "react"
4
- import { usePathname } from "next/navigation"
4
+ import { usePathname, useSearchParams } from "next/navigation"
5
5
  import { MainSidebar, type SidebarMode } from "./sidebar/main-sidebar"
6
6
  import { Sidebar, SidebarProvider, useSidebar } from "./sidebar/sidebar"
7
7
  import { type SidebarMenus, type MainMenuItem, type MenuApiResponse, resolveIcon } from "./sidebar/data"
@@ -19,19 +19,21 @@ interface LayoutContainerProps {
19
19
  mode?: SidebarMode
20
20
  userMenuConfig?: UserMenuConfig
21
21
  fetchMenus?: () => Promise<MenuApiResponse>
22
- getSidebarMode?: (pathname: string) => SidebarMode
23
- getCurrentMenu?: (pathname: string) => string
22
+ getSidebarMode?: (pathname: string, searchParams: URLSearchParams) => SidebarMode
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()
29
+ const searchParams = useSearchParams()
28
30
  const { setOpen } = useSidebar()
29
31
  const isMobile = useIsMobile()
30
32
  const [isMainSidebarOpen, setIsMainSidebarOpen] = useState(false)
31
33
  const [currentMenu, setCurrentMenu] = useState<string>("overview")
32
34
 
33
35
  // Use custom mode function if provided, otherwise use prop
34
- const effectiveMode = getSidebarMode ? getSidebarMode(pathname) : mode
36
+ const effectiveMode = getSidebarMode ? getSidebarMode(pathname, searchParams) : mode
35
37
  const isMinimized = effectiveMode === 'minimized'
36
38
  // Force hidden mode on mobile
37
39
  const isHidden = effectiveMode === 'hidden' || isMobile
@@ -84,9 +86,9 @@ function LayoutContent({ children, sidebarMenus = {}, user, onSignOut, mode = 'e
84
86
 
85
87
  useEffect(() => {
86
88
  // Use custom menu function if provided, otherwise use default getMenuFromPath
87
- const contextualMenu = getCurrentMenu ? getCurrentMenu(pathname) : getMenuFromPath(pathname)
89
+ const contextualMenu = getCurrentMenu ? getCurrentMenu(pathname, searchParams) : getMenuFromPath(pathname)
88
90
  setCurrentMenu(contextualMenu)
89
- }, [pathname, getCurrentMenu])
91
+ }, [pathname, searchParams, getCurrentMenu])
90
92
 
91
93
  const handleMainSidebarToggle = () => {
92
94
  setIsMainSidebarOpen(!isMainSidebarOpen)
@@ -110,6 +112,7 @@ function LayoutContent({ children, sidebarMenus = {}, user, onSignOut, mode = 'e
110
112
  sidebarMenus={effectiveSidebarMenus}
111
113
  main_base_url={main_base_url}
112
114
  sectionLabels={sectionLabels}
115
+ getCurrentMenuItem={getCurrentMenuItem}
113
116
  />
114
117
  )}
115
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
- const isActive = pathname === item.href || pathname.startsWith(`${item.href}/`)
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orsetra/shared-ui",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Shared UI components for Orsetra platform",
5
5
  "main": "./index.ts",
6
6
  "types": "./index.ts",