Skeleton(骨架屏)
在内容加载期间显示占位元素。
loading
安装
bash
npx shadcn@latest add skeleton1
1. 将以下代码复制并粘贴到你的项目中。
tsx
import { cn } from "cn"
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="skeleton"
className={cn("animate-pulse rounded-xl bg-muted", className)}
{...props}
/>
)
}
export { Skeleton }1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
2. 更新导入路径,使其与项目配置一致。
用法
tsx
import { Skeleton } from "@/components/ui/skeleton"1
tsx
<Skeleton className="h-[20px] w-[100px] rounded-full" />1
头像
loading
卡片
loading
文本
loading
表单
loading
表格
loading
RTL
要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南。
loading