import { Flex, Grid, Spacer, View, VStack } from "../wp"; import type { CSSProperties, ReactNode } from "react"; export type LoadingVariant = "default" | "inverse"; type SkeletonWidth = NonNullable; type SkeletonHeight = NonNullable; type SkeletonRadius = NonNullable; interface LoadingSkeletonItem { height?: SkeletonHeight; radius?: SkeletonRadius; width: SkeletonWidth; } interface ResolvedLoadingSkeletonItem { height: SkeletonHeight; radius: SkeletonRadius; width: SkeletonWidth; } type LoadingSkeletonItemInput = SkeletonWidth | LoadingSkeletonItem; interface LoadingSkeletonActions { direction?: "column" | "row"; gap?: CSSProperties["gap"]; items: LoadingSkeletonItemInput[]; } interface LoadingSkeletonLeading { radius?: SkeletonRadius; size: SkeletonWidth; } export interface LoadingSkeletonProps { actions?: LoadingSkeletonItemInput[] | LoadingSkeletonActions; align?: "center" | "start"; badge?: LoadingSkeletonItemInput; children?: ReactNode; header?: "control"; leading?: SkeletonWidth | LoadingSkeletonLeading; lines?: LoadingSkeletonItemInput[]; rowPadding?: CSSProperties["width"]; rows?: number; showLoadingBar?: boolean; spacing?: CSSProperties["width"]; style?: CSSProperties; variant?: LoadingVariant; } const styles = { skeleton: { animation: "market-sync-skeleton 1.4s ease-in-out infinite", backgroundSize: "220% 100%", borderRadius: 6, display: "block", }, loadingBar: { background: "#edf2f7", borderRadius: 999, display: "block", height: 3, margin: "10px 0 0", overflow: "hidden", position: "relative", }, loadingBarInner: { animation: "market-sync-loader 1.2s ease-in-out infinite", background: "linear-gradient(90deg, transparent, #008f72, transparent)", display: "block", height: "100%", left: "-45%", position: "absolute", top: 0, width: "45%", }, } satisfies Record; const LoadingStyles = () => { return ( ); }; function skeletonBackground(variant: LoadingVariant): string { if (variant === "inverse") { return "linear-gradient(90deg, rgba(255,255,255,.14) 0%, rgba(255,255,255,.26) 45%, rgba(255,255,255,.14) 90%)"; } return "linear-gradient(90deg, #eef2f6 0%, #f8fafc 45%, #eef2f6 90%)"; } const resolveItem = ( item: LoadingSkeletonItemInput, fallbackHeight: SkeletonHeight, fallbackRadius: SkeletonRadius, ): ResolvedLoadingSkeletonItem => { if (typeof item === "object") { return { height: item.height ?? fallbackHeight, radius: item.radius ?? fallbackRadius, width: item.width, }; } return { height: fallbackHeight, radius: fallbackRadius, width: item, }; }; export const SkeletonLine = ({ height = 12, style, variant = "default", width = "100%", }: { height?: CSSProperties["height"]; style?: CSSProperties; variant?: LoadingVariant; width?: CSSProperties["width"]; }) => { return (