| 1 |
import React from "react"; |
| 2 |
// PatternFly |
| 3 |
import { Td, Tr } from "@patternfly/react-table"; |
| 4 |
// Layouts |
| 5 |
import { Skeleton } from "@patternfly/react-core"; |
| 6 |
|
| 7 |
interface PropsToSkeletonTable { |
| 8 |
// Table-specific variables |
| 9 |
rows: number; |
| 10 |
colSpan?: number; |
| 11 |
// Skeleton-specific variables |
| 12 |
className?: string; |
| 13 |
fontSize?: "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl"; |
| 14 |
height?: string; |
| 15 |
screenreaderText?: string; |
| 16 |
shape?: "circle" | "square"; |
| 17 |
width?: string; |
| 18 |
} |
| 19 |
|
| 20 |
const SkeletonOnTableLayout = (propsToSkeletonTable: PropsToSkeletonTable) => { |
| 21 |
// Generating rows to JSX |
| 22 |
const prepareRows = () => { |
| 23 |
const rows: JSX.Element[] = []; |
| 24 |
|
| 25 |
for (let i = 0; i < propsToSkeletonTable.rows; i++) { |
| 26 |
rows.push( |
| 27 |
<Tr key={"row" + (i + 1)}> |
| 28 |
<Td colSpan={propsToSkeletonTable.colSpan}> |
| 29 |
<Skeleton |
| 30 |
className={propsToSkeletonTable.className} |
| 31 |
fontSize={propsToSkeletonTable.fontSize} |
| 32 |
height={propsToSkeletonTable.height} |
| 33 |
screenreaderText={ |
| 34 |
propsToSkeletonTable.screenreaderText || "Loading content" |
| 35 |
} |
| 36 |
shape={propsToSkeletonTable.shape} |
| 37 |
width={propsToSkeletonTable.width} |
| 38 |
/> |
| 39 |
</Td> |
| 40 |
</Tr> |
| 41 |
); |
| 42 |
} |
| 43 |
return rows; |
| 44 |
}; |
| 45 |
|
| 46 |
const rowsStructure = prepareRows(); |
| 47 |
|
| 48 |
// Render 'SkeletonOnTableLayout' |
| 49 |
return <>{rowsStructure.map((row) => row)}</>; |
| 50 |
}; |
| 51 |
|
| 52 |
export default SkeletonOnTableLayout; |