index.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use client'
  2. import cn from 'classnames'
  3. import React, { useRef } from 'react'
  4. import { useRouter } from 'next/navigation'
  5. import { useHover } from 'ahooks'
  6. import s from './style.module.css'
  7. import ItemOperation from '@/app/components/explore/item-operation'
  8. import AppIcon from '@/app/components/base/app-icon'
  9. export type IAppNavItemProps = {
  10. isMobile: boolean
  11. name: string
  12. id: string
  13. icon: string
  14. icon_background: string
  15. isSelected: boolean
  16. isPinned: boolean
  17. togglePin: () => void
  18. uninstallable: boolean
  19. onDelete: (id: string) => void
  20. }
  21. export default function AppNavItem({
  22. isMobile,
  23. name,
  24. id,
  25. icon,
  26. icon_background,
  27. isSelected,
  28. isPinned,
  29. togglePin,
  30. uninstallable,
  31. onDelete,
  32. }: IAppNavItemProps) {
  33. const router = useRouter()
  34. const url = `/explore/installed/${id}`
  35. const ref = useRef(null)
  36. const isHovering = useHover(ref)
  37. return (
  38. <div
  39. ref={ref}
  40. key={id}
  41. className={cn(
  42. s.item,
  43. isSelected ? s.active : 'hover:bg-gray-200',
  44. 'flex h-8 items-center justify-between mobile:justify-center px-2 mobile:px-1 rounded-lg text-sm font-normal',
  45. )}
  46. onClick={() => {
  47. router.push(url) // use Link causes popup item always trigger jump. Can not be solved by e.stopPropagation().
  48. }}
  49. >
  50. {isMobile && <AppIcon size='tiny' icon={icon} background={icon_background} />}
  51. {!isMobile && (
  52. <>
  53. <div className='flex items-center space-x-2 w-0 grow'>
  54. <AppIcon size='tiny' icon={icon} background={icon_background} />
  55. <div className='overflow-hidden text-ellipsis whitespace-nowrap' title={name}>{name}</div>
  56. </div>
  57. <div className='shrink-0 h-6' onClick={e => e.stopPropagation()}>
  58. <ItemOperation
  59. isPinned={isPinned}
  60. isItemHovering={isHovering}
  61. togglePin={togglePin}
  62. isShowDelete={!uninstallable && !isSelected}
  63. onDelete={() => onDelete(id)}
  64. />
  65. </div>
  66. </>
  67. )}
  68. </div>
  69. )
  70. }