2024-01-11 13:26:34 +08:00
|
|
|
import React, { useCallback, useState } from 'react'
|
2023-05-15 08:51:32 +08:00
|
|
|
import NavLink from './navLink'
|
2023-08-28 19:48:53 +08:00
|
|
|
import type { NavIcon } from './navLink'
|
2023-11-27 11:47:48 +08:00
|
|
|
import AppBasic from './basic'
|
|
|
|
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
|
2024-01-11 13:26:34 +08:00
|
|
|
import {
|
|
|
|
AlignLeft01,
|
|
|
|
AlignRight01,
|
|
|
|
} from '@/app/components/base/icons/src/vender/line/layout'
|
2023-08-28 19:48:53 +08:00
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
export type IAppDetailNavProps = {
|
2023-06-16 21:47:51 +08:00
|
|
|
iconType?: 'app' | 'dataset' | 'notion'
|
2023-05-15 08:51:32 +08:00
|
|
|
title: string
|
|
|
|
desc: string
|
2023-05-19 17:36:44 +08:00
|
|
|
icon: string
|
|
|
|
icon_background: string
|
2023-05-15 08:51:32 +08:00
|
|
|
navigation: Array<{
|
|
|
|
name: string
|
|
|
|
href: string
|
2023-08-28 19:48:53 +08:00
|
|
|
icon: NavIcon
|
|
|
|
selectedIcon: NavIcon
|
2023-05-15 08:51:32 +08:00
|
|
|
}>
|
2024-01-16 12:14:09 +08:00
|
|
|
extraInfo?: (modeState: string) => React.ReactNode
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-08-28 19:48:53 +08:00
|
|
|
const AppDetailNav = ({ title, desc, icon, icon_background, navigation, extraInfo, iconType = 'app' }: IAppDetailNavProps) => {
|
2024-01-11 13:26:34 +08:00
|
|
|
const localeMode = localStorage.getItem('app-detail-collapse-or-expand') || 'expand'
|
2023-11-27 11:47:48 +08:00
|
|
|
const media = useBreakpoints()
|
|
|
|
const isMobile = media === MediaType.mobile
|
|
|
|
const mode = isMobile ? 'collapse' : 'expand'
|
2024-01-11 13:26:34 +08:00
|
|
|
const [modeState, setModeState] = useState(isMobile ? mode : localeMode)
|
|
|
|
const expand = modeState === 'expand'
|
|
|
|
|
|
|
|
const handleToggle = useCallback(() => {
|
|
|
|
setModeState((prev) => {
|
|
|
|
const next = prev === 'expand' ? 'collapse' : 'expand'
|
|
|
|
localStorage.setItem('app-detail-collapse-or-expand', next)
|
|
|
|
return next
|
|
|
|
})
|
|
|
|
}, [])
|
2023-11-27 11:47:48 +08:00
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
return (
|
2024-01-11 13:26:34 +08:00
|
|
|
<div
|
|
|
|
className={`
|
|
|
|
shrink-0 flex flex-col bg-white border-r border-gray-200 transition-all
|
|
|
|
${expand ? 'w-[216px]' : 'w-14'}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={`
|
|
|
|
shrink-0
|
|
|
|
${expand ? 'p-4' : 'p-2'}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<AppBasic
|
|
|
|
mode={modeState}
|
|
|
|
iconType={iconType}
|
|
|
|
icon={icon}
|
|
|
|
icon_background={icon_background}
|
|
|
|
name={title}
|
|
|
|
type={desc}
|
|
|
|
/>
|
2023-05-15 08:51:32 +08:00
|
|
|
</div>
|
2024-01-11 13:26:34 +08:00
|
|
|
<nav
|
|
|
|
className={`
|
|
|
|
grow space-y-1 bg-white
|
|
|
|
${expand ? 'p-4' : 'px-2.5 py-4'}
|
|
|
|
`}
|
|
|
|
>
|
2023-05-15 08:51:32 +08:00
|
|
|
{navigation.map((item, index) => {
|
|
|
|
return (
|
2024-01-11 13:26:34 +08:00
|
|
|
<NavLink key={index} mode={modeState} iconMap={{ selected: item.selectedIcon, normal: item.icon }} name={item.name} href={item.href} />
|
2023-05-15 08:51:32 +08:00
|
|
|
)
|
|
|
|
})}
|
2024-01-16 12:14:09 +08:00
|
|
|
{extraInfo && extraInfo(modeState)}
|
2023-05-15 08:51:32 +08:00
|
|
|
</nav>
|
2024-01-11 13:26:34 +08:00
|
|
|
{
|
|
|
|
!isMobile && (
|
|
|
|
<div
|
|
|
|
className={`
|
|
|
|
shrink-0 py-3
|
|
|
|
${expand ? 'px-6' : 'px-4'}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className='flex items-center justify-center w-6 h-6 text-gray-500 cursor-pointer'
|
|
|
|
onClick={handleToggle}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
expand
|
|
|
|
? <AlignLeft01 className='w-[14px] h-[14px]' />
|
|
|
|
: <AlignRight01 className='w-[14px] h-[14px]' />
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2023-05-15 08:51:32 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default React.memo(AppDetailNav)
|