mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-16 10:51:06 +00:00
Tweaks to DataTable generics (#1968)
Adjust DataTable types. - Make key in `cell` slot prop less strict to prevent type errors in markup. - Resolve property path names up to one level deep for header keys.
This commit is contained in:
parent
140e8ff468
commit
e49369ef02
7 changed files with 79 additions and 27 deletions
|
@ -926,14 +926,15 @@ None.
|
|||
### Types
|
||||
|
||||
```ts
|
||||
export type DataTableKey<Row = DataTableRow> = Exclude<keyof Row, "id">;
|
||||
export type DataTableKey<Row = DataTableRow> =
|
||||
import("./DataTableTypes.d.ts").PropertyPath<Row>;
|
||||
|
||||
export type DataTableValue = any;
|
||||
|
||||
export interface DataTableEmptyHeader<Row = DataTableRow> {
|
||||
key: DataTableKey<Row>;
|
||||
empty: boolean;
|
||||
display?: (item: DataTableValue, row: Row) => DataTableValue;
|
||||
display?: (item: Value, row: Row) => DataTableValue;
|
||||
sort?: false | ((a: DataTableValue, b: DataTableValue) => number);
|
||||
columnMenu?: boolean;
|
||||
width?: string;
|
||||
|
@ -943,7 +944,7 @@ export interface DataTableEmptyHeader<Row = DataTableRow> {
|
|||
export interface DataTableNonEmptyHeader<Row = DataTableRow> {
|
||||
key: DataTableKey<Row>;
|
||||
value: DataTableValue;
|
||||
display?: (item: DataTableValue, row: Row) => DataTableValue;
|
||||
display?: (item: Value, row: Row) => DataTableValue;
|
||||
sort?: false | ((a: DataTableValue, b: DataTableValue) => number);
|
||||
columnMenu?: boolean;
|
||||
width?: string;
|
||||
|
@ -962,9 +963,9 @@ export interface DataTableRow {
|
|||
export type DataTableRowId = any;
|
||||
|
||||
export interface DataTableCell<Row = DataTableRow> {
|
||||
key: DataTableKey<Row>;
|
||||
key: DataTableKey<Row> | (string & {});
|
||||
value: DataTableValue;
|
||||
display?: (item: DataTableValue, row: DataTableRow) => DataTableValue;
|
||||
display?: (item: Value, row: DataTableRow) => DataTableValue;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue