hightable
Version:
A dynamic windowed scrolling table component for react
45 lines (44 loc) • 2.46 kB
TypeScript
import { CSSProperties, ReactNode } from 'react';
/**
* The width of a column depends on several factors.
* Some are given:
* - the number of columns
* - the global minimum width (minWidth prop, 50px by default)
* - the minimum width for a specific column, which overrides the default one (useColumnParameters context hook, optional)
* - the available width in the table (depends on the component resizes)
* Others are a state:
* - the fixed width, when a user resizes the column (note: it is stored in the local storage, and we don't adjust other columns when setting a fixed column)
* - the measured width (obtained by releasing any restriction on the column and measuring the content width - CSS max-width and other rules apply)
* - the adjusted width, computed to fill the available width when there are measured columns - not set if the column has a fixed width
*
* The width must be at least the minimum width. There is no maximum width.
*
* The priority order to decide the width of a column, based on these factors, is:
* 1. fixed width
* 2. measured width
* 3. adjusted width (if the column has been measured, and had to be adjusted)
* 4. undefined (free width, respects the CSS style rules if any)
*
* If any of the factors change, the widths of all the columns are recomputed. Special rules:
* - if a fixed or measured width does not respect the minimum width anymore, it is deleted.
* - when a column is resized manually (ie. fixed), the other columns remain unchanged and are not adjusted.
*/
interface ColumnWidthsContextType {
getWidth?: (columnIndex: number) => number | undefined;
getStyle?: (columnIndex: number) => CSSProperties;
getDataFixedWidth?: (columnIndex: number) => true | undefined;
releaseWidth?: (columnIndex: number) => void;
setAvailableWidth?: (value: number) => void;
setFixedWidth?: (columnIndex: number, value: number) => void;
setMeasuredWidth?: (columnIndex: number, value: number) => void;
}
export declare const ColumnWidthsContext: import("react").Context<ColumnWidthsContextType>;
interface ColumnWidthsProviderProps {
localStorageKey?: string;
numColumns: number;
minWidth?: number;
children: ReactNode;
}
export declare function ColumnWidthsProvider({ children, localStorageKey, numColumns, minWidth }: ColumnWidthsProviderProps): import("react/jsx-runtime").JSX.Element;
export declare function useColumnWidths(): ColumnWidthsContextType;
export {};