"use client"; import { useRef } from "react"; import { EyeOff, Scaling, Type } from "lucide-react"; import type { FrameLabelMode } from "@/lib/canvas-elements"; import styles from "./canvas.module.css"; const options = [ { value: "hidden", label: "隐藏名称", hint: "在画布上隐藏分区名称", Icon: EyeOff }, { value: "fixed", label: "固定字号", hint: "缩放画布时保持名称大小", Icon: Type }, { value: "scaled", label: "随画布缩放", hint: "名称随画布一起放大缩小", Icon: Scaling }, ] as const; export function FrameLabelMenu({ value, change }: { value: FrameLabelMode; change: (mode: FrameLabelMode) => void }) { const items = useRef<(HTMLButtonElement | null)[]>([]); const current = Math.max(0, options.findIndex((option) => option.value === value)); return
{ const delta = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 }[event.key]; if (delta !== undefined || event.key === "Home" || event.key === "End") { event.preventDefault(); event.stopPropagation(); const index = event.key === "Home" ? 0 : event.key === "End" ? 2 : (current + delta! + 3) % 3; change(options[index].value); items.current[index]?.focus(); } }}> {options.map(({ value: mode, label, hint, Icon }, index) => )}
; }