mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +03:00
Hide original element during lightbox transition (#12756)
* fix: Lightbox effect tweaks * refactor * refactor * fix: Address review feedback on image lightbox - Use useLayoutEffect in useHideElement to hide/restore before paint - Intersperse separators between image hover actions to avoid orphaned dividers when Download is hidden in edit mode Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
f5f81f8d3a
commit
283edf8ffd
3 files changed
+77
-31
No files matched your search
@@ -64,6 +64,7 @@ import { HStack } from "./primitives/HStack";
|
||||
import { useDocumentContext } from "./DocumentContext";
|
||||
import LightboxComments from "~/scenes/Document/components/Comments/LightboxComments";
|
||||
import { PortalContext } from "./Portal";
|
||||
import useHideElement from "~/hooks/useHideElement";
|
||||
|
||||
export enum LightboxStatus {
|
||||
READY_TO_OPEN,
|
||||
@@ -361,6 +362,15 @@ function Lightbox({ images, activeImage, onUpdate, onClose, readOnly }: Props) {
|
||||
}
|
||||
}, [status.image]);
|
||||
|
||||
// Hide the inline image in the editor while the lightbox zoom transition is
|
||||
// active, otherwise a duplicate is visible behind the fading overlay.
|
||||
useHideElement(
|
||||
activeImage.getElement(),
|
||||
status.lightbox !== null &&
|
||||
status.lightbox !== LightboxStatus.READY_TO_OPEN &&
|
||||
status.lightbox !== LightboxStatus.CLOSED
|
||||
);
|
||||
|
||||
const rememberImagePosition = () => {
|
||||
if (imgRef.current) {
|
||||
const lightboxImgDOMRect = imgRef.current.getBoundingClientRect();
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useLayoutEffect } from "react";
|
||||
|
||||
/**
|
||||
* Temporarily hides a DOM element while `enabled` is true, restoring its
|
||||
* previous visibility when disabled or unmounted. Useful for shared-element
|
||||
* transitions where an element should be hidden so it isn't visible behind the
|
||||
* animating clone.
|
||||
*
|
||||
* @param element The element to hide.
|
||||
* @param enabled Whether the element should currently be hidden.
|
||||
*/
|
||||
export default function useHideElement(
|
||||
element: Element | null | undefined,
|
||||
enabled: boolean
|
||||
) {
|
||||
useLayoutEffect(() => {
|
||||
if (
|
||||
!enabled ||
|
||||
(!(element instanceof HTMLElement) && !(element instanceof SVGElement))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const previousVisibility = element.style.visibility;
|
||||
element.style.visibility = "hidden";
|
||||
return () => {
|
||||
element.style.visibility = previousVisibility;
|
||||
};
|
||||
}, [element, enabled]);
|
||||
}
|
||||
@@ -114,6 +114,37 @@ const Image = (props: Props) => {
|
||||
}
|
||||
};
|
||||
|
||||
const actions = [
|
||||
isExternalUrl(src) && (
|
||||
<Button key="open" onClick={handleOpen} aria-label={t("Open")}>
|
||||
<GlobeIcon />
|
||||
</Button>
|
||||
),
|
||||
imgLink && (
|
||||
<Button
|
||||
key="zoom"
|
||||
// `mousedown` on ancestor `div.ProseMirror` was preventing the `onClick` handler from firing
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
onClick={props.onZoomIn}
|
||||
aria-label={t("Zoom in")}
|
||||
>
|
||||
<ZoomInIcon />
|
||||
</Button>
|
||||
),
|
||||
!isEditable && (
|
||||
<Button
|
||||
key="download"
|
||||
onClick={handleDownload}
|
||||
// `mousedown` on ancestor `div.ProseMirror` was preventing the `onClick` handler from firing
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
aria-label={t("Download")}
|
||||
disabled={isDownloading}
|
||||
>
|
||||
<DownloadIcon />
|
||||
</Button>
|
||||
),
|
||||
].filter(Boolean);
|
||||
|
||||
return (
|
||||
<div contentEditable={false} className={className} ref={ref}>
|
||||
<ImageWrapper
|
||||
@@ -126,38 +157,14 @@ const Image = (props: Props) => {
|
||||
}
|
||||
style={widthStyle}
|
||||
>
|
||||
{!dragging && width > 60 && isDownloadable && (
|
||||
{!dragging && width > 60 && isDownloadable && actions.length > 0 && (
|
||||
<Actions>
|
||||
{isExternalUrl(src) && (
|
||||
<>
|
||||
<Button onClick={handleOpen} aria-label={t("Open")}>
|
||||
<GlobeIcon />
|
||||
</Button>
|
||||
<Separator height={24} />
|
||||
</>
|
||||
)}
|
||||
{imgLink && (
|
||||
<>
|
||||
<Button
|
||||
// `mousedown` on ancestor `div.ProseMirror` was preventing the `onClick` handler from firing
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
onClick={props.onZoomIn}
|
||||
aria-label={t("Zoom in")}
|
||||
>
|
||||
<ZoomInIcon />
|
||||
</Button>
|
||||
<Separator height={24} />
|
||||
</>
|
||||
)}
|
||||
<Button
|
||||
onClick={handleDownload}
|
||||
// `mousedown` on ancestor `div.ProseMirror` was preventing the `onClick` handler from firing
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
aria-label={t("Download")}
|
||||
disabled={isDownloading}
|
||||
>
|
||||
<DownloadIcon />
|
||||
</Button>
|
||||
{actions.map((action, index) => (
|
||||
<React.Fragment key={index}>
|
||||
{index > 0 && <Separator height={24} />}
|
||||
{action}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</Actions>
|
||||
)}
|
||||
{error ? (
|
||||
|
||||
Reference in new issue
Block a user