prompt-option.tsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { memo } from 'react'
  2. type PromptMenuItemMenuItemProps = {
  3. icon: JSX.Element
  4. title: string
  5. disabled?: boolean
  6. isSelected: boolean
  7. onClick: () => void
  8. onMouseEnter: () => void
  9. setRefElement?: (element: HTMLDivElement) => void
  10. }
  11. export const PromptMenuItem = memo(({
  12. icon,
  13. title,
  14. disabled,
  15. isSelected,
  16. onClick,
  17. onMouseEnter,
  18. setRefElement,
  19. }: PromptMenuItemMenuItemProps) => {
  20. return (
  21. <div
  22. className={`
  23. flex items-center px-3 h-6 cursor-pointer hover:bg-gray-50 rounded-md
  24. ${isSelected && !disabled && '!bg-gray-50'}
  25. ${disabled ? 'cursor-not-allowed opacity-30' : 'hover:bg-gray-50 cursor-pointer'}
  26. `}
  27. tabIndex={-1}
  28. ref={setRefElement}
  29. onMouseEnter={() => {
  30. if (disabled)
  31. return
  32. onMouseEnter()
  33. }}
  34. onClick={() => {
  35. if (disabled)
  36. return
  37. onClick()
  38. }}>
  39. {icon}
  40. <div className='ml-1 text-[13px] text-gray-900'>{title}</div>
  41. </div>
  42. )
  43. })
  44. PromptMenuItem.displayName = 'PromptMenuItem'