-
Notifications
You must be signed in to change notification settings - Fork 11k
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
38a7e85
commit bd4fed4
Showing
9 changed files
with
104 additions
and
56 deletions.
There are no files selected for viewing
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
13 changes: 11 additions & 2 deletions
13
apps/meteor/client/components/ImageGallery/ImageGalleryLoader.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createContext } from 'react'; | ||
|
||
export type ImageGalleryContextValue = { | ||
imageUrl: string; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
}; | ||
|
||
export const ImageGalleryContext = createContext<ImageGalleryContextValue>({ | ||
imageUrl: '', | ||
isOpen: false, | ||
onClose: () => undefined, | ||
}); |
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,47 @@ | ||
import React, { type ReactNode, useEffect, useState } from 'react'; | ||
|
||
import ImageGallery from '../components/ImageGallery/ImageGallery'; | ||
import { ImageGalleryContext } from '../contexts/ImageGalleryContext'; | ||
|
||
type ImageGalleryProviderProps = { | ||
children: ReactNode; | ||
imageSelector?: string; | ||
containerSelector?: string; | ||
}; | ||
|
||
const ImageGalleryProvider = ({ children, imageSelector, containerSelector }: ImageGalleryProviderProps) => { | ||
const [imageUrl, setImageUrl] = useState<string>(); | ||
|
||
useEffect(() => { | ||
document.addEventListener('click', (event: Event) => { | ||
const target = event?.target as HTMLElement | null; | ||
|
||
if (target?.classList.contains('gallery-item')) { | ||
return setImageUrl(target.dataset.src || target?.parentElement?.parentElement?.querySelector('img')?.src); | ||
} | ||
|
||
if (target?.classList.contains('gallery-item-container')) { | ||
return setImageUrl((target.querySelector('img.rcx-avatar__element') as HTMLImageElement | null)?.src); | ||
} | ||
if ( | ||
target?.classList.contains('gallery-item') && | ||
target?.parentElement?.parentElement?.classList.contains('gallery-item-container') | ||
) { | ||
return setImageUrl((target.parentElement.parentElement.querySelector('img.rcx-avatar__element') as HTMLImageElement | null)?.src); | ||
} | ||
|
||
if (target?.classList.contains('rcx-avatar__element') && target?.parentElement?.classList.contains('gallery-item')) { | ||
return setImageUrl((target as HTMLImageElement).src); | ||
} | ||
}); | ||
}, [containerSelector, imageSelector]); | ||
|
||
return ( | ||
<ImageGalleryContext.Provider value={{ imageUrl: imageUrl || '', isOpen: !!imageUrl, onClose: () => setImageUrl(undefined) }}> | ||
{children} | ||
{!!imageUrl && <ImageGallery />} | ||
</ImageGalleryContext.Provider> | ||
); | ||
}; | ||
|
||
export default ImageGalleryProvider; |
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
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