open banner in image viewer

This commit is contained in:
7w1 committed 2026-05-13 21:39:44 -05:00
1 parent 43c69e78e1
commit 51eaef8ab9
1 file changed
+47
+47
View File
@@ -12,6 +12,10 @@ import {
Line,
Menu,
MenuItem,
Modal,
Overlay,
OverlayBackdrop,
OverlayCenter,
PopOut,
Spinner,
Text,
@@ -88,6 +92,8 @@ import { nameInitials } from '$utils/common';
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
import { CustomStateEvent } from '$types/matrix/room';
import type { RoomBannerContent } from '$types/matrix-sdk-events';
import { ModalWide } from '$styles/Modal.css';
import { ImageViewer } from '$components/image-viewer';
import * as css from './styles.css';
import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze';
@@ -283,6 +289,11 @@ function SpaceHeader({ hideText, mx }: { hideText?: boolean; mx: MatrixClient })
const bannerURI = mxcUrlToHttp(mx, bannerMXC ?? '', true);
const hasBanner = !!(bannerURI && !hideText && showBanners);
const [bannerViewerOpen, setBannerViewerOpen] = useState(false);
useEffect(() => {
if (!hasBanner) setBannerViewerOpen(false);
}, [hasBanner]);
return (
<>
<div className={hasBanner ? css.RoomCoverHeaderContainer : ''}>
@@ -368,6 +379,16 @@ function SpaceHeader({ hideText, mx }: { hideText?: boolean; mx: MatrixClient })
src={bannerURI}
alt={`${spaceName}'s banner`}
draggable="false"
role="button"
tabIndex={0}
aria-label={`View ${spaceName} banner`}
onClick={() => setBannerViewerOpen(true)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
setBannerViewerOpen(true);
}
}}
/>
<SidebarResizer
setCurWidth={setCurHeight}
@@ -383,6 +404,32 @@ function SpaceHeader({ hideText, mx }: { hideText?: boolean; mx: MatrixClient })
</div>
</>
)}
{hasBanner && bannerViewerOpen && (
<Overlay open backdrop={<OverlayBackdrop />}>
<OverlayCenter>
<FocusTrap
focusTrapOptions={{
initialFocus: false,
onDeactivate: () => setBannerViewerOpen(false),
clickOutsideDeactivates: true,
escapeDeactivates: stopPropagation,
}}
>
<Modal
className={ModalWide}
size="500"
onContextMenu={(evt: React.MouseEvent) => evt.stopPropagation()}
>
<ImageViewer
src={bannerURI}
alt={`${spaceName} banner`}
requestClose={() => setBannerViewerOpen(false)}
/>
</Modal>
</FocusTrap>
</OverlayCenter>
</Overlay>
)}
</>
);
}