audio-preview.tsx 1012 B

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