本文へ移動
日本語

仕組み

A bar above the content: the tone glyph on a 32px rounded square, a title with optional description, then an action slot and a close button. soft is a clean 10% wash of the tone colour over the surface with the glyph on a raised white square and a white pill action; outline keeps the surface colour with a tone-tinted hairline. The four tones use the status colours from the design tokens and each has its own glyph, so colour is never the only cue. The banner is its own size container: wider than 420px the action and close sit on the right, narrower the action drops under the text. It can be controlled or uncontrolled. On close the grid row goes from 1fr to 0fr while fading, then the element unmounts; showing it again mounts collapsed and expands, so content below moves smoothly both ways.

向いている場面

  • A note that should stay until read: email not verified, scheduled maintenance, a failed sync.
  • Status of a whole page or section, at the top of it, with a link to fix it.
  • Use it for the current situation; use a toast for the result of an action just taken.

向かない場面

  • An action just succeeded or failed (saved, copied): use a toast or change the button text.
  • One field is wrong: show the error under that field.
  • Something must be dealt with before continuing: use a confirmation dialog.
  • Three or four banners stacked: keep the most urgent one.

使い方

import { AlertBanner } from './AlertBanner.jsx'

// A note that is always shown
<AlertBanner tone="info" title="Maintenance tonight 2:00–4:00" description="Exports pause; running jobs are not affected" />

// With an action and a close button; the gap to the content below goes on --ds-alert-gap
<AlertBanner
  tone="warning"
  title="Email not verified"
  description="Verify to publish and invite teammates"
  action={
    <button type="button" className="ds-alert__btn" onClick={goVerify}>
      Verify
    </button>
  }
  closable
  style={{ '--ds-alert-gap': '16px' }}
/>

// Controlled: it can be shown again after closing
const [open, setOpen] = useState(true)
<AlertBanner tone="danger" variant="outline" title="1 project failed to sync" closable open={open} onOpenChange={setOpen} />

プロパティ

プロパティ型既定値説明
tone'info' | 'success' | 'warning' | 'danger''info'Sets color and icon. warning and danger use role="alert" and are announced at once; the others use role="status".
variant'soft' | 'outline''soft'soft is a pale wash of the tone colour; outline keeps the surface colour with a tone-tinted hairline, for areas that already have a background.
titleReactNode—One sentence saying what is going on. Required.
descriptionReactNode—Extra detail: cause, impact, what to do.
actionReactNode—Slot for a button, such as <button className="ds-alert__btn"> (a 32px pill). On the right in wide containers, under the text in narrow ones.
iconReactNode—Replaces the default glyph (16px, set on a 32px rounded square). Pass null to hide it.
closablebooleanfalseShows a close button. Closing collapses the height, then unmounts.
openboolean—Controlled visibility. If omitted the component manages it.
defaultOpenbooleantrueInitial visibility when uncontrolled.
onOpenChange(open: boolean) => void—Called with false when the close button is pressed. When controlled, update open here.
closeLabelstring'Dismiss'Accessible name of the close button.
labelsobject—Replaces the tone names read before the title (info, success, warning, danger) and the prefix function. Shallow-merged over the English defaults.
--ds-alert-gapCSS variable0pxGap to the content below. It collapses with the height. Set it in style or CSS.
className / ...restHTMLAttributes—Passed to the root element. A role prop overrides the default alert / status.

アクセシビリティ

  • warning and danger use role="alert" (announced at once); info and success use role="status".
  • The icon is not read; a screen-reader-only tone prefix such as “Warning:” comes before the title.
  • The close button is a real <button> with a focus ring; the action button comes before it in tab order.
  • On touch the buttons keep their size (32px action, 28px close) but the tap area is 44px.
  • Reduced motion skips the height transition and the banner disappears at once.

モーション

Enter: the bar settles from 6px above at 98% scale in 360ms ease-out (also when shown again). Close and show: height moves between 0 and its own height in 240ms on the standard curve while opacity changes in 160ms. The action pill presses to 0.96, the close button to 0.92 (100ms).

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

AlertBanner.jsxalert-banner.csstokens.cssREADME.md

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

フィードバック
「紙吹雪」は Pro に含まれます。解除するとプレビューが表示されます。
「ライブステータスピル」は Pro に含まれます。解除するとプレビューが表示されます。