-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
702f699
commit 828be4a
Showing
22 changed files
with
1,177 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import TaskApp from './src/multi-drag/task-app'; | ||
|
||
storiesOf('Multi drag', module) | ||
.add('pattern', () => ( | ||
<TaskApp /> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// @flow | ||
import type { Task } from './types'; | ||
import type { Task } from '../types'; | ||
|
||
const tasks: Task[] = [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// @flow | ||
import React, { Component } from 'react'; | ||
import styled from 'styled-components'; | ||
import memoizeOne from 'memoize-one'; | ||
import { Droppable } from '../../../src/'; | ||
import { grid, colors, borderRadius } from '../constants'; | ||
import Task from './task'; | ||
import type { DroppableProvided, DroppableStateSnapshot } from '../../../src/'; | ||
import type { Column as ColumnType } from './types'; | ||
import type { Task as TaskType, Id } from '../types'; | ||
|
||
type Props = {| | ||
column: ColumnType, | ||
tasks: TaskType[], | ||
selectedTaskIds: Id[], | ||
multiSelectTo: (taskId: Id) => void, | ||
draggingTaskId: ?Id, | ||
toggleSelection: (taskId: Id) => void, | ||
toggleSelectionInGroup: (taskId: Id) => void, | ||
multiSelectTo: (taskId: Id) => void, | ||
|} | ||
|
||
const Container = styled.div` | ||
width: 300px; | ||
margin: ${grid}px; | ||
border-radius: ${borderRadius}px; | ||
border: 1px solid ${colors.grey.dark}; | ||
background-color: ${colors.grey.medium}; | ||
/* we want the column to take up its full height */ | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
|
||
const Title = styled.h3` | ||
font-weight: bold; | ||
padding: ${grid}px; | ||
`; | ||
|
||
const TaskList = styled.div` | ||
padding: ${grid}px; | ||
min-height: 200px; | ||
flex-grow: 1; | ||
transition: background-color 0.2s ease; | ||
${props => (props.isDraggingOver ? `background-color: ${colors.grey.darker}` : '')}; | ||
`; | ||
|
||
type TaskIdMap = { | ||
[taskId: Id]: true, | ||
} | ||
|
||
const getSelectedMap = memoizeOne((selectedTaskIds: Id[]) => | ||
selectedTaskIds.reduce((previous: TaskIdMap, current: Id): TaskIdMap => { | ||
previous[current] = true; | ||
return previous; | ||
}, {})); | ||
|
||
export default class Column extends Component<Props> { | ||
render() { | ||
const column: ColumnType = this.props.column; | ||
const tasks: TaskType[] = this.props.tasks; | ||
const selectedTaskIds: Id[] = this.props.selectedTaskIds; | ||
const draggingTaskId: ?Id = this.props.draggingTaskId; | ||
return ( | ||
<Container> | ||
<Title>{column.title}</Title> | ||
<Droppable droppableId={column.id}> | ||
{(provided: DroppableProvided, snapshot: DroppableStateSnapshot) => ( | ||
<TaskList | ||
innerRef={provided.innerRef} | ||
isDraggingOver={snapshot.isDraggingOver} | ||
{...provided.droppableProps} | ||
> | ||
{tasks.map((task: TaskType, index: number) => { | ||
const isSelected: boolean = Boolean(getSelectedMap(selectedTaskIds)[task.id]); | ||
const isGhosting: boolean = | ||
isSelected && Boolean(draggingTaskId) && draggingTaskId !== task.id; | ||
return ( | ||
<Task | ||
task={task} | ||
index={index} | ||
key={task.id} | ||
isSelected={isSelected} | ||
isGhosting={isGhosting} | ||
selectionCount={selectedTaskIds.length} | ||
toggleSelection={this.props.toggleSelection} | ||
toggleSelectionInGroup={this.props.toggleSelectionInGroup} | ||
multiSelectTo={this.props.multiSelectTo} | ||
/> | ||
); | ||
})} | ||
{provided.placeholder} | ||
</TaskList> | ||
)} | ||
</Droppable> | ||
</Container> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// @flow | ||
import type { Column, Entities, TaskMap } from './types'; | ||
import type { Task, Id } from '../types'; | ||
|
||
const tasks: Task[] = Array.from({ length: 20 }, (v, k) => k).map((val: number): Task => ({ | ||
id: `task-${val}`, | ||
content: `Task ${val}`, | ||
})); | ||
|
||
const taskMap: TaskMap = tasks.reduce((previous: TaskMap, current: Task): TaskMap => { | ||
previous[current.id] = current; | ||
return previous; | ||
}, {}); | ||
|
||
const todo: Column = { | ||
id: 'todo', | ||
title: 'To do', | ||
taskIds: tasks.map((task: Task): Id => task.id), | ||
}; | ||
|
||
const done: Column = { | ||
id: 'done', | ||
title: 'Done', | ||
taskIds: [], | ||
}; | ||
|
||
const entities: Entities = { | ||
columnOrder: [todo.id, done.id], | ||
columns: { | ||
[todo.id]: todo, | ||
[done.id]: done, | ||
}, | ||
tasks: taskMap, | ||
}; | ||
|
||
export default entities; |
Oops, something went wrong.