video-preview.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import type { FC } from 'react'
  2. import { createPortal } from 'react-dom'
  3. import { RiCloseLine } from '@remixicon/react'
  4. import React from 'react'
  5. import { useHotkeys } from 'react-hotkeys-hook'
  6. type VideoPreviewProps = {
  7. url: string
  8. title: string
  9. onCancel: () => void
  10. }
  11. const VideoPreview: FC<VideoPreviewProps> = ({
  12. url,
  13. title,
  14. onCancel,
  15. }) => {
  16. useHotkeys('esc', onCancel)
  17. return createPortal(
  18. <div
  19. className='fixed inset-0 p-8 flex items-center justify-center bg-black/80 z-[1000]'
  20. onClick={e => e.stopPropagation()}
  21. tabIndex={-1}
  22. >
  23. <div>
  24. <video controls title={title} autoPlay={false} preload="metadata">
  25. <source
  26. type="video/mp4"
  27. src={url}
  28. className='max-w-full max-h-full'
  29. />
  30. </video>
  31. </div>
  32. <div
  33. className='absolute top-6 right-6 flex items-center justify-center w-8 h-8 bg-white/[0.08] rounded-lg backdrop-blur-[2px] cursor-pointer'
  34. onClick={onCancel}
  35. >
  36. <RiCloseLine className='w-4 h-4 text-gray-500'/>
  37. </div>
  38. </div>
  39. , document.body,
  40. )
  41. }
  42. export default VideoPreview