-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreviewDialog.tsx
More file actions
46 lines (42 loc) · 1.33 KB
/
Copy pathPreviewDialog.tsx
File metadata and controls
46 lines (42 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* A modal, in-app viewer showing one text file's content verbatim.
*
* §REQ:TWO-PNL-NVGT-OOX-090 the view command shows the textual content of the
* selected file to the user, and the user can close it again.
*/
import { useEffect, useRef } from 'react'
export interface PreviewDialogProps {
/** Name of the previewed file, shown so the user knows what they are reading. */
name: string
/** §REQ:TWO-PNL-NVGT-OOX-090 the file's textual content, rendered verbatim. */
content: string
onClose: () => void
}
export function PreviewDialog({ name, content, onClose }: PreviewDialogProps) {
const closeRef = useRef<HTMLButtonElement>(null)
useEffect(() => {
closeRef.current?.focus()
}, [])
return (
<div
className="pc-dialog pc-preview"
role="dialog"
aria-modal="true"
aria-label={`Preview of ${name}`}
onKeyDown={(event) => {
if (event.key === 'Escape') onClose()
}}
>
<p className="pc-preview__name">{name}</p>
{/* §REQ:TWO-PNL-NVGT-OOX-090 the content itself, line breaks preserved */}
<pre className="pc-preview__content" data-testid="preview-content">
{content}
</pre>
<div className="pc-dialog__actions">
<button type="button" ref={closeRef} onClick={onClose}>
Close
</button>
</div>
</div>
)
}