forked from github/cinny
Show image viewer when clicking url preview thumbnail (#2309)
* Show large image overlay when clicking url preview thumbnail * Move image overlay into its own component * Move ImageOverlay props into extended type * Remove export for internal type
This commit is contained in:
45
src/app/components/ImageOverlay.tsx
Normal file
45
src/app/components/ImageOverlay.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { as, Modal, Overlay, OverlayBackdrop, OverlayCenter } from 'folds';
|
||||
import React, { ReactNode } from 'react';
|
||||
import { ModalWide } from '../styles/Modal.css';
|
||||
import { stopPropagation } from '../utils/keyboard';
|
||||
|
||||
export type RenderViewerProps = {
|
||||
src: string;
|
||||
alt: string;
|
||||
requestClose: () => void;
|
||||
};
|
||||
|
||||
type ImageOverlayProps = RenderViewerProps & {
|
||||
viewer: boolean;
|
||||
renderViewer: (props: RenderViewerProps) => ReactNode;
|
||||
};
|
||||
|
||||
export const ImageOverlay = as<'div', ImageOverlayProps>(
|
||||
({ src, alt, viewer, requestClose, renderViewer, ...props }, ref) => (
|
||||
<Overlay {...props} ref={ref} open={viewer} backdrop={<OverlayBackdrop />}>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: () => requestClose(),
|
||||
clickOutsideDeactivates: true,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
className={ModalWide}
|
||||
size="500"
|
||||
onContextMenu={(evt: any) => evt.stopPropagation()}
|
||||
>
|
||||
{renderViewer({
|
||||
src,
|
||||
alt,
|
||||
requestClose,
|
||||
})}
|
||||
</Modal>
|
||||
</FocusTrap>
|
||||
</OverlayCenter>
|
||||
</Overlay>
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user