1 import { FieldValues } from "react-hook-form"
2
3 import {
4 DataGridBooleanCell,
5 DataGridCurrencyCell,
6 DataGridNumberCell,
7 DataGridReadOnlyCell,
8 DataGridRoot,
9 DataGridSkeleton,
10 DataGridTextCell,
11 type DataGridRootProps,
12 } from "./components"
13
14 interface DataGridProps<TData, TFieldValues extends FieldValues = FieldValues>
15 extends DataGridRootProps<TData, TFieldValues> {
16 isLoading?: boolean
17 }
18
19 const _DataGrid = <TData, TFieldValues extends FieldValues = FieldValues>({
20 isLoading,
21 ...props
22 }: DataGridProps<TData, TFieldValues>) => {
23 return isLoading ? (
24 <DataGridSkeleton
25 columns={props.columns}
26 rows={
27 props.data?.length && props.data.length > 0 ? props.data.length : 10
28 }
29 />
30 ) : (
31 <DataGridRoot {...props} />
32 )
33 }
34
35 export const DataGrid = Object.assign(_DataGrid, {
36 BooleanCell: DataGridBooleanCell,
37 TextCell: DataGridTextCell,
38 NumberCell: DataGridNumberCell,
39 CurrencyCell: DataGridCurrencyCell,
40 ReadonlyCell: DataGridReadOnlyCell,
41 })