"use client"; import { useEffect, useRef } from "react"; import type { IOptionToggle } from "../structures/IOptionToggle"; import type { ITransformOptions } from "../structures/ITransformOptions"; import { DEFAULT_OPTION_TOGGLES } from "./DEFAULT_OPTION_TOGGLES"; interface OptionsPanelProps { options: ITransformOptions; onChange: (next: ITransformOptions) => void; onClose: () => void; /** Defaults to the typia + lint pair from `DEFAULT_OPTION_TOGGLES`. */ toggles?: readonly IOptionToggle[]; /** Dialog heading. Defaults to "Transform Options". */ title?: string; } export function OptionsPanel({ options, onChange, onClose, toggles = DEFAULT_OPTION_TOGGLES, title = "Transform Options", }: OptionsPanelProps) { const dialogRef = useRef(null); const toggle = (key: string) => onChange({ ...options, [key]: !options[key] }); // Escape closes. Focus traps inside the dialog. useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") { e.preventDefault(); onClose(); return; } if (e.key !== "Tab" || !dialogRef.current) return; const focusable = dialogRef.current.querySelectorAll( 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])', ); if (focusable.length === 0) return; const first = focusable[0]!; const last = focusable[focusable.length - 1]!; if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); } else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); } }; window.addEventListener("keydown", onKey); // Auto-focus the first focusable on mount. const focusable = dialogRef.current?.querySelector( 'button, input, [tabindex]:not([tabindex="-1"])', ); focusable?.focus(); return () => window.removeEventListener("keydown", onKey); }, [onClose]); return (
e.stopPropagation()} >

{title}

Plugins
{toggles.map((t) => ( ))}
); }