Skip to content

Commit

Permalink
Merge pull request #52 from bleu-fi/chart-skeleton
Browse files Browse the repository at this point in the history
Add chart skeleton
  • Loading branch information
luizakp authored Apr 4, 2024
2 parents 0f0925c + e886a63 commit 6b17d8c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/components/ChartSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import { Skeleton } from "./ui/Skeleton";

function BarSet() {
return (
<>
<Skeleton className="h-48 w-10" />
<Skeleton className="h-64 w-10" />
<Skeleton className="h-56 w-10" />
<Skeleton className="h-64 w-10" />
</>
);
}
export function ChartSkeleton({ barsSetCount = 3, className = "" }) {
const barSet = new Array(barsSetCount).fill(null);

return (
<div className={`${className} p-4`}>
<div className="flex flex-col items-center">
<div className="flex items-end space-x-2">
<span className="sr-only">Loading...</span>
{barSet.map((_, barIndex) => (
// eslint-disable-next-line react/no-array-index-key
<BarSet key={barIndex} />
))}
</div>
</div>
</div>
);
}
10 changes: 8 additions & 2 deletions src/components/Plot/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { merge } from "lodash";
import { PlotParams } from "react-plotly.js";
import React, { Suspense, lazy } from "react";
import { cn } from "#/lib";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "..";
import {
ChartSkeleton,
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "..";

// @ts-ignore Type 'Promise<typeof /@types/react-plotly.js/index")>' is not assignable to type 'Promise<{ default: ComponentType<any>; }>'
const PlotPrimitive = lazy(() => import("react-plotly.js"));
Expand Down Expand Up @@ -100,7 +106,7 @@ export function Plot(props: PlotProps) {
<PlotTitle title={plotProps.title} tooltip={plotProps.toolTip} />
)}
{/* @ts-ignore */}
<Suspense fallback={<div>Loading...</div>}>
<Suspense fallback={<ChartSkeleton />}>
<PlotPrimitive {...plotProps} />
</Suspense>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from "./StrictModeDroppable";
export * from "./Plot";
export * from "./TableSkeleton";
export * from "./KpiSkeleton";
export * from "./ChartSkeleton";

0 comments on commit 6b17d8c

Please sign in to comment.