Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added light weight skeleton loader for navigation #566

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Route, Switch } from "wouter"
import "./components/CmdKMenu"
import { ContextProviders } from "./ContextProviders"
import React from "react"
import { SkeletonLoader } from "@/components/SkeletonLoader"

const lazyImport = (importFn: () => Promise<any>) =>
lazy<ComponentType<any>>(async () => {
Expand Down Expand Up @@ -85,7 +86,7 @@ function App() {
return (
<ContextProviders>
<ErrorBoundary>
<Suspense fallback={<div>Loading...</div>}>
<Suspense fallback={<SkeletonLoader/>}>
<Switch>
<Route path="/" component={LandingPage} />
<Route path="/editor" component={EditorPage} />
Expand Down
64 changes: 64 additions & 0 deletions src/components/SkeletonLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import styled, { keyframes } from 'styled-components';

// Interfaces for Props
interface SkeletonLoaderProps {
width?: string;
height?: string;
borderRadius?: string;
count?: number;
className?: string;
}

// Skeleton Loader Component
export const SkeletonLoader: React.FC<SkeletonLoaderProps> = ({
width = '100%',
height = '100vh',
borderRadius = '0.25rem',
count = 1,
className = ''
}) => {
return (
<>
{[...Array(count)].map((_, index) => (
<SkeletonWrapper
key={index}
width={width}
height={height}
borderRadius={borderRadius}
className={className}
/>
))}
</>
);
};

// Styled Components for Animation
const shimmer = keyframes`
0% {
background-position: -1000px 0;
}
100% {
background-position: 1000px 0;
}
`;

interface SkeletonWrapperProps {
width: string;
height: string;
borderRadius: string;
}

const SkeletonWrapper = styled.div<SkeletonWrapperProps>`
width: ${props => props.width};
height: ${props => props.height};
border-radius: ${props => props.borderRadius};
background: linear-gradient(
to right,
#f0f0f0 8%,
#e0e0e0 18%,
#f0f0f0 33%
);
background-size: 1000px 100%;
animation: ${shimmer} 2s infinite cubic-bezier(0.645, 0.045, 0.355, 1);
`;
Loading