index.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import cn from 'classnames'
  5. import { useTranslation } from 'react-i18next'
  6. import { Edit03, Pin02, Trash03 } from '../../base/icons/src/vender/line/general'
  7. import s from './style.module.css'
  8. import Popover from '@/app/components/base/popover'
  9. export type IItemOperationProps = {
  10. className?: string
  11. isPinned: boolean
  12. isShowRenameConversation?: boolean
  13. onRenameConversation?: () => void
  14. isShowDelete: boolean
  15. togglePin: () => void
  16. onDelete: () => void
  17. }
  18. const ItemOperation: FC<IItemOperationProps> = ({
  19. className,
  20. isPinned,
  21. togglePin,
  22. isShowRenameConversation,
  23. onRenameConversation,
  24. isShowDelete,
  25. onDelete,
  26. }) => {
  27. const { t } = useTranslation()
  28. return (
  29. <Popover
  30. htmlContent={
  31. <div className='w-full py-1' onClick={(e) => {
  32. e.stopPropagation()
  33. }}>
  34. <div className={cn(s.actionItem, 'hover:bg-gray-50 group')} onClick={togglePin}>
  35. <Pin02 className='shrink-0 w-4 h-4 text-gray-500'/>
  36. <span className={s.actionName}>{isPinned ? t('explore.sidebar.action.unpin') : t('explore.sidebar.action.pin')}</span>
  37. </div>
  38. {isShowRenameConversation && (
  39. <div className={cn(s.actionItem, 'hover:bg-gray-50 group')} onClick={onRenameConversation}>
  40. <Edit03 className='shrink-0 w-4 h-4 text-gray-500'/>
  41. <span className={s.actionName}>{t('explore.sidebar.action.rename')}</span>
  42. </div>
  43. )}
  44. {isShowDelete && (
  45. <div className={cn(s.actionItem, s.deleteActionItem, 'hover:bg-gray-50 group')} onClick={onDelete} >
  46. <Trash03 className={cn(s.deleteActionItemChild, 'shrink-0 w-4 h-4 stroke-current text-gray-500 stroke-2')} />
  47. <span className={cn(s.actionName, s.deleteActionItemChild)}>{t('explore.sidebar.action.delete')}</span>
  48. </div>
  49. )}
  50. </div>
  51. }
  52. trigger='click'
  53. position='br'
  54. btnElement={<div />}
  55. btnClassName={open => cn(className, s.btn, 'h-6 w-6 rounded-md border-none py-1', open && '!bg-gray-100 !shadow-none')}
  56. className={'!w-[120px] !px-0 h-fit !z-20'}
  57. />
  58. )
  59. }
  60. export default React.memo(ItemOperation)