import React from 'react'; import { Property } from 'csstype'; import { Component, PropGetterFn, UnknownProperties, Intergalactic } from 'intergalactic/core'; import { BoxProps, FlexProps } from 'intergalactic/flex-box'; import type { Column } from './types'; declare const ROW_GROUP: unique symbol; export type DataTableData = { [key: string]: unknown; }; export type DataTableSort = [sortBy: Column, sortDirection: 'desc' | 'asc']; export type DataTableTheme = 'muted' | 'info' | 'success' | 'warning' | 'danger'; export type DataTableUse = 'primary' | 'secondary'; export type DataTableRow = DataTableCell[]; export type DataTableCell = { /** Name of column */ name: string; /** Data of column */ data: React.ReactNode; [key: string]: unknown; }; /** * Datatable must have an accessible name (aria-table-name). * It should describe table content. */ type DataTableAriaProps = Intergalactic.RequireAtLeastOne<{ 'aria-label'?: string; 'aria-labelledby'?: string; title?: string; }>; /** @deprecated */ export interface IDataTableProps extends Omit, keyof DataTableAriaProps> { } export type DataTableProps = BoxProps & { /** Table theme according to visual hierarchy on the page * @default primary * */ use?: DataTableUse; /** Data for table */ data?: DataTableData; /** Active sort object */ sort?: DataTableSort; /** Handler call when request will change sort */ onSortChange?: (sort: DataTableSort, e?: React.SyntheticEvent) => void; /** Field name in one data entity that is unique accross all dataset * @default id */ uniqueKey?: keyof DataTableData[0]; /** Make cells compact by changing left and right paddings to smaller ones*/ compact?: boolean; /** Count of total rows if table using virtual scroll. Needs for accessibility */ totalRows?: number; } & DataTableAriaProps; /** @deprecated */ export interface IDataTableHeadProps extends DataTableHeadProps, UnknownProperties { } export type DataTableHeadProps = BoxProps & { /** Sticky table header * @deprecated * */ sticky?: boolean; /** Hidden header */ hidden?: boolean; /** Disabled scroll (as action) */ disabledScroll?: boolean; /** Enable scroll bar element in header */ withScrollBar?: boolean; /** Disables column width change animation **/ animationsDisabled?: boolean; }; /** @deprecated */ export interface IDataTableColumnProps extends DataTableColumnProps, UnknownProperties { } export type DataTableColumnProps = FlexProps & { /** Unique column name */ name?: string; /** Enable sorting for column. And if you are passing a string, you can also set the default sorting */ sortable?: boolean | 'desc' | 'asc'; /** Enable resize for column * @ignore */ resizable?: boolean; /** Fix column on the left o right side of the table */ fixed?: 'left' | 'right'; /** Fields to control the size of the column */ flex?: Property.Flex | 'inherit'; /** Add vertical border to the column */ vBorders?: boolean; /** Add vertical border to the right side of the cell */ borderRight?: boolean; /** Add vertical border to the left side of the cell */ borderLeft?: boolean; /** * Enable changing column width with sort icon * @default false */ changeSortSize?: boolean; /** * Enable column to use as a column for recalculation width * @default false (By default used first column with maximum width) */ sortSizeRecalculation?: boolean; }; /** @deprecated */ export interface IDataTableBodyProps extends DataTableBodyProps, UnknownProperties { } export type DataTableBodyProps = BoxProps & { /** Rows table */ rows?: DataTableRow[]; /** When enabled, only visually acessable rows are rendered. * `tollerance` property controls how many rows outside of viewport are render. * `rowHeight` fixes the rows height if it has known. If not provided, first row node height is measured. * @default { tollerance: 2 } */ virtualScroll?: boolean | { tollerance?: number; rowHeight?: number; }; /** Allows to redefine rows renderning for a very deep and even fragile customization like building custom virtual scrolling */ renderRows?: (props: { rows: DataTableRow[]; columns: Column[]; renderRow: (row: DataTableRow, details: { dataIndex: number; }) => React.ReactNode; }) => React.ReactNode; /** * Called every time user scrolls area */ onScroll?: (event: React.SyntheticEvent) => void; /** Disabled scroll */ disabledScroll?: boolean; /** Disables column width change animation **/ animationsDisabled?: boolean; /** Ref for table body container */ scrollContainerRef?: React.Ref; }; /** @deprecated */ export interface IDataTableRowProps extends DataTableRowProps, UnknownProperties { } export type DataTableRowProps = BoxProps & { /** Theme for row */ theme?: DataTableTheme; /** Sets row state to active*/ active?: boolean; }; /** @deprecated */ export interface IDataTableCellProps extends DataTableCellProps, UnknownProperties { } export type DataTableCellProps = FlexProps & { /** Unique name for column or columns separated by / */ name: Name; /** Theme for cell */ theme?: DataTableTheme; }; type DataTableCtx = { getHeadProps: PropGetterFn; getBodyProps: PropGetterFn; }; type IntergalacticDataTableComponent = ((props: Intergalactic.InternalTypings.ComponentProps & PropsExtending, DataTableCtx, never>) => Intergalactic.InternalTypings.ComponentRenderingResults) & Intergalactic.InternalTypings.ComponentAdditive<'div', 'div', DataTableProps>; type IntergalacticDataTableRowComponent = ((props: Intergalactic.InternalTypings.PropsRenderingResultComponentProps... is used. */ data?: Data; } & PropsExtending, DataTableCtx & { data: Data; }, [ row: Data[0], index: number ]>) => Intergalactic.InternalTypings.ComponentRenderingResults) & Intergalactic.InternalTypings.ComponentAdditive<'div', 'div', DataTableRowProps>; type IntergalacticDataTableCellComponent = ((props: Intergalactic.InternalTypings.PropsRenderingResultComponentProps & { /** * That property is ONLY used for the componenct strict typings. In the component runtime `data` prop set on `... is used. */ data?: Data; } & PropsExtending, DataTableCtx & { data: Data; }, [ row: Data[0], index: number ]>) => Intergalactic.InternalTypings.ComponentRenderingResults) & Intergalactic.InternalTypings.ComponentAdditive<'div', 'div', DataTableCellProps>; declare const DefinitionTable: ((props: Intergalactic.InternalTypings.ComponentProps & {}, DataTableCtx, never>) => Intergalactic.InternalTypings.ComponentRenderingResults) & Intergalactic.InternalTypings.ComponentAdditive<"div", "div", DataTableProps, {}, {}> & { Head: Intergalactic.Component<'div', DataTableHeadProps>; Body: Intergalactic.Component<'div', DataTableBodyProps>; Column: Intergalactic.Component<'div', DataTableColumnProps>; Row: IntergalacticDataTableRowComponent; Cell: IntergalacticDataTableCellComponent; }; export { ROW_GROUP }; export default DefinitionTable; export declare const wrapDataTable: (wrapper: (props: Intergalactic.InternalTypings.EfficientOmit>, "tag" | "ref"> & { ref: React.Ref; tag: Intergalactic.InternalTypings.ComponentTag; } & PropsExtending) => React.ReactNode) => IntergalacticDataTableComponent; export declare const wrapDataTableRow: (wrapper: (props: Intergalactic.InternalTypings.EfficientOmit>, "tag" | "ref"> & { ref: React.Ref; tag: Intergalactic.InternalTypings.ComponentTag; } & PropsExtending) => React.ReactNode) => IntergalacticDataTableRowComponent; export declare const wrapDataTableCell: (wrapper: (props: Intergalactic.InternalTypings.EfficientOmit>, "tag" | "ref"> & { ref: React.Ref; tag: Intergalactic.InternalTypings.ComponentTag; } & PropsExtending) => React.ReactNode) => IntergalacticDataTableCellComponent;