本文へ移動
日本語
「封筒を開く」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

The envelope is seen from the back: its inside, a blank sheet, the pocket and the top flap with a seal. The flap has two faces, each turned with its own perspective and hidden from behind, so the coloured outside shows until it stands on edge and the lined inside after. Pressing the envelope breaks the seal (160ms), folds the flap back (360ms) and lifts the sheet clear of the pocket (360ms). The letter waits invisibly, scaled exactly onto the risen sheet; it then takes the sheet's place in a single frame, so the swap cannot be seen, and grows to its own size in 560ms while the envelope drops and fades; its content fades in last. Putting it back plays the same steps in reverse and presses the seal on again with a slight overshoot. The letter's size is measured with a ResizeObserver, never during the animation, and every move is a transform or an opacity change.

向いている場面

  • Opening an invitation, a gift card or a voucher someone sent.
  • A reward or milestone that deserves a small ceremony before its button.
  • A welcome note or a thank-you letter shown once.

向かない場面

  • Everyday messages or notifications: the ceremony wears thin fast; use a card or a toast.
  • Content people need at once, such as a receipt or an error: do not hide it behind a press.
  • A list of many letters: one envelope per view reads best.

使い方

import { useState } from 'react'
import { EnvelopeOpen } from './EnvelopeOpen.jsx'

export function GiftReveal({ gift, onClaim }) {
  const [open, setOpen] = useState(false)
  return (
    <EnvelopeOpen to={`For ${gift.recipient}`} tone="tertiary" open={open} onOpenChange={setOpen} letterWidth={300}>
      <div style={{ padding: 24 }}>
        <h3>{gift.title}</h3>
        <p>{gift.message}</p>
        <button type="button" onClick={onClaim}>Claim</button>
      </div>
    </EnvelopeOpen>
  )
}

プロパティ

プロパティ型既定値説明
toReactNode—Who it is for, written on the envelope. When it is a string it also names the envelope button and the letter.
childrenReactNode—The letter: any content, including links, buttons and form fields. Leave about 40px free at the top right for the close button.
openboolean—Whether the letter is out (controlled).
defaultOpenbooleanfalseStart with the letter out, without playing the opening, when uncontrolled.
onOpenChange(open: boolean) => void—Called when the envelope is pressed, or the letter is put back with the close button or Escape.
tone'accent' | 'secondary' | 'tertiary''accent'The colour role of the envelope: accent for a call to act, secondary for a quieter note, tertiary for a gift or a celebration.
colorstring—Any CSS colour for the envelope instead of a role, for a seasonal or brand envelope. Set onColor to keep the name readable.
onColorstring—Colour of the name on the envelope when color is set.
sealReactNode—A small icon pressed into the seal; a four-point star by default.
widthnumber220Envelope width in pixels; its height is 62% of it. The component is at least about 2.2 times the envelope's height tall, so the open flap and the risen sheet have room; the closed envelope sits a little below the centre for the same reason.
letterWidthnumber280Width of the open letter in pixels (never wider than the component). Its height follows its content.
closablebooleantrueShow a close button on the letter, and let Escape put it back into the envelope.
hintbooleantrueShow the small "Tap to open" line under the envelope.
labels{ open, hint, close }—Replace the built-in text, for example to localize. open prefixes the envelope's accessible name.
...restHTMLAttributes—Other attributes go to the root element.

アクセシビリティ

  • The envelope is one native button named "Open: <to>", with aria-expanded and aria-controls pointing at the letter.
  • Until it is open the letter is inert, so neither the keyboard nor a screen reader reaches its content; once open, the envelope is inert instead.
  • When the envelope was opened from the keyboard or a press, focus moves to the letter once it is readable, and back to the envelope when it is put away.
  • The letter is a group named after the recipient; its close button and Escape put it back (turn both off with closable).
  • Reduced motion swaps the envelope and the letter in place: no folding, rising, growing or hover peek.

モーション

Opening: seal 160ms, flap 360ms in-out, sheet 360ms ease-out, letter 560ms ease-out, envelope drops 360ms ease-in, content fades 240ms. Closing reverses it and the seal returns on a spring. Hover lifts the envelope 4px and the flap peeks 14 degrees.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

EnvelopeOpen.jsxenvelope-open.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

カード
「動く枠線カード」は Pro に含まれます。解除するとプレビューが表示されます。
「ビームボーダー」は Pro に含まれます。解除するとプレビューが表示されます。
「カード詳細とロック」は Pro に含まれます。解除するとプレビューが表示されます。