@combine-labs/combine-polaris
Version:
Combine Lab's product component library. Forked from Shopify's Polaris.
92 lines (91 loc) • 3.62 kB
TypeScript
import * as React from 'react';
import { WithAppProviderProps } from '../AppProvider';
export declare type CombinedProps = Props & WithAppProviderProps;
export declare type TableRowContent = Props['headings'] | Props['rows'] | Props['totals'];
export declare type TableData = string | number | React.ReactNode;
export declare type SortDirection = 'ascending' | 'descending' | 'none';
export declare type ColumnContentType = 'text' | 'numeric';
export interface TableRow {
/** A url for the entire row */
url?: string;
/** Lists of data points which map to table body rows. */
columns: TableData[];
}
export interface ColumnVisibilityData {
leftEdge: number;
rightEdge: number;
isVisible?: boolean;
}
export interface ScrollPosition {
left?: number;
top?: number;
}
export interface Props {
/** List of data types, which determines content alignment for each column. Data types are "text," which aligns left, or "numeric," which aligns right. */
columnContentTypes: ColumnContentType[];
/** If true, last column will be fixed to the right and always visible, even when scrolling horizontally. */
hasActionSuffix?: boolean;
/** List of column headings. */
headings: string[];
/** List of numeric column totals, highlighted in the table’s header below column headings. Use empty strings as placeholders for columns with no total. */
totals?: TableData[];
/** Array of rows to render the table body */
rows: TableRow[];
/** Truncate content in first column instead of wrapping.
* @default false
*/
truncate?: boolean;
/** Content centered in the full width cell of the table footer row. */
footerContent?: TableData;
/** List of booleans, which maps to whether sorting is enabled or not for each column. Defaults to false for all columns. */
sortable?: boolean[];
/**
* The direction to sort the table rows on first click or keypress of a sortable column heading. Defaults to ascending.
* @default 'ascending'
*/
defaultSortDirection?: SortDirection;
/**
* The index of the heading that the table rows are initially sorted by. Defaults to the first column.
* @default 0
*/
initialSortColumnIndex?: number;
/** Callback fired on click or keypress of a sortable column heading. */
onSort?(headingIndex: number, direction: SortDirection): void;
}
export interface State {
collapsed: boolean;
columnVisibilityData: ColumnVisibilityData[];
previousColumn?: ColumnVisibilityData;
currentColumn?: ColumnVisibilityData;
sortedColumnIndex?: number;
sortDirection?: SortDirection;
heights: number[];
prefixColumnWidth?: number;
preservedScrollPosition: ScrollPosition;
isScrolledFarthestLeft?: boolean;
isScrolledFarthestRight?: boolean;
}
export declare class DataTable extends React.PureComponent<CombinedProps, State> {
state: State;
private dataTable;
private scrollContainer;
private table;
private totalsRowHeading;
constructor(props: CombinedProps);
componentDidMount(): void;
componentDidUpdate(prevProps: Props): void;
render(): JSX.Element;
private handleResize;
private tallestCellHeights;
private resetScrollPosition;
private setHeightsAndScrollPosition;
private calculateColumnVisibilityData;
private scrollListener;
private navigateTable;
private renderTotals;
private defaultRenderRow;
private renderFooter;
private defaultOnSort;
}
declare const _default: React.ComponentClass<Props> & typeof DataTable;
export default _default;