UNPKG

@payfit/unity-components

Version:

78 lines (77 loc) 2.84 kB
/** * Strategy for detecting scrollable content */ export type ScrollDetectionStrategy = 'size' | 'style' | 'both'; /** * Detailed detection results for both size and style methods */ export interface DetectionMethod { size: { vertical: boolean; horizontal: boolean; }; style: { vertical: boolean; horizontal: boolean; }; } /** * Result of scroll detection */ export interface ScrollDetectionResult { hasVerticalScroll: boolean; hasHorizontalScroll: boolean; hasAnyScroll: boolean; detectionMethod: DetectionMethod; } /** * Detects if an element has scrollable content using the specified strategy. * This is a pure function with no side effects, making it easy to test * and reuse in different contexts (React hooks, vanilla JS, etc.) * @param {HTMLElement} element - DOM element to check * @param {ScrollDetectionStrategy} strategy - Detection strategy to use * @returns {ScrollDetectionResult} Detailed scroll detection result * @example * ```ts * const element = document.getElementById('container'); * const result = detectScroll(element, 'size'); * if (result.hasVerticalScroll) { * console.log('Element has vertical scroll'); * } * ``` * @example * ```ts * // Check both strategies for debugging * const result = detectScroll(element, 'both'); * console.log('Size detection:', result.detectionMethod.size); * console.log('Style detection:', result.detectionMethod.style); * ``` */ export declare function detectScroll(element: HTMLElement, strategy?: ScrollDetectionStrategy): ScrollDetectionResult; /** * Simplified helper to check if element has any scrollable content * @param {HTMLElement} element - DOM element to check * @param {ScrollDetectionStrategy} strategy - Detection strategy to use * @returns {boolean} True if element has any scrollable content * @example * ```ts * if (hasScroll(document.getElementById('container'))) { * console.log('Has scroll'); * } * ``` */ export declare function hasScroll(element: HTMLElement, strategy?: ScrollDetectionStrategy): boolean; /** * Check if element has vertical scrollable content * @param {HTMLElement} element - DOM element to check * @param {ScrollDetectionStrategy} strategy - Detection strategy to use * @returns {boolean} True if element has vertical scrollable content */ export declare function hasVerticalScroll(element: HTMLElement, strategy?: ScrollDetectionStrategy): boolean; /** * Check if element has horizontal scrollable content * @param {HTMLElement} element - DOM element to check * @param {ScrollDetectionStrategy} strategy - Detection strategy to use * @returns {boolean} True if element has horizontal scrollable content */ export declare function hasHorizontalScroll(element: HTMLElement, strategy?: ScrollDetectionStrategy): boolean;