Optimize code
This commit is contained in:
@@ -11,7 +11,7 @@ interface IndicatorProps {
|
||||
const Indicator: React.FC<IndicatorProps> = ({ total, current, onSwitch }) => {
|
||||
const handleClick = (index: number) => {
|
||||
return () => {
|
||||
onSwitch && onSwitch(index)
|
||||
onSwitch?.(index)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ const Item: React.FC<ItemProps> = (props) => {
|
||||
|
||||
const showSubmenu = (e: React.MouseEvent) => {
|
||||
const parentElement = e.currentTarget.parentElement
|
||||
if (parentElement && parentElement.childElementCount === 2) {
|
||||
if (parentElement?.childElementCount === 2) {
|
||||
const parentClientRect = parentElement.getBoundingClientRect()
|
||||
if (parentClientRect.top <= screen.height / 2) {
|
||||
setSubmenuTop(parentClientRect.top)
|
||||
@@ -42,18 +42,16 @@ const Item: React.FC<ItemProps> = (props) => {
|
||||
}
|
||||
>
|
||||
<div className={'icon-box'}>
|
||||
{props.icon ? (
|
||||
<Icon className={'icon'} component={props.icon} />
|
||||
) : undefined}
|
||||
{props.icon && <Icon className={'icon'} component={props.icon} />}
|
||||
</div>
|
||||
<span className={'text'}>{props.text}</span>
|
||||
</NavLink>
|
||||
</div>
|
||||
{props.children ? (
|
||||
{props.children && (
|
||||
<Submenu submenuTop={submenuTop} submenuLeft={submenuLeft}>
|
||||
{props.children}
|
||||
</Submenu>
|
||||
) : undefined}
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ const Sidebar: React.FC<SidebarProps> & {
|
||||
const switchSidebar = () => {
|
||||
setLocalStorage('HIDE_SIDEBAR', !hideSidebar ? 'true' : 'false')
|
||||
setHideSidebar(!hideSidebar)
|
||||
props.onSidebarSwitch && props.onSidebarSwitch(hideSidebar)
|
||||
props.onSidebarSwitch?.(hideSidebar)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user