Files
outline/app/hooks/useHideElement.ts
Tom MoorandClaude Opus 4.8 283edf8ffd 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>
2026-06-19 17:19:36 -04:00

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]);
}