本文へ移動
日本語
「スナップドロワー」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

During a drag the offset is written straight to CSS variables, so no React render happens per frame. On release the position is projected 220ms ahead with the release velocity and the nearest snap point wins; a flick always moves at least one point. Past the top edge the drag resists with a rubber-band curve. The second-highest point to full drives --ds-snap-p, which scales the background to 0.93, rounds its corners and dims a scrim.

向いている場面

  • Map, media or list screens on phones where the content behind should stay visible.
  • Progressive detail: a peek summary that expands into the full list.

向かない場面

  • A short choice or confirmation: use a simple bottom sheet or dialog.
  • Wide desktop layouts: use a side panel.

使い方

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

export function MapScreen() {
  const [open, setOpen] = useState(true)
  return (
    <SnapDrawer
      open={open}
      onOpenChange={setOpen}
      snapPoints={[0.22, 0.55, 0.92]}
      background={<Map />}
      header={<h2>Nearby</h2>}
    >
      <PlaceList />
    </SnapDrawer>
  )
}

プロパティ

プロパティ型既定値説明
openbooleantrueWhether the drawer is shown.
onOpenChange(open: boolean) => void—Called when it is swiped away or Escape is pressed.
snapPointsnumber[][0.22, 0.55, 0.92]Visible heights as fractions of the frame, lowest first.
snap / defaultSnap / onSnapChangenumberdefaultSnap 1The current snap index, controlled or not.
snapLabelsstring[]['Peek', 'Half', 'Full']Spoken names of the snap points.
backgroundReactNode—The screen behind the drawer; it scales back as the drawer reaches full.
headerReactNode—Always-visible top part; it is also a drag area.
childrenReactNode—The body; it scrolls only at full height.
dismissiblebooleantrueAllow swiping below the lowest point to close.
scaleBackgroundbooleantruePush the background back near full height.
containedbooleanfalseFill the nearest positioned ancestor instead of the viewport.
label / handleLabelstringhandleLabel 'Resize sheet'Accessible names of the drawer (defaults to the header) and its handle.

アクセシビリティ

  • The drawer is role dialog (modal only at full height) labelled by its header.
  • The handle is a vertical role slider with aria-valuetext naming the snap point; Up and Down move between points, Home and End jump, Enter cycles.
  • Escape closes it when dismissible; a closed drawer is inert and aria-hidden.
  • Drag areas use touch-action none, while the body scrolls natively at full height; the handle is 88 by 26 px plus the header area.
  • With reduced motion snapping is instant and only the scrim fades.

モーション

Snap 520ms cubic-bezier(0.32, 0.72, 0, 1); velocity projection 220ms; rubber band (1 − 1/(0.55·d/D + 1))·D with D = 15% of the frame; background scale 1 → 0.93, radius 0 → 18px, scrim 0 → 30%.

プロジェクトに追加

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

SnapDrawer.jsxsnap-drawer.csstokens.cssREADME.md

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

オーバーレイ
「ボトムシート」は Pro に含まれます。解除するとプレビューが表示されます。