Components

Envelope

An envelope on the desk with a stamp, a postmark and address lines. It opens: the flap, which belongs to the back panel, stands up behind, and a letter slides out from between the panels, the front panel hiding its foot. Built on Collapsible, so it has a real trigger, `aria-expanded`, and content that is not in the page until it is out.

Install

terminal
npx shadcn@latest add @wobko/envelope

First time here? Add the registry to components.json first. How to install

Examples

An envelope

Press it, or Tab to it and press Space: the flap stands up behind and the letter slides out. Hover lifts the flap a sliver.

Manila, white, airmail

Kraft (the default), white paper with a sky-blue stamp, and an airmail envelope with its striped border. Each stamp is perforated; each has a postmark over it.

Opens when you look

`openOnHover` opens it under a mouse and closes it again on leaving, unless you clicked it open. On touch and keyboard the trigger works as always.

An inbox

A real use: messages that arrive as envelopes. Opening one marks it read; only one is open at a time. State lives in your app; the envelope only shows it.

API reference

Envelope

The outer element (`w-full max-w-sm`, a container for its own measurements) around the body (`aspect-[8/5]`), whose drawing is the back panel: a sheet with the flap that lifts a sliver on hover and stands up when open. When open the envelope makes room above itself for the flap and the letter.

PropTypeDefaultDescription
stockStockName"kraft"What it is made of: kraft (manila), paper, index-card, a sticky stock ...
stampAccent | false"tomato"The postage stamp in the top corner (perforated, with a little picture), in a stationery color, or none. It sits at the end corner and mirrors in RTL.
postmarkbooleantrueTwo rings and wavy cancellation lines over the stamp (only with a stamp).
airmailbooleanfalseA border of slanted red and blue stripes.
open / defaultOpen / onOpenChangeboolean / boolean / (open: boolean) => void-As Collapsible: controlled or not.
disabledbooleanfalseSealed: the trigger is disabled (as Collapsible's `disabled`) and hovering opens nothing.
openOnHoverbooleanfalseAlso open while a mouse is over it and close when it leaves (unless it was opened by a click). Touch never opens it on hover.
tilt / seed / sizeboolean | number / string | number / [w, h]-A seeded turn under 1.1 degrees (front and back turn together); pins the hand; the box in px for server-rendered drawings.

EnvelopeLetter

The letter: a Paper (paper stock by default) absolutely placed between the panels. It is not in the page while the envelope is closed; when it opens it slides up (and fades in), rising about a third of the envelope's height above its top edge. Only that upper part shows; the front panel hides the rest.

PropTypeDefaultDescription
stockStockName"paper"The letter's paper.

Accessibility

  • The trigger is a real button with `aria-expanded` and `aria-controls`, named by its content: make the name say what opening does ("Read the letter from Ada"). The letter is not rendered until it is open, so a screen reader never meets it twice. Open and closed are not carried by the drawing alone.
  • Source order is tab order: put `EnvelopeFront` (with its trigger) before `EnvelopeLetter`, so that Tab from the trigger reaches a link or button inside the letter it just opened. The letter clips to its sheet and most of it sits behind the front: keep it to a few lines, a heading and a link, and put long messages on a page the letter links to. With `openOnHover`, a letter that holds keyboard focus stays open when the mouse leaves.
  • Hover opening is a mouse nicety (`openOnHover`); touch and keyboard always use the trigger. The slide-in is skipped with reduced motion, and the flap simply appears.
  • The paper, seams, stamp, postmark and flap are aria-hidden decoration. Ink on the kraft is 9:1, and so is the address; the postmark is decoration only. Windows high contrast replaces the drawing with outlines.

Source

The files the CLI copies into your project.

Loading the source