forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 1
/
react-dnd-multi-backend-tests.tsx
68 lines (62 loc) · 2.04 KB
/
react-dnd-multi-backend-tests.tsx
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
import * as React from 'react';
import { DndProviderProps } from 'react-dnd';
import MultiBackend, { createTransition, TouchTransition, Backends, Preview, PreviewGenerator } from 'react-dnd-multi-backend';
import HTML5ToTouchEsm from 'react-dnd-multi-backend/dist/esm/HTML5toTouch';
import HTML5ToTouchCjs from 'react-dnd-multi-backend/dist/cjs/HTML5toTouch';
import TouchBackend from 'react-dnd-touch-backend';
// Legacy versions of `react-dnd` rely on implicit children of `React.FC` which was removed in `@types/react@18`
declare const DndProvider: React.FC<React.PropsWithChildren<DndProviderProps<any, any>>>;
const context = {};
/**
* Most common use case - using the default HTML5 with Touch as a fallback.
*/
const multiDndComponentEsm = (
<DndProvider backend={MultiBackend} options={HTML5ToTouchEsm}>
<div>A page of Text</div>
</DndProvider>
);
const multiDndComponentCjs = (
<DndProvider backend={MultiBackend} options={HTML5ToTouchCjs}>
<div>A page of Text</div>
</DndProvider>
);
/**
* Creating a custom list of backends, including creating a touch transition.
*/
const CustomBackends: Backends = {
backends: [
{
backend: TouchBackend,
options: { enableMouseEvents: false },
preview: true,
transition: createTransition('touchstart', (event: TouchEvent) => {
return event.touches != null;
})
},
{
backend: TouchBackend,
transition: TouchTransition
}]
};
const multiCustomBackendsComponent = (
<DndProvider backend={MultiBackend} options={CustomBackends}>
<div>A page of Text</div>
</DndProvider>
);
/**
* Testing the Preview component.
*/
class App extends React.Component {
generator: PreviewGenerator = ({item, itemType, style}) =>
(itemType === 'card')
? <div style={style}>{item.label}</div>
: <div />
render() {
return (
<div>
<Preview generator={this.generator} />
<div>A page of text</div>
</div>
);
}
}