-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileSelect.tsx
61 lines (53 loc) · 1.42 KB
/
FileSelect.tsx
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Icons
import { FaCaretDown } from 'react-icons-ng/fa';
// Our Imports
import { BoardFile } from '../utils/types/board';
type FileSelectProps = {
fileName?: string;
setFileName?: Function;
file?: BoardFile;
edit?: boolean;
};
const FileSelect: React.FC<FileSelectProps> = ({
fileName,
setFileName,
file,
edit,
}) => {
function showEdit(file: BoardFile) {
const div = document.getElementsByClassName(
`edit-${file.name.replaceAll('.', '-')}`
)[0];
const input = document.getElementsByClassName(
`file-name-${file.name.replaceAll('.', '-')}`
)[0];
const back = document.querySelector<HTMLElement>(`.backdrop`);
(div as HTMLElement).style['display'] = 'flex';
(input as HTMLInputElement).focus();
back.style['display'] = 'block';
}
return (
<div
onContextMenu={(e) => {
e.preventDefault();
edit ? showEdit(file) : null;
}}
onClick={() => setFileName(file.name)}
className={
file.name === fileName ? 'fileSelect active-file' : 'fileSelect'
}>
<button title={file.name}>
<div>{file.name}</div>
</button>
<div>
{edit ? (
<button className="file" title="Edit" onClick={() => showEdit(file)}>
<FaCaretDown title="Edit" />
</button>
) : null}
</div>
</div>
);
};
export default FileSelect;
// Didnt use Million.block as it breaks its block rules