88 lines
2.5 KiB
TypeScript
Raw Normal View History

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'
import classNames from '@/utils/classnames'
2023-06-27 18:02:01 +08:00
import { ArrowNarrowLeft } from '@/app/components/base/icons/src/vender/line/arrows'
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
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,
isApp,
2023-05-15 08:51:32 +08:00
}: INavProps) => {
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={`
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
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
<>
<div className='font-light text-gray-300 '>/</div>
<NavSelector
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