vira
Version:
A simple and highly versatile design system using element-vir.
26 lines (25 loc) • 1.18 kB
TypeScript
/**
* Creates an observer that monitors whether an element's content overflows its visible width. Uses
* a ResizeObserver for size changes and a MutationObserver for DOM content changes.
*
* @category Util
* @returns A cleanup function that disconnects all observers.
*/
export declare function createOverflowObserver({ element, widthElement, onChange, hysteresisPx, }: Readonly<{
/** The element whose `scrollWidth` is measured for content size. */
element: Element;
/**
* Optional separate element whose `clientWidth` is used as the available width. Defaults to
* `element`. Useful when `element` may be collapsed but the available width should come from a
* parent.
*/
widthElement?: Element | undefined;
onChange: (isOverflowing: boolean) => void;
/**
* Pixel margin required to flip the overflow state. Once overflowing, the content must fit
* within `availableWidth - hysteresisPx` to flip back; once not overflowing, the content must
* exceed `availableWidth + hysteresisPx` to flip on. Prevents rapid toggling from minute size
* changes.
*/
hysteresisPx?: number | undefined;
}>): () => void;