# Closing call to action with a share panel (带分享面板的收尾行动区)

A large centered headline, one line and two actions, with a single piece of product UI below: a share-deck panel with slide thumbnails, a copy-link field and viewer avatars. A compact variant fits a band at the end of a blog post.

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

## Install

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

## Dependencies

`lucide-react`

## shadcn/ui components it builds on

- `avatar`, `button`, `input`. The shadcn CLI installs them together with the block.

## Layout borrowed from

- https://www.framer.com: Borrowed the centered oversized headline, the short line and button pair, and the single product visual below it. The share panel is original.

## 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/framer.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/cta-closing/cta-closing.tsx | source | 7.6 KB |
| components/blocks/cta-closing/examples/compact.tsx | demo | 251 B |
| components/blocks/cta-closing/examples/content.ts | demo | 2.3 KB |
| components/blocks/cta-closing/examples/default.tsx | demo | 219 B |

### components/blocks/cta-closing/cta-closing.tsx

```tsx
"use client";

import { useRef, useState } from "react";
import { ArrowRight, Check, Copy, Globe, X } from "lucide-react";
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";

export interface CtaClosingProps {
  readonly title: string;
  readonly description: string;
  readonly actions: {
    readonly primary: string;
    readonly secondary: string;
  };
  readonly share: {
    readonly deckTitle: string;
    readonly deckMeta: string;
    readonly slides: readonly string[];
    readonly link: string;
    readonly copy: string;
    readonly copied: string;
    readonly failed: string;
    readonly access: string;
    readonly viewers: readonly { readonly name: string; readonly initials: string }[];
    readonly viewing: string;
  };
  readonly variant?: "default" | "compact";
}

const avatarTones = ["bg-chart-1/20", "bg-chart-2/20", "bg-chart-3/20", "bg-chart-4/20", "bg-chart-5/20"] as const;

function ViewerStack({ viewers, label }: { readonly viewers: CtaClosingProps["share"]["viewers"]; readonly label: string }) {
  if (viewers.length === 0) return null;
  return (
    <div className="flex items-center gap-3">
      <div className="flex -space-x-1">
        {viewers.map(({ name, initials }, i) => (
          <Avatar key={name} className="size-8 bg-background ring-2 ring-background" aria-label={name}>
            <AvatarFallback className={cn("text-xs font-medium text-foreground", avatarTones[i % avatarTones.length])}>{initials}</AvatarFallback>
          </Avatar>
        ))}
      </div>
      <p className="min-w-0 truncate text-sm text-muted-foreground">{label}</p>
    </div>
  );
}

type CopyState = "idle" | "copied" | "failed";

function CopyLinkRow({ share }: { readonly share: CtaClosingProps["share"] }) {
  const [state, setState] = useState<CopyState>("idle");
  const inputRef = useRef<HTMLInputElement>(null);

  async function copyLink() {
    try {
      await navigator.clipboard.writeText(share.link);
      setState("copied");
    } catch {
      inputRef.current?.select();
      setState("failed");
    }
    window.setTimeout(() => setState("idle"), 1800);
  }

  const label = state === "copied" ? share.copied : state === "failed" ? share.failed : share.copy;
  return (
    <div className="flex items-center gap-2">
      <Input ref={inputRef} readOnly value={share.link} title={share.link} aria-label={share.link} className="min-w-0 flex-1 bg-background" />
      <Button variant="outline" className="shrink-0" onClick={copyLink} aria-label={label}>
        {state === "copied" ? <Check /> : state === "failed" ? <X /> : <Copy />}
        <span className="sr-only @md:not-sr-only" aria-live="polite">
          {label}
        </span>
      </Button>
    </div>
  );
}

function ThumbLayout({ index }: { readonly index: number }) {
  switch (index % 4) {
    case 0:
      return (
        <>
          <span className="h-2 w-3/5 rounded-full bg-foreground/70" />
          <span className="h-1 w-2/5 rounded-full bg-foreground/30" />
        </>
      );
    case 1:
      return (
        <div className="grid h-full grid-cols-2 gap-1.5">
          <span className="rounded-sm bg-foreground/30" />
          <span className="rounded-sm bg-chart-4/50" />
        </div>
      );
    case 2:
      return (
        <div className="flex h-full flex-col items-center justify-center gap-1">
          <span className="h-3 w-1/3 rounded-sm bg-chart-2/60" />
          <span className="h-1 w-1/2 rounded-full bg-foreground/30" />
        </div>
      );
    default:
      return (
        <div className="flex h-full items-end gap-1">
          <span className="h-1/3 flex-1 rounded-sm bg-chart-2/40" />
          <span className="h-2/3 flex-1 rounded-sm bg-chart-2/60" />
          <span className="h-full flex-1 rounded-sm bg-chart-2/80" />
        </div>
      );
  }
}

function SlideThumb({ label, index }: { readonly label: string; readonly index: number }) {
  return (
    <li className="min-w-0 flex-1">
      <div
        className={cn(
          "flex aspect-video flex-col justify-end gap-1 rounded-md border bg-background p-2",
          index === 0 && "ring-2 ring-ring/40 ring-offset-2 ring-offset-card"
        )}
      >
        <ThumbLayout index={index} />
      </div>
      <p className="mt-1.5 truncate text-xs text-muted-foreground">{label}</p>
    </li>
  );
}

function SharePanel({ share, compact }: { readonly share: CtaClosingProps["share"]; readonly compact: boolean }) {
  return (
    <div
      className={cn(
        "flex flex-col gap-4 text-left",
        !compact && "rounded-xl border bg-card p-4 text-card-foreground shadow-lg @3xl:p-5"
      )}
    >
      {!compact && (
        <>
          <div className="flex items-baseline justify-between gap-3">
            <p className="min-w-0 truncate text-base font-medium">{share.deckTitle}</p>
            <p className="shrink-0 text-sm text-muted-foreground">{share.deckMeta}</p>
          </div>
          <ul className="flex gap-2">
            {share.slides.map((label, i) => (
              <SlideThumb key={label} label={label} index={i} />
            ))}
          </ul>
        </>
      )}
      <CopyLinkRow share={share} />
      <div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-3">
        <ViewerStack viewers={share.viewers} label={share.viewing} />
        <p className="flex items-center gap-1.5 text-sm text-muted-foreground">
          <Globe className="size-4" />
          {share.access}
        </p>
      </div>
    </div>
  );
}

export function CtaClosing({ title, description, actions, share, variant = "default" }: CtaClosingProps) {
  if (variant === "compact") {
    return (
      <section className="@container bg-background text-foreground">
        <div className="mx-auto w-full max-w-4xl px-4 py-12 @3xl:px-8">
          <div className="grid items-center gap-8 rounded-xl bg-muted p-6 @3xl:grid-cols-2 @3xl:gap-10 @3xl:p-10">
            <div>
              <h2 className="font-heading text-2xl font-medium leading-tight tracking-tight text-balance @3xl:text-3xl">{title}</h2>
              <p className="mt-3 text-base break-keep text-pretty text-muted-foreground">{description}</p>
              <div className="mt-6 flex flex-wrap gap-3">
                <Button size="lg">
                  {actions.primary}
                  <ArrowRight />
                </Button>
                <Button size="lg" variant="outline">
                  {actions.secondary}
                </Button>
              </div>
            </div>
            <SharePanel share={share} compact />
          </div>
        </div>
      </section>
    );
  }

  return (
    <section className="@container bg-background text-foreground">
      <div className="mx-auto w-full max-w-6xl px-4 pt-20 pb-16 @3xl:px-8 @3xl:pt-32 @3xl:pb-24">
        <div className="mx-auto flex max-w-3xl flex-col items-center text-center">
          <h2 className="font-heading text-4xl font-medium leading-tight tracking-tight text-balance @3xl:text-7xl">{title}</h2>
          <p className="mt-5 max-w-xl text-base break-keep text-balance text-muted-foreground @3xl:text-xl">{description}</p>
          <div className="mt-8 flex flex-wrap justify-center gap-3">
            <Button size="lg">
              {actions.primary}
              <ArrowRight />
            </Button>
            <Button size="lg" variant="outline">
              {actions.secondary}
            </Button>
          </div>
        </div>
        <div className="mx-auto mt-14 w-full max-w-2xl @3xl:mt-16">
          <SharePanel share={share} compact={false} />
        </div>
      </div>
    </section>
  );
}
```

Not inlined (3 files, 2.8 KB). Full sources: https://uifino.com/r/blocks/cta-closing.json
