@primer/react
Version:
An implementation of GitHub's Primer Design System using React
76 lines (75 loc) • 2.66 kB
TypeScript
import { ObjectPaths } from "./utils.js";
import { UniqueRow } from "./row.js";
import { SortDirection } from "./sorting.js";
import { Column } from "./column.js";
import React from "react";
//#region src/DataTable/DataTable.d.ts
type DataTableProps<Data extends UniqueRow> = {
/**
* Provide an id to an element which uniquely describes this table
*/
'aria-describedby'?: string;
/**
* Provide an id to an element which uniquely labels this table
*/
'aria-labelledby'?: string;
/**
* Specify the amount of space that should be available around the contents of
* a cell
*/
cellPadding?: 'condensed' | 'normal' | 'spacious';
/**
* Provide a collection of the rows which will be rendered inside of the table
*/
data: Array<Data>;
/**
* Provide the columns for the table and the fields in `data` to which they
* correspond
*/
columns: Array<Column<Data>>;
/**
* Provide the id or field of the column by which the table is sorted. When
* using this `prop`, the input data must be sorted by this column in
* ascending order
*/
initialSortColumn?: ObjectPaths<Data> | string | number;
/**
* Provide the sort direction that the table should be sorted by on the
* currently sorted column
*/
initialSortDirection?: Exclude<SortDirection, 'NONE'>;
/**
* When true, disables client-side sorting for all sortable columns in the
* table. Use this when sorting is handled server-side. The `onToggleSort`
* callback will still be fired when a sortable column header is clicked.
*/
externalSorting?: boolean;
/**
* Provide a function to determine the unique identifier for each row.
* This function allows you to customize the key used for the row.
* By default, the table uses the `id` field from the data.
* @param rowData The row data object for which the ID is being retrieved.
* @returns The unique identifier for the row, which can be a string or number.
*/
getRowId?: (rowData: Data) => string | number;
/**
* Fires every time the user clicks a sortable column header. It reports
* the column id that is now sorted and the direction after the toggle
* (never `"NONE"`).
*/
onToggleSort?: (columnId: ObjectPaths<Data> | string | number, direction: Exclude<SortDirection, 'NONE'>) => void;
};
declare function DataTable<Data extends UniqueRow>({
'aria-labelledby': labelledby,
'aria-describedby': describedby,
cellPadding,
columns,
data,
initialSortColumn,
initialSortDirection,
externalSorting,
getRowId,
onToggleSort
}: DataTableProps<Data>): React.JSX.Element;
//#endregion
export { DataTable, DataTableProps };