|
1 | 1 | import React, {Component} from 'react' |
2 | | -import {withInfo} from '@storybook/addon-info' |
3 | 2 | import {storiesOf} from '@storybook/react' |
4 | 3 | import update from 'immutability-helper' |
5 | 4 |
|
6 | 5 | import Board from '../src' |
7 | 6 |
|
8 | 7 | const CustomCard = props => { |
9 | 8 | return ( |
10 | | - <div |
11 | | - style={{backgroundColor: props.cardColor, padding: 6}}> |
| 9 | + <div style={{backgroundColor: props.cardColor, padding: 6}}> |
12 | 10 | <header |
13 | 11 | style={{ |
14 | | - borderBottom: '1px solid #eee', |
15 | | - paddingBottom: 6, |
16 | | - marginBottom: 10, |
17 | | - display: 'flex', |
18 | | - flexDirection: 'row', |
19 | | - justifyContent: 'space-between' |
20 | | - }} |
21 | | - > |
22 | | - <div style={{fontSize: 14, fontWeight: 'bold'}}> |
23 | | - {props.name} |
24 | | - </div> |
| 12 | + borderBottom: '1px solid #eee', |
| 13 | + paddingBottom: 6, |
| 14 | + marginBottom: 10, |
| 15 | + display: 'flex', |
| 16 | + flexDirection: 'row', |
| 17 | + justifyContent: 'space-between' |
| 18 | + }}> |
| 19 | + <div style={{fontSize: 14, fontWeight: 'bold'}}>{props.name}</div> |
25 | 20 | </header> |
26 | 21 | <div style={{fontSize: 12, color: '#BD3B36'}}> |
27 | | - <div style={{color: '#4C4C4C', fontWeight: 'bold'}}> |
28 | | - {props.subTitle} |
29 | | - </div> |
| 22 | + <div style={{color: '#4C4C4C', fontWeight: 'bold'}}>{props.subTitle}</div> |
30 | 23 | <div style={{padding: '5px 0px'}}> |
31 | | - <i> |
32 | | - {props.body} |
33 | | - </i> |
| 24 | + <i>{props.body}</i> |
34 | 25 | </div> |
35 | 26 | </div> |
36 | 27 | </div> |
37 | 28 | ) |
38 | 29 | } |
39 | 30 |
|
40 | 31 | const customCardData = { |
41 | | - lanes: [ |
| 32 | + lanes: [ |
42 | 33 | { |
43 | | - id: 'lane1', |
44 | | - title: 'Planned', |
45 | | - cards: [ |
46 | | - { |
47 | | - id: 'Card1', |
48 | | - name: 'John Smith', |
49 | | - subTitle: 'SMS received at 12:13pm today', |
50 | | - body: 'Thanks. Please schedule me for an estimate on Monday.', |
51 | | - metadata: {id: 'Card1'} |
52 | | - }, |
53 | | - { |
54 | | - id: 'Card2', |
55 | | - name: 'Card Weathers', |
56 | | - subTitle: 'Email received at 1:14pm', |
57 | | - body: 'Is the estimate free, and can someone call me soon?', |
58 | | - metadata: {id: 'Card1'} |
59 | | - } |
60 | | - ] |
| 34 | + id: 'lane1', |
| 35 | + title: 'Planned', |
| 36 | + cards: [ |
| 37 | + { |
| 38 | + id: 'Card1', |
| 39 | + name: 'John Smith', |
| 40 | + subTitle: 'SMS received at 12:13pm today', |
| 41 | + body: 'Thanks. Please schedule me for an estimate on Monday.', |
| 42 | + metadata: {id: 'Card1'} |
61 | 43 | }, |
62 | 44 | { |
63 | | - id: 'lane2', |
64 | | - title: 'Work In Progress', |
65 | | - cards: [ |
66 | | - { |
67 | | - id: 'Card3', |
68 | | - name: 'Michael Caine', |
69 | | - subTitle: 'Email received at 4:23pm today', |
70 | | - body: 'You are welcome. Interested in doing business with you again', |
71 | | - metadata: {id: 'Card1'}, |
72 | | - } |
73 | | - ] |
| 45 | + id: 'Card2', |
| 46 | + name: 'Card Weathers', |
| 47 | + subTitle: 'Email received at 1:14pm', |
| 48 | + body: 'Is the estimate free, and can someone call me soon?', |
| 49 | + metadata: {id: 'Card1'} |
| 50 | + } |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + id: 'lane2', |
| 55 | + title: 'Work In Progress', |
| 56 | + cards: [ |
| 57 | + { |
| 58 | + id: 'Card3', |
| 59 | + name: 'Michael Caine', |
| 60 | + subTitle: 'Email received at 4:23pm today', |
| 61 | + body: 'You are welcome. Interested in doing business with you again', |
| 62 | + metadata: {id: 'Card1'} |
74 | 63 | } |
75 | | - ] |
| 64 | + ] |
| 65 | + } |
| 66 | + ] |
76 | 67 | } |
77 | 68 |
|
78 | 69 | class BoardWithCustomCard extends Component { |
| 70 | + state = {boardData: customCardData, draggedData: undefined} |
79 | 71 |
|
80 | | - state = {boardData: customCardData, draggedData: undefined} |
81 | | - |
82 | | - updateBoard = (newData) => { |
83 | | - console.log('calling updateBoard') |
84 | | - this.setState({draggedData: newData}) |
85 | | - } |
86 | | - |
87 | | - onDragEnd = (cardId, sourceLandId, targetLaneId) => { |
88 | | - console.log('Calling onDragENd') |
89 | | - const {draggedData} = this.state |
90 | | - const laneIndex = draggedData.lanes.findIndex((lane) => lane.id === targetLaneId) |
91 | | - const cardIndex = draggedData.lanes[laneIndex].cards.findIndex((card) => card.id === cardId) |
92 | | - const updatedData = update(draggedData, {lanes: {[laneIndex]: {cards: {[cardIndex]: {cardColor: {$set: '#d0fdd2'}}}}}}) |
93 | | - this.setState({boardData: updatedData}) |
94 | | - } |
| 72 | + updateBoard = newData => { |
| 73 | + console.log('calling updateBoard') |
| 74 | + this.setState({draggedData: newData}) |
| 75 | + } |
95 | 76 |
|
96 | | - render() { |
97 | | - return <Board |
98 | | - tagStyle={{fontSize: '80%'}} |
99 | | - data={this.state.boardData} |
100 | | - draggable |
101 | | - customCardLayout |
102 | | - onDataChange={this.updateBoard} |
103 | | - handleDragEnd={this.onDragEnd} |
104 | | - onCardClick={(cardId, metadata) => alert(`Card with id:${cardId} clicked. Has metadata.id: ${metadata.id}`)} |
105 | | - > |
106 | | - <CustomCard /> |
107 | | - </Board> |
108 | | - } |
| 77 | + onDragEnd = (cardId, sourceLandId, targetLaneId) => { |
| 78 | + console.log('Calling onDragENd') |
| 79 | + const {draggedData} = this.state |
| 80 | + const laneIndex = draggedData.lanes.findIndex(lane => lane.id === targetLaneId) |
| 81 | + const cardIndex = draggedData.lanes[laneIndex].cards.findIndex(card => card.id === cardId) |
| 82 | + const updatedData = update(draggedData, {lanes: {[laneIndex]: {cards: {[cardIndex]: {cardColor: {$set: '#d0fdd2'}}}}}}) |
| 83 | + this.setState({boardData: updatedData}) |
| 84 | + } |
109 | 85 |
|
| 86 | + render() { |
| 87 | + return ( |
| 88 | + <Board |
| 89 | + tagStyle={{fontSize: '80%'}} |
| 90 | + data={this.state.boardData} |
| 91 | + draggable |
| 92 | + customCardLayout |
| 93 | + onDataChange={this.updateBoard} |
| 94 | + handleDragEnd={this.onDragEnd} |
| 95 | + onCardClick={(cardId, metadata) => alert(`Card with id:${cardId} clicked. Has metadata.id: ${metadata.id}`)}> |
| 96 | + <CustomCard /> |
| 97 | + </Board> |
| 98 | + ) |
| 99 | + } |
110 | 100 | } |
111 | 101 |
|
112 | 102 | storiesOf('Custom Templates', module).add( |
113 | 103 | 'Drag-n-Drop Styling', |
114 | | - withInfo('Change card color on drag-n-drop')(() => { |
| 104 | + () => { |
115 | 105 | return <BoardWithCustomCard /> |
116 | | - }) |
| 106 | + }, |
| 107 | + {info: 'Change card color on drag-n-drop'} |
117 | 108 | ) |
0 commit comments