@@ -3,8 +3,13 @@ import { connect } from 'react-redux'
3
3
import { CirclePicker } from 'react-color'
4
4
5
5
import Header from 'components/Header' ;
6
- import { createCard } from 'actions/cardActions' ;
7
6
import NewCardItem from 'components/NewCardItem' ;
7
+ import { createCard } from 'actions/cardActions' ;
8
+
9
+ const colors = [
10
+ "#f44336" , "#e91e63" , "#9c27b0" , "#673ab7" ,
11
+ "#3f51b5" , "#2196f3" , "#03a9f4" , "#607d8b" ,
12
+ "#009688" , "#4caf50" , "#ff5722" , "#795548" ] ;
8
13
9
14
class NewCard extends Component {
10
15
constructor ( props ) {
@@ -14,12 +19,17 @@ class NewCard extends Component {
14
19
card : {
15
20
type : null ,
16
21
title : null ,
17
- color : null ,
22
+ color : '' ,
18
23
expiry : null ,
19
24
number : null
20
25
}
21
26
}
22
27
}
28
+
29
+ componentWillMount ( ) {
30
+ this . changeColor ( colors [ 0 ] ) ;
31
+ }
32
+
23
33
handleCard ( ) {
24
34
let card = {
25
35
id : 5 ,
@@ -35,11 +45,27 @@ class NewCard extends Component {
35
45
this . props . dispatch ( createCard ( card ) ) ;
36
46
}
37
47
48
+ changeColor ( color ) {
49
+ let newState = this . state . card ;
50
+
51
+ newState = Object . assign ( { } , this . state . card , {
52
+ color
53
+ } )
54
+ this . setState ( {
55
+ card : newState
56
+ } , ( ) => console . log ( "changes" , color , this . state . card ) )
57
+ }
58
+
59
+ handleChange = ( color , event ) => {
60
+ console . log ( color )
61
+ this . changeColor ( color . hex ) ;
62
+ } ;
63
+
38
64
render ( ) {
39
65
return (
40
66
< div className = "pane" style = { { flex : 1 } } >
41
67
< div className = "pane pane-main" >
42
- < Header title = "New card " />
68
+ < Header title = "Новая карта " />
43
69
< div className = "pane pane-body" >
44
70
< div className = "pane pane-newcard" id = "primary_block" >
45
71
< div id = "newcard-form" >
@@ -51,20 +77,24 @@ class NewCard extends Component {
51
77
< p > Можно добавить желаемое число карт. < a href = "https://cib.az#bl1-f" > Подробная информация</ a > </ p >
52
78
</ div >
53
79
</ div >
54
- < NewCardItem />
80
+ < NewCardItem
81
+ { ...this . state . card } />
55
82
</ div >
56
83
57
84
< div id = "palette-block" className = "pane newcard-info-block picker-width" >
58
- < div class = "pane newcard-txt" >
59
- < h2 class = "pane title" > Цвет карты</ h2 >
85
+ < div className = "pane newcard-txt" >
86
+ < h2 className = "pane title" > Цвет карты</ h2 >
60
87
< div className = "picker" >
61
- < CirclePicker />
88
+ < CirclePicker
89
+ color = { this . state . card . color }
90
+ colors = { colors }
91
+ onChange = { this . handleChange } />
62
92
</ div >
63
93
</ div >
64
94
< div className = "pane buttons" >
65
95
< div className = "fields field-button" >
66
96
< div className = "field" >
67
- < button onClick = { ( ) => this . handleCard ( ) } className = "btn primary" > Добавить карту</ button >
97
+ < button onClick = { ( ) => this . handleCard ( ) } className = "btn primary" > Сохранить карту</ button >
68
98
</ div >
69
99
</ div >
70
100
</ div >
0 commit comments