React Trello

Pluggable components to add a kanban board to your application

README

React Trello


Pluggable components to add a Trello (like) kanban board to your application
Build Status yarn version bundlephobia.com

This library is not affiliated, associated, authorized, endorsed by or in any way officially connected to Trello, Inc. Trello is a registered trademark of Atlassian, Inc.


Basic Demo Edit react-trello-example


Features Showcase


Features


alt tag

Responsive and extensible
Easily pluggable into existing react application
Supports pagination when scrolling individual lanes
Drag-And-Drop on cards and lanes (compatible with touch devices)
Edit functionality to add/delete cards
Custom elements to define lane and card appearance
Event bus for triggering events externally (e.g.: adding or removing cards based on events coming from backend)
Inline edit lane's title

Getting Started


Install using npm or yarn

  1. ``` sh
  2. $ npm install --save react-trello
  3. ```

or

  1. ``` sh
  2. $ yarn add react-trello
  3. ```

Usage


The Board component takes a prop called data that contains all the details related to rendering the board. A sample data json is given here to illustrate the contract:

  1. ``` js
  2. const data = {
  3.   lanes: [
  4.     {
  5.       id: 'lane1',
  6.       title: 'Planned Tasks',
  7.       label: '2/2',
  8.       cards: [
  9.         {id: 'Card1', title: 'Write Blog', description: 'Can AI make memes', label: '30 mins', draggable: false},
  10.         {id: 'Card2', title: 'Pay Rent', description: 'Transfer via NEFT', label: '5 mins', metadata: {sha: 'be312a1'}}
  11.       ]
  12.     },
  13.     {
  14.       id: 'lane2',
  15.       title: 'Completed',
  16.       label: '0/0',
  17.       cards: []
  18.     }
  19.   ]
  20. }
  21. ```

draggable property of Card object is true by default.

The data is passed to the board component and that's it.

  1. ``` js
  2. import React from 'react'
  3. import Board from 'react-trello'

  4. export default class App extends React.Component {
  5.   render() {
  6.     return <Board data={data} />
  7.   }
  8. }
  9. ```

Refer to storybook for detailed examples: https://rcdexta.github.io/react-trello/

Also refer to the sample project that uses react-trello as illustration: https://github.com/rcdexta/react-trello-example

Use edge version of project (current master branch)


  1. ``` sh
  2. $ yarn add rcdexta/react-trello
  3. ```

and

  1. ``` js
  2. import Board from 'react-trello/src'
  3. ```

Upgrade


Breaking changes. Since version 2.2 these properties are removed: addLaneTitle, addCardLink, customLaneHeader, newCardTemplate, newLaneTemplate,
and customCardLayout with children element.

Follow upgrade instructions to make easy migration.

Properties


This is the container component that encapsulates the lanes and cards

Required parameters


NameTypeDescription
---------------------------------------------------------------------------------------------------------------------------------------------------------
dataobjectActual

Optionable flags


NameTypeDescription
---------------------------------------------------------------------------------------------------------------------------------------------------------
draggablebooleanMakes
laneDraggablebooleanSet
cardDraggablebooleanSet
collapsibleLanesbooleanMake
editablebooleanMakes
canAddLanesbooleanAllows
hideCardDeleteIconbooleanDisable
editLaneTitlebooleanAllow

Callbacks and handlers


NameTypeDescription
---------------------------------------------------------------------------------------------------------------------------------------------------------
handleDragStartfunctionCallback
handleDragEndfunctionCallback
handleLaneDragStartfunctionCallback
handleLaneDragEndfunctionCallback
onDataChangefunctionCalled
onCardClickfunctionCalled
onCardAddfunctionCalled
onBeforeCardDeletefunctionCalled
onCardDeletefunctionCalled
onCardMoveAcrossLanesfunctionCalled
onLaneAddfunctionCalled
onLaneDeletefunctionCalled
onLaneUpdatefunctionCalled
onLaneClickfunctionCalled
onLaneScrollfunctionCalled

Other functions


NameTypeDescription
---------------------------------------------------------------------------------------------------------------------------------------------------------
eventBusHandlefunctionThis
laneSortFunctionfunctionUsed

I18n support


NameTypeDescription
---------------------------------------------------------------------------------------------------------------------------------------------------------
langstringLanguage
tfunctionTranslation

Style customization


NameTypeDescription
---------------------------------------------------------------------------------------------------------------------------------------------------------
styleobjectPass
cardStyleobjectCSS
laneStyleobjectCSS
tagStyleobjectIf
cardDragClassstringCSS
cardDropClassstringCSS
laneDragClassstringCSS
laneDropClassstringCSS
componentsobjectMap

Lane specific props


NameTypeDescription
---------------------------------------------------------------------------------------------------------------------------------------------------------
idstringID
styleobjectPass
labelStyleobjectPass
cardStyleobjectPass
disallowAddingCardbooleanDisallow

Refer to stories folder for examples on many more options for customization.

Editable Board


It is possible to make the entire board editable by setting the editable prop to true. This switch prop will enable existing cards to be deleted and show a Add Card link at the bottom of each lane, clicking which will show an inline editable new card.

Check out the editable board story and its corresponding source code for more details.

Styling and customization


There are three ways to apply styles to the library components including Board, Lane or Card:

1. Predefined CSS classnames


Use the predefined css classnames attached to these elements that go by .react-trello-lane, .react-trello-card, .react-trello-board:

  1. ```css
  2. .react-trello-lane {
  3.   border: 0;
  4.   background-color: initial;
  5. }
  6. ```

2. Pass custom style attributes as part of data.


This method depends on used Card and Lane components.

  1. ``` js
  2. const data = {
  3.   lanes: [
  4.     {
  5.       id: 'lane1',
  6.       title: 'Planned Tasks',
  7.       style: { backgroundColor: 'yellow' },  // Style of Lane
  8.       cardStyle: { backgroundColor: 'blue' } // Style of Card
  9.       ...
  10. };

  11. <Board
  12.   style={{backgroundColor: 'red'}}  // Style of BoardWrapper
  13.   data={data}
  14.   />
  15. ```

Storybook example - stories/Styling.story.js

3. Completely customize the look-and-feel by using components dependency injection.


You can override any of used components (ether one or completery all)

  1. ``` js
  2. const components = {
  3.   GlobalStyle: MyGlobalStyle, // global style created with method `createGlobalStyle` of `styled-components`
  4.   LaneHeader: MyLaneHeader,
  5.   Card: MyCard,
  6.   AddCardLink: MyAddCardLink,
  7.   ...
  8. };

  9. <Board components={components} />
  10. ```

Total list of customizable components: src/components/index.js

Refer to components definitions to discover their properties list and types.

Refer more examples in storybook.

Publish Events


When defining the board, it is possible to obtain a event hook to the component to publish new events later after the board has been rendered. Refer the example below:

  1. ``` js
  2. let eventBus = undefined

  3. const setEventBus = (handle) => {
  4.   eventBus = handle
  5. }
  6. //To add a card
  7. eventBus.publish({type: 'ADD_CARD', laneId: 'COMPLETED', card: {id: "M1", title: "Buy Milk", label: "15 mins", description: "Also set reminder"}})

  8. //To update a card
  9. eventBus.publish({type: 'UPDATE_CARD', laneId: 'COMPLETED', card: {id: "M1", title: "Buy Milk (Updated)", label: "20 mins", description: "Also set reminder (Updated)"}})

  10. //To remove a card
  11. eventBus.publish({type: 'REMOVE_CARD', laneId: 'PLANNED', cardId: "M1"})

  12. //To move a card from one lane to another. index specifies the position to move the card to in the target lane
  13. eventBus.publish({type: 'MOVE_CARD', fromLaneId: 'PLANNED', toLaneId: 'WIP', cardId: 'Plan3', index: 0})

  14. //To update the lanes
  15. eventBus.publish({type: 'UPDATE_LANES', lanes: newLaneData})

  16. <Board data={data} eventBusHandle={setEventBus}/>
  17. ```

The first event in the above example will move the card Buy Milk from the planned lane to completed lane. We expect that this library can be wired to a backend push api that can alter the state of the board in realtime.

I18n and text translations


Custom text translation function


Pass translation function to provide custom or localized texts:

  1. ``` js

  2. // If your translation table is flat
  3. //
  4. // For example: { 'placeholder.title': 'some text' }
  5. const customTranslation = (key) => TRANSLATION_TABLE[key]

  6. // If your translation table has nested hashes (provided translations table is it)
  7. //
  8. // For example: { 'placeholder': { 'title': 'some text' } }
  9. import { createTranslate } from 'react-trello'
  10. const customTranslation = createTranslate(TRANSLATION_TABLE)

  11. <Board t={customTranslation} .../>
  12. ```

List of available keys - locales/en/translation.json

react-i18next example


  1. ``` js
  2. import { withTranslation } from 'react-i18next';

  3. const I18nBoard = withTranslation()(Board)
  4. ```

Compatible Browsers


Tested to work with following browsers using Browserling:

Chrome 60 or above
Firefox 52 or above
Opera 51 or above
Safari 4.0 or above
Microsoft Edge 15 or above

Logging


Pass environment variable REDUX_LOGGING as true to enable Redux logging in any environment

Development


  1. ```
  2. cd react-trello/
  3. yarn install
  4. yarn run storybook
  5. ```

Scripts


1.  yarn run lint : Lint all js files
2.  yarn run lintfix : fix linting errors of all js files
3.  yarn run semantic-release : make a release. Leave it for CI to do.
4.  yarn run storybook: Start developing by using storybook
5.  yarn run test : Run tests. tests file should be written as *.test.js and using ES2015
6.  yarn run test:watch : Watch tests while writing
7.  yarn run test:cover : Show coverage report of your tests
8.  yarn run test:report : Report test coverage to codecov.io. Leave this for CI
9.  yarn run build: transpile all ES6 component files into ES5(commonjs) and put it in dist directory
10. yarn run docs: create static build of storybook in docs directory that can be used for github pages

Learn how to write stories here

Maintainers



rcdexta

dapi

License


MIT