-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Table Widget: Add a skeleton for loading state (#689)
- Loading branch information
Showing
6 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/react-ui/src/widgets/TableWidgetUI/Skeleton/TableSkeleton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
TableHead, | ||
TableRow, | ||
styled | ||
} from '@mui/material'; | ||
import TableSkeletonRow from './TableSkeletonRow'; | ||
|
||
const StyledTableContainer = styled(TableContainer)(({ theme }) => ({ | ||
overflow: 'hidden' | ||
})); | ||
|
||
const TableSkeleton = ({ style }) => { | ||
return ( | ||
<StyledTableContainer style={style}> | ||
<Table aria-label='skeleton table'> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell /> | ||
<TableSkeletonRow width={56} /> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{[...Array(10)].map((_, i) => ( | ||
<TableRow key={i}> | ||
<TableSkeletonRow rows={1} width={8} /> | ||
<TableSkeletonRow index={i} /> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</StyledTableContainer> | ||
); | ||
}; | ||
|
||
export default TableSkeleton; |
19 changes: 19 additions & 0 deletions
19
packages/react-ui/src/widgets/TableWidgetUI/Skeleton/TableSkeletonRow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { Skeleton, TableCell } from '@mui/material'; | ||
|
||
const TableSkeletonRow = ({ width, rows = 4, index }) => { | ||
function getSkeletonWidth(index) { | ||
const sizes = [72, 48, 96, 32, 64]; | ||
let chosenIndex = index % sizes.length; | ||
|
||
return sizes[chosenIndex]; | ||
} | ||
|
||
return [...Array(rows)].map((_, i) => ( | ||
<TableCell key={i}> | ||
<Skeleton width={width || getSkeletonWidth(index)} height={8} /> | ||
</TableCell> | ||
)); | ||
}; | ||
|
||
export default TableSkeletonRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters