Ripple Button
點擊擴散漣漪的按鈕,從點擊點放射出 Material 風格水波。
點擊時以游標落點為圓心放射出一圈漣漪,直徑取到最遠角落,確保水波蓋滿整顆按鈕。漣漪疊在內容底下、被 overflow-hidden 裁切成按鈕形狀。
載入預覽⋯
Playground
即時調整 props、程式碼片段同步更新——直接試出你要的樣子再複製。
0.6
0.5
<RippleButton />
安裝
npx shadcn@latest add https://webberui.com/r/ripple-button.json或在 components.json 設定 registries 後,改用 @webberui/ripple-button 安裝。
安裝依賴後,從 registry JSON(/r/ripple-button.json 的 files[0].content)複製 ripple-button.tsx 原始碼到你的 components/ui/ 目錄:
npm install motion clsx tailwind-merge使用
import { RippleButton } from "@/components/ui/ripple-button";
<RippleButton onClick={() => console.log("clicked")}>
點我擴散
</RippleButton>換色只要傳 rippleColor,其餘 <button> 屬性(type、disabled、onClick…)都會透傳。
Props
除下列以外,其餘原生 <button> 屬性皆會透傳。
| Prop | 型別 | 預設值 | 說明 |
|---|---|---|---|
rippleColor | string | "rgba(255, 255, 255, 0.55)" | 漣漪顏色,任何 CSS 顏色值 |
duration | number | 0.6 | 單一漣漪擴散時長(秒) |
opacity | number | 0.5 | 漣漪起始不透明度 |
className | string | — | 透傳到按鈕,可覆蓋預設樣式 |
children | ReactNode | — | 按鈕內容 |
可及性
- 使用者系統開啟「減少動態效果」時,略過漣漪、僅保留一般按鈕行為
- 漣漪層帶
aria-hidden且pointer-events-none,不影響輔助科技與點擊 - 保留原生
<button>語意與鍵盤 focus ring,disabled時停用互動