@uxf/data-grid 11.93.3 → 11.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -65,6 +65,27 @@ const { state, actions } = useDataGridControl({
65
65
  useUserConfig(actions);
66
66
  ```
67
67
 
68
+ ## Row type
69
+
70
+ Create a `column-types.d.ts` file in your project and add the following:
71
+
72
+ ```tsx
73
+ declare module "@uxf/data-grid/column-types" {
74
+ export interface ColumnTypes {
75
+ "my-custom-type": MyCustomType;
76
+ }
77
+ }
78
+ ```
79
+
80
+ Then you can use it in your code:
81
+
82
+ ```tsx
83
+ import { InferDataGridRow } from "@uxf/data-grid";
84
+ import { schema } from "@generated/data-grid/schema/example";
85
+
86
+ type Row = InferDataGridRow<typeof schema>;
87
+ ```
88
+
68
89
  ## Supported FilterHandlers
69
90
 
70
91
  - `bool` - Select (yes / no / null)
@@ -31,7 +31,11 @@ function generateRowType(gridName, schema, columnTypes) {
31
31
  return "";
32
32
  }
33
33
 
34
- return `export type DataGridRow_${camelize(gridName)} = {
34
+ return `/**
35
+ * @deprecated
36
+ * Use: \`InferDataGridRow<typeof schema>;\`
37
+ */
38
+ export type DataGridRow_${camelize(gridName)} = {
35
39
  ${schema.columns.map((column) => `"${column.name}": ColumnTypes["${column.type}"]`).join("\n ")}
36
40
  }`;
37
41
  }
@@ -0,0 +1,25 @@
1
+ import { DateString, DatetimeString } from "@uxf/core/date";
2
+ import { Money } from "@uxf/core/money";
3
+ export interface ColumnTypes {
4
+ bool: boolean | null;
5
+ chip: {
6
+ id: string | number;
7
+ label: string;
8
+ color?: string;
9
+ } | null;
10
+ chips: Array<{
11
+ id: string | number;
12
+ label: string;
13
+ color?: string;
14
+ }>;
15
+ date: DateString | null;
16
+ datetime: DatetimeString | null;
17
+ email: string | null;
18
+ id: number;
19
+ int: number | null;
20
+ money: Money | null;
21
+ phone: string | null;
22
+ string: string | null;
23
+ url: string | null;
24
+ uuid: string;
25
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/data-grid-v2.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
2
  import { BaseGridType, DataGridProps } from "./types";
3
- export declare function DataGridV2<GridType extends BaseGridType, R = any>(props: DataGridProps<GridType, R>): React.JSX.Element;
3
+ export declare function DataGridV2<GridType extends BaseGridType>(props: DataGridProps<GridType>): React.JSX.Element;
package/data-grid.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
2
  import { BaseGridType, DataGridProps } from "./types";
3
- export declare function DataGrid<GridType extends BaseGridType, R = any>(props: DataGridProps<GridType, R>): React.JSX.Element;
3
+ export declare function DataGrid<GridType extends BaseGridType>(props: DataGridProps<GridType>): React.JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import { FunctionComponent } from "react";
2
2
  import { Column, Schema } from "../types";
3
3
  import { DataGridControl } from "../use-data-grid-control";
4
- export type ColumnWithId = Column<any, any> & {
4
+ export type ColumnWithId = Column & {
5
5
  id: string;
6
6
  };
7
7
  export type SectionKey = "visible" | "hidden";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/data-grid",
3
- "version": "11.93.3",
3
+ "version": "11.94.0",
4
4
  "description": "UXF DataGrid",
5
5
  "homepage": "https://gitlab.com/uxf-npm/data-grid#readme",
6
6
  "main": "index.js",
@@ -38,7 +38,7 @@
38
38
  "@dnd-kit/sortable": "10.0.0",
39
39
  "@uxf/core": "11.93.0",
40
40
  "@uxf/core-react": "11.93.0",
41
- "@uxf/ui": "11.93.3",
41
+ "@uxf/ui": "11.94.0",
42
42
  "dayjs": "1.11.19",
43
43
  "deepmerge": "4.3.1",
44
44
  "fast-glob": "3.3.3",
@@ -1,7 +1,7 @@
1
1
  import React, { ReactNode } from "react";
2
2
  import { Column } from "../../types";
3
3
  interface CellProps {
4
- column: Column<any, any>;
4
+ column: Column;
5
5
  children: ReactNode;
6
6
  }
7
7
  export declare function Cell(props: CellProps): React.JSX.Element;
@@ -2,7 +2,7 @@ import { Nullish } from "@uxf/core/types";
2
2
  import React from "react";
3
3
  import { Column, DataGridSort } from "../../types";
4
4
  export interface HeaderCellProps {
5
- column: Column<any, any>;
5
+ column: Column;
6
6
  onResizeStart: () => void;
7
7
  onAutoSize?: () => void;
8
8
  sort: DataGridSort | Nullish;
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
- import { KeyExtractor } from "../../types";
2
+ import { BaseGridType, KeyExtractor } from "../../types";
3
3
  import { DataGridTableProps } from "../types";
4
- interface SelectRowCheckboxProps extends Pick<DataGridTableProps<any>, "state" | "data" | "actions" | "isRowSelectDisabled"> {
4
+ interface SelectRowCheckboxProps<GridType extends BaseGridType> extends Pick<DataGridTableProps<GridType>, "state" | "data" | "actions" | "isRowSelectDisabled"> {
5
5
  keyExtractor: KeyExtractor;
6
6
  }
7
- export declare function HeaderSelectAllRowsCheckbox(props: SelectRowCheckboxProps): React.JSX.Element;
7
+ export declare function HeaderSelectAllRowsCheckbox<GridType extends BaseGridType>(props: SelectRowCheckboxProps<GridType>): React.JSX.Element;
8
8
  export {};
@@ -1,8 +1,8 @@
1
1
  import { Nullish } from "@uxf/core/types";
2
- import { Column } from "../../types";
2
+ import { BaseGridType, Column } from "../../types";
3
3
  import { DataGridControl } from "../../use-data-grid-control";
4
4
  import { DataGridTableProps } from "../types";
5
- export declare function useResizableColumns(columns: Column<any, any>[], actionCell: DataGridTableProps<any>["actionCell"], actions: DataGridControl["actions"], selectRowsCellWidth: number | Nullish): {
5
+ export declare function useResizableColumns<GridType extends BaseGridType>(columns: Column[], actionCell: DataGridTableProps<GridType>["actionCell"], actions: DataGridControl["actions"], selectRowsCellWidth: number | Nullish): {
6
6
  tableRef: import("react").RefObject<HTMLDivElement>;
7
7
  columnRefs: import("react").MutableRefObject<(HTMLDivElement | null)[]>;
8
8
  onResizeStart(index: number): void;
@@ -1,3 +1,4 @@
1
1
  import React from "react";
2
+ import { BaseGridType } from "../types";
2
3
  import { DataGridTableProps } from "./types";
3
- export declare function DataGridTableV2(props: DataGridTableProps<any>): React.JSX.Element;
4
+ export declare function DataGridTableV2<GridType extends BaseGridType>(props: DataGridTableProps<GridType>): React.JSX.Element;
@@ -1,24 +1,24 @@
1
1
  import { Nullish } from "@uxf/core/types";
2
- import { ActionCellComponent, BodyCellComponents, KeyExtractor, RowAccent, Schema } from "../types";
2
+ import { ActionCellComponent, BaseGridType, BodyCellComponents, InferDataGridRow, KeyExtractor, RowAccent, Schema } from "../types";
3
3
  import { DataGridControl } from "../use-data-grid-control";
4
4
  import { NoRowsFallbackComponent } from "./no-rows-fallback";
5
- export interface DataGridTableProps<Row> extends DataGridControl {
6
- schema: Schema<any>;
7
- data: Row[];
5
+ export interface DataGridTableProps<GridType extends BaseGridType> extends DataGridControl {
6
+ schema: Schema<GridType>;
7
+ data: any[];
8
8
  isLoading?: boolean;
9
- error?: any | Nullish;
9
+ error?: unknown | Nullish;
10
10
  reload: () => Promise<any>;
11
- rowHeight?: number | ((row: Row) => number) | "auto";
11
+ rowHeight?: number | ((row: InferDataGridRow<Schema<GridType>>) => number) | "auto";
12
12
  headerRowHeight?: number;
13
- rowAccent?: (row: Row) => RowAccent;
14
- rowClassName?: (row: Row) => string | Nullish;
13
+ rowAccent?: (row: InferDataGridRow<Schema<GridType>>) => RowAccent;
14
+ rowClassName?: (row: InferDataGridRow<Schema<GridType>>) => string | Nullish;
15
15
  keyExtractor?: KeyExtractor;
16
16
  bodyCells?: BodyCellComponents;
17
17
  actionCell?: {
18
18
  width: number;
19
- Component: ActionCellComponent<Row>;
19
+ Component: ActionCellComponent<InferDataGridRow<Schema<GridType>>>;
20
20
  };
21
21
  NoRowsFallback?: NoRowsFallbackComponent;
22
- isRowSelectDisabled?: (row: Row) => boolean;
22
+ isRowSelectDisabled?: (row: InferDataGridRow<Schema<GridType>>) => boolean;
23
23
  isRowsSelectable?: boolean;
24
24
  }
@@ -1,2 +1,3 @@
1
+ import { BaseGridType } from "../../types";
1
2
  import { DataGridTableProps } from "../types";
2
- export declare function getGridTemplateRows(rows: any[], headerRowHeight: number, rowHeight: DataGridTableProps<any>["rowHeight"]): string | undefined;
3
+ export declare function getGridTemplateRows<GridType extends BaseGridType>(rows: any[], headerRowHeight: number, rowHeight: DataGridTableProps<GridType>["rowHeight"]): string | undefined;
@@ -11,7 +11,7 @@ export type DataGridActionCell<Row> = {
11
11
  };
12
12
  export interface BodyCellProps<Value> {
13
13
  value: Value;
14
- column: Column<any, any>;
14
+ column: Column;
15
15
  /** @deprecated will be removed */
16
16
  row: any;
17
17
  reload: () => Promise<any>;
@@ -1,4 +1,5 @@
1
1
  import { Nullish } from "@uxf/core/types";
2
+ import { ColumnTypes } from "../column-types";
2
3
  import { FilterHandlers } from "../filter-handler";
3
4
  import { HiddenColumnsComponentComponent } from "../hidden-columns/types";
4
5
  import { SelectedRowsToolbarActionsComponent } from "../selected-rows-toolbar";
@@ -10,13 +11,16 @@ import { DataGridFetchingResult } from "../use-data-grid-fetching";
10
11
  import { BodyCellComponents, ChangeTabFilterBehavior } from "./components";
11
12
  import { CsvDownloadGetUrl, KeyExtractor, RowAccent } from "./core";
12
13
  import { BaseGridType, Schema } from "./schema";
14
+ export type InferDataGridRow<S> = S extends Schema<infer G extends BaseGridType> ? {
15
+ [K in keyof G["columns"]]: G["columns"][K] extends keyof ColumnTypes ? ColumnTypes[G["columns"][K]] : never;
16
+ } : never;
13
17
  export type DataGridControlProps = DataGridControl;
14
18
  export type DataGridDataProps<Row> = DataGridFetchingResult<Row>;
15
- export type DataGridBaseProps<GridType extends BaseGridType, Row> = {
19
+ export type DataGridBaseProps<GridType extends BaseGridType> = {
16
20
  HiddenColumnsComponent?: HiddenColumnsComponentComponent;
17
21
  NoRowsFallback?: NoRowsFallbackComponent;
18
22
  SelectedRowsToolbarActions?: SelectedRowsToolbarActionsComponent;
19
- actionCell?: DataGridTableProps<Row>["actionCell"];
23
+ actionCell?: DataGridTableProps<GridType>["actionCell"];
20
24
  bodyCells?: BodyCellComponents;
21
25
  changeTabFilterBehavior?: ChangeTabFilterBehavior;
22
26
  className?: string;
@@ -26,13 +30,14 @@ export type DataGridBaseProps<GridType extends BaseGridType, Row> = {
26
30
  gridName?: string;
27
31
  headerRowHeight?: number;
28
32
  isDebug?: boolean;
29
- isRowSelectDisabled?: (row: Row) => boolean;
33
+ isHiddenColumnsSortable?: boolean;
34
+ isRowSelectDisabled?: (row: InferDataGridRow<Schema<GridType>>) => boolean;
30
35
  isRowsSelectable?: boolean;
31
36
  keyExtractor?: KeyExtractor;
32
- rowAccent?: (row: Row) => RowAccent;
33
- rowClassName?: (row: Row) => string | Nullish;
34
- rowHeight?: number | ((row: Row) => number) | "auto";
37
+ rowAccent?: (row: InferDataGridRow<Schema<GridType>>) => RowAccent;
38
+ rowClassName?: (row: InferDataGridRow<Schema<GridType>>) => string | Nullish;
39
+ rowHeight?: number | ((row: InferDataGridRow<Schema<GridType>>) => number) | "auto";
35
40
  schema: Schema<GridType>;
36
41
  tabsVariant?: "default" | "segmented";
37
42
  };
38
- export type DataGridProps<GridType extends BaseGridType, Row> = DataGridBaseProps<GridType, Row> & DataGridDataProps<Row> & DataGridControlProps;
43
+ export type DataGridProps<GridType extends BaseGridType> = DataGridBaseProps<GridType> & DataGridDataProps<InferDataGridRow<Schema<GridType>>> & DataGridControlProps;
package/types/schema.d.ts CHANGED
@@ -10,8 +10,8 @@ export interface Tab {
10
10
  s?: DataGridSort;
11
11
  }
12
12
  export type BaseGridType = {
13
- columns: any;
14
- filters: any;
13
+ columns: Record<string, string>;
14
+ filters: Record<string, string>;
15
15
  };
16
16
  export type ColumnWidthUnit = number | `${number}fr`;
17
17
  export type ColumnConfig = {
@@ -19,17 +19,14 @@ export type ColumnConfig = {
19
19
  width?: ColumnWidthUnit;
20
20
  minWidth?: number;
21
21
  };
22
- export type Column<Name, Type> = {
23
- name: Name;
22
+ export type Column = {
23
+ name: string;
24
24
  label: string | ReactElement;
25
- type: Type;
25
+ type: string;
26
26
  sort?: boolean;
27
27
  hidden?: boolean;
28
28
  config?: ColumnConfig;
29
29
  };
30
- export type Columns<C extends BaseGridType["columns"]> = {
31
- [K in keyof C]: Column<K, C[K]>;
32
- }[keyof C];
33
30
  export type FilterConfig = {
34
31
  placeholder?: string;
35
32
  };
@@ -47,7 +44,7 @@ export interface Filter {
47
44
  }
48
45
  export interface Schema<GridType extends BaseGridType> {
49
46
  name: string;
50
- columns: Columns<GridType["columns"]>[];
47
+ columns: Column[];
51
48
  filters: Filter[];
52
49
  tabs?: Tab[];
53
50
  s: DataGridSort;
@@ -11,7 +11,7 @@ export interface UseDataGridControlConfig<GridType extends BaseGridType> {
11
11
  middleware?: Middleware<DataGridState<any>, Action>;
12
12
  }
13
13
  export declare function useDataGridControl<T extends BaseGridType>(config: UseDataGridControlConfig<T>): {
14
- state: DataGridState<T>;
14
+ state: DataGridState<any>;
15
15
  actions: {
16
16
  changePage: (page: number) => void;
17
17
  changePerPage: (perPage: number) => void;