Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example from react-beautiful-dnd and typescript #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16,525 changes: 0 additions & 16,525 deletions package-lock.json

This file was deleted.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/react": "^16.8.12",
"@types/react-beautiful-dnd": "^10.1.1",
"react": "^16.8.6",
"react-beautiful-dnd": "^11.0.0-beta",
"react-dom": "^16.8.6",
"react-scripts": "2.1.8"
"react-scripts": "2.1.8",
"typescript": "^3.4.2"
},
"scripts": {
"start": "react-scripts start",
Expand Down
15 changes: 15 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
.list-ct {
background-color: #e2e2e2;
display: flex;
flex-direction: column;
padding-bottom: 10px;
}
.list-item {
padding: 6px 10px;
margin: 10px 10px 0 10px;
cursor: pointer;
color: white;
background: #e03d49;
}


.App {
text-align: center;
}
Expand Down
28 changes: 0 additions & 28 deletions src/App.js

This file was deleted.

111 changes: 111 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import React from "react";
import {
DragDropContext,
Droppable,
Draggable,
DropResult,
DraggableProvided,
DraggableStateSnapshot,
DroppableProvided,
DroppableStateSnapshot
} from "react-beautiful-dnd";
import "./App.css";

const listCtStyle = {
width: "200px",
margin: "12px"
};

const reorder = (list: Item[], startIndex: number, endIndex: number) => {
const result = Array.from(list);
const [removed] = result.splice(startIndex, 1);
result.splice(endIndex, 0, removed);

return result;
};

interface Item {
id: number;
}

interface State {
items: Item[];
}

class App extends React.Component {
state: State = {
items: [
{
id: 1
},
{
id: 2
},
{
id: 3
}
]
};

handleDragEnd = (result: DropResult) => {
console.log(result);
if (!result.destination) {
return;
}

const items = reorder(
this.state.items,
result.source.index,
result.destination.index
);

this.setState({
items
});
};

render() {
return (
<DragDropContext onDragEnd={this.handleDragEnd}>
<Droppable droppableId="droppable">
{(provided: DroppableProvided, snapshot: DroppableStateSnapshot) => (
<div
ref={provided.innerRef}
style={listCtStyle}
className="list-ct"
>
{this.state.items.map((item, index) => (
<Draggable
key={item.id}
draggableId={`${item.id}`}
index={index}
>
{(
provided: DraggableProvided,
snapshot: DraggableStateSnapshot
) => (
<div>
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
className="list-item"
style={{ ...provided.draggableProps.style }}
>
ITEM {item.id}
</div>
{provided.placeholder}
</div>
)}
</Draggable>
))}
{provided.placeholder}
</div>
)}
</Droppable>
</DragDropContext>
);
}
}

export default App;
1 change: 1 addition & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react-scripts" />
25 changes: 25 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": [
"src"
]
}
Loading