web-ui-pack
Version:
Web package with UI elements
36 lines (35 loc) • 1.61 kB
TypeScript
type BasicRect = Pick<DOMRect, "top" | "right" | "bottom" | "left">;
interface IntoViewOptions {
/** Point parents if it's already defined outside function */
scrollParents?: HTMLElement[] | null;
/** Point el.getBoundingClientRect result if it's already defined outside function */
elRect?: BasicRect;
/** Virtual margin of target element [top, right, bottom, left] or [top/bottom, right/left] in px */
offset?: [number, number] | [number, number, number, number];
}
interface IntoViewResult {
/** Completely hidden by parents x-scroll (hidden within horizontal scroll) */
hiddenX: false | HTMLElement;
/** Completely hidden by parents y-scroll (hidden within vertical scroll) */
hiddenY: false | HTMLElement;
/** Partially hidden/visible by parents x-scroll */
partialHiddenX: false | HTMLElement;
/** Partially hidden/visible by parents y-scroll */
partialHiddenY: false | HTMLElement;
/** Completely hidden (when hiddenX || hiddenY) */
hidden: false | HTMLElement;
/** Completely visible */
visible: boolean;
/** Partial hidden/visible (when partialHiddenX || partialHiddenY) */
partialVisible: false | HTMLElement;
}
/** Checks if element is visible in scrollable parents and returns detailed result;
*
* If need to get scrollable parents too then use the following logic
* @example
* ```js
* const scrollParents = findScrollParentAll(el) || [document.body];
* const result = isIntoView(el, { scrollParents });
* ``` */
export default function isIntoView(el: Element, options?: IntoViewOptions): IntoViewResult;
export {};