Refactor sidebar navigation menu item rendering and styling (#150)
- Improve sidebar menu item layout and responsiveness - Extract and optimize classNames for link and span elements - Remove conditional rendering of `renderAction` - Enhance dynamic styling for collapsed and expanded sidebar states
This commit is contained in:
committed by
GitHub
parent
08d5b16123
commit
97e4bc9bad
@@ -526,7 +526,7 @@ const SidebarMenuItem: React.FC<React.ComponentProps<'li'>> = ({
|
|||||||
<li
|
<li
|
||||||
data-sidebar="menu-item"
|
data-sidebar="menu-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
'group/menu-item relative flex group-data-[collapsible=icon]:justify-center',
|
'group/menu-item relative group-data-[collapsible=icon]:justify-center',
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -940,22 +940,27 @@ export function SidebarNavigation({
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{children.map((child) => {
|
{children.map((child) => {
|
||||||
if (child.renderAction) {
|
|
||||||
return (
|
|
||||||
<SidebarMenuSubItem
|
|
||||||
key={child.path}
|
|
||||||
>
|
|
||||||
{child.renderAction}
|
|
||||||
</SidebarMenuSubItem>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const isActive = isRouteActive(
|
const isActive = isRouteActive(
|
||||||
child.path,
|
child.path,
|
||||||
currentPath,
|
currentPath,
|
||||||
child.end,
|
child.end,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const linkClassName = cn(
|
||||||
|
'flex items-center',
|
||||||
|
{
|
||||||
|
'mx-auto w-full gap-0! [&>svg]:flex-1':
|
||||||
|
!open,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const spanClassName = cn(
|
||||||
|
'w-auto transition-opacity duration-300',
|
||||||
|
{
|
||||||
|
'w-0 opacity-0': !open,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarMenuSubItem key={child.path}>
|
<SidebarMenuSubItem key={child.path}>
|
||||||
<SidebarMenuSubButton
|
<SidebarMenuSubButton
|
||||||
@@ -963,24 +968,12 @@ export function SidebarNavigation({
|
|||||||
asChild
|
asChild
|
||||||
>
|
>
|
||||||
<Link
|
<Link
|
||||||
className={cn(
|
className={linkClassName}
|
||||||
'flex items-center',
|
|
||||||
{
|
|
||||||
'mx-auto w-full gap-0! [&>svg]:flex-1':
|
|
||||||
!open,
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
href={child.path}
|
href={child.path}
|
||||||
>
|
>
|
||||||
{child.Icon}
|
{child.Icon}
|
||||||
<span
|
|
||||||
className={cn(
|
<span className={spanClassName}>
|
||||||
'w-auto transition-opacity duration-300',
|
|
||||||
{
|
|
||||||
'w-0 opacity-0': !open,
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey={child.label}
|
i18nKey={child.label}
|
||||||
defaults={child.label}
|
defaults={child.label}
|
||||||
|
|||||||
Reference in New Issue
Block a user