import { useEffect, useId, useRef, useState, type ReactNode } from "react"; import { createPortal } from "react-dom"; import { Check, ChevronDown, ChevronUp, X } from "lucide-react"; import { Button } from "./ui/button"; import { FieldHint } from "./ui/field-hint"; import type { StatusTone } from "../domain/statuses"; export type OpsTone = StatusTone | "brand"; export function OpsDialog({ title, subtitle, onClose, className, children }: { title: string; subtitle?: string; onClose: () => void; className?: string; children: ReactNode; }) { const ref = useRef(null); const titleId = useId(); useEffect(() => { const dialog = ref.current; if (!dialog) return; dialog.showModal(); return () => dialog.close(); }, []); return ( { event.preventDefault(); event.stopPropagation(); onClose(); }} onClick={(event) => { if (event.target === event.currentTarget) onClose(); }} >
{subtitle &&

{subtitle}

}

{title}

{children}
); } export function OpsDrawer({ title, subtitle, onClose, children }: { title: string; subtitle: string; onClose: () => void; children: ReactNode }) { const ref = useRef(null); useEffect(() => { const dialog = ref.current; if (!dialog) return; const previous = document.activeElement as HTMLElement | null; const overflow = document.body.style.overflow; document.body.style.overflow = "hidden"; dialog.showModal(); return () => { dialog.close(); document.body.style.overflow = overflow; previous?.focus(); }; }, []); return { if (event.target === event.currentTarget) onClose(); }}>

{subtitle}

{title}

{children}
; } /** 状态徽章:颜色只表达状态,文字始终保留。 */ export function OpsStatus({ tone, title, children }: { tone: OpsTone; title?: string; children: ReactNode }) { return