2023-05-15 08:51:32 +08:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
import React, { useState } from 'react'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import { useSelectedLayoutSegment } from 'next/navigation'
|
|
|
|
import type { INavSelectorProps } from './nav-selector'
|
|
|
|
import NavSelector from './nav-selector'
|
2024-07-09 15:05:40 +08:00
|
|
|
import classNames from '@/utils/classnames'
|
2023-06-27 18:02:01 +08:00
|
|
|
import { ArrowNarrowLeft } from '@/app/components/base/icons/src/vender/line/arrows'
|
2024-04-08 18:51:46 +08:00
|
|
|
import { useStore as useAppStore } from '@/app/components/app/store'
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
type INavProps = {
|
|
|
|
icon: React.ReactNode
|
2023-06-27 18:02:01 +08:00
|
|
|
activeIcon?: React.ReactNode
|
2023-05-15 08:51:32 +08:00
|
|
|
text: string
|
|
|
|
activeSegment: string | string[]
|
|
|
|
link: string
|
2024-04-08 18:51:46 +08:00
|
|
|
isApp: boolean
|
2023-05-15 08:51:32 +08:00
|
|
|
} & INavSelectorProps
|
|
|
|
|
|
|
|
const Nav = ({
|
|
|
|
icon,
|
2023-06-27 18:02:01 +08:00
|
|
|
activeIcon,
|
2023-05-15 08:51:32 +08:00
|
|
|
text,
|
|
|
|
activeSegment,
|
|
|
|
link,
|
|
|
|
curNav,
|
|
|
|
navs,
|
|
|
|
createText,
|
|
|
|
onCreate,
|
2023-06-06 10:42:32 +08:00
|
|
|
onLoadmore,
|
2024-04-08 18:51:46 +08:00
|
|
|
isApp,
|
2023-05-15 08:51:32 +08:00
|
|
|
}: INavProps) => {
|
2024-04-24 04:07:28 +00:00
|
|
|
const setAppDetail = useAppStore(state => state.setAppDetail)
|
2023-05-15 08:51:32 +08:00
|
|
|
const [hovered, setHovered] = useState(false)
|
|
|
|
const segment = useSelectedLayoutSegment()
|
2024-09-08 12:14:11 +07:00
|
|
|
const isActivated = Array.isArray(activeSegment) ? activeSegment.includes(segment!) : segment === activeSegment
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={`
|
2023-11-27 11:47:48 +08:00
|
|
|
flex items-center h-8 mr-0 sm:mr-3 px-0.5 rounded-xl text-sm shrink-0 font-medium
|
2024-09-08 12:14:11 +07:00
|
|
|
${isActivated && 'bg-components-main-nav-nav-button-bg-active shadow-md font-semibold'}
|
|
|
|
${!curNav && !isActivated && 'hover:bg-components-main-nav-nav-button-bg-hover'}
|
2023-05-15 08:51:32 +08:00
|
|
|
`}>
|
|
|
|
<Link href={link}>
|
|
|
|
<div
|
2024-04-08 18:51:46 +08:00
|
|
|
onClick={() => setAppDetail()}
|
2023-05-15 08:51:32 +08:00
|
|
|
className={classNames(`
|
2023-06-27 18:02:01 +08:00
|
|
|
flex items-center h-7 px-2.5 cursor-pointer rounded-[10px]
|
2024-09-08 12:14:11 +07:00
|
|
|
${isActivated ? 'text-components-main-nav-nav-button-text-active' : 'text-components-main-nav-nav-button-text'}
|
|
|
|
${curNav && isActivated && 'hover:bg-components-main-nav-nav-button-bg-active-hover'}
|
2023-05-15 08:51:32 +08:00
|
|
|
`)}
|
|
|
|
onMouseEnter={() => setHovered(true)}
|
|
|
|
onMouseLeave={() => setHovered(false)}
|
|
|
|
>
|
2023-06-27 18:02:01 +08:00
|
|
|
<div className='mr-2'>
|
|
|
|
{
|
|
|
|
(hovered && curNav)
|
|
|
|
? <ArrowNarrowLeft className='w-4 h-4' />
|
2024-09-08 12:14:11 +07:00
|
|
|
: isActivated
|
2023-06-27 18:02:01 +08:00
|
|
|
? activeIcon
|
|
|
|
: icon
|
|
|
|
}
|
|
|
|
</div>
|
2023-05-15 08:51:32 +08:00
|
|
|
{text}
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
{
|
2024-09-08 12:14:11 +07:00
|
|
|
curNav && isActivated && (
|
2023-05-15 08:51:32 +08:00
|
|
|
<>
|
2025-02-17 17:05:13 +08:00
|
|
|
<div className='font-light text-divider-deep'>/</div>
|
2023-05-15 08:51:32 +08:00
|
|
|
<NavSelector
|
2024-04-08 18:51:46 +08:00
|
|
|
isApp={isApp}
|
2023-05-15 08:51:32 +08:00
|
|
|
curNav={curNav}
|
|
|
|
navs={navs}
|
|
|
|
createText={createText}
|
|
|
|
onCreate={onCreate}
|
2023-06-06 10:42:32 +08:00
|
|
|
onLoadmore={onLoadmore}
|
2023-05-15 08:51:32 +08:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Nav
|