WebberUI

Bubble Menu

浮動圓形泡泡逐一展開的選單,扇形彈出、彈簧節奏、支援連結與回呼。

點主按鈕,選單項目化為圓形泡泡沿扇形逐一彈出,再點一次由外而內收回。方向、扇角、半徑與配色皆可調。

載入預覽⋯

Playground

即時調整 props、程式碼片段同步更新——直接試出你要的樣子再複製。

180
96
0.05
<BubbleMenu />

安裝

npx shadcn@latest add https://webberui.com/r/bubble-menu.json

或在 components.json 設定 registries 後,改用 @webberui/bubble-menu 安裝。

安裝依賴後,從 registry JSON(/r/bubble-menu.jsonfiles[0].content)複製 bubble-menu.tsx 原始碼到你的 components/ui/ 目錄:

npm install motion lucide-react clsx tailwind-merge

使用

import { BubbleMenu } from "@/components/ui/bubble-menu";
import { Home, Search, Settings } from "lucide-react";

<BubbleMenu
  direction="up"
  items={[
    { label: "Home", icon: Home, href: "/" },
    { label: "Search", icon: Search, onClick: () => console.log("search") },
    { label: "Settings", icon: Settings, color: "hsl(280 65% 60%)" },
  ]}
/>;

每個項目至少要有 labelicon。給 href 會渲染成連結,或改用 onClick 綁定行為;兩者擇一即可。

Props

Prop型別預設值說明
itemsBubbleMenuItem[]選單項目,逐一從主按鈕彈出
direction"up" | "down" | "left" | "right""up"泡泡展開方向
spreadnumber180扇形總角度(度)
radiusnumber96泡泡距主按鈕中心的半徑(px)
sizenumber56主按鈕直徑(px)
itemSizenumber46子泡泡直徑(px)
staggernumber0.05每顆泡泡間的彈出間隔(秒)
colorstring"hsl(221 83% 53%)"主色(未被項目 color 覆寫時採用)
showLabelsbooleantrue展開時 hover 泡泡顯示文字標籤
iconLucideIconPlus主按鈕圖示(關閉狀態)

BubbleMenuItem

欄位型別說明
labelstring泡泡標籤,同時作為 aria-label
iconLucideIconlucide-react 圖示元件
hrefstring?導向連結;有值時渲染為 a
onClick() => void點擊回呼;與 href 擇一
colorstring?單獨覆寫此泡泡顏色

可及性

  • 主按鈕帶 aria-expanded 與中文 aria-label,切換開闔狀態
  • 每顆泡泡帶 aria-label;收合時泡泡層標記 aria-hidden
  • 使用者系統開啟「減少動態效果」時,改用極短的淡入淡出取代彈簧位移

On this page