From e2fa9e6afb4d0c48cee1793c1bcdbe2027299775 Mon Sep 17 00:00:00 2001 From: Keith Ingram Date: Mon, 9 Mar 2020 20:23:35 +1300 Subject: [PATCH] Drag and drop types (#2346) * Reorderable InputAddressMulti * add types * merge * merge * remove module * Manually re-apply missing changes from master * Add missing style (manual merge again) * Re-add FIXME (src import, manual merge) Co-authored-by: Jaco Greeff --- .../src/InputAddressMulti.tsx | 13 ++++++----- .../src/react-beautiful-dnd.d.ts | 5 ----- yarn.lock | 22 +++++++++---------- 3 files changed, 18 insertions(+), 22 deletions(-) delete mode 100644 packages/react-components/src/react-beautiful-dnd.d.ts diff --git a/packages/react-components/src/InputAddressMulti.tsx b/packages/react-components/src/InputAddressMulti.tsx index 9bed5bc131..6959e667ae 100644 --- a/packages/react-components/src/InputAddressMulti.tsx +++ b/packages/react-components/src/InputAddressMulti.tsx @@ -1,10 +1,11 @@ // Copyright 2017-2020 @polkadot/react-components authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +/* eslint-disable @typescript-eslint/unbound-method */ import React, { useMemo, useState } from 'react'; import ReactDOM from 'react-dom'; -import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd'; +import { DragDropContext, Droppable, Draggable, DraggableLocation, DraggableProvided, DraggableStateSnapshot, DroppableProvided, DropResult } from 'react-beautiful-dnd'; import styled from 'styled-components'; import { useDebounce } from '@polkadot/react-hooks'; @@ -54,7 +55,7 @@ function InputAddressMulti ({ available: propsAvailable = [], className, help, m [value, available] ); - const onReorder = (source: any, destination: any): void => { + const onReorder = (source: DraggableLocation, destination: DraggableLocation): void => { const result = Array.from(value); const [removed] = result.splice(source.index, 1); result.splice(destination.index, 0, removed); @@ -90,10 +91,10 @@ function InputAddressMulti ({ available: propsAvailable = [], className, help, m }; }; - const onDragEnd = (result: any): void => { + const onDragEnd = (result: DropResult): void => { const { source, destination } = result; - onReorder(source, destination); + !!destination && onReorder(source, destination); }; return ( @@ -134,7 +135,7 @@ function InputAddressMulti ({ available: propsAvailable = [], className, help, m /> - {(provided: any): React.ReactNode => ( + {(provided: DroppableProvided): React.ReactElement => (
- {(provided: any, snapshot: any): React.ReactNode => { + {(provided: DraggableProvided, snapshot: DraggableStateSnapshot): React.ReactElement => { const element = (