仕組み
Each press spends a use. The outline is drawn as one smooth path, and every use takes a round bite out of it with two or three soft scallops. The bars beside the label and the quota line show what is left. When the last bite has crumbled the button away, the empty message and the optional next action take its place. Crumbs settle 12px under the button by default (the --ds-bite-floor variable), so leave that much room below it.
向いている場面
- Show a small daily or trial allowance next to the action that spends it.
- Use a single bite for a one-use action, such as claiming a coupon.
使い方
import { BiteButton } from './BiteButton.jsx'
export function GenerationAction({ remaining, generate, openPlans }) {
return (
<BiteButton
bites={4}
remaining={remaining}
labels={{ button: 'Generate', empty: 'See plans', emptyMessage: 'No free generations left today' }}
onBite={generate}
onEmptyAction={openPlans}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
bites | number | 4 | Total quota, from 1 to 8. In uncontrolled use, changing the total preserves the number of uses already spent. |
remaining | number | — | Controlled quota from 0 to bites. Update it to commit a bite or refill, or omit it to let the button manage the count. |
defaultRemaining | number | bites | Starting count when the button manages the quota. |
onBite | (remaining: number) => void | — | Called once per activation with the requested count after one use. |
onEmpty | () => void | — | Called when the quota changes from positive to zero. |
onRefill | (remaining: number) => void | — | Receives the full count when a timed refill is due. In controlled use, apply the new count in the parent. |
onEmptyAction | () => void | — | Provide the handler for the empty action, such as opening the plan picker. The action is shown when this handler is supplied. |
renderEmptyAction | (buttonProps: BiteEmptyActionProps) => ReactNode | — | Optional renderer for the quiet action. Forward ref, type, title, onClick, onKeyDown and children to a native button, and use size to match the active control. |
refill | 'manual' | number | 'manual' | Use manual mode with an externally controlled reset, or set a delay in milliseconds after the empty state appears. |
size | 'sm' | 'md' | 'lg' | 'md' | Visual height of 28, 36 or 44 pixels. The hit area is at least 44 pixels tall. |
variant | 'ink' | 'accent' | 'outline' | 'ink' | Ink, accent fill or an outline that traces every bite. Crumbs take the same colour. |
pips | boolean | true | Shows one short bar per use beside the label; each bite eats the last one still standing. |
labels | { button?: string, empty?: string, emptyMessage?: string, quota?: (remaining: number, total: number) => string, name?: (label: string, remaining: number, total: number) => string, remaining?: (remaining: number, total: number) => string, depleted?: string, refilled?: (remaining: number, total: number) => string } | — | Overrides the visible labels, the action's accessible name and the live announcements. |
アクセシビリティ
- Tab focuses the native button. Enter and Space spend one use per press, including when a key is held.
- The accessible name includes the available count, and a polite region announces changes. The bars, the bites and the crumbs are hidden from assistive technology.
- When the focused button disappears, focus moves to the next action or to the empty message. The hit area stays a full rectangle, at least 44px tall, however much is eaten.
モーション
A bite closes in about 110ms while the button tugs towards it and springs back, and one bar swells and is eaten. Four to six crumbs hop out of the bite with a spin, bounce once, settle in a small heap under it and fade after about three seconds. The last bite clears the heap; what is left of the button collapses towards its middle and crumbles, and the empty state rises in. With reduced motion nothing travels: bites and bars change at once and the last step is a short fade.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
BiteButton.jsxbite-button.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。



