@payfit/unity-components
Version:
52 lines (51 loc) • 1.6 kB
TypeScript
/**
* Strategy for detecting scrollable content
*/
export type ScrollDetectionStrategy = 'size' | 'style' | 'both';
/**
* Detailed detection results for both size and style methods
*/
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;
export {};