Skip to content

Commit e0e6050

Browse files
authored
feat: add Skeleton component
1 parent 69abf0d commit e0e6050

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Skeleton component > renders correctly 1`] = `
4+
<div>
5+
<div
6+
class="animate-pulse rounded-md bg-gray-300"
7+
/>
8+
</div>
9+
`;

src/components/skeleton.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { render } from "@testing-library/react";
2+
import { describe, expect, it } from "vitest";
3+
import { Skeleton } from "./skeleton";
4+
5+
describe("Skeleton component", () => {
6+
it("renders correctly", () => {
7+
const { container } = render(<Skeleton />);
8+
expect(container).toMatchSnapshot();
9+
});
10+
});

src/components/skeleton.stories.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
3+
import { Skeleton } from "./skeleton";
4+
5+
const meta = {
6+
title: "Skeleton",
7+
component: Skeleton,
8+
parameters: {
9+
layout: "centered",
10+
},
11+
} satisfies Meta<typeof Skeleton>;
12+
13+
export default meta;
14+
type Story = StoryObj<typeof meta>;
15+
16+
export const Example: Story = {
17+
render() {
18+
return (
19+
<div className="flex items-center space-x-4">
20+
<Skeleton className="h-12 w-12 rounded-full" />
21+
<div className="space-y-2">
22+
<Skeleton className="h-4 w-[250px]" />
23+
<Skeleton className="h-4 w-[200px]" />
24+
</div>
25+
</div>
26+
);
27+
},
28+
};
29+
30+
export const Card: Story = {
31+
render() {
32+
return (
33+
<div className="flex flex-col space-y-3">
34+
<Skeleton className="h-[125px] w-[250px] rounded-xl" />
35+
<div className="space-y-2">
36+
<Skeleton className="h-4 w-[250px]" />
37+
<Skeleton className="h-4 w-[200px]" />
38+
</div>
39+
</div>
40+
);
41+
},
42+
};

src/components/skeleton.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { cn } from "@/lib/utils";
2+
3+
function Skeleton({
4+
className,
5+
...props
6+
}: React.HTMLAttributes<HTMLDivElement>) {
7+
return (
8+
<div
9+
className={cn("animate-pulse rounded-md bg-gray-300", className)}
10+
{...props}
11+
/>
12+
);
13+
}
14+
15+
export { Skeleton };

0 commit comments

Comments
 (0)