1 import { FieldValues } from "react-hook-form"
2
3 import {
4 DataGridBooleanCell,
5 DataGridCurrencyCell,
6 DataGridMultilineCell,
7 DataGridNumberCell,
8 DataGridReadOnlyCell,
9 DataGridRoot,
10 DataGridSkeleton,
11 DataGridTextCell,
12 DataGridExpandableTextCell,
13 type DataGridRootProps,
14 } from "./components"
15
16 export interface DataGridProps<TData, TFieldValues extends FieldValues = FieldValues>
17 extends DataGridRootProps<TData, TFieldValues> {
18 isLoading?: boolean
19 }
20
21 const _DataGrid = <TData, TFieldValues extends FieldValues = FieldValues>({
22 isLoading,
23 // Lazy loading props - passed through to DataGridRoot
24 totalRowCount,
25 onFetchMore,
26 isFetchingMore,
27 hasNextPage,
28 ...props
29 }: DataGridProps<TData, TFieldValues>) => {
30 return isLoading ? (
31 <DataGridSkeleton
32 columns={props.columns}
33 rows={
34 props.data?.length && props.data.length > 0 ? props.data.length : 10
35 }
36 />
37 ) : (
38 <DataGridRoot
39 {...props}
40 totalRowCount={totalRowCount}
41 onFetchMore={onFetchMore}
42 isFetchingMore={isFetchingMore}
43 hasNextPage={hasNextPage}
44 />
45 )
46 }
47
48 export const DataGrid = Object.assign(_DataGrid, {
49 BooleanCell: DataGridBooleanCell,
50 TextCell: DataGridTextCell,
51 MultilineCell: DataGridMultilineCell,
52 ExpandableTextCell: DataGridExpandableTextCell,
53 NumberCell: DataGridNumberCell,
54 CurrencyCell: DataGridCurrencyCell,
55 ReadonlyCell: DataGridReadOnlyCell,
56 })