audio-preview.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 AudioPreviewProps = {
  7. url: string
  8. title: string
  9. onCancel: () => void
  10. }
  11. const AudioPreview: FC<AudioPreviewProps> = ({
  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. <audio controls title={title} autoPlay={false} preload="metadata">
  25. <source
  26. type="audio/mpeg"
  27. src={url}
  28. className='max-w-full max-h-full'
  29. />
  30. </audio>
  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. ,
  40. document.body,
  41. )
  42. }
  43. export default AudioPreview