index.tsx 2.3 KB

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