import { type ComponentType, type ReactNode } from "react"; import { type StyleProp, type ViewStyle } from "../../style/index.js"; import { type CheckboxProps } from "../../atoms/checkbox/checkbox.shared.js"; import { type PaginationProps } from "../../atoms/pagination/pagination.shared.js"; import { type SkeletonProps } from "../../atoms/skeleton/skeleton.shared.js"; import { type Density, type DataTableSkin } from "./data-table.styles.js"; export type { Density }; /** * A column descriptor. Plain strings stay supported (a string is shorthand for * `{ label }`); the object form unlocks per-column alignment, fixed widths, and * sorting. */ export interface DataTableColumn { /** Column header label. */ label: string; /** Stable identity used by `sort.column`; defaults to the label. */ key?: string; /** Right-align the header and cells (amounts, counts, measurements). */ numeric?: boolean; /** Center the header and cells (short status/flag columns). */ centered?: boolean; /** Fixed width in px instead of the equal flex share. */ width?: number; /** * Opt this column into header-press sorting. Unnecessary when the table-level * `sortable` is set (there it opts back OUT via `sortable: false`). */ sortable?: boolean; /** * Derive the comparable value for sorting when this column's cells are custom * ReactNodes (a Badge, a link). String/number cells sort out of the box; * without this, custom-node cells sort last. */ sortValue?: (cell: ReactNode, row: ReactNode[], rowIndex: number) => string | number | null | undefined; } /** The active sort: which column (by `key`, or label) and which direction. */ export interface DataTableSort { /** The sorted column's `key` (the label when no key was given). */ column: string; /** Descending when true; ascending otherwise. */ descending?: boolean; } export interface DataTableProps { /** * Columns: a header label per column, or a `DataTableColumn` descriptor for * per-column alignment (`numeric`/`centered`), a fixed `width`, and sorting * (`sortable`, `sortValue`). Strings and descriptors mix freely. */ columns: Array; /** * Row data: an array of rows, each an array of cells (one per column). A cell is * a string (rendered in the default cell type) or any ReactNode for a custom * cell — a link, a `Badge`, a monospace name, etc. (rendered directly). */ rows: ReactNode[][]; /** Tint every other data row for easier horizontal scanning. */ striped?: boolean; /** Wrap the table in a rounded outer border. */ bordered?: boolean; /** Tighter vertical padding on header and data cells. */ compact?: boolean; /** Looser vertical padding on header and data cells. */ comfortable?: boolean; /** * Make every column sortable: pressing a header cycles ascending, descending, * off. A column descriptor opts back out with `sortable: false`. Sorting is * self-managed out of the box; control it via `sort`/`onSortChange`. */ sortable?: boolean; /** Controlled sort state (`null` = unsorted). Omit for uncontrolled use. */ sort?: DataTableSort | null; /** Initial sort for uncontrolled use. */ defaultSort?: DataTableSort | null; /** Fired with the next sort (or `null` when cleared) on header press. */ onSortChange?: (sort: DataTableSort | null) => void; /** * Row selection: a leading checkbox column with a select-all header checkbox * (indeterminate on a partial selection). Selection is keyed by `rowKey` (the * row's original index when omitted) and self-managed out of the box; control * it via `selectedKeys`/`onSelectionChange`. When no `onRowPress` is set, * pressing anywhere on a row toggles it. */ selectable?: boolean; /** Controlled selected row keys. Omit for uncontrolled use. */ selectedKeys?: Array; /** Initial selected row keys for uncontrolled use. */ defaultSelectedKeys?: Array; /** Fired with the next selected keys when a row or the select-all is toggled. */ onSelectionChange?: (keys: Array) => void; /** * Page the rows through a built-in footer (the kit Pagination): a * "Showing X-Y of N" range with Prev/Next, plus the selection count when * `selectable`. Sorting applies before paging. Self-managed out of the box; * control the page via `page`/`onPageChange`. */ paginated?: boolean; /** Rows per page (CONTROLLED; default 10, or the first of `pageSizes`). */ pageSize?: number; /** Initial rows per page for uncontrolled use. */ defaultPageSize?: number; /** * Selectable rows-per-page values. Supplying them upgrades the footer to the * Pagination `withSize` variant (a "Rows per page" selector). */ pageSizes?: number[]; /** Fired with the next rows-per-page value when the footer selector changes it. */ onPageSizeChange?: (size: number) => void; /** Current page, 1-based (CONTROLLED). Omit for uncontrolled use. */ page?: number; /** Initial page for uncontrolled use. */ defaultPage?: number; /** Fired with the next 1-based page when the footer pagination navigates. */ onPageChange?: (page: number) => void; /** * Loading state: the body renders pulsing skeleton placeholder rows (one per * would-be row on the page) instead of data. */ loading?: boolean; /** * What to render, centered under the header, when `rows` is empty (and not * `loading`). A string gets the muted caption type; any ReactNode renders as * given (an `EmptyState`, a retry Button). Omitted = just the header row, as * before. */ emptyMessage?: ReactNode; /** When set, each data row is pressable, reporting the row data and its index in `rows`. */ onRowPress?: (row: ReactNode[], index: number) => void; /** * Row editing: passing this adds a trailing actions column with a pencil * button per row. Pressing the pencil opens the row's edit mode (its string * cells become fields with a trailing Save/Cancel pair) and fires this with * the row's original index in `rows`. Save reports the edited cells through * `onRowCommit`; Cancel (or Escape in a field) closes without committing. */ onRowEdit?: (rowIndex: number) => void; /** * Row deletion: passing this adds a delete (bin) button to the trailing * actions column. Delete is second-press confirm: the first press ARMS it * (the bin turns destructive and its accessible name says confirm), a second * press within the confirm window fires this with the row's original index, * and pressing anywhere else in the table (or the window lapsing) disarms. */ onRowDelete?: (rowIndex: number) => void; /** * Let string cells be edited in place: pressing one swaps it to a field. * Enter or blur commits through `onCellCommit`; Escape restores the cell. * Custom ReactNode cells (badges, links) are not editable. */ inlineEdit?: boolean; /** * Fired when an `inlineEdit` cell commits (Enter or blur) with a changed * value: the row's original index in `rows`, the column index, and the next * text. Data stays yours: re-render with updated `rows` to keep the edit. */ onCellCommit?: (rowIndex: number, colIndex: number, next: string) => void; /** * Fired when a pencil-opened row edit is saved: the row's original index in * `rows` and the full cells array with the edited strings in place (custom * ReactNode cells pass through unchanged). */ onRowCommit?: (rowIndex: number, cells: ReactNode[]) => void; /** * Render the data rows through a windowed `FlatList` instead of mounting every * row up front, for large tables. The header row stays fixed above it. Give the * table a bounded height (via `style`, e.g. `{ maxHeight: 400 }`) so the body can * scroll; without one it warns and renders eagerly. Default mounts all rows. */ virtualized?: boolean; /** * Stable key for a row, derived from the row data and its index in `rows`. * Selection is keyed by it, and it keeps React row identity stable when rows * reorder (sorting, live data) and a cell is a stateful custom ReactNode. When * omitted, rows key off their original array index (safe for string/number * cells and stateless custom cells; selection then tracks row POSITIONS, so * supply a real key when the data itself can be reordered, inserted, or * deleted). */ rowKey?: (row: ReactNode[], index: number) => string | number; /** E2E hook forwarded to the root element. */ testID?: string; /** Outer layout composition only (width/flex within a parent), never a restyle hook. */ style?: StyleProp; } export interface DataTableParts { Checkbox: ComponentType; Pagination: ComponentType; Skeleton: ComponentType; } /** Build a DataTable component from a platform skin plus its platform parts. */ export declare function createDataTable(skin: DataTableSkin, parts: DataTableParts): (props: DataTableProps) => import("react").JSX.Element; //# sourceMappingURL=data-table.shared.d.ts.map