mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
* 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>
30 lines
875 B
TypeScript
30 lines
875 B
TypeScript
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]);
|
|
}
|