1 import type { ChangeEvent, MouseEvent } from 'react';
2 import { useCallback } from 'react';
4 import { useSelection } from '../state/useSelection';
6 export const useFileBrowserCheckbox = (id: string) => {
7 const selectionControls = useSelection();
8 const isSelected = Boolean(selectionControls?.isSelected(id));
10 const handleCheckboxChange = useCallback((e: ChangeEvent<HTMLElement>) => {
11 const el = document.activeElement ?? e.currentTarget;
12 if (isSelected && 'blur' in el) {
17 const handleCheckboxClick = useCallback(
18 (e: MouseEvent<HTMLElement>) => {
20 selectionControls?.toggleSelectItem(id);
23 [selectionControls?.toggleSelectItem]
26 const handleCheckboxWrapperClick = useCallback(
27 (e: MouseEvent<HTMLElement>) => {
29 // Wrapper handles shift key, because FF has issues: https://bugzilla.mozilla.org/show_bug.cgi?id=559506
31 selectionControls?.toggleRange?.(id);
34 [selectionControls?.toggleRange]
40 handleCheckboxWrapperClick,