# Magazine footer with newsletter signup (带订阅表单的杂志页脚)

An editorial footer for an independent architecture magazine: masthead, a working newsletter form with invalid, failed and subscribed states, three link columns and a legal row with the issue line.

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

## Install

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

## Dependencies

`lucide-react`

## shadcn/ui components it builds on

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

## Layout borrowed from

- https://ghost.org: Borrowed the split between a brand and message block on the left and quiet link columns on the right, a hairline, then a slim bottom row. Magazine sections, copy and the form are our own.

## 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/editorial-serif.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/site-footer/examples/content.ts | demo | 4.0 KB |
| components/blocks/site-footer/examples/default.tsx | demo | 219 B |
| components/blocks/site-footer/examples/failed.tsx | demo | 278 B |
| components/blocks/site-footer/examples/invalid.tsx | demo | 263 B |
| components/blocks/site-footer/examples/subscribed.tsx | demo | 283 B |
| components/blocks/site-footer/site-footer.tsx | source | 7.6 KB |

### components/blocks/site-footer/site-footer.tsx

```tsx
"use client";

import { useId, useState, type FormEvent } from "react";
import { Check } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Separator } from "@/components/ui/separator";

export type SubscribeStatus = "idle" | "submitting" | "subscribed" | "error";

export interface FooterLink {
  readonly label: string;
  readonly href: string;
}

export interface FooterColumn {
  readonly title: string;
  readonly links: readonly FooterLink[];
}

export interface FooterNewsletter {
  readonly title: string;
  readonly description: string;
  readonly emailLabel: string;
  readonly placeholder: string;
  readonly button: string;
  readonly submitting: string;
  readonly success: string;
  readonly invalid: string;
  readonly failed: string;
  readonly note: string;
  readonly change?: string;
}

export interface FooterBottom {
  readonly rights: string;
  readonly legal: readonly FooterLink[];
  readonly issue: string;
}

export interface SiteFooterProps {
  readonly brand: string;
  readonly tagline: string;
  readonly colophon?: string;
  readonly newsletter: FooterNewsletter;
  readonly columns: readonly FooterColumn[];
  readonly bottom: FooterBottom;
  readonly initialStatus?: SubscribeStatus;
  readonly initialError?: "invalid" | "failed";
  readonly initialEmail?: string;
  readonly onSubscribe?: (email: string) => Promise<void> | void;
}

const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

export function SiteFooter({
  brand,
  tagline,
  colophon,
  newsletter,
  columns,
  bottom,
  initialStatus = "idle",
  initialError,
  initialEmail = "",
  onSubscribe
}: SiteFooterProps) {
  const [email, setEmail] = useState(initialEmail);
  const [status, setStatus] = useState<SubscribeStatus>(initialError ? "error" : initialStatus);
  const [error, setError] = useState<string | null>(initialError ? newsletter[initialError] : null);
  const inputId = useId();
  const errorId = `${inputId}-error`;

  async function handleSubmit(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();
    if (!emailPattern.test(email.trim())) {
      setError(newsletter.invalid);
      setStatus("error");
      return;
    }
    setError(null);
    setStatus("submitting");
    try {
      await onSubscribe?.(email.trim());
      setStatus("subscribed");
    } catch {
      setError(newsletter.failed);
      setStatus("error");
    }
  }

  const subscribed = status === "subscribed";
  const submitting = status === "submitting";

  return (
    <footer className="@container bg-background text-foreground">
      <div className="mx-auto max-w-6xl px-4 pt-16 pb-8 @3xl:px-8 @3xl:pt-24">
        <div className="grid gap-14 @3xl:grid-cols-12 @3xl:gap-8">
          <div className="flex min-w-0 flex-col gap-8 @3xl:col-span-5 @3xl:pr-8">
            <div className="flex flex-col gap-3">
              <p className="font-heading text-3xl font-semibold tracking-tight">{brand}</p>
              <p className="text-muted-foreground max-w-sm text-sm text-balance">{tagline}</p>
              {colophon ? <p className="text-muted-foreground max-w-sm text-sm italic">{colophon}</p> : null}
            </div>

            <div className="flex flex-col gap-3">
              <p className="font-heading text-xl font-medium text-balance">{newsletter.title}</p>
              <p className="text-muted-foreground text-sm text-pretty">{newsletter.description}</p>

              {subscribed ? (
                <div role="status" className="flex flex-col items-start gap-3 text-sm">
                  <p className="flex items-start gap-2.5">
                    <Check className="text-chart-2 mt-0.5 size-4 shrink-0" />
                    <span className="min-w-0 break-words">{newsletter.success.replace("{email}", email.trim())}</span>
                  </p>
                  {newsletter.change ? (
                    <Button type="button" variant="link" className="h-auto p-0" onClick={() => setStatus("idle")}>
                      {newsletter.change}
                    </Button>
                  ) : null}
                </div>
              ) : (
                <form onSubmit={handleSubmit} noValidate className="flex flex-col gap-2">
                  <Label htmlFor={inputId} className="sr-only">
                    {newsletter.emailLabel}
                  </Label>
                  <div className="flex flex-col gap-2 @md:flex-row">
                    <Input
                      id={inputId}
                      type="email"
                      name="email"
                      autoComplete="email"
                      value={email}
                      placeholder={newsletter.placeholder}
                      disabled={submitting}
                      aria-invalid={status === "error"}
                      aria-describedby={error ? errorId : undefined}
                      onChange={(event) => {
                        setEmail(event.target.value);
                        if (status === "error") setStatus("idle");
                      }}
                      className="h-10 min-w-0 @md:flex-1"
                    />
                    <Button type="submit" disabled={submitting} className="h-10">
                      {submitting ? newsletter.submitting : newsletter.button}
                    </Button>
                  </div>
                  {error ? (
                    <p id={errorId} role="alert" className="text-destructive text-sm text-pretty">
                      {error}
                    </p>
                  ) : (
                    <p className="text-muted-foreground text-sm">{newsletter.note}</p>
                  )}
                </form>
              )}
            </div>
          </div>

          <nav
            aria-label={brand}
            className="grid grid-cols-1 gap-x-6 gap-y-10 @xl:grid-cols-3 @3xl:col-span-7 @3xl:pl-8"
          >
            {columns.map((column) => (
              <div key={column.title} className="flex min-w-0 flex-col gap-4">
                <p className="text-base font-medium">{column.title}</p>
                <ul className="flex flex-col gap-2.5">
                  {column.links.map((link) => (
                    <li key={link.label}>
                      <a
                        href={link.href}
                        className="text-muted-foreground hover:text-foreground focus-visible:ring-ring rounded-sm text-sm transition-colors focus-visible:ring-2 focus-visible:outline-none"
                      >
                        {link.label}
                      </a>
                    </li>
                  ))}
                </ul>
              </div>
            ))}
          </nav>
        </div>

        <Separator className="mt-16 mb-6" />

        <div className="text-muted-foreground flex flex-col gap-4 text-sm @3xl:grid @3xl:grid-cols-12 @3xl:items-center @3xl:gap-8">
          <p className="@3xl:col-span-5">{bottom.rights}</p>
          <div className="flex flex-col gap-4 @3xl:col-span-7 @3xl:flex-row @3xl:items-center @3xl:justify-between @3xl:pl-8">
            <ul className="flex flex-wrap gap-x-5 gap-y-2">
              {bottom.legal.map((link) => (
                <li key={link.label}>
                  <a
                    href={link.href}
                    className="hover:text-foreground focus-visible:ring-ring rounded-sm transition-colors focus-visible:ring-2 focus-visible:outline-none"
                  >
                    {link.label}
                  </a>
                </li>
              ))}
            </ul>
            <p className="italic">{bottom.issue}</p>
          </div>
        </div>
      </div>
    </footer>
  );
}
```

Not inlined (5 files, 5.1 KB). Full sources: https://uifino.com/r/blocks/site-footer.json
