-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4704e6
commit 3b3078c
Showing
4 changed files
with
149 additions
and
50 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
packages/common-app/src/dialogs/ImageLightbox/ImageLightbox.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { createPortal } from 'react-dom'; | ||
import { usePortal, DialogWrapper, Times } from '@youfoundation/common-app'; | ||
import { EmbeddedThumb, TargetDrive } from '@youfoundation/js-lib/core'; | ||
import { Image } from '@youfoundation/common-app'; | ||
import { useEffect } from 'react'; | ||
|
||
export const ImageLightbox = ({ | ||
targetDrive, | ||
fileId, | ||
previewThumbnail, | ||
onClose, | ||
}: { | ||
targetDrive: TargetDrive; | ||
fileId: string; | ||
previewThumbnail?: EmbeddedThumb; | ||
|
||
onClose: () => void; | ||
}) => { | ||
const target = usePortal('modal-container'); | ||
|
||
useEffect(() => { | ||
const handleKeyDown = (e: KeyboardEvent) => { | ||
if (e.key === 'Escape') { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
onClose(); | ||
} | ||
}; | ||
|
||
window.addEventListener('keydown', handleKeyDown); | ||
|
||
return () => window.removeEventListener('keydown', handleKeyDown); | ||
}, [onClose]); | ||
|
||
useEffect(() => { | ||
document.documentElement.classList.add('overflow-hidden'); | ||
return () => { | ||
document.documentElement.classList.remove('overflow-hidden'); | ||
}; | ||
}); | ||
|
||
const dialog = ( | ||
<div className="fixed inset-0 z-50 bg-black lg:bg-transparent" role="dialog" aria-modal="true"> | ||
<div className="inset-0 bg-black transition-opacity lg:fixed"></div> | ||
<div className="inset-0 z-10 lg:fixed lg:overflow-y-auto"> | ||
<div className="relative flex h-full min-h-screen flex-col lg:flex-row"> | ||
{onClose ? ( | ||
<button | ||
onClick={onClose} | ||
className="bg-secondary text-secondary-contrast absolute left-4 top-4 rounded-full p-3 hover:brightness-90 hover:filter" | ||
> | ||
<Times className="h-4 w-4" /> | ||
</button> | ||
) : null} | ||
<Image | ||
className={`m-auto h-auto max-h-[calc(100vh-5rem)] w-auto max-w-full object-contain`} | ||
fileId={fileId} | ||
targetDrive={targetDrive} | ||
alt="post" | ||
fit="contain" | ||
previewThumbnail={previewThumbnail} | ||
explicitSize={'full'} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
return createPortal(dialog, target); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './ConfirmDialog/ConfirmDialog'; | ||
export * from './InfoDialog/InfoDialog'; | ||
export * from './ImageLightbox/ImageLightbox'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters