index.tsx 1.9 KB

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