| 
									
										
										
										
											2024-12-10 10:53:37 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import { createPortal } from 'react-dom' | 
					
						
							|  |  |  | import { RiCloseLine } from '@remixicon/react' | 
					
						
							|  |  |  | import React from 'react' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { useHotkeys } from 'react-hotkeys-hook' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type AudioPreviewProps = { | 
					
						
							|  |  |  |   url: string | 
					
						
							|  |  |  |   title: string | 
					
						
							|  |  |  |   onCancel: () => void | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | const AudioPreview: FC<AudioPreviewProps> = ({ | 
					
						
							|  |  |  |   url, | 
					
						
							|  |  |  |   title, | 
					
						
							|  |  |  |   onCancel, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   useHotkeys('esc', onCancel) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return createPortal( | 
					
						
							|  |  |  |     <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       className='fixed inset-0 z-[1000] flex items-center justify-center bg-black/80 p-8' | 
					
						
							| 
									
										
										
										
											2024-12-10 10:53:37 +08:00
										 |  |  |       onClick={e => e.stopPropagation()} | 
					
						
							|  |  |  |       tabIndex={-1} | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <div> | 
					
						
							|  |  |  |         <audio controls title={title} autoPlay={false} preload="metadata"> | 
					
						
							|  |  |  |           <source | 
					
						
							|  |  |  |             type="audio/mpeg" | 
					
						
							|  |  |  |             src={url} | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             className='max-h-full max-w-full' | 
					
						
							| 
									
										
										
										
											2024-12-10 10:53:37 +08:00
										 |  |  |           /> | 
					
						
							|  |  |  |         </audio> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         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]' | 
					
						
							| 
									
										
										
										
											2024-12-10 10:53:37 +08:00
										 |  |  |         onClick={onCancel} | 
					
						
							|  |  |  |       > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         <RiCloseLine className='h-4 w-4 text-gray-500'/> | 
					
						
							| 
									
										
										
										
											2024-12-10 10:53:37 +08:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |     </div>, | 
					
						
							| 
									
										
										
										
											2024-12-10 10:53:37 +08:00
										 |  |  |     document.body, | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default AudioPreview |