Spinner(加载指示器)
用于显示加载状态的指示器。
loading
安装
bash
npx shadcn@latest add spinner1
1. 将以下代码复制并粘贴到你的项目中。
tsx
import { cn } from "cn"
import { Loader2Icon } from "lucide-react"
function Spinner({ className, ...props }: React.ComponentProps<"svg">) {
return (
<Loader2Icon data-slot="spinner" role="status" aria-label="Loading" className={cn("size-4 animate-spin", className)} {...props} />
)
}
export { Spinner }1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
2. 更新导入路径,使其与项目配置一致。
用法
tsx
import { Spinner } from "@/components/ui/spinner"1
tsx
<Spinner />1
自定义
编辑 Spinner 组件,即可用其他图标替换默认的加载图标。
loading
components/ui/spinner.tsx
tsx
import { cn } from "cn"
import { LoaderIcon } from "lucide-react"
function Spinner({ className, ...props }: React.ComponentProps<"svg">) {
return (
<LoaderIcon
role="status"
aria-label="Loading"
className={cn("size-4 animate-spin", className)}
{...props}
/>
)
}
export { Spinner }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
尺寸
使用 size-* 工具类调整加载指示器的尺寸。
loading
按钮
在按钮中添加加载指示器来表示加载状态。要将 <Spinner /> 放在开头,请将其置于标签前并设置 data-icon="inline-start";要放在末尾,请将其置于标签后并设置 data-icon="inline-end"。
loading
徽章
在徽章中添加加载指示器来表示加载状态。要将 <Spinner /> 放在开头,请将其置于标签前并设置 data-icon="inline-start";要放在末尾,请将其置于标签后并设置 data-icon="inline-end"。
loading
输入框组
loading
空状态
loading
RTL
要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南。
loading