File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
chartlets.js/packages/lib/src/plugins/mui Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 99} from "@mui/material" ;
1010import type { ComponentProps , ComponentState } from "@/index" ;
1111import type { SxProps } from "@mui/system" ;
12+ import { Skeleton } from "@/plugins/mui/Skeleton" ;
13+ import type { ReactElement } from "react" ;
14+ import { useLoadingState } from "@/hooks" ;
1215
1316interface TableCellProps {
1417 id : string | number ;
@@ -38,8 +41,19 @@ export const Table = ({
3841 columns,
3942 hover,
4043 stickyHeader,
44+ skeletonProps,
4145 onChange,
4246} : TableProps ) => {
47+ const loadingState = useLoadingState ( ) ;
48+ console . log ( "loadingState" , loadingState ) ;
49+ if ( ! id ) {
50+ return ;
51+ }
52+ const isLoading = loadingState [ id ] ;
53+ if ( isLoading == "failed" ) {
54+ return < div > An error occurred while loading the data.</ div > ;
55+ }
56+
4357 if ( ! columns || columns . length === 0 ) {
4458 return < div > No columns provided.</ div > ;
4559 }
@@ -69,7 +83,7 @@ export const Table = ({
6983 }
7084 } ;
7185
72- return (
86+ const table : ReactElement | null = (
7387 < TableContainer component = { Paper } sx = { style } id = { id } >
7488 < MuiTable stickyHeader = { stickyHeader } >
7589 < TableHead >
@@ -107,4 +121,20 @@ export const Table = ({
107121 </ MuiTable >
108122 </ TableContainer >
109123 ) ;
124+
125+ const isSkeletonRequired = skeletonProps !== undefined ;
126+ if ( ! isSkeletonRequired ) {
127+ return table ;
128+ }
129+ const skeletonId = id + "-skeleton" ;
130+ return (
131+ < Skeleton
132+ isLoading = { isLoading }
133+ id = { skeletonId }
134+ style = { style }
135+ { ...skeletonProps }
136+ >
137+ { table }
138+ </ Skeleton >
139+ ) ;
110140} ;
You can’t perform that action at this time.
0 commit comments