Enhance DashboardSidebar with CollapsedItemIcon and Tooltip integration
- Introduced a new CollapsedItemIcon component to improve the display of sidebar items when collapsed, providing additional context through tooltips. - Updated the DashboardSidebar to utilize the CollapsedItemIcon for better user experience and visual clarity when navigating collapsed sidebar items. - Enhanced code readability by organizing the new component and its prop types within the DashboardSidebar file.
This commit is contained in:
parent
d52a8eb570
commit
4ea6d1e7a3
@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useContext } from 'react'
|
||||
import { cloneElement, isValidElement, useState, useEffect, useContext } from 'react'
|
||||
import { Layout, Menu, Flex, Button } from 'antd'
|
||||
import { CaretDownFilled } from '@ant-design/icons'
|
||||
import CollapseSidebarIcon from '../../Icons/CollapseSidebarIcon'
|
||||
@ -12,8 +12,29 @@ import { getSidebarIconNode } from '../../Icons/sidebarIconMap'
|
||||
import SimpleBar from 'simplebar-react'
|
||||
import { useThemeContext } from '../context/ThemeContext'
|
||||
import { filterSidebarItemsByListPermission } from '../../../database/Sidebars'
|
||||
import Tooltip from './Tooltip'
|
||||
const { Sider } = Layout
|
||||
|
||||
const CollapsedItemIcon = ({ className, icon, title }) => {
|
||||
const iconNode = isValidElement(icon)
|
||||
? cloneElement(icon, {
|
||||
className: [icon.props.className, className].filter(Boolean).join(' ')
|
||||
})
|
||||
: icon
|
||||
|
||||
return (
|
||||
<Tooltip title={title}>
|
||||
{iconNode ?? <span className={className} />}
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
CollapsedItemIcon.propTypes = {
|
||||
className: PropTypes.string,
|
||||
icon: PropTypes.node,
|
||||
title: PropTypes.node
|
||||
}
|
||||
|
||||
const DashboardSidebar = ({
|
||||
items = [],
|
||||
selectedKey = '',
|
||||
@ -52,9 +73,15 @@ const DashboardSidebar = ({
|
||||
return item
|
||||
}
|
||||
|
||||
const icon = item.icon || getSidebarIconNode(item.iconKey)
|
||||
const mappedItem = {
|
||||
key: item.key,
|
||||
icon: item.icon || getSidebarIconNode(item.iconKey),
|
||||
icon:
|
||||
collapsed && !isMobile ? (
|
||||
<CollapsedItemIcon title={item.label} icon={icon} />
|
||||
) : (
|
||||
icon
|
||||
),
|
||||
label: item.label
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user