# Cancel flow

> Three-step subscription cancellation flow (Reason, tailored retention Offer, Confirm) with explicit acknowledgment before cancelling.

- Kind: block · Category: Settings · Interactivity: script
- Install: `npx shadcn@latest add @haze/cancel-flow`
- File: `src/components/haze/blocks/cancel-flow.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/blocks/cancel-flow

## Use when
- Collecting cancellation reasons and surfacing a relevant pause or discount offer before offboarding
- Requiring an explicit confirmation acknowledgment on the final destructive step

## Avoid when
- Confirming a simple single-item deletion; use alert-dialog or hold-to-confirm

## Alternatives
- [alert-dialog](https://hazeui.com/ui/alert-dialog.md)
- [hold-to-confirm](https://hazeui.com/ui/hold-to-confirm.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-cancel-flow" | no | Unique prefix for radio group and heading IDs. |
| planName | `string` | "Team ($89/mo)" | no | Plan name shown in the cancellation header. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- Reasons are grouped in a semantic fieldset with native radio inputs and adapt step 2's retention offer automatically.
- Validation errors, accepted offers and cancellation confirmation announce via role="status".
- Key Tab / Arrow keys: Choose a cancellation reason, review the offer and confirm cancellation
- Key Enter / Space: Accept the retention offer, check acknowledgment or confirm cancellation

## Agent prompts

### Install and use

Install the Haze UI block "Cancel flow" with `npx shadcn@latest add @haze/cancel-flow`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import CancelFlow from "@/components/haze/blocks/cancel-flow.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/cancel-flow.md

### Customize with real content

Adapt the Haze cancel-flow block for our product. Replace the demo values of these props with our real content: id, planName, class. Keep the layout, the heading level rules and these accessibility details: Reasons are grouped in a semantic fieldset with native radio inputs and adapt step 2's retention offer automatically. Validation errors, accepted offers and cancellation confirmation announce via role="status". Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using cancel-flow, check it fits: use it when collecting cancellation reasons and surfacing a relevant pause or discount offer before offboarding; requiring an explicit confirmation acknowledgment on the final destructive step. Avoid it when confirming a simple single-item deletion; use alert-dialog or hold-to-confirm. Alternatives: @haze/alert-dialog, @haze/hold-to-confirm.

## Example requests that should lead here
- Build a 3-step subscription cancel flow with Reason radios, tailored retention Offer and final Confirm step

## Source

```astro
---
import { AlertTriangle, ArrowLeft, ArrowRight, Check, Gift, ShieldAlert } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  id?: string;
  planName?: string;
  class?: string;
}

const { id = "haze-cancel-flow", planName = "Team ($89/mo)", class: className } = Astro.props;

const reasons = [
  { id: "price", label: "Too expensive for our current stage", offer: "Take 40% off for the next 3 months ($53.40/mo) while keeping all 20 seats." },
  { id: "pause", label: "Project is temporarily paused", offer: "Pause your subscription for up to 60 days at $0 with all workspace data preserved." },
  { id: "missing", label: "Missing a feature we need", offer: "Book a 15-minute roadmap session with our team and get 1 month free while we review." },
] as const;
---

<section aria-labelledby={`${id}-title`} data-haze-cancel-flow class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-lg rounded-2xl border border-border bg-card p-6 sm:p-7">
    <header class="flex items-center justify-between gap-2 border-b border-border pb-4">
      <div class="flex items-center gap-2">
        <ShieldAlert class="size-4 text-muted-foreground" aria-hidden="true" />
        <h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-foreground">Cancel {planName}</h2>
      </div>
      <span data-cf-step-label class="font-mono text-xs text-muted-foreground tabular-nums">1 / 3 · Reason</span>
    </header>

    <div data-cf-pane="0" class="mt-5 space-y-2.5">
      <p class="text-xs/5 text-muted-foreground">Tell us why you are leaving so we can suggest the best option.</p>
      <fieldset class="space-y-2">
        <legend class="sr-only">Cancellation reason</legend>
        {
          reasons.map((r, i) => (
            <label class="flex cursor-pointer items-center gap-3 rounded-xl border border-border bg-muted/40 p-3.5 text-xs font-medium text-foreground transition-colors duration-150 hover:border-border-strong">
              <input type="radio" name={`${id}-reason`} value={r.id} data-cf-offer={r.offer} checked={i === 0} class="size-4 shrink-0 cursor-pointer appearance-none rounded-full border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-[5px] checked:border-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring" />
              <span>{r.label}</span>
            </label>
          ))
        }
      </fieldset>
    </div>

    <div data-cf-pane="1" hidden class="mt-5 space-y-4">
      <div class="rounded-xl border border-frame bg-muted p-4">
        <p class="inline-flex items-center gap-1.5 text-xs font-semibold text-foreground">
          <Gift class="size-4" aria-hidden="true" />
          Before you go
        </p>
        <p data-cf-offer-box class="mt-2 text-sm/6 text-pretty text-foreground">{reasons[0].offer}</p>
        <button type="button" data-cf-claim class="mt-3 inline-flex h-9 cursor-pointer items-center rounded-lg bg-primary px-3.5 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">Accept offer &amp; stay</button>
      </div>
    </div>

    <div data-cf-pane="2" hidden class="mt-5 space-y-4">
      <div class="rounded-xl border border-frame-destructive bg-destructive/10 p-4 text-xs/5 text-foreground">
        <p class="inline-flex items-center gap-1.5 font-semibold text-destructive">
          <AlertTriangle class="size-4" aria-hidden="true" />
          Your plan ends on Dec 1, 2026
        </p>
        <p class="mt-1.5 text-muted-foreground">Workspace seats will drop to the Free tier after the current billing period. Your data remains exportable.</p>
      </div>
      <label class="flex cursor-pointer items-center gap-2.5 text-xs text-foreground">
        <span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" data-cf-ack class="peer col-start-1 row-start-1 size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
        I understand my team will lose paid features on Dec 1, 2026.
      </label>
    </div>

    <footer class="mt-6 flex items-center justify-between gap-2 border-t border-border pt-4">
      <button type="button" data-cf-prev disabled class="inline-flex h-9 cursor-pointer items-center gap-1 rounded-lg border border-frame bg-field px-3 text-xs font-medium text-foreground hover:bg-accent disabled:cursor-not-allowed disabled:opacity-45 focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
        <ArrowLeft class="size-3.5" aria-hidden="true" />
        Back
      </button>
      <button type="button" data-cf-next class="inline-flex h-9 cursor-pointer items-center gap-1.5 rounded-lg bg-primary px-4 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
        <span data-cf-next-label>Continue</span>
        <ArrowRight class="size-3.5" aria-hidden="true" />
      </button>
    </footer>

    <p data-cf-status role="status" class="mt-3 min-h-4 text-xs/4 text-muted-foreground"></p>
  </div>
</section>

<script>
  function initCancelFlows() {
    const names = ["1 / 3 · Reason", "2 / 3 · Offer", "3 / 3 · Confirm"];
    document.querySelectorAll<HTMLElement>("[data-haze-cancel-flow]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");
      const panes = Array.from(root.querySelectorAll<HTMLElement>("[data-cf-pane]"));
      const label = root.querySelector<HTMLElement>("[data-cf-step-label]");
      const offerBox = root.querySelector<HTMLElement>("[data-cf-offer-box]");
      const ack = root.querySelector<HTMLInputElement>("[data-cf-ack]");
      const prev = root.querySelector<HTMLButtonElement>("[data-cf-prev]");
      const next = root.querySelector<HTMLButtonElement>("[data-cf-next]");
      const nextLabel = root.querySelector<HTMLElement>("[data-cf-next-label]");
      const status = root.querySelector<HTMLElement>("[data-cf-status]");
      let step = 0;

      const render = (msg?: string) => {
        panes.forEach((p, i) => (p.hidden = i !== step));
        if (label) label.textContent = names[step];
        if (prev) prev.disabled = step === 0;
        if (nextLabel) nextLabel.textContent = step === 2 ? "Confirm cancellation" : step === 1 ? "Continue to cancel" : "Continue";
        if (step === 1 && offerBox) {
          const picked = root.querySelector<HTMLInputElement>('input[type="radio"]:checked');
          if (picked?.dataset.cfOffer) offerBox.textContent = picked.dataset.cfOffer;
        }
        if (status && msg) status.textContent = msg;
      };

      prev?.addEventListener("click", () => { if (step > 0) { step--; render(); } });
      next?.addEventListener("click", () => {
        if (step < 2) { step++; render(); return; }
        if (!ack?.checked) { render("Check the confirmation box before cancelling."); return; }
        render("Subscription scheduled to cancel on Dec 1, 2026.");
      });
      root.querySelector<HTMLButtonElement>("[data-cf-claim]")?.addEventListener("click", () => {
        render("Retention offer applied. Your subscription remains active.");
      });
    });
  }
  initCancelFlows();
  document.addEventListener("astro:page-load", initCancelFlows);
</script>
```
