# Course library empty states (课程库空状态)

First-run, no-results and offline views for a craft-learning course library, each with a next step.

- Ref: `component/learning-empty` (component · empty)
- Page: https://uifino.com/en/components/empty/learning-empty
- Markdown: https://uifino.com/md/components/learning-empty.md
- Preview image: https://uifino.com/blocks/covers/learning-empty-dark.webp

## Install

- shadcn: `npx shadcn@latest add "https://uifino.com/r/blocks/learning-empty.json"`
- UIFino CLI: `npx uifino@latest add component/learning-empty`

## Dependencies

`lucide-react`

## shadcn/ui components it builds on

- `button`, `empty`, `spinner`. The shadcn CLI installs them together with the block.

## Theme

The block reads the project's shadcn theme variables, so it follows whatever DESIGN.md the project uses and needs no options of its own.
To give the project the look of a UIFino brand or style, install its theme: `npx shadcn@latest add "https://uifino.com/r/themes/claude.json"`.

## Usage

The files under `examples/` show the block wired with content, including its loading, empty and error states where it has them.

## Files

| Path | Role | Size |
| :--- | :--- | ---: |
| components/blocks/learning-empty/examples/content.ts | demo | 4.4 KB |
| components/blocks/learning-empty/examples/default.tsx | demo | 341 B |
| components/blocks/learning-empty/examples/no-results.tsx | demo | 343 B |
| components/blocks/learning-empty/examples/offline.tsx | demo | 559 B |
| components/blocks/learning-empty/learning-empty.tsx | source | 4.4 KB |

### components/blocks/learning-empty/learning-empty.tsx

```tsx
import type { ComponentType } from "react";
import { BookOpen, Search, SearchX, WifiOff } from "lucide-react";

import { Button } from "@/components/ui/button";
import {
  Empty,
  EmptyContent,
  EmptyDescription,
  EmptyHeader,
  EmptyTitle
} from "@/components/ui/empty";
import { Spinner } from "@/components/ui/spinner";
import { cn } from "@/lib/utils";

export type LearningEmptyVariant = "first-run" | "no-results" | "offline";

export interface LearningEmptyItem {
  readonly title: string;
  readonly meta: readonly string[];
  readonly href?: string;
}

export interface LearningEmptyLabels {
  readonly title: string;
  readonly description: string;
  readonly primaryAction: string;
  readonly secondaryAction?: string;
  readonly listTitle: string;
}

export interface LearningEmptyProps {
  readonly variant?: LearningEmptyVariant;
  readonly query?: string;
  readonly items: readonly LearningEmptyItem[];
  readonly labels: LearningEmptyLabels;
  readonly pending?: boolean;
  readonly onPrimary?: () => void;
  readonly onSecondary?: () => void;
  readonly onSelectItem?: (item: LearningEmptyItem) => void;
  readonly className?: string;
}

const VARIANT_ICONS: Record<LearningEmptyVariant, ComponentType<{ className?: string }>> = {
  "first-run": BookOpen,
  "no-results": SearchX,
  offline: WifiOff
};

const CARD_CLASS =
  "flex h-full min-w-0 flex-col gap-1 rounded-xl border border-border bg-card p-4 text-left outline-none transition-colors";
const CARD_INTERACTIVE_CLASS =
  "hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring";

interface CourseCardProps {
  readonly item: LearningEmptyItem;
  readonly onSelect?: (item: LearningEmptyItem) => void;
}

function CourseCard({ item, onSelect }: CourseCardProps) {
  const body = (
    <>
      <span className="line-clamp-2 font-medium text-pretty text-card-foreground">{item.title}</span>
      <span className="truncate text-sm text-muted-foreground">{item.meta.join(" · ")}</span>
    </>
  );

  if (item.href) {
    return (
      <a
        href={item.href}
        className={cn(CARD_CLASS, CARD_INTERACTIVE_CLASS)}
        onClick={onSelect ? () => onSelect(item) : undefined}
      >
        {body}
      </a>
    );
  }
  if (onSelect) {
    return (
      <button type="button" className={cn(CARD_CLASS, CARD_INTERACTIVE_CLASS)} onClick={() => onSelect(item)}>
        {body}
      </button>
    );
  }
  return <div className={CARD_CLASS}>{body}</div>;
}

export function LearningEmpty({
  variant = "first-run",
  query,
  items,
  labels,
  pending = false,
  onPrimary,
  onSecondary,
  onSelectItem,
  className
}: LearningEmptyProps) {
  const isOffline = variant === "offline";
  const VariantIcon = VARIANT_ICONS[variant];

  return (
    <section className={cn("@container mx-auto w-full max-w-3xl px-4 py-16", className)}>
      <Empty className="border-0 p-0 md:p-0">
        <EmptyHeader className="max-w-md">
          <VariantIcon className="mb-2 size-8 text-muted-foreground" aria-hidden />
          {variant === "no-results" && query ? (
            <p className="mb-1 inline-flex max-w-full items-center gap-1.5 text-sm text-muted-foreground">
              <Search className="size-3.5 shrink-0" aria-hidden />
              <span className="truncate">{query}</span>
            </p>
          ) : null}
          <EmptyTitle className="font-heading text-2xl tracking-normal text-balance">{labels.title}</EmptyTitle>
          <EmptyDescription className="text-pretty break-keep">{labels.description}</EmptyDescription>
        </EmptyHeader>
        <EmptyContent className="max-w-none flex-row flex-wrap justify-center gap-2">
          <Button onClick={onPrimary} disabled={pending}>
            {pending ? <Spinner /> : null}
            {labels.primaryAction}
          </Button>
          {labels.secondaryAction ? (
            <Button variant="outline" onClick={onSecondary}>
              {labels.secondaryAction}
            </Button>
          ) : null}
        </EmptyContent>
        <div className="w-full">
          <h3 className="mb-3 text-center text-sm font-medium text-muted-foreground">{labels.listTitle}</h3>
          <ul className={cn("grid gap-3", isOffline ? "@md:grid-cols-2" : "@xl:grid-cols-3 @md:grid-cols-2")}>
            {items.map((item) => (
              <li key={item.title} className="min-w-0">
                <CourseCard item={item} onSelect={onSelectItem} />
              </li>
            ))}
          </ul>
        </div>
      </Empty>
    </section>
  );
}
```

Not inlined (4 files, 5.6 KB). Full sources: https://uifino.com/r/blocks/learning-empty.json
