import { Fragment, useState, type ReactNode } from 'react'; import { Drawer as MuiDrawer, List, ListItem, ListItemButton, ListItemIcon, ListItemText, Collapse, type DrawerProps, type SxProps, } from '@mui/material'; import { ExpandLess, ExpandMore, DashboardOutlined, GroupsOutlined, AppsOutlined, ManageAccounts, DesignServicesOutlined, ReceiptLongOutlined, FolderOutlined, MailOutline, CampaignOutlined, RequestQuoteOutlined } from '@mui/icons-material'; import RdsAvatar from '../rds-avatar/rds-avatar'; import RdsSearch from '../rds-search/rds-search'; import RdsTooltip from '../rds-tooltip/rds-tooltip'; import clsx from 'clsx'; import './rds-sidebar.scss'; const ANZ_MENU_ITEMS: RdsSidebarItem[] = [ { label: 'Dashboard', icon: }, { label: 'Saas', icon: }, { label: 'Administration', icon: }, { label: 'Demo UI Components', icon: }, ]; const ABP_MENU_ITEMS: RdsSidebarItem[] = [ { label: 'Dashboard', icon: }, { label: 'Saas', icon: }, { label: 'Invoices', icon: }, { label: 'Ticket Allocation', icon: }, { label: 'Communication', icon: }, { label: 'Advertisements', icon: }, { label: 'Requests', icon: }, ]; export interface RdsSidebarItem { label: string; icon?: ReactNode; onClick?: () => void; active?: boolean; disabled?: boolean; typeOf?: 'collapse' | 'expanded' | 'fixed'; platform?: 'abp-list' | 'anz-list'; children?: RdsSidebarItem[]; /** Optional navigation path (alias used by some consumers). */ path?: string; /** Optional href for link-style items. */ href?: string; } export interface RdsSidebarProps extends Omit { items: RdsSidebarItem[]; isOpen: boolean; onClose?: () => void; width?: number; showSearch?: boolean; layout?: 'raaghu' | 'list' | 'toolbar'; typeOf?: 'collapse' | 'expanded' | 'fixed'; platform?: 'abp-list' | 'anz-list'; avatarSrc?: string; avatarCollapsedSrc?: string; showLogo?: boolean; container?: Element | (() => Element | null) | null; } const RdsSidebar = ({ items, isOpen, onClose, width = 240, variant = 'temporary', showSearch = true, typeOf = 'expanded', platform, avatarSrc, avatarCollapsedSrc, showLogo, container, layout, ModalProps: modalPropsFromProps, sx: propsSx, ...props }:RdsSidebarProps) => { const [searchValue, setSearchValue] = useState(""); const [openMap, setOpenMap] = useState>({}); const menuItems = platform === 'abp-list' ? ABP_MENU_ITEMS : platform === 'anz-list' ? ANZ_MENU_ITEMS : items; const toggleOpen = (idx: number) => { setOpenMap(prev => ({ ...prev, [idx]: !prev[idx] })); }; const isCollapsed = typeOf === 'collapse' || typeOf === 'fixed'; const isNarrowCollapsed = width < 200; const shouldShowIconsOnly = isCollapsed || isNarrowCollapsed; const showLabels = !shouldShowIconsOnly; let showAvatar = true; let showSearchBox = !shouldShowIconsOnly && showSearch; if (layout === 'list' && shouldShowIconsOnly) { showAvatar = true; showSearchBox = showSearch; } if (layout === 'raaghu' || layout === 'toolbar') { showAvatar = false; // Keep search available in collapse/fixed (icon-only) mode when showSearch is true showSearchBox = showSearch; } const sidebarClasses = clsx('rds-sidebar', `rds-sidebar--${typeOf}`, isNarrowCollapsed && 'rds-sidebar--narrow-collapsed'); const headerClasses = clsx('rds-sidebar__header', `rds-sidebar__header--${typeOf}`); const contentClasses = 'rds-sidebar__content'; const navItemClasses = clsx('rds-sidebar__nav-item', `rds-sidebar__nav-item--${typeOf}`); const navButtonClasses = clsx('rds-sidebar__nav-button', `rds-sidebar__nav-button--${typeOf}`); const avatarContainerClasses = clsx('rds-sidebar__avatar-container', `rds-sidebar__avatar-container--${typeOf}`); const getLogoClass = () => clsx('rds-sidebar__logo', shouldShowIconsOnly ? 'rds-sidebar__logo--collapse' : 'rds-sidebar__logo--expanded'); const drawerSx: Record = { width: shouldShowIconsOnly ? 64 : width, flexShrink: 0, ['& .MuiDrawer-paper']: { width: shouldShowIconsOnly ? 64 : width, boxSizing: 'border-box', display: 'flex', flexDirection: 'column', height: shouldShowIconsOnly && typeOf === 'fixed' ? '100vh' : '100%', ...(shouldShowIconsOnly && { alignItems: 'center', overflow: 'hidden', ...(typeOf === 'fixed' && { position: 'fixed', top: 0, left: 0, zIndex: 'var(--rds-z-index-banner, 1200)', }) }) } }; const searchIconOnlySize = 'var(--rds-sidebar-search-icon-only-size, var(--rds-menu-item-min-height, 40px))'; const searchSx = shouldShowIconsOnly ? { width: searchIconOnlySize, maxWidth: searchIconOnlySize, minWidth: 0, margin: '0 auto', '& .MuiInputBase-root': { minWidth: 0, width: searchIconOnlySize, maxWidth: searchIconOnlySize, height: searchIconOnlySize, margin: '0 auto', padding: 0, overflow: 'hidden', display: 'flex', justifyContent: 'center', alignItems: 'center', backgroundColor: 'transparent', }, '& .MuiOutlinedInput-notchedOutline': { borderColor: 'var(--rds-sidebar-search-icon-border-color, var(--rds-border-default))', borderWidth: 'var(--rds-border-width-thin, 1px)', borderRadius: 'var(--rds-sidebar-search-icon-border-radius, var(--rds-border-radius-sm, 4px))', }, '& .MuiInputBase-input': { display: 'none', width: 0, padding: 0, flex: '0 0 0', position: 'absolute', }, '& .MuiInputAdornment-root': { margin: 0, width: '100%', display: 'flex', justifyContent: 'center', }, '& .MuiIconButton-root': { margin: 0, }, } : { width: '100%', maxWidth: Math.min(width - 32, 205) }; const modalProps = { disableScrollLock: true, ...(container ? { disableAutoFocus: true, disableEnforceFocus: true, disableRestoreFocus: true, } : {}), ...modalPropsFromProps, }; return (
{showLogo && (
{layout === 'toolbar' ? ( shouldShowIconsOnly ? ( ) : ( ) ) : ( Raaghu Design System Logo )}
)} {showSearchBox && ( <>

setSearchValue(value)} onSearch={() => {}} placeholder={shouldShowIconsOnly ? '' : 'Search...'} showClearButton={!shouldShowIconsOnly} size="small" variant="outlined" value={searchValue} sx={searchSx} />
)} {menuItems.map((item, index) => { const listItemButton = ( { if (item.children && item.children.length) { toggleOpen(index); } else { item.onClick && item.onClick(); } }} disabled={item.disabled} selected={item.active} className={navButtonClasses} aria-expanded={!!openMap[index]} sx={{ minHeight: 'var(--rds-sidebar-nav-min-height, 48px)', justifyContent: shouldShowIconsOnly ? 'center' : 'flex-start', px: shouldShowIconsOnly ? 0 : 2, }} > {item.icon && ( {item.icon} )} {showLabels && } {item.children && item.children.length > 0 && !shouldShowIconsOnly && ( (openMap[index]) ? : )} ); return ( {shouldShowIconsOnly && item.icon ? ( {listItemButton} ) : ( listItemButton )} {item.children && item.children.length > 0 && ( {item.children.map((child, cIdx) => { const childListItemButton = ( {child.icon && ( {child.icon} )} {showLabels && } ); return ( {shouldShowIconsOnly && child.icon ? ( {childListItemButton} ) : ( childListItemButton )} ); })} )} ); })}

{showAvatar && (
{!shouldShowIconsOnly ? ( ) : ( )}
)}
); }; RdsSidebar.displayName = 'RdsSidebar'; export default RdsSidebar;