Skip to content

Commit

Permalink
2 merge types (christopher-caldwell#16)
Browse files Browse the repository at this point in the history
* fix: Consolidating types and adding a one board

* chore(release): 0.0.6

* fix: Correcting index signatures

* feat: Improving types for bags

* fix: Removing BoundingFunc
  • Loading branch information
christopher-caldwell authored Nov 1, 2022
1 parent c8cd185 commit 27a2ba7
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 32 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.6](https://github.com/christopher-caldwell/react-kanban/compare/v0.0.5...v0.0.6) (2022-11-01)


### Bug Fixes

* Consolidating types and adding a one board ([ef36872](https://github.com/christopher-caldwell/react-kanban/commit/ef36872a7d1d2e61a8a6f6322d515379f83e6ce4))

### [0.0.5](https://github.com/christopher-caldwell/react-kanban/compare/v0.0.2...v0.0.5) (2022-10-31)


Expand Down
12 changes: 12 additions & 0 deletions demo/src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ export const board: KanbanBoard<CustomCard> = {
]
}

export const createNewCard = () => {
return {
id: uuid(),
title: 'Super New Card',
description: 'Card content',
assigneeId: assigneeIdGenerator(),
storyPoints: storyPointGenerator(),
ticketType: TicketType.Feature,
createdAt: faker.date.past()
}
}

// export const cardsKeyedById: Record<string | number, Card> = board.columns.reduce<Record<string | number, Card>>(
// (total, current) => {
// const cards: Record<string | number, Card> = current.cards.reduce((cardTotal, card) => {
Expand Down
9 changes: 7 additions & 2 deletions demo/src/features/notion/components/ColumnHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import AddIcon from '@mui/icons-material/Add'
import MoreHorizIcon from '@mui/icons-material/MoreHoriz'
import randomRgba from 'random-rgba'

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

export const renderColumnHeader: UncontrolledBoardProps<CustomCard>['renderColumnHeader'] = (column, { addCard }) => {
const onAddCard = () => {
const newCard = createNewCard()
// Can be async, do mutation here awaiting result, then call `addCard`
addCard(newCard, { on: 'top' })
}
return (
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Box sx={{ flexGrow: 1, display: 'flex' }}>
Expand All @@ -18,7 +23,7 @@ export const renderColumnHeader: UncontrolledBoardProps<CustomCard>['renderColum
<IconButton>
<MoreHorizIcon />
</IconButton>
<IconButton onClick={addCard}>
<IconButton onClick={onAddCard}>
<AddIcon />
</IconButton>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@caldwell619/react-kanban",
"version": "0.0.5",
"version": "0.0.6",
"description": "(fork of) Yet another Kanban/Trello board lib for React",
"scripts": {
"lint": "eslint --ext .ts,.tsx src",
Expand Down
8 changes: 4 additions & 4 deletions src/features/board/components/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import {
import { withDroppable } from '@/features/with-droppable'
import { RenderCard } from '@/features/column'
import { Card, Column as ColumnType, KanbanBoard } from '@/types'
import { SharedProps } from './shared'
import { ControlledBoardProps } from './Controlled'

const Columns = forwardRef<HTMLDivElement>((props, ref) => (
<div ref={ref} style={{ whiteSpace: 'nowrap' }} {...props} />
))
const DroppableBoard = withDroppable(Columns)

export const BoardContainer = function <TCard extends Card>({
children: board,
board,
renderCard,
disableColumnDrag,
disableCardDrag,
Expand Down Expand Up @@ -90,11 +90,11 @@ export interface OnDragEnd<TSubject> extends Partial<Coordinates> {
subject: TSubject
}
interface Props<TCard extends Card> {
children: KanbanBoard<TCard>
board: KanbanBoard<TCard>
renderCard: RenderCard<TCard>
disableColumnDrag: boolean
disableCardDrag: boolean
renderColumnHeader: SharedProps<TCard>['renderColumnHeader']
renderColumnHeader: ControlledBoardProps<TCard>['renderColumnHeader']
renderColumnAdder: () => JSX.Element | null
allowRemoveColumn: boolean
onColumnRemove?: (column: ColumnType<TCard>) => void
Expand Down
9 changes: 6 additions & 3 deletions src/features/board/components/Controlled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ export const ControlledBoard = function <TCard extends Card>({
//
}}
allowAddCard
>
{board}
</BoardContainer>
board={board}
/>
)
}

Expand All @@ -94,4 +93,8 @@ export type OnDragEndNotification<TSubject> = (
) => void
export interface ControlledBoardProps<TCard extends Card> extends SharedProps<TCard> {
children: KanbanBoard<TCard>
/** If not provided , will render the default column adder */
renderColumnAdder?: () => JSX.Element
/** If not provided , will render the default column header */
renderColumnHeader?: (column: Column<TCard>) => JSX.Element
}
24 changes: 21 additions & 3 deletions src/features/board/components/Uncontrolled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,30 @@ export const UncontrolledBoard = function <TCard extends Card>({
disableCardDrag={disableCardDrag}
onCardNew={async (column, card) => await handleDraftCardAdd(column, card, allowAddCard)}
allowAddCard={!!allowAddCard && !!onNewCardConfirm}
>
{board}
</BoardContainer>
board={board}
/>
)
}

interface ColumnAdderBag<TCard extends Card> {
addColumn: (newColumn: Column<TCard>) => Promise<void>
}

interface Position {
on: 'top' | 'bottom'
}

// TODO: Fix bound function into proper signature
interface ColumnHeaderBag<TCard extends Card> {
removeColumn: () => void
renameColumn: (title: string) => void
addCard: (card: TCard, options?: Position) => void
}

export interface UncontrolledBoardProps<TCard extends Card> extends SharedProps<TCard> {
initialBoard: KanbanBoard<TCard>
/** If not provided , will render the default column adder */
renderColumnAdder?: (options: ColumnAdderBag<TCard>) => JSX.Element
/** If not provided , will render the default column header */
renderColumnHeader?: (column: Column<TCard>, options: ColumnHeaderBag<TCard>) => JSX.Element
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,17 @@ interface ColumnCallbackInfo<TCard extends Card> {
board: KanbanBoard<TCard>
column: Column<TCard>
}

interface ColumnAdderBag<TCard extends Card> {
addColumn: (newColumn: Column<TCard>) => Promise<void>
}
interface ColumnHeaderBag {
removeColumn: BoundFunction
renameColumn: BoundFunction
addCard: BoundFunction
}
interface CardBag {
removeCard?: BoundFunction
removeCard?: () => void
dragging: boolean
}

export interface SharedProps<TCard extends Card> {
onCardDragEnd?: OnDragEndNotification<TCard>
onColumnDragEnd?: OnDragEndNotification<Column<TCard>>
onColumnRemove?: (info: ColumnCallbackInfo<TCard>) => void
onCardRemove?: (info: CardCallbackInfo<TCard>) => void
renderCard?: (card: TCard, options: CardBag) => JSX.Element
/** If not provided , will render the default column adder */
renderColumnAdder?: (options?: ColumnAdderBag<TCard>) => JSX.Element
/** If not provided , will render the default column header */
renderColumnHeader?: (column: Column<TCard>, options?: ColumnHeaderBag) => JSX.Element
/** If not provided , will render the default card */
onColumnRename?: (info: ColumnCallbackInfo<TCard>) => void
onCardNew?: (info: CardCallbackInfo<TCard>) => void
onColumnNew?: (info: ColumnCallbackInfo<TCard>) => void
Expand Down Expand Up @@ -65,5 +52,3 @@ export type OnDragEndNotification<TSubject> = (
export interface OnDragEnd<TSubject> extends Partial<Coordinates> {
subject: TSubject
}

type BoundFunction = any
6 changes: 4 additions & 2 deletions src/features/board/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { ControlledBoard, ControlledBoardProps, UncontrolledBoard, UncontrolledB

export const Board = function <TCard extends Card>({ initialBoard, children, ...restProps }: Props<TCard>) {
if (initialBoard) return <UncontrolledBoard initialBoard={initialBoard} {...restProps} />
if (children) return <ControlledBoard {...restProps}>{children}</ControlledBoard>
if (children) return <ControlledBoard {...(restProps as ControlledBoardProps<TCard>)}>{children}</ControlledBoard>
throw new Error('Must provide either "children" or "initialBoard" props')
}

export type Props<TCard extends Card> = Partial<UncontrolledBoardProps<TCard>> & Partial<ControlledBoardProps<TCard>>
export type Props<TCard extends Card> =
| (Partial<UncontrolledBoardProps<TCard>> & { children?: never })
| (Partial<ControlledBoardProps<TCard>> & { initialBoard?: never })

export * from './components'

0 comments on commit 27a2ba7

Please sign in to comment.