import React, { forwardRef, type ElementRef } from 'react'; import { type ElementProps } from '../../types'; import { cn } from '../../utils/cn'; import { Navigation, NavigationDropdown, NavigationItem, type NavigationDropdownProps, type NavigationItemProps, } from '../navigation'; import { useSidebarContext } from './sidebar.context'; const SidebarBodyRoot = forwardRef, ElementProps<'div'>>(({ children, className, ...props }, ref) => { return (
{children}
); }); const SidebarSection = forwardRef, ElementProps<'div'>>(({ children, className, ...props }, ref) => { return (
{children}
); }); const SidebarNavTitle = forwardRef, ElementProps<'div'>>(({ children, className, ...props }, ref) => { const { isExpanded } = useSidebarContext(); return (
<>{children}
); }); const SidebarNavList = forwardRef, ElementProps<'ul'>>(({ className, children, ...props }, ref) => { const { isExpanded } = useSidebarContext(); return ( {children} ); }); export interface SidebarNavListDropdownProps extends NavigationDropdownProps {} const SidebarNavListDropdown = forwardRef, SidebarNavListDropdownProps>( (props, ref) => { const { active, isExpanded } = useSidebarContext(); return ; } ); export interface SidebarNavListItemProps extends NavigationItemProps { value: string; } const SidebarNavListItem = forwardRef, SidebarNavListItemProps>( ({ active: activeProp, value, withActiveCursor = true, onClick, ...props }, ref) => { const { active, setActive } = useSidebarContext(); return ( { onClick?.(e); setActive(value); }} withActiveCursor={withActiveCursor} active={activeProp || active === value} ref={ref} {...props} /> ); } ); const List = Object.assign(SidebarNavList, { Dropdown: SidebarNavListDropdown, Item: SidebarNavListItem, }); export const SidebarBody = Object.assign(SidebarBodyRoot, { Section: SidebarSection, Title: SidebarNavTitle, List, });