forked from AdaGold/inspiration-board
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathNewCardForm.js
More file actions
74 lines (60 loc) · 1.66 KB
/
NewCardForm.js
File metadata and controls
74 lines (60 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import emoji from 'emoji-dictionary';
import './NewCardForm.css';
const EMOJI_LIST = ["", "heart_eyes", "beer", "clap", "sparkling_heart", "heart_eyes_cat", "dog"]
//text/quote, emoji
class NewCardForm extends Component {
constructor(props) {
super(props)
this.state = {
text: "",
emoji: ""
}
}
onSubmit = (event) => {
event.preventDefault();
this.props.addCardCallback(this.state);
this.setState({
text: "",
emoji: ""
})
}
onFormChange = (event) => {
const field = event.target.name;
const value = event.target.value;
const updatedState = {};
updatedState[field] = value;
this.setState(updatedState);
}
emojiSelect = () => {
const emojis = EMOJI_LIST.map((emoji, index) => {
return <option key={index} value={emoji}>{emoji}</option>
});
return emojis;
};
render() {
return(
<div className="form">
<form onSubmit={this.onSubmit}>
<div>
<label className="" htmlFor="Quote">Quote</label>
<input name="text" placeholder="quote" onChange={this.onFormChange} value={this.state.text} />
</div>
<div>
<label className="" htmlFor="Emoji">Emoji</label>
<select name="emoji" value={this.state.emoji}
onChange={this.onFormChange}>
{this.emojiSelect()}
</select>
</div>
<input type="submit" name="submit" value="Add a Card" />
</form>
</div>
)
}
}
NewCardForm.propTypes = {
addCardCallback: PropTypes.func
};
export default NewCardForm;