Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/ui/src/stories/LoadingState.stories.tsx
T

124 lines
3.0 KiB
TypeScript

import type { Meta, StoryObj } from "@storybook/react";
const meta: Meta = {
title: "UI / Feedback / LoadingState",
};
export default meta;
type Story = StoryObj;
function SkeletonLine({ width }: { width: string | number }) {
return (
<span
aria-hidden
style={{
display: "block",
height: 12,
width,
borderRadius: 6,
background: "var(--color-accent)",
animation: "demo-pulse 1.2s ease-in-out infinite",
}}
/>
);
}
function injectKeyframesOnce() {
if (typeof document === "undefined") return;
if (document.getElementById("demo-pulse-keyframes")) return;
const style = document.createElement("style");
style.id = "demo-pulse-keyframes";
style.textContent = "@keyframes demo-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }";
document.head.appendChild(style);
}
export const SkeletonCard: Story = {
name: "Skeleton card",
render: () => {
injectKeyframesOnce();
return (
<div
role="status"
aria-label="Loading"
style={{
border: "1px solid var(--color-border)",
borderRadius: 8,
padding: 16,
width: 360,
display: "flex",
flexDirection: "column",
gap: 10,
}}
>
<SkeletonLine width="40%" />
<SkeletonLine width="100%" />
<SkeletonLine width="100%" />
<SkeletonLine width="60%" />
</div>
);
},
};
export const InlineSpinner: Story = {
name: "Inline spinner",
render: () => (
<div
role="status"
aria-label="Loading"
style={{ display: "inline-flex", alignItems: "center", gap: 8 }}
>
<span
aria-hidden
style={{
width: 14,
height: 14,
borderRadius: "50%",
border: "2px solid var(--color-muted)",
borderRightColor: "transparent",
display: "inline-block",
animation: "demo-spin 600ms linear infinite",
}}
/>
<span style={{ fontSize: 13 }}>Loading workspace…</span>
</div>
),
};
export const TableLoading: Story = {
name: "Table loading",
render: () => {
injectKeyframesOnce();
return (
<div
role="status"
aria-label="Loading rows"
style={{
border: "1px solid var(--color-border)",
borderRadius: 6,
overflow: "hidden",
width: 480,
}}
>
{Array.from({ length: 4 }).map((_, index) => (
<div
key={index}
style={{
display: "grid",
gridTemplateColumns: "1fr 1fr 1fr 60px",
gap: 12,
padding: "10px 14px",
borderTop: index === 0 ? "none" : "1px solid var(--color-border)",
}}
>
<SkeletonLine width="80%" />
<SkeletonLine width="60%" />
<SkeletonLine width="40%" />
<SkeletonLine width="100%" />
</div>
))}
</div>
);
},
};