DefinitelyTyped/types/react-dnd-multi-backend/react-dnd-multi-backend-tests.tsx
Janeene Beeforth b9c5f5256a Create typescript definitions for the react-dnd-multi-backend library. (#20790)
* Create typescript definitions for the react-dnd-multi-backend library.

https://github.com/LouisBrunner/react-dnd-multi-backend

* Attempt to fix relative path to index.
2017-10-23 11:32:02 -07:00

61 lines
1.8 KiB
TypeScript

// Examples based on documentation at https://github.com/LouisBrunner/react-dnd-multi-backend
import * as React from 'react';
import * as ReactDnd from 'react-dnd';
import MultiBackend, { Backends, createTransition, Preview, TouchTransition, HTML5DragTransition } from 'react-dnd-multi-backend';
import HTML5toTouch from 'react-dnd-multi-backend/lib/HTML5toTouch';
import HTML5Backend from 'react-dnd-html5-backend';
import TouchBackend from 'react-dnd-touch-backend';
const component = () => null;
/**
* Most common use case - using the default HTML5 with Touch as a fallback.
*/
const multiDndComponent = ReactDnd.DragDropContext(MultiBackend(HTML5toTouch))(component);
/**
* Creating a custom list of backends, including creating a touch transition.
*/
const CustomBackends: Backends = {
backends: [{
backend: HTML5Backend
},
{
backend: TouchBackend({ enableMouseEvents: false }),
preview: true,
transition: createTransition('touchstart', (event: TouchEvent) => {
return event.touches != null;
})
},
{
backend: HTML5Backend,
transition: HTML5DragTransition,
preview: true
},
{
backend: TouchBackend({}),
transition: TouchTransition
}]
};
const multiCustomBackendsComponent = ReactDnd.DragDropContext(MultiBackend(CustomBackends))(component);
/**
* Testing the Preview component.
*/
class App extends React.Component {
generator = (type: string, item: any, style: React.CSSProperties) =>
(type === 'card')
? <div style={style}>{item.label}</div>
: <div />
render() {
return (
<div>
<Preview generator={this.generator} />
<div>A page of text</div>
</div>
);
}
}