-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathClickItemToExpandInteractionManager.ts
70 lines (65 loc) · 1.76 KB
/
ClickItemToExpandInteractionManager.ts
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
62
63
64
65
66
67
68
69
70
import { HTMLProps } from 'react';
import {
InteractionMode,
InteractionManager,
TreeEnvironmentContextProps,
TreeItem,
TreeItemActions,
TreeItemRenderFlags,
} from '../types';
import { isControlKey } from '../isControlKey';
export class ClickItemToExpandInteractionManager implements InteractionManager {
public readonly mode = InteractionMode.ClickItemToExpand;
private environment: TreeEnvironmentContextProps;
constructor(environment: TreeEnvironmentContextProps) {
this.environment = environment;
}
createInteractiveElementProps(
item: TreeItem,
treeId: string,
actions: TreeItemActions,
renderFlags: TreeItemRenderFlags
): HTMLProps<HTMLElement> {
return {
onClick: e => {
actions.focusItem();
if (e.shiftKey) {
actions.selectUpTo(!isControlKey(e));
} else if (isControlKey(e)) {
if (renderFlags.isSelected) {
actions.unselectItem();
} else {
actions.addToSelectedItems();
}
} else {
if (item.isFolder) {
actions.toggleExpandedState();
}
actions.selectItem();
if (
!item.isFolder ||
this.environment.canInvokePrimaryActionOnItemContainer
) {
actions.primaryAction();
}
}
},
onFocus: () => {
actions.focusItem();
},
onDragStart: e => {
e.dataTransfer.dropEffect = 'move';
actions.startDragging();
},
onDragOver: e => {
e.preventDefault(); // Allow drop
},
draggable: renderFlags.canDrag && !renderFlags.isRenaming,
tabIndex: !renderFlags.isRenaming
? renderFlags.isFocused
? 0
: -1
: undefined,
};
}
}