返回组件列表
反馈

空状态

带语义操作和状态标记的可复用产品空状态组件。

页面预览
源码
这里展示 registry 中会被 shadcn 安装到目标项目的组件源码。
registry/default/empty-state/empty-state.tsx
import { FileSearchIcon, PlusIcon } from "lucide-react"

import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
  Empty,
  EmptyContent,
  EmptyDescription,
  EmptyHeader,
  EmptyMedia,
  EmptyTitle,
} from "@/components/ui/empty"

type EmptyStateCopy = {
  badge: string
  title: string
  description: string
  action: string
}

type EmptyStateProps = {
  copy?: EmptyStateCopy
}

const defaultCopy: EmptyStateCopy = {
  badge: "No components yet",
  title: "Start your registry with one reusable block.",
  description:
    "Add a component, document the install command, and verify it with shadcn add before publishing.",
  action: "Add component",
}

export function EmptyState({ copy = defaultCopy }: EmptyStateProps) {
  return (
    <Empty className="border bg-card">
      <EmptyHeader>
        <EmptyMedia variant="icon">
          <FileSearchIcon />
        </EmptyMedia>
        <Badge variant="secondary">{copy.badge}</Badge>
        <EmptyTitle>{copy.title}</EmptyTitle>
        <EmptyDescription>
          {copy.description}
        </EmptyDescription>
      </EmptyHeader>
      <EmptyContent>
        <Button>
          <PlusIcon data-icon="inline-start" />
          {copy.action}
        </Button>
      </EmptyContent>
    </Empty>
  )
}