import { useState } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@godxjp/ui/data-display"; import { Button, Text } from "@godxjp/ui/general"; import { Flex, PageContainer } from "@godxjp/ui/layout"; import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@godxjp/ui/navigation"; import { MoreHorizontal } from "lucide-react"; /** * DropdownMenu — react-aria dropdown. Compose root/Trigger(asChild)/Content/Item/Separator. * Use asChild on Trigger so a godx-ui Button is the real trigger (no double-button). * `trigger` picks the gestures (click / hover / contextMenu) — antd's own prop. * Composed only from real @godxjp/ui components. */ export default function Demo() { const [status, setStatus] = useState("draft"); const [showAmount, setShowAmount] = useState(true); const [showPartner, setShowPartner] = useState(true); const [showDate, setShowDate] = useState(false); return ( メニュー幅 {(["auto", "trigger", "sm", "md", "lg"] as const).map((width) => ( 編集 ))} {/* Row action menu — the most common use */} 行アクションメニュー (DataTable 行の "…") DropdownMenuTrigger に asChild を付けて godx-ui Button をトリガーにする。 DropdownMenuItem の variant は default と destructive の 2 つ。削除だけを variant="destructive" にし、className で色を上書きしない。 JE-0042 · 売上計上 ¥480,000 編集 複製 アーカイブに移動 削除 {/* antd `trigger` — which gestures open the menu */} trigger · 右クリック(コンテキストメニュー) trigger={"{"}["contextMenu"]{"}"} は右クリックの位置にメニューを開き、 ブラウザ標準のメニューを抑止する。左クリックでは開かない。キーボードからは Shift+F10 または ContextMenu キーで開く(トリガーにフォーカスしてから)。専用の ContextMenu コンポーネントは v23 で廃止され、これがその置き換え。 {/* data-axe-open="contextmenu": the gate RIGHT-clicks this before its overlay scan. It is declared here rather than on one of the click menus above because the `defaultOpen` card at the bottom of this page already holds a click-opened menu mounted at rest, so the click path is measured either way — the right-click path is the one nothing else on this page reaches. */} 編集 複製 削除 trigger · ホバーで開く trigger={"{"}["hover"]{"}"} はポインタが乗ると mouseEnterDelay(既定 0.15 秒)後に開き、離れると mouseLeaveDelay(既定 0.1 秒)後に閉じる。トリガーとメニューの間の隙間を渡れるよう、閉じるのは取り消せる予約。 ホバーでフォーカスは移動せず、キーボードでは Enter / Space / ↓ で開くので、ポインタ専用にはならない。 CSV PDF 編集 複製 編集 {/* Status quick-change with RadioGroup */} RadioGroup · ステータス即時変更 DropdownMenuRadioGroup + DropdownMenuRadioItem でステータスを切り替える。 Select の代替。フォーム外でのインライン状態遷移に使う。 現在のステータス:{" "} {status === "draft" ? "下書き" : status === "posted" ? "承認済" : "取消済"} ステータス 下書き 承認済 取消済 {/* Column visibility toggle */} CheckboxItem · 列の表示 / 非表示 DropdownMenuCheckboxItem で DataTable の列表示を切り替える。 checked + onCheckedChange で各列の状態を管理する。 表示する列 金額 取引先 日付 {/* Nested sub-menu for export */} Sub-menu · エクスポート形式の選択 DropdownMenuSub + DropdownMenuSubTrigger + DropdownMenuSubContent でネスト。 ChevronRight は DropdownMenuSubTrigger が自動で表示する。 承認 却下 エクスポート CSV Excel (.xlsx) PDF 一括削除 {/* Avatar chip / account menu */} アカウントメニュー · トップバーのアバターチップ DropdownMenuLabel でユーザー情報を表示し、アクションを下に並べる標準パターン。 田中 太郎 tanaka@example.co.jp プロフィール 設定 ログアウト {/* defaultOpen — OPEN ON MOUNT, on purpose, and this is the only example on the page that is. A menu paints nothing until it is opened, so for as long as this page has existed no sweep has ever measured a single menu pixel: that is how `.ui-dropdown-menu-item[data-variant="destructive"]` — the label on a Delete row, i.e. prose — kept the destructive FILL tier at 2.95:1 on dark (gh#612). Same reasoning as `?toast=` in check-contrast's route list: a surface that needs an interaction is a surface no gate sees. */} defaultOpen · 計測できる状態で開いておく antd の open/defaultOpen。ここだけはマウント時から開いたままにしてある。 閉じたメニューは 1 ピクセルも描かないので、どのスイープにも測れない。 destructive の行が読める色で描かれているかは、開いていて初めて測れる。 編集 複製 削除 ); }