clickworks
Works / Forms

Mail Slot

The visitor writes their address on a card and posts it: push Send, or drag the card down into the slot. The flap swings, the card drops through, and the plate thanks them. Give it your own subscribe handler, or put it in a form.

Free1 file0 dependencies8.6 kB gzippedRenders on the serverKeyboard and screen reader

Install

npx shadcn@latest add https://clickworks.dev/r/mail-slot.json

The files land in components/clickworks/mail-slot/. No other packages are added.

Usage

"use client"

import { MailSlot } from "@/components/clickworks/mail-slot/react/MailSlot"

export function Newsletter() {
  return (
    <MailSlot
      card={{ heading: "One short email a month." }}
      onSubscribe={(email) => fetch("/api/subscribe", { method: "POST", body: JSON.stringify({ email }) }).then((r) => r.ok)}
    />
  )
}

Props

onSubscribe
(email: string) => unknown

Sends the address to your list. Return false or throw to show the failed state. Without it, a surrounding form submits, or a demo plays.

card
{ kicker?, heading?, placeholder?, button? }

Words on the card.

plate
{ engraving?, note? }

The engraving on the slot and the small note under it.

thanks
{ thanksTitle?, thanksText?, again? }

What the plate says once it's sent.

messages
{ empty?, invalid?, failed?, posting? }

Status lines for each state.

theme
"auto" | "light" | "dark"

Auto follows the page (its background, data-theme or dark class), then the device.

Default "auto"

light / dark
object

Colours for each theme. Every shade and shadow is mixed from them.

behaviour
{ drag?, sound?, haptics? }

Drag to post, sound and phone vibration.

Default all on

Events

onSuccess
() => void

The card went through.

onError
() => void

Sending failed. The address stays on the card.

Styling

Colours come in through the light and dark props, so each theme gets its own palette. It fills its width and keeps its proportions.

Behaviour and accessibility

  • The address field is a real email input with its own label, checked before anything is sent.
  • Enter sends, like Send. Dragging is extra, never the only way.
  • Status changes are announced to screen readers.
  • With reduced motion the card posts without the drop.

Files

react/MailSlot.tsxReact component