Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

@di0fref/react-kanban

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@di0fref/react-kanban

Yet another Kanban/Trello board lib for React.

  • 2.1.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
ย 
Created
Source

๐Ÿ”ด๐Ÿ”ด๐Ÿ”ด THIS PROJECT IS DEPRECATED ๐Ÿ”ด๐Ÿ”ด๐Ÿ”ด

Unfortunately this project is deprecated and it is not maintained anymore.

In the past, our core product was using react-kanban and indirectly we were improving this project. But nowadays we replaced it for another internal simplier version.

As a small dev team, it's impossible for us to continue improving both sources without an external help.

This source is going to continue available here, but, unfortunately, none effort is going to be done to improve the project.

react-kanban

Test Coverage Build Status JavaScript Style Guide

Yet another Kanban/Trello board lib for React.

Kanban Demo

โ–ถ๏ธ Demo

Usage

Edit react-kanban-demo

โ“ Why?

  • ๐Ÿ‘Š Reliable: 100% tested on CI; 100% coverage; 100% SemVer.
  • ๐ŸŽฎ Having fun: Play with Hooks ๐ŸŽฃ and Styled Components.
  • โ™ฟ๏ธ Accessible: Keyboard and mobile friendly.
  • ๐Ÿ”Œ Pluggable: For use in projects.

๐Ÿ›  Install and usage

Since this project use Hooks, you have to install them:

  • react>=16.8.5

After, Install the lib on your project:

yarn add @asseinfo/react-kanban

Import the lib and use it on your project:

import Board from '@asseinfo/react-kanban'
import '@asseinfo/react-kanban/dist/styles.css'

const board = {
  columns: [
    {
      id: 1,
      title: 'Backlog',
      cards: [
        {
          id: 1,
          title: 'Add card',
          description: 'Add capability to add a card in a column'
        },
      ]
    },
    {
      id: 2,
      title: 'Doing',
      cards: [
        {
          id: 2,
          title: 'Drag-n-drop support',
          description: 'Move a card between the columns'
        },
      ]
    }
  ]
}

<Board initialBoard={board} />

๐Ÿ”ฅ API

๐Ÿ•น Controlled and Uncontrolled

When you need a better control over the board, you should stick with the controlled board. A controlled board means you need to deal with the board state yourself, you need to keep the state in your hands (component) and pass this state to the <Board />, we just reflect this state. This also means a little more of complexity, although we make available some helpers to deal with the board shape. You can read more in the React docs, here and here.

If you go with the controlled one, you need to pass your board through the children prop, otherwise you need to pass it through the initialBoard prop.

Helpers to work with the controlled board

We expose some APIs that you can import to help you to work with the controlled state. Those are the same APIs we use internally to manage the uncontrolled board. We really recommend you to use them, they are 100% unit tested and they don't do any side effect to your board state.

To use them, you just need to import them together with your board:

import Board, { addCard, addColumn, ... } from '@asseinfo/react-kanban'

All the helpers you need to pass your board and they will return a new board to pass to your state:

import Board, { addColumn } from '@asseinfo/react-kanban'
...
const [board, setBoard] = useState(initialBoard)
...
const newBoard = addColumn(board, newColumn)
setBoard(newBoard)
...
<Board>{board}</Board>

You can see the list of helpers in the end of the props documentation.

๐Ÿ”ท Shape of a board

{
  columns: [{
    id: ${unique-required-columnId},
    title: {$required-columnTitle**},
    cards: [{
      id: ${unique-required-cardId},
      title: ${required-cardTitle*}
      description: ${required-description*}
    }]
  }]
}

* The title and the description are required if you are using the card's default template. You can render your own card template through the renderCard prop.

** The title is required if you are using the column's default template. You can render your own column template through the renderColumnHeader prop.

โš™๏ธ Props

PropDescriptionControlledUncontrolled
children (required if controlled)The board to renderโœ…๐Ÿšซ
initialBoard (required if uncontrolled)The board to render๐Ÿšซโœ…
onCardDragEndCallback that will be called when the card move endsโœ…โœ…
onColumnDragEndCallback that will be called when the column move endsโœ…โœ…
renderCardA card to be rendered instead of the default cardโœ…โœ…
renderColumnHeaderA column header to be rendered instead of the default column headerโœ…โœ…
allowAddColumnAllow a new column be added by the userโœ…โœ…
onNewColumnConfirm (required if use the default column adder template)Callback that will be called when a new column is confirmed by the user through the default column adder templateโœ…โœ…
onColumnNew (required if allowAddColumn or when addColumn is called)Callback that will be called when a new column is added through the default column adder template๐Ÿšซโœ…
renderColumnAdderA column adder to be rendered instead of the default column adder templateโœ…โœ…
disableColumnDragDisable the column moveโœ…โœ…
disableCardDragDisable the card moveโœ…โœ…
allowRemoveColumnAllow to remove a column in default column headerโœ…โœ…
onColumnRemove (required if allowRemoveColumn or when removeColumn is called)Callback that will be called when a column is removedโœ…โœ…
allowRenameColumnAllow to rename a column in default column headerโœ…โœ…
onColumnRename (required if allowRenameColumn or when renameColumn is called)Callback that will be called when a column is renamedโœ…โœ…
allowRemoveCardAllow to remove a card in default card templateโœ…โœ…
onCardRemove (required if allowRemoveCard)Callback that will be called when a card is removedโœ…โœ…
allowAddCardAllow to add a card. Expect an object with the position to add the card in the column.๐Ÿšซโœ…
onCardNew (required if allowAddCard or when addCard is called)Callback that will be called when a new card is added through the default card adder template๐Ÿšซโœ…
onNewCardConfirm (required if allowAddCard)Callback that will be called when a new card is confirmed by the user through the default card adder template๐Ÿšซโœ…
children

The board. Use this prop if you want to control the board's state.

initialBoard

The board. Use this prop if you don't want to control the board's state.

onCardDragEnd

When the user moves a card, this callback will be called passing these parameters:

ArgDescription
boardThe modified board
cardThe moved card
sourceAn object with the card source { fromColumnId, fromPosition }
destinationAn object with the card destination { toColumnId, toPosition }
Source and destination
PropDescription
fromColumnIdColumn source id.
toColumnIdColumn destination id.
fromPositionCard's index in column source's array.
toPositionCard's index in column destination's array.
onColumnDragEnd

When the user moves a column, this callback will be called passing these parameters:

ArgDescription
boardThe modified board
columnThe moved column
sourceAn object with the column source { fromPosition }
destinationAn object with the column destination { toPosition }
Source and destination
PropDescription
fromPositionColumn index before the moving.
toPositionColumn index after the moving.
renderCard

Use this if you want to render your own card. You have to pass a function and return your card component. The function will receive these parameters:

ArgDescription
cardThe card props
cardBagA bag with some helper functions and state to work with the card
cardBag
functionDescription
removeCard*Call this function to remove the card from the column
draggingWhether the card is being dragged or not

* It's unavailable when the board is controlled.

Ex.:

const board = {
  columns: [{
    id: ${unique-required-columnId},
    title: ${columnTitle},
    cards: [{
      id: ${unique-required-cardId},
      dueDate: ${cardDueDate},
      content: ${cardContent}
    }]
  }]
}

<Board
  renderCard={({ content }, { removeCard, dragging }) => (
    <YourCard dragging={dragging}>
      {content}
      <button type="button" onClick={removeCard}>Remove Card</button>
    </YourCard>
  )}
>
{board}
</Board>
renderColumnHeader

Use this if you want to render your own column header. You have to pass a function and return your column header component. The function will receive these parameters:

ArgDescription
columnThe column props
columnBagA bag with some helper functions to work with the column
columnBag
functionDescription
removeColumn*Call this function to remove the column from the board
renameColumn*Call this function with a title to rename the column
addCard*Call this function with a new card to add it in the column

addCard: As a second argument you can pass an option to define where in the column you want to add the card:

  • { on: 'top' }: to add on the top of the column.
  • { on: 'bottom' }: to add on the bottom of the column (default).

* It's unavailable when the board is controlled.

Ex.:

const board = {
  columns: [{
    id: ${unique-required-columnId},
    title: ${columnTitle},
    wip: ${wip},
    cards: [{
      id: ${unique-required-cardId},
      title: ${required-cardTitle},
      description: ${required-cardDescription}
    }]
  }]
}

<Board
  renderColumnHeader={({ title }, { removeColumn, renameColumn, addCard }) => (
    <YourColumnHeader>
      {title}
      <button type='button' onClick={removeColumn}>Remove Column</button>
      <button type='button' onClick={() => renameColumn('New title')}>Rename Column</button>
      <button type='button' onClick={() => addCard({ id: 99, title: 'New Card' })}>Add Card</button>
    </YourColumnHeader
  )}
>
  {board}
</Board>
allowAddColumn

Allow the user to add a new column directly by the board.

onNewColumnConfirm

When the user confirms a new column through the default column adder template, this callback will be called with a draft of a column with the title typed by the user.

If your board is uncontrolled you must return the new column with its new id in this callback.

If your board is controlled use this to get the new column title.

Ex.:

function onColumnNew (newColumn) {
  const newColumn = { id: ${required-new-unique-columnId}, ...newColumn }
  return newColumn
}

<Board initialBoard={board} allowAddColumn onColumnNew={onColumnNew} />
onColumnNew

When the user adds a new column through the default column adder template, this callback will be called passing the updated board and the new column.

This callback will not be called in an uncontrolled board.

renderColumnAdder

Use this if you want to render your own column adder. You have to pass a function and return your column adder component. The function will receive these parameters:

ArgDescription
columnBagA bag with some helper functions
columnBag
functionDescription
addColumn*Call this function with a new column to add the new column

* It's unavailable when the board is controlled.

Ex.:

const ColumnAdder = ({ addColumn }) {
  return (
    <div onClick={()=> addColumn({id: ${required-new-unique-columnId}, title: 'Title', cards:[]})}>
      Add column
    </div>
  )
}

<Board
  allowAddColumn
  renderColumnAdder={({ addColumn }) => <ColumnAdder addColumn={addColumn} />}
  {board}
</Board>
disableColumnDrag

Disallow the user from move a column.

disableCardDrag

Disallow the user from move a card.

allowRemoveColumn

When using the default header template, when you don't pass a template through the renderColumnHeader, it will allow the user to remove a column.

onColumnRemove

When the user removes a column, this callback will be called passing these parameters:

ArgDescription
boardThe board without the removed column
columnThe removed column
allowRenameColumn

When using the default header template, when you don't pass a template through the renderColumnHeader, it will allow the user to rename a column.

onColumnRename

When the user renames a column, this callback will be called passing these parameters:

ArgDescription
boardThe board with the renamed column
columnThe renamed column
allowRemoveCard

When using the default card template, when you don't pass a template through the renderCard, it will allow the user to remove a card.

onCardRemove

When the user removes a card, this callback will be called passing these parameters:

ArgDescription
boardThe board without the removed column
columnThe column without the removed card
cardThe removed card
allowAddCard

Allow the user to add a card in the column directly by the board. By default, it adds the card on the bottom of the column, but you can specify whether you want to add at the top or at the bottom of the board by passing an object with 'on' prop.

E.g.: // at the bottom by default <Board allowAddCard={{ on: 'bottom' }} /> // in the bottom of the column <Board allowAddCard={{ on: 'top' }} /> // at the top of the column

๐Ÿ”ฉ Helpers to be used with an controlled board

moveColumn
ArgDescription
boardYour board
{ fromPosition }Index of column to be moved
{ toPosition }Index destination of column to be moved
moveCard

Use this on a controlled board, the "from" and "to" are the same ones passed to onCardDragEnd callback. You can used this within your onCardDragEnd call back to actually update your board as it will return a new board which you can save down into state.

ArgDescription
boardYour board
{ fromPosition, fromColumnId }An object with the card source { fromColumnId, fromPosition } which are the indexes of the cards current position
{ toPosition, toColumnId }An object with the card destination { fromColumnId, fromPosition } which are the indexes of the cards new position
addColumn
ArgDescription
boardYour board
columnColumn to be added
removeColumn
ArgDescription
boardYour board
columnColumn to be removed
changeColumn
ArgDescription
boardYour board
columnColumn to be renamed
objectPass a object to be merged with the column. You can add new props and/or change the existing ones
addCard
ArgDescription
boardYour board
inColumnColumn to add the card be added
cardCard to be added
`{ on: 'bottomtop' }`
changeCard
ArgDescription
boardYour board
cardIdCard's id to be changed
objectPass a object to be merged with the card. You can add new props and/or change the existing ones
onCardNew

When the user adds a new card through the default card adder template, this callback will be called passing the updated board and the new card.

onNewCardConfirm

When the user confirms a new card through the default card adder template, this callback will be called with a draft of a card with the title and the description typed by the user.

You must return the new card with its new id in this callback.

Ex.:

function onCardNew (newCard) {
  const newCard = { id: ${required-new-unique-cardId}, ...newCard }
  return newCard
}

<Board initialBoard={board} allowAddCard onNewCardConfirm={onCardNew} onCardNew={console.log} />
removeCard
ArgDescription
boardYour board
fromColumnColumn where the card is
cardCard to be removed

๐Ÿ’…๐Ÿป Styling

You can either style all the board or import our style and override it with the styles you want:

Class
react-kanban-board
react-kanban-card
react-kanban-card-skeleton
react-kanban-card--dragging
react-kanban-card__description
react-kanban-card__title
react-kanban-column
react-kanban-card-adder-form
react-kanban-card-adder-button
react-kanban-card-adder-form__title
react-kanban-card-adder-form__description
react-kanban-card-adder-form__button
react-kanban-column-header
react-kanban-column-header__button
react-kanban-column-adder-button

๐Ÿงช Tests

Unit

yarn test

Code coverage is saved in coverage folder. Open HTML report for example with

open coverage/lcov-report/index.html

End-to-end

Using Cypress test runner. Start dev server and open Cypress using

yarn dev

All tests are in the cypress/integration folder. These tests also collect code coverage and save in several formats in the coverage folder. Open HTML report

open coverage/lcov-report/index.html

Read Cypress code coverage guide

Note: to avoid inserting babel-plugin-istanbul twice during Jest tests, E2E tests run with NODE_ENV=cypress environment variable. The babel-plugin-istanbul plugin is included in .babelrc file only in the cypress Node environment, leaving the default Jest configuration during NODE_ENV=test the same.

๐Ÿšดโ€โ™€๏ธ Roadmap

You can view the next features here. Feel welcome to help us with some PRs.

๐Ÿค Contributing

PRs are welcome:

  • Fork this project.
  • Setup it:
    yarn
    yarn start
    
  • Make your change.
  • Please add yourself to the contributors table (we use all contributors for that, we you will need that installed first):
    yarn contributors:add
    
  • Open the PR.

โœ๏ธ Guidelines for contributing

  • You need to test your change.
  • Try to be clean on your change. CodeClimate will keep an eye on you.
  • It has to pass on CI.

FAQs

Package last updated on 07 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc