forked from christopher-caldwell/react-kanban
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
52 lines (47 loc) · 1.49 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { FC, useState } from 'react'
import { Board, OnDragEndNotification, Card, moveCard, KanbanBoard } from '@caldwell619/react-kanban'
import { board } from '@/data'
import { Source } from '@/components'
// If you want to use the library like the old one, you can do so by determining which board you want to use
export const UncontrolledBoardDemo: FC = () => {
return (
<>
<Source
title='Uncontrolled'
url='https://github.com/christopher-caldwell/react-kanban/blob/main/demo/src/features/on-board/index.tsx'
/>
<Board
initialBoard={board}
onCardRemove={({ board, card, column }) => {
console.log({ board, card, column })
}}
/>
</>
)
}
export const ControlledBoardDemo: FC = () => {
// You need to control the state yourself.
const [controlledBoard, setBoard] = useState<KanbanBoard<Card>>({ ...board })
const handleCardMove: OnDragEndNotification<Card> = (_card, source, destination) => {
setBoard(currentBoard => {
return moveCard(currentBoard, source, destination)
})
}
return (
<>
<Source
title='Controlled'
url='https://github.com/christopher-caldwell/react-kanban/blob/main/demo/src/features/controlled/index.tsx'
/>
<Board
onCardDragEnd={handleCardMove}
disableColumnDrag
onCardRemove={({ board, card, column }) => {
console.log({ board, card, column })
}}
>
{controlledBoard}
</Board>
</>
)
}