Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Update table loading skeleton to use patterns (#78361)

Nick Fitzpatrick528ae0a38175
diff --git a/.loki/reference/chrome_laptop_Viz_Components_ChartSkeleton_Default.png b/.loki/reference/chrome_laptop_Viz_Components_ChartSkeleton_Default.png
index 082dea0266f..ec14042f27d 100644
Binary files a/.loki/reference/chrome_laptop_Viz_Components_ChartSkeleton_Default.png and b/.loki/reference/chrome_laptop_Viz_Components_ChartSkeleton_Default.png differ
diff --git a/.loki/reference/chrome_laptop_Viz_Components_ChartSkeleton_Table.png b/.loki/reference/chrome_laptop_Viz_Components_ChartSkeleton_Table.png
index 6d409353b38..65387940fbb 100644
Binary files a/.loki/reference/chrome_laptop_Viz_Components_ChartSkeleton_Table.png and b/.loki/reference/chrome_laptop_Viz_Components_ChartSkeleton_Table.png differ
diff --git a/frontend/src/metabase/visualizations/components/skeletons/TableSkeleton/TableSkeleton.styled.tsx b/frontend/src/metabase/visualizations/components/skeletons/TableSkeleton/TableSkeleton.styled.tsx
index 6157a608a4d..3fec4f2e12f 100644
--- a/frontend/src/metabase/visualizations/components/skeletons/TableSkeleton/TableSkeleton.styled.tsx
+++ b/frontend/src/metabase/visualizations/components/skeletons/TableSkeleton/TableSkeleton.styled.tsx
@@ -6,5 +6,6 @@ import { animationStyles } from "metabase/visualizations/components/skeletons/Ch
export const SkeletonImage = styled.svg`
${animationStyles};
flex: 1 1 0;
+ width: 100%;
margin-top: 1.5rem;
`;
diff --git a/frontend/src/metabase/visualizations/components/skeletons/TableSkeleton/TableSkeleton.tsx b/frontend/src/metabase/visualizations/components/skeletons/TableSkeleton/TableSkeleton.tsx
index a49404a1955..959c283e3a1 100644
--- a/frontend/src/metabase/visualizations/components/skeletons/TableSkeleton/TableSkeleton.tsx
+++ b/frontend/src/metabase/visualizations/components/skeletons/TableSkeleton/TableSkeleton.tsx
@@ -1,19 +1,76 @@
+import { useId } from "react";
+
import { SkeletonImage } from "./TableSkeleton.styled";
+const COLUMN_WIDTHS = [110, 150, 96, 176, 132];
+const TILE_WIDTH = COLUMN_WIDTHS.reduce((sum, width) => sum + width, 0);
+const COLUMNS = COLUMN_WIDTHS.map((width, index) => ({
+ width,
+ x: COLUMN_WIDTHS.slice(0, index).reduce((sum, w) => sum + w, 0),
+}));
+
+const ROW_HEIGHT = 27;
+const HEADER_PILL_HEIGHT = 11;
+const HEADER_PILL_RADIUS = 5.5;
+const CELL_HEIGHT = 10;
+const HEADER_PILL_PADDING = 65;
+const CELL_PADDING = 35;
+
const TableSkeleton = (): JSX.Element => {
+ const id = useId();
+ const headerPatternId = `table-skeleton-header-${id}`;
+ const bodyPatternId = `table-skeleton-body-${id}`;
+
return (
- <SkeletonImage
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 369 144"
- preserveAspectRatio="none"
- >
- <path fill="currentColor" d="M0 27h94v10H0z" />
- <rect width="58" height="11" rx="5.5" fill="currentColor" />
- <rect x="138" width="58" height="11" rx="5.5" fill="currentColor" />
- <rect x="275" width="58" height="11" rx="5.5" fill="currentColor" />
- <path
- fill="currentColor"
- d="M0 53h94v10H0zM0 80h94v10H0zM0 107h94v10H0zM0 134h94v10H0zM138 27h93v10h-93zM138 53h93v10h-93zM138 80h93v10h-93zM138 107h93v10h-93zM138 134h93v10h-93zM275 27h94v10h-94zM275 53h94v10h-94zM275 80h94v10h-94zM275 107h94v10h-94zM275 134h94v10h-94z"
+ <SkeletonImage xmlns="http://www.w3.org/2000/svg">
+ <defs>
+ <pattern
+ id={headerPatternId}
+ width={TILE_WIDTH}
+ height={ROW_HEIGHT}
+ patternUnits="userSpaceOnUse"
+ >
+ {COLUMNS.map(({ x, width }, index) => (
+ <rect
+ key={index}
+ x={x}
+ width={width - HEADER_PILL_PADDING}
+ height={HEADER_PILL_HEIGHT}
+ rx={HEADER_PILL_RADIUS}
+ fill="currentColor"
+ />
+ ))}
+ </pattern>
+ <pattern
+ id={bodyPatternId}
+ width={TILE_WIDTH}
+ height={ROW_HEIGHT}
+ patternUnits="userSpaceOnUse"
+ >
+ {COLUMNS.map(({ x, width }, index) => (
+ <rect
+ key={index}
+ x={x}
+ width={width - CELL_PADDING}
+ height={CELL_HEIGHT}
+ fill="currentColor"
+ />
+ ))}
+ </pattern>
+ </defs>
+ <rect
+ x="0"
+ y="0"
+ width="100%"
+ height={ROW_HEIGHT}
+ fill={`url(#${headerPatternId})`}
+ />
+ <rect
+ x="0"
+ y={ROW_HEIGHT}
+ width="100%"
+ height="100%"
+ fill={`url(#${bodyPatternId})`}
/>
</SkeletonImage>
);