Skip to content
Browse documentation

Settings → Webhooks, done properly: "Send test" runs a bead down the wire to the endpoint and back in the answer's colour, and every delivery opens into its request and response.

Used forDeveloper dashboardsPayments and billing platformsIntegration platformsDelivery debugging

Install with the shadcn CLI

$ npx shadcn@latest add @hairline/webhooks

Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/webhooks.json. More

Templates

Need the whole page?

65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.

Where it’s used

  • Developer dashboards

    The Settings → Webhooks page of a product that sends events.

  • Payments and billing platforms

    Let customers choose which events go to which URL.

  • Integration platforms

    Show where events are sent and whether they arrived.

  • Delivery debugging

    Inspect the request and response of a failed delivery.

What it handles for you

Webhook settings are usually a table of URLs and a “Send test” button that answers with a toast somewhere else. This shows the test as the request it is, and keeps every delivery inspectable.

Instead of wiring upan endpoints tablea Send test buttona deliveries loga request and response viewera Redeliver buttona secret revealan enable switch
  1. Add endpoints with events

    A URL and event chips. A bad URL shakes the field and says why.

  2. Send test, visibly

    A bead runs the wire to the endpoint, the chip pulses while it answers, and the bead returns in the answer’s colour with “200 OK in 182 ms”.

  3. Every delivery is inspectable

    Each shows its status, event, time and duration, and opens into the request and the response as JSON.

  4. Redeliver

    Send a delivery again and the new attempt arrives on top of the list.

  5. The secret stays hidden

    The signing secret is dots until someone asks to reveal it, with a copy button once shown.

  6. Enable and delete safely

    The enabled switch saves itself and goes back if it fails. Delete asks first.

Overview

Webhook settings are usually a table of URLs and a "Send test" button that answers with a toast somewhere else. Here every endpoint opens in place. The test is drawn as the request it is: a bead leaves your app and runs the hairline to the endpoint, the endpoint's chip pulses while it answers, and the bead comes home in the answer's colour as "200 OK in 182 ms" rolls in; the delivery lands on top of the list below. Every delivery opens into its request and response, the tab highlight sliding between them, and Redeliver sends it again: the new attempt arrives on top. The signing secret stays dots until you reveal it. Enabled is a switch that saves itself, and Delete stretches the bin into a confirm and folds the endpoint away. A new endpoint fades in on top, already open on Send test.

States

add
"Add endpoint" opens the form by height: the URL (https://, or http://localhost) and event chips whose checks draw in. A bad URL shakes the field and says why. The new endpoint fades down 6px out of a blur on top of the list, open, with focus on Send test.
open
A row opens by height in 460ms; its chevron turns. The first time, recent deliveries load (loadDeliveries) with a spinner, then fade in.
test
The bead fades in and runs the wire to the endpoint in 620ms; the endpoint's chip pulses a ring every 900ms until onTest resolves; the bead comes back in emerald (2xx), amber (3xx/4xx) or red (5xx, no answer) in 640ms. Then the status code and the milliseconds roll in, the button says Delivered or shakes and says Send again, and the delivery glides in on top of the list.
delivery
Each row shows the status code in its colour, the event, how long ago and how long the endpoint took. It opens by height into Request and Response (pretty-printed JSON); the tab highlight slides 360ms between them.
redeliver
Redeliver → Sending → Sent with a drawn check; the new attempt ("attempt 2") fades in on top while the rest glide down, and the endpoint's last status updates.
secret
Dots until Reveal (which says Revealing while onRevealSecret runs); then the secret fades in from a blur with a copy button whose icon draws a check, and Hide.
enable / delete
The switch's thumb is thrown with a slight overshoot and its label says Saving until onToggle resolves (or is thrown back if it throws). Delete endpoint stretches out of the bin; a check draws, then the endpoint folds away.

Usage

usage.tsx
import { Webhooks } from "@/components/webhooks";<Webhooks  defaultValue={endpoints}  events={[{ value: "invoice.paid" }, { value: "customer.created" }]}  onCreate={(input) => api.createEndpoint(input)}  onTest={(endpoint, event) => api.sendTest(endpoint.id, event)}   // → the delivery  loadDeliveries={(endpoint, before) => api.deliveries(endpoint.id, before?.id)}/>

Depends on lucide-react, installed for you by the CLI along with the keyframes it needs.

Works with

Signed deliveries from your own route

The test route signs the body with the endpoint's secret, posts it with a 10 second timeout, times the answer and stores the delivery, which is exactly what the card shows. Real events go through the same function from your queue. With Svix or Hookdeck, these routes call their APIs instead and map the attempts to the same shape.

example.tsx
// lib/deliver.tsimport { createHmac, randomUUID } from "node:crypto";import { db } from "@/lib/db";export async function deliver(endpoint: { id: string; url: string; secret: string }, event: string, data: unknown) {  const body = JSON.stringify({ id: `evt_${randomUUID()}`, type: event, created: Math.floor(Date.now() / 1000), data });  const timestamp = Math.floor(Date.now() / 1000);  const signature = createHmac("sha256", endpoint.secret).update(`${timestamp}.${body}`).digest("hex");  const started = performance.now();  let status: number | null = null;  let response = "";  try {    const res = await fetch(endpoint.url, {      method: "POST",      body,      headers: { "Content-Type": "application/json", "Webhook-Timestamp": String(timestamp), "Webhook-Signature": signature },      signal: AbortSignal.timeout(10_000),    });    status = res.status;    response = (await res.text()).slice(0, 8000);  } catch {    // No answer: status stays null.  }  return db.delivery.create({    data: { endpointId: endpoint.id, event, status, durationMs: Math.round(performance.now() - started), request: body, response },  });}// app/api/webhooks/[id]/test/route.tsexport async function POST(req: Request, { params }: { params: Promise<{ id: string }> }) {  const endpoint = await db.endpoint.findUniqueOrThrow({ where: { id: (await params).id } });  const { event } = await req.json();  return Response.json(await deliver(endpoint, event, sampleFor(event)));}// app/settings/webhooks.tsx"use client";<Webhooks  defaultValue={endpoints}  events={eventTypes}  appName="Relay"  onCreate={async (input) => (await fetch("/api/webhooks", { method: "POST", body: JSON.stringify(input) })).json()}  onTest={async (ep, event) => (await fetch(`/api/webhooks/${ep.id}/test`, { method: "POST", body: JSON.stringify({ event }) })).json()}  loadDeliveries={async (ep, before) => (await fetch(`/api/webhooks/${ep.id}/deliveries?before=${before?.id ?? ""}`)).json()}  onRedeliver={async (d, ep) => (await fetch(`/api/webhooks/${ep.id}/deliveries/${d.id}/retry`, { method: "POST" })).json()}  onRevealSecret={async (ep) => (await (await fetch(`/api/webhooks/${ep.id}/secret`)).json()).secret}/>

Props

events
{ value, description? }[]
Event types an endpoint can subscribe to.
onCreate
({ url, events }) => Promise<WebhookEndpoint>
Creates an endpoint: { id, url, events, enabled?, lastDelivery? }. Throw to keep the form and show the message.
onTest
(endpoint, event) => Promise<WebhookDelivery>
Sends a test and returns the delivery: { id, event, status (null for no answer), durationMs?, at, attempt?, request?, response? }.
loadDeliveries
(endpoint, before?) => Promise<WebhookDelivery[]>
Recent deliveries, newest first, loaded the first time an endpoint opens; before is the oldest one shown when paging back. Return an empty list when there are no more.
onRedeliver
(delivery, endpoint) => Promise<WebhookDelivery>
Sends a delivery again and returns the new attempt. Without it there is no Redeliver.
onRevealSecret
(endpoint) => Promise<string>
Fetches the signing secret when someone asks to see it. Without it the secret stays dots.
onToggle
(endpoint, enabled) => Promise<unknown>
Turns an endpoint on or off; the switch moves at once and goes back if this throws.
onDelete
(endpoint) => Promise<unknown>
Deletes an endpoint after a confirm.
value
WebhookEndpoint[]
Controlled endpoints. lastDelivery updates after every test and redelivery.
defaultValue
WebhookEndpoint[]
Starting endpoints when uncontrolled.
onValueChange
(endpoints) => void
Every add, toggle, delete and new delivery.
appName= "Your app"
string
The near end of the test's wire.

Accessibility and motion

  • Each endpoint is a button with aria-expanded; its details are its own region. Deliveries are a list whose rows open with aria-expanded, and Request / Response is a tablist that arrows move between.
  • The test result ("200 OK in 182 ms") is a status message; adding, deleting, toggling and redelivering are announced too. The wire itself is for the eye only.
  • Status codes are told by number and word, not colour alone: 2xx emerald, 3xx and 4xx amber, 5xx and no answer red.
  • The bead and the pulse are Web Animations that only run while a test is in flight; deliveries glide with additive transforms (use-row-motion).
  • Reduced motion skips the bead, the pulse, the fades and the glides; results and rows still change in place.

Requirements

React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

The CLI also installs Text morph, Number roll, Status button.

Source

"use client";import * as React from "react";import { Copy, Plus, Trash2 } from "lucide-react";import { ConfirmAction } from "./confirm-action";import { NumberRoll } from "./number-roll";import { RelativeTime, type DateLike } from "./relative-time";import { StatusButton, type ActionStatus } from "./status-button";import { TextMorph } from "./text-morph";import { DeliveryList, StatusChip, type WebhookDelivery } from "./webhook-deliveries";import { WebhookWire } from "./webhook-wire";/* ───────────────────────────────────────────────────────── * WEBHOOKS: Settings → Webhooks, done properly * *   add       "Add endpoint" opens the form above the list: the *             URL and the events it wants. The new endpoint *             fades in on top, already open on "Send test" *   test      the test is drawn as the request it is: a bead *             runs the hairline to the endpoint, waits while it *             answers, and comes home in the answer's colour; *             "200 OK in 182 ms" rolls in, and the delivery *             lands on top of the list *   inspect   every delivery opens into its request and *             response; Redeliver sends it again and the new *             attempt arrives on top *   secret    the signing secret stays dots until you reveal *             it, then copies with a drawn check *   pause     Enabled is a switch that saves itself; Delete *             stretches the bin into a confirm and folds the *             endpoint away * * Endpoints and deliveries are plain records; every action is * one async function, so it fits Svix, Hookdeck or your own * queue. * ───────────────────────────────────────────────────────── */export type { WebhookDelivery, DateLike };export interface WebhookEndpoint {  id: string;  url: string;  /** The event types it receives. */  events: string[];  enabled?: boolean;  /** Shown on the collapsed row. */  lastDelivery?: { status: number | null; at: DateLike } | null;}export interface WebhookEventType {  value: string;  description?: string;}export interface WebhooksProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue" | "onChange" | "onToggle"> {  value?: WebhookEndpoint[];  defaultValue?: WebhookEndpoint[];  onValueChange?: (endpoints: WebhookEndpoint[]) => void;  /** Event types an endpoint can subscribe to. */  events: WebhookEventType[];  /** Creates an endpoint. Throw to keep the form and say why. */  onCreate: (input: { url: string; events: string[] }) => Promise<WebhookEndpoint>;  /** Sends a test event and returns the delivery it made. */  onTest: (endpoint: WebhookEndpoint, event: string) => Promise<WebhookDelivery>;  /** Recent deliveries, newest first; pass the oldest one shown to page back. An empty list means there are no more. */  loadDeliveries?: (endpoint: WebhookEndpoint, before?: WebhookDelivery) => Promise<WebhookDelivery[]>;  onRedeliver?: (delivery: WebhookDelivery, endpoint: WebhookEndpoint) => Promise<WebhookDelivery>;  onRevealSecret?: (endpoint: WebhookEndpoint) => Promise<string>;  /** Turns an endpoint on or off. Throw to put the switch back. */  onToggle?: (endpoint: WebhookEndpoint, enabled: boolean) => Promise<unknown>;  onDelete?: (endpoint: WebhookEndpoint) => Promise<unknown>;  /** Your app's name, at the near end of the test's wire. */  appName?: string;  title?: string;  description?: string;}type Draft = { url: string; events: string[]; status: ActionStatus; error: string | null };type Log = { items: WebhookDelivery[]; loading: boolean; more: boolean; loaded: boolean };const EASE = "cubic-bezier(0.16,1,0.3,1)";const THROW = "cubic-bezier(0.34,1.36,0.64,1)";const FOCUS = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40";const NONE: WebhookEndpoint[] = [];const SHAKE = [{ transform: "none" }, { transform: "translateX(-4px)" }, { transform: "translateX(4px)" }, { transform: "translateX(-2px)" }, { transform: "none" }];const reducedQuery = "(prefers-reduced-motion: reduce)";const subscribeReduced = (onChange: () => void) => {  const query = window.matchMedia(reducedQuery);  query.addEventListener("change", onChange);  return () => query.removeEventListener("change", onChange);};const useReducedMotion = () =>  React.useSyncExternalStore(subscribeReduced, () => window.matchMedia(reducedQuery).matches, () => false);const message = (e: unknown, fallback: string) => (e instanceof Error && e.message ? e.message : fallback);const split = (url: string) => {  try {    const u = new URL(url);    return { host: u.host, path: `${u.pathname === "/" ? "" : u.pathname}${u.search}` };  } catch {    return { host: url, path: "" };  }};const checkUrl = (v: string) => {  try {    const u = new URL(v.trim());    if (u.protocol === "https:" || (u.protocol === "http:" && /^(localhost|127\.0\.0\.1)$/.test(u.hostname))) return null;    return "Endpoints need https:// (http:// works for localhost).";  } catch {    return v.trim() ? "That isn't a full URL. Start it with https://." : "Enter the URL that should receive events.";  }};function Fold({ open, reduced, children }: { open: boolean; reduced: boolean; children: React.ReactNode }) {  const [kept, setKept] = React.useState(children);  if (open && kept !== children) {    setKept(children);  }  return (    <div className="grid" inert={!open} aria-hidden={!open || undefined} style={{ gridTemplateRows: open ? "1fr" : "0fr", opacity: open ? 1 : 0, transition: reduced ? "none" : `grid-template-rows 460ms ${EASE}, opacity ${open ? 320 : 180}ms ${EASE}` }}>      <div className="min-h-0 min-w-0 overflow-clip [overflow-clip-margin:6px]">{open ? children : kept}</div>    </div>  );}function Check({ drawn, reduced }: { drawn: boolean; reduced: boolean }) {  return (    <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="size-3.5">      <path d="M3.5 8.5 6.5 11.5 12.5 4.5" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" pathLength={1} strokeDasharray={1} style={{ strokeDashoffset: drawn ? 0 : 1, transition: drawn && !reduced ? `stroke-dashoffset 420ms ${EASE} 100ms` : "none" }} />    </svg>  );}function EventChip({ value, on, reduced, onToggle }: { value: string; on: boolean; reduced: boolean; onToggle: () => void }) {  return (    <button      type="button"      aria-pressed={on}      onClick={onToggle}      className={`inline-flex h-7 cursor-pointer items-center rounded-full px-2.5 font-mono text-[11.5px] transition-[background-color,color,box-shadow] duration-200 ${FOCUS} ${        on ? "bg-accent text-foreground shadow-[inset_0_0_0_1px_var(--border)]" : "text-muted-foreground shadow-[inset_0_0_0_1px_var(--border)] hover:text-foreground"      }`}    >      <span className="grid" style={{ gridTemplateColumns: on ? "1fr" : "0fr", transition: reduced ? "none" : `grid-template-columns 320ms ${EASE}` }}>        <span className="min-w-0 overflow-clip">          <span className="mr-1 block">            <Check drawn={on} reduced={reduced} />          </span>        </span>      </span>      {value}    </button>  );}/** The signing secret: dots until it's revealed, then the value and a copy button. */function Secret({ value, onReveal, onHide, reduced }: { value: string | null; onReveal?: () => Promise<void>; onHide: () => void; reduced: boolean }) {  const [status, setStatus] = React.useState<ActionStatus>("idle");  const [copied, setCopied] = React.useState(false);  const ref = React.useRef<HTMLElement>(null);  React.useLayoutEffect(() => {    if (value && !reduced) ref.current?.animate([{ opacity: 0, filter: "blur(4px)" }, { opacity: 1, filter: "blur(0px)" }], { duration: 360, easing: EASE });  }, [value, reduced]);  React.useEffect(() => {    if (!copied) return;    const timer = window.setTimeout(() => setCopied(false), 1400);    return () => window.clearTimeout(timer);  }, [copied]);  return (    <div className="flex min-w-0 items-center gap-1.5">      <code ref={ref} className="min-w-0 flex-1 truncate rounded-[8px] bg-muted px-2 py-1 font-mono text-[11.5px] text-foreground shadow-[inset_0_0_0_1px_var(--border)]">        {value ?? "whsec_••••••••••••••••"}      </code>      {value ? (        <>          <button            type="button"            aria-label={copied ? "Secret copied" : "Copy secret"}            onClick={async () => {              try {                await navigator.clipboard.writeText(value);                setCopied(true);              } catch {                /* Selectable on screen. */              }            }}            className={`relative grid size-7 shrink-0 cursor-pointer place-items-center rounded-full transition-colors hover:bg-accent ${FOCUS} ${copied ? "text-emerald-600 dark:text-emerald-400" : "text-muted-foreground hover:text-foreground"}`}          >            {[false, true].map((on) => (              <span key={String(on)} aria-hidden="true" className="absolute inset-0 grid place-items-center" style={{ opacity: copied === on ? 1 : 0, transform: copied === on ? "none" : "scale(0.6)", transition: reduced ? "none" : `opacity 220ms ${EASE}, transform 340ms ${EASE}` }}>                {on ? <Check drawn={copied} reduced={reduced} /> : <Copy className="size-3.5" strokeWidth={1.75} />}              </span>            ))}          </button>          <button type="button" onClick={onHide} className={`h-7 shrink-0 cursor-pointer rounded-full px-2.5 text-[12px] font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground ${FOCUS}`}>            Hide          </button>        </>      ) : onReveal ? (        <StatusButton          size="sm"          variant="ghost"          status={status}          labels={{ idle: "Reveal", pending: "Revealing", success: "Reveal", error: "Try again" }}          onClick={async () => {            setStatus("pending");            try {              await onReveal();              setStatus("idle");            } catch {              setStatus("error");            }          }}        />      ) : null}    </div>  );}function Switch({ on, label, onToggle, reduced, busy }: { on: boolean; label: string; onToggle: () => void; reduced: boolean; busy: boolean }) {  return (    <button      type="button"      role="switch"      aria-checked={on}      aria-busy={busy || undefined}      onClick={onToggle}      className={`inline-flex h-7 cursor-pointer items-center gap-2 rounded-full pr-2.5 pl-1 text-[12px] font-medium transition-colors hover:bg-accent aria-busy:cursor-default ${FOCUS}`}    >      <span className={`relative h-5 w-9 shrink-0 rounded-full transition-[background-color,box-shadow] duration-300 ${on ? "bg-primary" : "bg-muted shadow-[inset_0_0_0_1px_var(--border)]"}`}>        <span className="absolute top-0.5 left-0.5 size-4 rounded-full bg-background shadow-[0_0_0_1px_var(--border)]" style={{ transform: on ? "translateX(16px)" : "none", transition: reduced ? "none" : `transform 420ms ${THROW}` }} />      </span>      <TextMorph>{busy ? "Saving" : label}</TextMorph>    </button>  );}interface EndpointProps {  ep: WebhookEndpoint;  open: boolean;  log?: Log;  secret: string | null;  fresh: boolean;  gone: boolean;  toggling: boolean;  reduced: boolean;  appName: string;  canReveal: boolean;  canToggle: boolean;  canDelete: boolean;  canRedeliver: boolean;  act: React.RefObject<Actions>;}type Actions = {  open: (id: string) => void;  test: (ep: WebhookEndpoint, event: string) => Promise<WebhookDelivery>;  delivered: (ep: WebhookEndpoint, d: WebhookDelivery) => void;  more: (ep: WebhookEndpoint) => void;  redeliver: (ep: WebhookEndpoint, d: WebhookDelivery) => Promise<unknown>;  reveal: (ep: WebhookEndpoint) => Promise<void>;  hide: (ep: WebhookEndpoint) => void;  toggle: (ep: WebhookEndpoint) => void;  remove: (ep: WebhookEndpoint) => Promise<void>;};const Endpoint = React.memo(function Endpoint({ ep, open, log, secret, fresh, gone, toggling, reduced, appName, canReveal, canToggle, canDelete, canRedeliver, act }: EndpointProps) {  const ref = React.useRef<HTMLLIElement>(null);  const { host, path } = split(ep.url);  const enabled = ep.enabled !== false;  const last = ep.lastDelivery;  const failing = enabled && last && (last.status === null || last.status >= 500);  React.useLayoutEffect(() => {    if (fresh && !reduced) ref.current?.animate([{ opacity: 0, filter: "blur(4px)", transform: "translateY(-6px)" }, { opacity: 1, filter: "blur(0px)", transform: "none" }], { duration: 460, easing: EASE });    // eslint-disable-next-line react-hooks/exhaustive-deps  }, []);  return (    <li ref={ref} className="border-t border-border first:border-t-0">      <Fold open={!gone} reduced={reduced}>        <button          type="button"          aria-expanded={open}          onClick={() => act.current.open(ep.id)}          className={`flex w-full cursor-pointer items-center gap-3 px-4 py-3 text-left transition-colors hover:bg-accent/40 @md:px-5 ${FOCUS} focus-visible:ring-inset`}        >          <span            aria-hidden="true"            className={`size-1.5 shrink-0 rounded-full transition-colors duration-500 ${!enabled ? "bg-muted-foreground/40" : failing ? "bg-red-500" : "bg-emerald-500"}`}          />          <span className="min-w-0 flex-1">            <span className="block truncate font-mono text-[12.5px]">              <span className="text-foreground">{host}</span>              <span className="text-muted-foreground">{path}</span>            </span>            <span className="mt-0.5 flex flex-wrap items-center gap-x-1.5 text-[11.5px] text-muted-foreground">              <span className="inline-flex items-baseline tabular-nums">                <NumberRoll value={ep.events.length} />                &nbsp;<TextMorph>{ep.events.length === 1 ? "event" : "events"}</TextMorph>              </span>              <span aria-hidden="true">·</span>              {!enabled ? (                <span>Disabled</span>              ) : last ? (                <span className="inline-flex items-center gap-1.5">                  <StatusChip status={last.status} />                  <RelativeTime date={last.at} />                </span>              ) : (                <span>No deliveries yet</span>              )}            </span>          </span>          <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="size-3.5 shrink-0 text-muted-foreground" style={{ transform: open ? "rotate(180deg)" : "none", transition: reduced ? "none" : `transform 340ms ${EASE}` }}>            <path d="M4.5 6.25 8 9.75l3.5-3.5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />          </svg>        </button>        <Fold open={open} reduced={reduced}>          <div className="space-y-5 px-4 pt-1 pb-4 @md:px-5 @md:pb-5">            <section aria-label="Send a test event">              <p className="mb-2 text-[11.5px] font-medium text-muted-foreground">Send a test</p>              <WebhookWire                host={host}                events={ep.events}                from={appName}                reduced={reduced}                autoFocus={fresh && open}                onSend={(event) => act.current.test(ep, event)}                onDelivered={(d) => act.current.delivered(ep, d)}              />            </section>            <section aria-label="Recent deliveries">              <p className="mb-1 text-[11.5px] font-medium text-muted-foreground">Recent deliveries</p>              <div className="rounded-[14px] px-1 shadow-[inset_0_0_0_1px_var(--border)]">                <DeliveryList                  deliveries={log?.items ?? []}                  loading={Boolean(log?.loading) || !log}                  more={Boolean(log?.more)}                  onMore={() => act.current.more(ep)}                  onRedeliver={canRedeliver ? (d) => act.current.redeliver(ep, d) : undefined}                  reduced={reduced}                />              </div>            </section>            <div className="grid gap-4 @lg:grid-cols-2">              <section aria-label="Signing secret" className="min-w-0">                <p className="mb-1.5 text-[11.5px] font-medium text-muted-foreground">Signing secret</p>                <Secret value={secret} onReveal={canReveal ? () => act.current.reveal(ep) : undefined} onHide={() => act.current.hide(ep)} reduced={reduced} />              </section>              <section aria-label="Events" className="min-w-0">                <p className="mb-1.5 text-[11.5px] font-medium text-muted-foreground">Events</p>                <p className="flex flex-wrap gap-1">                  {ep.events.map((e) => (                    <span key={e} className="rounded-full px-2 py-0.5 font-mono text-[11px] text-muted-foreground shadow-[inset_0_0_0_1px_var(--border)]">                      {e}                    </span>                  ))}                </p>              </section>            </div>            {(canToggle || canDelete) && (              <div className="flex items-center justify-between gap-3 border-t border-border pt-3">                {canToggle ? <Switch on={enabled} label={enabled ? "Enabled" : "Disabled"} busy={toggling} reduced={reduced} onToggle={() => !toggling && act.current.toggle(ep)} /> : <span />}                {canDelete && (                  <ConfirmAction                    icon={<Trash2 strokeWidth={1.75} />}                    label={`Delete endpoint ${host}`}                    labels={{ idle: "Delete endpoint", pending: "Deleting", success: "Deleted", error: "Try again" }}                    onConfirm={() => act.current.remove(ep)}                  />                )}              </div>            )}          </div>        </Fold>      </Fold>    </li>  );});export function Webhooks({  value,  defaultValue = NONE,  onValueChange,  events,  onCreate,  onTest,  loadDeliveries,  onRedeliver,  onRevealSecret,  onToggle,  onDelete,  appName = "Your app",  title = "Webhooks",  description = "Send events to your own server as they happen.",  className = "",  ...props}: WebhooksProps) {  const reduced = useReducedMotion();  const id = React.useId();  const [inner, setInner] = React.useState(defaultValue);  const endpoints = value ?? inner;  const [draft, setDraft] = React.useState<Draft | null>(null);  const [openId, setOpenId] = React.useState<string | null>(null);  const [logs, setLogs] = React.useState<Record<string, Log>>({});  const [secrets, setSecrets] = React.useState<Record<string, string>>({});  const [toggling, setToggling] = React.useState<Record<string, boolean>>({});  const [gone, setGone] = React.useState<string[]>([]);  const [fresh, setFresh] = React.useState<string | null>(null);  const [announce, setAnnounce] = React.useState("");  const urlRef = React.useRef<HTMLInputElement>(null);  const addRef = React.useRef<HTMLButtonElement>(null);  const formRef = React.useRef<HTMLFormElement>(null);  const latest = React.useRef(endpoints);  latest.current = endpoints;  const commit = (next: WebhookEndpoint[]) => {    if (value === undefined) setInner(next);    onValueChange?.(next);  };  const patch = (epId: string, p: Partial<WebhookEndpoint>) => commit(latest.current.map((e) => (e.id === epId ? { ...e, ...p } : e)));  const setLog = (epId: string, f: (l: Log) => Log) => setLogs((all) => ({ ...all, [epId]: f(all[epId] ?? { items: [], loading: false, more: false, loaded: false }) }));  const load = async (ep: WebhookEndpoint, before?: WebhookDelivery) => {    if (!loadDeliveries) return setLog(ep.id, (l) => ({ ...l, loaded: true }));    setLog(ep.id, (l) => ({ ...l, loading: true }));    try {      const page = await loadDeliveries(ep, before);      setLog(ep.id, (l) => ({ items: before ? [...l.items, ...page] : page, loading: false, loaded: true, more: page.length > 0 }));    } catch {      setLog(ep.id, (l) => ({ ...l, loading: false, loaded: true }));    }  };  const act = React.useRef<Actions>(null!);  act.current = {    open: (epId) => {      setFresh(null);      setOpenId((o) => (o === epId ? null : epId));      const ep = latest.current.find((e) => e.id === epId);      if (ep && openId !== epId && !logs[epId]?.loaded && !logs[epId]?.loading) load(ep);    },    test: (ep, event) => onTest(ep, event),    delivered: (ep, d) => {      setLog(ep.id, (l) => ({ ...l, loaded: true, items: [d, ...l.items.filter((x) => x.id !== d.id)] }));      patch(ep.id, { lastDelivery: { status: d.status, at: d.at } });    },    more: (ep) => {      const items = logs[ep.id]?.items ?? [];      load(ep, items[items.length - 1]);    },    redeliver: async (ep, d) => {      if (!onRedeliver) return;      const next = await onRedeliver(d, ep);      act.current.delivered(ep, next);      setAnnounce(`Redelivered ${d.event}: ${next.status ?? "no answer"}.`);    },    reveal: async (ep) => {      if (!onRevealSecret) return;      const s = await onRevealSecret(ep);      setSecrets((all) => ({ ...all, [ep.id]: s }));    },    hide: (ep) => setSecrets((all) => Object.fromEntries(Object.entries(all).filter(([k]) => k !== ep.id))),    toggle: async (ep) => {      const next = ep.enabled === false;      patch(ep.id, { enabled: next });      setToggling((t) => ({ ...t, [ep.id]: true }));      try {        await onToggle?.(ep, next);        setAnnounce(`${split(ep.url).host} ${next ? "enabled" : "disabled"}.`);      } catch (e) {        patch(ep.id, { enabled: !next });        setAnnounce(message(e, "That change couldn't be saved."));      } finally {        setToggling((t) => Object.fromEntries(Object.entries(t).filter(([k]) => k !== ep.id)));      }    },    remove: async (ep) => {      await onDelete?.(ep);      setAnnounce(`${split(ep.url).host} deleted.`);      window.setTimeout(() => setGone((g) => [...g, ep.id]), 500);      window.setTimeout(() => {        commit(latest.current.filter((e) => e.id !== ep.id));        setGone((g) => g.filter((x) => x !== ep.id));        setOpenId((o) => (o === ep.id ? null : o));      }, 1000);    },  };  const openDraft = () => {    if (draft) return;    setDraft({ url: "", events: events.slice(0, 1).map((e) => e.value), status: "idle", error: null });    requestAnimationFrame(() => urlRef.current?.focus({ preventScroll: true }));  };  const closeDraft = () => {    setDraft(null);    requestAnimationFrame(() => addRef.current?.focus({ preventScroll: true }));  };  const submit = async () => {    if (!draft || draft.status === "pending") return;    const why = checkUrl(draft.url) ?? (draft.events.length ? null : "Pick at least one event.");    if (why) {      setDraft({ ...draft, error: why, status: "idle" });      if (!reduced) formRef.current?.querySelector("[data-url]")?.animate(SHAKE, { duration: 380, easing: "ease-out" });      return;    }    setDraft({ ...draft, status: "pending", error: null });    try {      const ep = await onCreate({ url: draft.url.trim(), events: draft.events });      commit([ep, ...latest.current]);      setLogs((all) => ({ ...all, [ep.id]: { items: [], loading: false, more: false, loaded: true } }));      setFresh(ep.id);      setOpenId(ep.id);      setDraft(null);      setAnnounce(`${split(ep.url).host} added. Send a test to check it.`);    } catch (e) {      setDraft((d) => d && { ...d, status: "error", error: message(e, "The endpoint couldn't be added.") });    }  };  const busyDraft = draft?.status === "pending";  return (    <div className={`@container w-full rounded-[22px] border border-border bg-background text-foreground ${className}`} {...props}>      <div className="flex items-start justify-between gap-3 px-4 pt-4 pb-3.5 @md:px-5 @md:pt-5">        <div className="min-w-0">          <p className="flex items-baseline gap-2 text-[14px] font-medium tracking-[-0.01em]">            {title}            <span className="text-[12px] font-normal text-muted-foreground tabular-nums">              <NumberRoll value={endpoints.length} />            </span>          </p>          <p className="mt-0.5 text-[12px] text-muted-foreground">{description}</p>        </div>        <button          ref={addRef}          type="button"          onClick={openDraft}          aria-disabled={Boolean(draft) || undefined}          aria-expanded={Boolean(draft)}          aria-controls={`${id}-form`}          className={`inline-flex h-7 shrink-0 cursor-pointer items-center gap-1.5 rounded-full px-3 text-[12px] font-medium shadow-[inset_0_0_0_1px_var(--border)] transition-[background-color,opacity] hover:bg-accent aria-disabled:cursor-default aria-disabled:opacity-40 aria-disabled:hover:bg-transparent ${FOCUS}`}        >          <Plus className="size-3.5" strokeWidth={1.75} aria-hidden="true" />          Add endpoint        </button>      </div>      <Fold open={Boolean(draft)} reduced={reduced}>        <form          ref={formRef}          id={`${id}-form`}          noValidate          className="border-t border-border px-4 py-3.5 @md:px-5"          onSubmit={(e) => {            e.preventDefault();            submit();          }}          onKeyDown={(e) => {            if (e.key === "Escape" && !busyDraft) {              e.preventDefault();              closeDraft();            }          }}        >          <label htmlFor={`${id}-url`} className="text-[11.5px] text-muted-foreground">            Endpoint URL          </label>          <input            ref={urlRef}            data-url=""            id={`${id}-url`}            type="url"            inputMode="url"            value={draft?.url ?? ""}            readOnly={busyDraft}            onChange={(e) => setDraft((d) => d && { ...d, url: e.target.value, error: null, status: "idle" })}            placeholder="https://api.yourcompany.com/webhooks"            autoComplete="off"            spellCheck={false}            aria-invalid={Boolean(draft?.error) || undefined}            aria-describedby={`${id}-line`}            className={`mt-1 h-9 w-full rounded-[10px] bg-transparent px-3 font-mono text-[16px] text-foreground outline-none transition-shadow placeholder:font-sans placeholder:text-muted-foreground/70 [@media(pointer:fine)]:text-[12.5px] ${              draft?.error ? "shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--color-red-500)_45%,transparent)]" : "shadow-[inset_0_0_0_1px_var(--border)] focus:shadow-[inset_0_0_0_1px_var(--ring)]"            }`}          />          <p className="mt-3 text-[11.5px] text-muted-foreground">Events</p>          <div role="group" aria-label="Events to send" className="mt-1.5 flex flex-wrap gap-1.5">            {events.map((ev) => {              const on = Boolean(draft?.events.includes(ev.value));              return (                <EventChip                  key={ev.value}                  value={ev.value}                  on={on}                  reduced={reduced}                  onToggle={() => setDraft((d) => d && { ...d, error: null, events: on ? d.events.filter((x) => x !== ev.value) : [...d.events, ev.value] })}                />              );            })}          </div>          <div className="mt-3.5 flex flex-wrap items-center justify-end gap-x-3 gap-y-2">            <p id={`${id}-line`} className={`mr-auto min-w-0 text-[11.5px] ${draft?.error ? "text-red-600 dark:text-red-400" : "text-muted-foreground"}`}>              {draft?.error ?? "We sign every request so your server can check it came from us."}            </p>            <div className="flex items-center gap-1">              <button type="button" onClick={closeDraft} disabled={busyDraft} className={`h-7 cursor-pointer rounded-full px-2.5 text-[12px] font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:cursor-default disabled:opacity-50 ${FOCUS}`}>                Cancel              </button>              <StatusButton type="submit" size="sm" status={draft?.status ?? "idle"} labels={{ idle: "Add endpoint", pending: "Adding", error: "Try again" }} />            </div>          </div>        </form>      </Fold>      <div className="border-t border-border">        <ul aria-label={title}>          {endpoints.map((ep) => (            <Endpoint              key={ep.id}              ep={ep}              open={openId === ep.id}              log={logs[ep.id]}              secret={secrets[ep.id] ?? null}              fresh={fresh === ep.id}              gone={gone.includes(ep.id)}              toggling={Boolean(toggling[ep.id])}              reduced={reduced}              appName={appName}              canReveal={Boolean(onRevealSecret)}              canToggle={Boolean(onToggle)}              canDelete={Boolean(onDelete)}              canRedeliver={Boolean(onRedeliver)}              act={act}            />          ))}        </ul>        <Fold open={!endpoints.length && !draft} reduced={reduced}>          <p className="px-4 py-6 text-center text-[12.5px] text-muted-foreground @md:px-5">No endpoints yet. Add one to start receiving events.</p>        </Fold>      </div>      <span className="sr-only" role="status">        {announce}      </span>    </div>  );}

Registry item: /r/webhooks.json