1 import { c } from 'ttag';
3 import { Button } from '@proton/atoms';
4 import { Badge, Checkbox, FileNameDisplay, Icon } from '@proton/components';
5 import clsx from '@proton/utils/clsx';
7 import { stopPropagation } from '../../../utils/stopPropagation';
8 import { useCheckbox, useItemContextMenu, useSelection } from '../../FileBrowser';
9 import { SelectionState } from '../../FileBrowser/hooks/useSelectionControls';
10 import type { DeviceItem } from '../Devices/Devices';
11 import type { DriveItem } from '../Drive/Drive';
12 import type { SharedLinkItem } from '../SharedLinks/SharedLinks';
13 import type { SharedWithMeItem } from '../SharedWithMe/SharedWithMe';
14 import type { TrashItem } from '../Trash/Trash';
16 const GridViewItemBase = ({
18 SignatureIconComponent,
20 disableSelection = false,
22 IconComponent: React.ReactNode;
23 SignatureIconComponent?: React.ReactNode;
24 item: DriveItem | TrashItem | SharedLinkItem | DeviceItem | SharedWithMeItem;
25 disableSelection?: boolean;
27 const selectionControls = useSelection()!;
28 const contextMenuControls = useItemContextMenu();
29 const { handleCheckboxChange, handleCheckboxClick, handleCheckboxWrapperClick } = useCheckbox(item.id);
31 const isContextMenuButtonActive = contextMenuControls.isOpen && selectionControls.selectedItemIds.includes(item.id);
36 'flex flex-1 justify-center items-center file-browser-grid-item--container',
37 item.isInvitation && 'file-browser-grid-item--invitation'
40 // Show Accept/Decline context menu if you click on the box
41 if (item.isInvitation) {
42 selectionControls?.selectItem(item.id);
43 contextMenuControls.handleContextMenu(e);
47 if (item.isInvitation) {
48 selectionControls?.selectItem(item.id);
49 contextMenuControls.handleContextMenuTouch?.(e);
54 {item.isInvitation && (
55 <Badge className="absolute top-0 right-0 mt-1 mr-1" type="primary">{c('Badge')
63 'flex file-browser-grid-item--select',
64 selectionControls?.selectionState !== SelectionState.NONE ? null : 'mouse:group-hover:opacity-100',
66 onTouchStart={stopPropagation}
67 onKeyDown={stopPropagation}
68 onClick={handleCheckboxWrapperClick}
70 {!disableSelection ? (
72 disabled={item.isLocked}
73 className="expand-click-area file-browser-grid-item-checkbox"
74 checked={selectionControls.isSelected(item.id)}
75 onChange={handleCheckboxChange}
76 onClick={handleCheckboxClick}
82 'file-browser-grid-item--file-name flex border-top',
83 item.isInvitation && 'file-browser-grid-item--invitation'
86 {SignatureIconComponent ? SignatureIconComponent : null}
87 <FileNameDisplay text={item.name} className="mx-auto" data-testid="grid-item-name" />
93 'file-browser-grid-view--options',
94 isContextMenuButtonActive ? 'file-browser--options-focus' : 'mouse:group-hover:opacity-100',
97 selectionControls?.selectItem(item.id);
98 contextMenuControls.handleContextMenu(e);
101 selectionControls?.selectItem(item.id);
102 contextMenuControls.handleContextMenuTouch?.(e);
105 <Icon name="three-dots-vertical" alt={c('Action').t`More options`} />
112 export default GridViewItemBase;