-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathBottomButtons.js
More file actions
127 lines (121 loc) · 4.14 KB
/
BottomButtons.js
File metadata and controls
127 lines (121 loc) · 4.14 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// @flow
import { Trans } from '@lingui/macro';
import { t } from '@lingui/macro';
import { I18n } from '@lingui/react';
import * as React from 'react';
import { Line, Column } from '../../UI/Grid';
import ElementWithMenu from '../../UI/Menu/ElementWithMenu';
import { enumerateEventsMetadata } from '../EnumerateEventsMetadata';
import { type DropTargetComponent } from '../../UI/DragAndDrop/DropTarget';
import { type SortableTreeNode } from './SortableEventsTree';
import { moveEventToEventsList } from './helpers';
import GDevelopThemeContext from '../../UI/Theme/GDevelopThemeContext';
import { useScreenType } from '../../UI/Responsive/ScreenTypeMeasurer';
const styles = {
addButton: {
cursor: 'pointer',
},
dropIndicator: {
border: '2px solid black',
outline: '1px solid white',
},
};
type Props = {|
onAddEvent: (eventType: string) => void,
// Connect a drop target to be able to drop an event at the end of the sheet.
DnDComponent: DropTargetComponent<SortableTreeNode>,
draggedNode: ?SortableTreeNode,
rootEventsList: gdEventsList,
|};
const makeMenuTemplateBuilderForEvents = (
onAddEvent: (eventType: string) => void
) => () =>
enumerateEventsMetadata().map(metadata => {
return {
label: metadata.fullName,
click: () => onAddEvent(metadata.type),
};
});
const addButtonTooltipLabelMouse = t`Right-click for more events`;
const addButtonTooltipLabelTouch = t`Long press for more events`;
export default function BottomButtons({
onAddEvent,
DnDComponent,
draggedNode,
rootEventsList,
}: Props): React.Node {
const screenType = useScreenType();
const gdevelopTheme = React.useContext(GDevelopThemeContext);
const onDrop = () => {
draggedNode &&
draggedNode.event &&
moveEventToEventsList({
targetEventsList: rootEventsList,
movingEvent: draggedNode.event,
initialEventsList: draggedNode.eventsList,
// Drops node at the end of root events list.
toIndex: -1,
});
};
return (
<I18n>
{({ i18n }) => (
<DnDComponent canDrop={() => true} drop={onDrop}>
{({ connectDropTarget, isOver }) =>
connectDropTarget(
<div>
{isOver && (
<div
style={{
...styles.dropIndicator,
borderColor: gdevelopTheme.dropIndicator.canDrop,
outlineColor: gdevelopTheme.dropIndicator.border,
}}
/>
)}
<Column>
<Line justifyContent="space-between">
<ElementWithMenu
openMenuWithSecondaryClick
element={
<button
style={styles.addButton}
className="add-link"
onClick={() =>
onAddEvent('BuiltinCommonInstructions::Standard')
}
title={i18n._(
screenType === 'touch'
? addButtonTooltipLabelTouch
: addButtonTooltipLabelMouse
)}
>
<Trans>+ Add a new event</Trans>
</button>
}
// $FlowFixMe[incompatible-type]
buildMenuTemplate={makeMenuTemplateBuilderForEvents(
onAddEvent
)}
/>
<ElementWithMenu
element={
<button style={styles.addButton} className="add-link">
<Trans>+ Add...</Trans>
</button>
}
// $FlowFixMe[incompatible-type]
buildMenuTemplate={makeMenuTemplateBuilderForEvents(
onAddEvent
)}
/>
</Line>
</Column>
</div>
)
}
</DnDComponent>
)}
</I18n>
);
}