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

This feature improves the store's experience and perceived performanc… #387

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions components/ui/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { HTMLAttributes } from "preact/compat";

interface SkeletonProps extends HTMLAttributes<HTMLDivElement> {
/**
* Sets Skeleton's style variation
*/
variant: "rect" | "circle" | "text";
/**
* Sets the height of the Skeleton style
*/
height: number;
/**
* Sets the width of the Skeleton style
*/
width: number;
}

export default function Skeleton(props: SkeletonProps) {
const style: React.CSSProperties = {};
if (props.variant !== "text") {
style.width = props.width;
style.height = props.height;
}

const variants = {
circle: `rounded-[100%]`,
rect: `shadow rounded-md p-4 max-w-sm w-full mx-auto`,
text: `rounded-[50%] shadow rounded-md p-4 max-w-sm w-full mx-auto `,
};

const variantClass = props.variant === "text"
? variants.text
: variants[props.variant];

return (
<div
className={`block animate-pulse space-x-4 bg-[rgba(0,0,0,0.11)] animate-[Skeleton-keyframes-pulse_1.5s_ease-in-out_0.5s_infinite] Skeleton-${props.variant} ${variantClass}`}
style={style}
/>
);
}