Skip to content

Commit de0b5ca

Browse files
committed
fix: Hide delete icon based on prop hideCardDeleteIcon
The user might add his own delete action button and this fix will introduce the ability to hide the default delete icon #62
1 parent fb3cce5 commit de0b5ca

File tree

7 files changed

+38
-33
lines changed

7 files changed

+38
-33
lines changed

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,28 @@ Also please refer to this sample project that uses react-trello for usage: https
7070

7171
This is the container component that encapsulates the lanes and cards
7272

73-
| Name | Type | Description |
74-
| ---------------- | -------- | ---------------------------------------- |
75-
| draggable | boolean | Makes all cards in the lanes draggable. Default: false |
76-
| editable | boolean | Makes the entire board editable. Allow cards to be added or deleted Default: false |
77-
| handleDragStart | function | Callback function triggered when card drag is started: `handleDragStart(cardId, laneId)` |
78-
| handleDragEnd | function | Callback function triggered when card drag ends: `handleDragEnd(cardId, sourceLaneId, targetLaneId, position)` |
79-
| onLaneScroll | function | Called when a lane is scrolled to the end: `onLaneScroll(requestedPage, laneId)` |
80-
| onCardClick | function | Called when a card is clicked: `onCardClick(cardId, metadata, laneId) ` |
81-
| onCardAdd | function | Called when a new card is added: `onCardAdd(card, laneId) ` |
82-
| addCardLink | node | Pass custom element to replace the `Add Card` link at the end of the lane (when board is editable) |
83-
| newCardTemplate | node | Pass a custom new card template to add new cards to a lane (when board is editable) |
84-
| onCardDelete | function | Called when a card is deleted: `onCardDelete(cardId, laneId) ` |
85-
| onLaneClick | function | Called when a lane is clicked: `onLaneClick(laneId) `. Card clicks are not propagated to lane click event |
86-
| laneSortFunction | function | Used to specify the logic to sort cards on a lane: `laneSortFunction(card1, card2)` |
87-
| eventBusHandle | function | This is a special function that providers a publishHook to pass new events to the board. See details in Publish Events section |
88-
| onDataChange | function | Called everytime the data changes due to user interaction or event bus: `onDataChange(newData)` |
89-
| style | object | Pass css style props to board container |
90-
| customCardLayout | function | Boolean to indicate a custom card template will be specified. Add the card component as child to Board |
91-
| customLaneHeader | element | Pass custom lane header as react component to modify appearance |
92-
| data | object | Actual board data in the form of json |
93-
| tagStyle | object | If cards have tags, use this prop to modify their style |
73+
| Name | Type | Description |
74+
| --------------------- | -------- | ---------------------------------------- |
75+
| draggable | boolean | Makes all cards in the lanes draggable. Default: false |
76+
| editable | boolean | Makes the entire board editable. Allow cards to be added or deleted Default: false |
77+
| handleDragStart | function | Callback function triggered when card drag is started: `handleDragStart(cardId, laneId)` |
78+
| handleDragEnd | function | Callback function triggered when card drag ends: `handleDragEnd(cardId, sourceLaneId, targetLaneId, position)` |
79+
| onLaneScroll | function | Called when a lane is scrolled to the end: `onLaneScroll(requestedPage, laneId)` |
80+
| onCardClick | function | Called when a card is clicked: `onCardClick(cardId, metadata, laneId) ` |
81+
| onCardAdd | function | Called when a new card is added: `onCardAdd(card, laneId) ` |
82+
| addCardLink | node | Pass custom element to replace the `Add Card` link at the end of the lane (when board is editable) |
83+
| newCardTemplate | node | Pass a custom new card template to add new cards to a lane (when board is editable) |
84+
| hideCardDeleteIcon | boolean | Disable showing the delete icon to the top right corner of the card (when board is editable) |
85+
| onCardDelete | function | Called when a card is deleted: `onCardDelete(cardId, laneId) ` |
86+
| onLaneClick | function | Called when a lane is clicked: `onLaneClick(laneId) `. Card clicks are not propagated to lane click event |
87+
| laneSortFunction | function | Used to specify the logic to sort cards on a lane: `laneSortFunction(card1, card2)` |
88+
| eventBusHandle | function | This is a special function that providers a publishHook to pass new events to the board. See details in Publish Events section |
89+
| onDataChange | function | Called everytime the data changes due to user interaction or event bus: `onDataChange(newData)` |
90+
| style | object | Pass css style props to board container |
91+
| customCardLayout | function | Boolean to indicate a custom card template will be specified. Add the card component as child to Board |
92+
| customLaneHeader | element | Pass custom lane header as react component to modify appearance |
93+
| data | object | Actual board data in the form of json |
94+
| tagStyle | object | If cards have tags, use this prop to modify their style |
9495

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

src/components/BoardContainer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class BoardContainer extends Component {
8181
'laneSortFunction',
8282
'draggable',
8383
'editable',
84+
'hideCardDeleteIcon',
8485
'customCardLayout',
8586
'newCardTemplate',
8687
'customLaneHeader',
@@ -125,6 +126,7 @@ BoardContainer.propTypes = {
125126
laneSortFunction: PropTypes.func,
126127
draggable: PropTypes.bool,
127128
editable: PropTypes.bool,
129+
hideCardDeleteIcon: PropTypes.bool,
128130
handleDragStart: PropTypes.func,
129131
handleDragEnd: PropTypes.func,
130132
customCardLayout: PropTypes.bool,
@@ -139,6 +141,7 @@ BoardContainer.defaultProps = {
139141
handleDragStart: () => {},
140142
handleDragEnd: () => {},
141143
editable: false,
144+
hideCardDeleteIcon: false,
142145
draggable: false
143146
}
144147

src/components/Card.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ class Card extends Component {
3535
getItemStyle = (isDragging, draggableStyle) => ({
3636
backgroundColor: isDragging ? '#fbfbbc' : '#fff',
3737
...draggableStyle,
38-
margin: '0px 0px 5px 0px',
38+
margin: '0px 0px 7px 0px',
3939
})
4040

4141
render() {
42-
const {id, index, cardStyle, draggable, editable, customCardLayout, ...otherProps} = this.props
42+
const {id, index, cardStyle, draggable, editable, hideCardDeleteIcon, customCardLayout, ...otherProps} = this.props
4343
const style = customCardLayout ? {...cardStyle, padding: 0} : cardStyle
4444
const isDragDisabled = !draggable
4545
return (
@@ -61,7 +61,7 @@ class Card extends Component {
6161
}}
6262
{...otherProps}>
6363
{this.renderBody()}
64-
{editable && <DeleteButton onClick={this.removeCard} />}
64+
{editable && !hideCardDeleteIcon && <DeleteButton onClick={this.removeCard} />}
6565
</MovableCardWrapper>
6666
{dragProvided.placeholder}
6767
</Fragment>

src/components/Lane.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Lane extends Component {
146146
}
147147

148148
renderDragContainer = (isDraggingOver) => {
149-
const {laneSortFunction, editable, tagStyle, cardStyle, draggable} = this.props
149+
const {laneSortFunction, editable, hideCardDeleteIcon, tagStyle, cardStyle, draggable} = this.props
150150
const {addCardMode} = this.state
151151

152152
const cardList = this.sortCards(this.state.cards, laneSortFunction).map((card, idx) => (
@@ -164,6 +164,7 @@ class Lane extends Component {
164164
onDelete={this.props.onCardDelete}
165165
draggable={draggable}
166166
editable={editable}
167+
hideCardDeleteIcon={hideCardDeleteIcon}
167168
{...card}
168169
/>
169170
))

src/styles/Base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const CardWrapper = styled.article`
8787
padding: 10px;
8888
cursor: pointer;
8989
max-width: 250px;
90-
margin-bottom: 5px;
90+
margin-bottom: 7px;
9191
min-width: 230px;
9292
`
9393

src/styles/Elements.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const DeleteWrapper = styled.div`
1111
export const DeleteIcon = styled.span`
1212
position: relative;
1313
display: inline-block;
14-
width: 6px;
15-
height: 6px;
14+
width: 4px;
15+
height: 4px;
1616
opacity: 0;
1717
overflow: hidden;
1818
border: 1px solid #83bd42;

stories/EditableBoard.story.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ class NewCard extends Component {
1515
this.props.onAdd(this.state)
1616
}
1717

18-
render () {
18+
render() {
1919
const {onCancel} = this.props
2020
return (
2121
<div style={{background: 'white', borderRadius: 3, border: '1px solid #eee', borderBottom: '1px solid #ccc'}}>
2222
<div style={{padding: 5, margin: 5}}>
2323
<div>
2424
<div style={{marginBottom: 5}}>
25-
<input type='text' onChange={evt => this.updateField('title', evt)} placeholder='Title' />
25+
<input type="text" onChange={evt => this.updateField('title', evt)} placeholder="Title" />
2626
</div>
2727
<div style={{marginBottom: 5}}>
28-
<input type='text' onChange={evt => this.updateField('description', evt)} placeholder='Description' />
28+
<input type="text" onChange={evt => this.updateField('description', evt)} placeholder="Description" />
2929
</div>
3030
</div>
3131
<button onClick={this.handleAdd}>Add</button>
@@ -58,7 +58,7 @@ storiesOf('Editable Board', module)
5858
<Board
5959
data={data}
6060
draggable
61-
id='EditableBoard1'
61+
id="EditableBoard1"
6262
onDataChange={shouldReceiveNewData}
6363
onCardDelete={handleCardDelete}
6464
onCardAdd={handleCardAdd}
@@ -71,7 +71,7 @@ storiesOf('Editable Board', module)
7171
.add(
7272
'Custom Buttons',
7373
withInfo('Allow editable elements on the board to be customized')(() => {
74-
return <Board data={data} editable addCardLink={<button>New Card</button>} />
74+
return <Board data={data} editable hideCardDeleteIcon addCardLink={<button>New Card</button>} />
7575
})
7676
)
7777
.add(

0 commit comments

Comments
 (0)