MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / UrlInputModal

Function UrlInputModal

src/components/modals/UrlInputModal.tsx:40–142  ·  view source on GitHub ↗
({ isOpen, onClose, onLoad, loading = false }: UrlInputModalProps)

Source from the content-addressed store, hash-verified

38 * - Enter key to submit, Escape to close
39 */
40export function UrlInputModal({ isOpen, onClose, onLoad, loading = false }: UrlInputModalProps) {
41 const titleId = useId();
42 const descriptionId = useId();
43 const [url, setUrl] = useState('');
44 const [showHelp, setShowHelp] = useState(false);
45 const inputRef = useRef<HTMLInputElement>(null);
46 const actionState = getUrlInputActionState(url, loading);
47 const helpIconKind = getUrlInputHelpIconKind(showHelp);
48
49 // Clear URL when modal closes
50 useEffect(() => {
51 if (!isOpen) {
52 const timeout = setTimeout(() => setUrl(''), 0);
53 return () => clearTimeout(timeout);
54 }
55 }, [isOpen]);
56
57 // Handle load action
58 const handleLoad = useCallback(() => {
59 const submitUrl = getUrlInputSubmitUrl(url, loading);
60 if (!submitUrl) return;
61 onLoad(submitUrl);
62 }, [url, loading, onLoad]);
63
64 // Handle key events
65 const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
66 if (shouldSubmitUrlInputKey(e.key, loading)) {
67 handleLoad();
68 }
69 }, [handleLoad, loading]);
70
71 return (
72 <ModalDialogShell
73 isOpen={isOpen}
74 onClose={onClose}
75 ariaLabelledBy={titleId}
76 ariaDescribedBy={descriptionId}
77 overlayClassName="fixed inset-0 flex items-center justify-center bg-ds-void/50"
78 overlayStyle={getUrlInputModalOverlayStyle()}
79 panelClassName="bg-ds-tertiary border border-ds rounded-lg shadow-ds-lg p-5 min-w-[400px] max-w-[520px]"
80 panelTestId="url-modal"
81 initialFocusRef={inputRef}
82 closeOnBackdrop={shouldCloseUrlInputFromBackdrop(true, loading)}
83 closeOnEscape={!loading}
84 >
85 <h3 id={titleId} className="text-ds-primary font-medium mb-3">Load from URL</h3>
86 <p id={descriptionId} className="text-ds-muted text-sm mb-4">
87 {URL_INPUT_DESCRIPTION}
88 </p>
89
90 {/* URL input */}
91 <input
92 ref={inputRef}
93 type="url"
94 value={url}
95 onChange={(e) => setUrl(e.target.value)}
96 onKeyDown={handleKeyDown}
97 placeholder={URL_INPUT_PLACEHOLDER}

Callers

nothing calls this directly

Calls 7

getUrlInputActionStateFunction · 0.90
getUrlInputHelpIconKindFunction · 0.90
getUrlInputSubmitUrlFunction · 0.90
shouldSubmitUrlInputKeyFunction · 0.90
getButtonClassFunction · 0.90

Tested by

no test coverage detected