forked from Saifullah-dev/react-file-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilesHeader.jsx
More file actions
41 lines (35 loc) · 1.28 KB
/
FilesHeader.jsx
File metadata and controls
41 lines (35 loc) · 1.28 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
import { useMemo, useState } from "react";
import Checkbox from "../../components/Checkbox/Checkbox";
import { useSelection } from "../../contexts/SelectionContext";
import { useFileNavigation } from "../../contexts/FileNavigationContext";
const FilesHeader = ({ unselectFiles, children }) => {
const [showSelectAll, setShowSelectAll] = useState(false);
const { selectedFiles, setSelectedFiles } = useSelection();
const { currentPathFiles } = useFileNavigation();
const allFilesSelected = useMemo(() => {
return currentPathFiles.length > 0 && selectedFiles.length === currentPathFiles.length;
}, [selectedFiles, currentPathFiles]);
const handleSelectAll = (e) => {
if (e.target.checked) {
setSelectedFiles(currentPathFiles);
setShowSelectAll(true);
} else {
unselectFiles();
}
};
return (
<div
className="files-header"
onMouseOver={() => setShowSelectAll(true)}
onMouseLeave={() => setShowSelectAll(false)}
>
<div className="file-select-all">
{(showSelectAll || allFilesSelected) && (
<Checkbox checked={allFilesSelected} onChange={handleSelectAll} title="Select all" disabled={currentPathFiles.length === 0} />
)}
</div>
{children}
</div>
);
};
export default FilesHeader;