UNPKG

@rkosafo/cai.components

Version:

This package is under development and not ready for public use.

47 lines (46 loc) 1.47 kB
import { browser } from '$app/environment'; const defaultConfig = { headerOffset: 200, footerOffset: 70, additionalOffset: 0 }; /** * Calculate table height based on window dimensions and offsets */ export function calculateTableHeight(config = {}) { const { headerOffset, footerOffset, additionalOffset } = { ...defaultConfig, ...config }; return window.innerHeight - headerOffset - footerOffset - additionalOffset; } /** * Create a reactive table height store that updates on window resize */ export function createTableHeightStore(config = {}) { let height = calculateTableHeight(config); const updateHeight = () => { height = calculateTableHeight(config); }; // Initialize and set up resize listener if (browser) { window.addEventListener('resize', updateHeight); } return { get height() { return height; }, update: updateHeight, dispose: () => { if (browser) { window.removeEventListener('resize', updateHeight); } } }; } /** * Get table height for specific use cases with predefined offsets */ export const tableHeightPresets = { default: () => calculateTableHeight(), compact: () => calculateTableHeight({ headerOffset: 150, footerOffset: 50 }), spacious: () => calculateTableHeight({ headerOffset: 250, footerOffset: 100 }), custom: (config) => calculateTableHeight(config) };