35
Componentregistry:componentModern collection

Mailpick

Turns every mailto link into a small menu: Gmail, Outlook, Outlook for work or school, Yahoo Mail, the default mail app, or copy the address. Wrap the app once and existing links just work, with to, cc, subject and body filled in. On phones it slides up as a bottom sheet. Built on ui-sdk Menu, so focus, arrow keys and ARIA are done.

Preview

Start a project with us

Tell us what you're building. We reply within one working day.

Email the studio
Options
On phones

onSelect–

Installation

$ npx shadcn@latest add @creative-ui/mailpick

On an older shadcn CLI, use the URL: npx shadcn@latest add https://ui.krutikraut.com/r/mailpick.json

Add `@layer ui-sdk;` at the top of your global stylesheet, above `@import "tailwindcss"`. Then wrap your app in <MailpickProvider>.

Usage

Example.tsx
// app/layout.tsx
import { MailpickProvider } from "@/components/mailpick"

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <MailpickProvider>{children}</MailpickProvider>
      </body>
    </html>
  )
}

// That's all most sites need: every mailto link now opens the menu.
// To build a link from its parts, inside a shadcn Button:
import { MailpickLink, useMailpick } from "@/components/mailpick"

<Button asChild>
  <MailpickLink to="hello@studio.com" subject="New project">Email us</MailpickLink>
</Button>

// Open it from code:
const { open } = useMailpick()
<Button onClick={(e) => open("mailto:sales@acme.com", e.currentTarget)}>Talk to sales</Button>

// Fewer options, a webmail of your own, and analytics:
<MailpickProvider
  providers={[
    "gmail",
    "outlook",
    { id: "acme", label: "Acme Mail", icon: AcmeLogo, href: (mail) => `https://mail.acme.com/compose?to=${encodeURIComponent(mail.to.join(","))}` },
    "copy",
  ]}
  onSelect={({ provider }) => track("email_click", { provider })}
>

// Leave one link alone:
<a href="mailto:jobs@studio.com" data-mailpick="off">jobs@studio.com</a>

Props

2 components

<MailpickProvider />

Wrap the app once. It listens for clicks on mailto links and opens one shared menu.
PropTypeDefaultDescription
providers(ProviderId | Provider)[]["gmail", "outlook", "office", "yahoo", "app", "copy"]Which choices show, in order. office is Outlook for work and school accounts, app the default mail app. Custom options are { id, label, hint?, icon?, mark?, href: (mail) => string }: icon is a component for the tile, and without one the tile shows mark or the label's first letter.
titlestring"Send with"The small label above the address.
interceptbooleantrueCatch plain mailto links. With false, only MailpickLink and open() show the menu.
mobile"native" | "menu""menu"On phones, show the choices as a bottom sheet (ui-sdk's sheet presentation), or let the phone's own mail app open as usual.
rememberLastbooleantrueFocus the visitor's last pick when the menu opens and tag it "Last used". Stored in localStorage only.
onSelect(e: { provider, mail, href }) => void—Fires when someone picks an option, with its id, the parsed message and the original link. For analytics.
side"top" | "bottom""bottom"Which side of the link the menu opens on. It flips when there's no room.
align"start" | "center" | "end""start"How the menu lines up with the link.
classNamestring—Classes for the menu, for one-off tweaks.

<MailpickLink />

A real mailto link built from its parts, so it works with JavaScript off. It opens the menu even with intercept={false}.
PropTypeDefaultDescription
tostring | string[]—The addresses.
ccstring | string[]—Copied addresses.
bccstring | string[]—Blind-copied addresses.
subjectstring—The subject line.
bodystring—The message. Line breaks are kept.
hrefstring—A ready mailto link. Wins over the parts.

Also accepts every a prop, which is spread onto the root element.

Also exported

useMailpick(): { open(mailto, anchor?), close(), parseMailto(href) }
Opens the menu from code. mailto is a link or { to, cc, bcc, subject, body }. Without anchor the menu opens near the top of the window. Outside a provider, open() follows the plain link.
parseMailto(href): { to, cc, bcc, subject, body }
In lib/parse-mailto.ts, with no React, so it also runs on the server. buildMailto(parts) goes the other way.
mailpickProviders, type Provider
In lib/mailpick-providers.ts: the built-in options and their compose URLs, to reuse or extend.

Notes

  • Only a plain left click opens the menu. Ctrl/⌘, Shift or Alt clicks, right clicks, links inside data-mailpick="off", and clicks something else already handled with preventDefault() all behave as if Mailpick weren't there.
  • On phones the choices slide up as a bottom sheet you can swipe away, so a tap never jumps straight into one mail app. Set mobile="native" to let the phone's own mail app open instead.
  • Gmail, Outlook and Yahoo open in a new tab with to, cc, bcc, subject and body filled in. They're real links, not window.open, so popup blockers leave them alone. A target="_blank" mailto link no longer leaves an empty tab behind.
  • + in an address stays a plus, as the mailto spec says, so name+tag@x.com survives. Bad percent-encoding is shown as written instead of throwing.
  • Copy address shows a check for 900 ms and closes. If the browser refuses the clipboard, the address is shown as text to select instead.
  • Gmail, Outlook and Yahoo show their colour logos on white tiles, the same in light and dark. The logos are trademarks of Google, Microsoft and Yahoo, used to name their services; the SVGs come from openly licensed sets (credits in the file). Give a provider your own icon to replace one.
  • Web options show a small ↗ on the highlighted row, since they open in a new tab.
  • Built on @ui-sdk/react Menu, which handles focus, the arrow keys, Home and End, typeahead, Escape, Tab and the ARIA menu roles. Add @layer ui-sdk; at the top of your global stylesheet, above @import "tailwindcss". It needs React 19, and this item pins 0.1.0-beta.20.

Dependencies

@ui-sdk/react@0.1.0-beta.20@ui-sdk/core@0.1.0-beta.20lucide-reactshadcn/utils