Skip to content
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
5 changes: 5 additions & 0 deletions demo/src/features/controlled/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const ControlledBoardDemo: FC = () => {
onCardRemove={({ board, card, column }) => {
console.log({ board, card, column })
}}
allowRenameColumn
onColumnRename={({ board, column }) => {
setBoard(board)
window.alert(`Column renamed to ${column.title}`)
}}
>
{controlledBoard}
</ControlledBoard>
Expand Down
15 changes: 13 additions & 2 deletions demo/src/features/notion/components/ColumnHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { UncontrolledBoardProps } from '@caldwell619/react-kanban'
import { Box, IconButton, Typography } from '@mui/material'
import { Box, Button, IconButton, Typography } from '@mui/material'
import AddIcon from '@mui/icons-material/Add'
import MoreHorizIcon from '@mui/icons-material/MoreHoriz'
import randomRgba from 'random-rgba'

import { createNewCard, CustomCard } from '@/data'
import { ColoredBgText } from './Card'

export const renderColumnHeader: UncontrolledBoardProps<CustomCard>['renderColumnHeader'] = (column, { addCard }) => {
export const renderColumnHeader: UncontrolledBoardProps<CustomCard>['renderColumnHeader'] = (
column,
{ addCard, renameColumn }
) => {
const onAddCard = () => {
const newCard = createNewCard()
// Can be async, do mutation here awaiting result, then call `addCard`
Expand All @@ -26,6 +29,14 @@ export const renderColumnHeader: UncontrolledBoardProps<CustomCard>['renderColum
<IconButton onClick={onAddCard}>
<AddIcon />
</IconButton>
<Button
onClick={() => {
const title = window.prompt('new title')
title && renameColumn(title)
}}
>
Rename column
</Button>
</Box>
</Box>
)
Expand Down
4 changes: 2 additions & 2 deletions demo/src/features/uncontrolled/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const UncontrolledBoardDemo: FC = () => {
/>
<UncontrolledBoard
initialBoard={board}
onCardRemove={({ board, card, column }) => {
console.log({ board, card, column })
onColumnRename={({ column }) => {
window.alert(`Column renamed to ${column.title}`)
}}
/>
</>
Expand Down
7 changes: 6 additions & 1 deletion src/features/board/components/Controlled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Card, Column, KanbanBoard } from '@/types'
import { DefaultColumn } from '@/features/column'
import { BoardContainer, OnDragEnd } from './Container'
import { SharedProps } from './shared'
import { changeColumn } from '@/services'

export const ControlledBoard = function <TCard extends Card>({
children: board,
Expand Down Expand Up @@ -34,6 +35,10 @@ export const ControlledBoard = function <TCard extends Card>({
onColumnDragEnd(subject, source, destination)
}
}
const handleColumnRename = (column: Column<TCard>, title: string) => {
const boardWithRenamedColumn = changeColumn<TCard>(board, column, { title })
onColumnRename?.({ board: boardWithRenamedColumn, column: { ...column, title } })
}

return (
<BoardContainer
Expand All @@ -53,7 +58,7 @@ export const ControlledBoard = function <TCard extends Card>({
allowRemoveColumn={allowRemoveColumn}
onColumnRemove={(updatedColumn) => onColumnRemove?.({ board, column: updatedColumn })}
allowRenameColumn={allowRenameColumn}
onColumnRename={(renamedColumn) => onColumnRename?.({ board, column: renamedColumn })}
onColumnRename={handleColumnRename}
>
{column}
</DefaultColumn>
Expand Down
2 changes: 1 addition & 1 deletion src/features/board/components/Uncontrolled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const UncontrolledBoard = function <TCard extends Card>({
allowRemoveColumn={allowRemoveColumn}
onColumnRemove={(updatedColumn) => onColumnRemove?.({ board, column: updatedColumn })}
allowRenameColumn={allowRenameColumn}
onColumnRename={(renamedColumn) => onColumnRename?.({ board, column: renamedColumn })}
onColumnRename={handleColumnRename}
>
{column}
</DefaultColumn>
Expand Down