updated react-beautiful-dnd to 6.0

Included updates from version 5.0 and version 6.0 as per the docs:
https://github.com/atlassian/react-beautiful-dnd/releases/tag/v5.0.0
https://github.com/atlassian/react-beautiful-dnd/releases/tag/v6.0.0
This commit is contained in:
Austin Turner
2018-03-25 09:47:48 -06:00
parent 106d393592
commit 5cb7a9ee17
2 changed files with 35 additions and 16 deletions

View File

@@ -1,7 +1,8 @@
// Type definitions for react-beautiful-dnd 4.0
// Type definitions for react-beautiful-dnd 6.0
// Project: https://github.com/atlassian/react-beautiful-dnd
// Definitions by: varHarrie <https://github.com/varHarrie>
// Bradley Ayers <https://github.com/bradleyayers>
// Austin Turner <https://github.com/paustint>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
@@ -12,12 +13,18 @@ export type DraggableId = Id;
export type DroppableId = Id;
export type TypeId = Id;
export type ZIndex = number | string;
export type DropReason = 'DROP' | 'CANCEL';
export type Announce = (message: string) => void;
export interface DraggableLocation {
droppableId: DroppableId;
index: number;
}
export interface HookProvided {
announce: Announce;
}
/**
* DragDropContext
*/
@@ -32,17 +39,14 @@ export interface DragUpdate extends DragStart {
destination?: DraggableLocation | null;
}
export interface DropResult {
draggableId: DraggableId;
type: TypeId;
source: DraggableLocation;
destination?: DraggableLocation | null;
export interface DropResult extends DragUpdate {
reason: DropReason;
}
export interface DragDropContextProps {
onDragStart?(initial: DragStart): void;
onDragUpdate?(initial: DragUpdate): void;
onDragEnd(result: DropResult): void;
onDragStart?(initial: DragStart, provided: HookProvided): void;
onDragUpdate?(initial: DragUpdate, provided: HookProvided): void;
onDragEnd(result: DropResult, provided: HookProvided): void;
}
export class DragDropContext extends React.Component<DragDropContextProps> {}
@@ -51,9 +55,14 @@ export class DragDropContext extends React.Component<DragDropContextProps> {}
* Droppable
*/
export interface DroppableProvidedProps {
// used for shared global styles
'data-react-beautiful-dnd-droppable': string;
}
export interface DroppableProvided {
innerRef(element: HTMLElement | null): any;
placeholder?: React.ReactElement<any> | null;
droppableProps: DroppableProvidedProps;
}
export interface DroppableStateSnapshot {
@@ -103,12 +112,14 @@ export interface DraggableProvidedDraggableProps {
export interface DraggableProvidedDragHandleProps {
onMouseDown: React.MouseEventHandler<any>;
onKeyDown: React.KeyboardEventHandler<any>;
onClick: React.MouseEventHandler<any>;
onTouchStart: React.TouchEventHandler<any>;
onTouchMove: React.TouchEventHandler<any>;
'data-react-beautiful-dnd-drag-handle': string;
'aria-roledescription': string;
tabIndex: number;
'aria-grabbed': boolean;
draggable: boolean;
onDragStart(): void;
onDrop(): void;
onDragStart: React.DragEventHandler<any>;
}
export interface DraggableProvided {

View File

@@ -1,6 +1,6 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { DragDropContext, Draggable, Droppable, DropResult } from 'react-beautiful-dnd';
import { DragDropContext, Draggable, Droppable, DropResult, DragStart, DragUpdate, HookProvided } from 'react-beautiful-dnd';
interface Item {
id: string;
@@ -49,7 +49,15 @@ class App extends React.Component<{}, AppState> {
this.onDragEnd = this.onDragEnd.bind(this);
}
onDragEnd(result: DropResult) {
onDragStart(dragStart: DragStart, provided: HookProvided) {
//
}
onDragUpdate(dragUpdate: DragUpdate, provided: HookProvided) {
//
}
onDragEnd(result: DropResult, provided: HookProvided) {
if (!result.destination) {
return;
}
@@ -65,10 +73,10 @@ class App extends React.Component<{}, AppState> {
render() {
return (
<DragDropContext onDragEnd={this.onDragEnd}>
<DragDropContext onDragStart={this.onDragStart} onDragUpdate={this.onDragUpdate} onDragEnd={this.onDragEnd}>
<Droppable droppableId="droppable">
{(provided, snapshot) => (
<div ref={provided.innerRef} style={getListStyle(snapshot.isDraggingOver)}>
<div ref={provided.innerRef} style={getListStyle(snapshot.isDraggingOver)} {...provided.droppableProps}>
{this.state.items.map((item, index) => (
<Draggable key={item.id} draggableId={item.id} index={index}>
{(provided, snapshot) => (