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
78 lines (60 loc) · 1.9 KB
/
NewCardForm.js
File metadata and controls
78 lines (60 loc) · 1.9 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
75
76
77
78
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"]
console.log(emoji);
class NewCardForm extends Component {
constructor(props) {
super(props);
this.state = {
text: '',
emoji: '',
};
}
resetState = () => {
this.setState({
text: '',
emoji: '',
});
}
emojiDropDown = () => {
const emojis = [""].concat(emoji.names);
return emojis.map((emojiname, i) => {
return <option value={emojiname} key={i}> {emoji.getUnicode(emojiname)} </option>;
});
};
onFormChange = (event) => {
const field = event.target.name;
const value = event.target.value;
const updatedState = {};
updatedState[field] = value;
this.setState(updatedState);
}
onSubmit = (event) => {
event.preventDefault();
if (this.state.text === '') return;
console.log(event);
this.props.addCardCallback(this.state);
this.resetState();
}
render() {
return (
<form onSubmit={this.onSubmit} name="new-card-form" id="new-card-form" className="new-card-form">
<div className="new-card-form__form">
<label className="new-card-form--label" htmlFor="Text">Text</label>
<input name="text" placeholder="write text here" onChange={this.onFormChange} value={this.state.text} />
<label className="new-card-form--label" htmlFor="species">Emoji</label>
<select name="emoji" placeholder="" onChange={this.onFormChange} value={this.state.emoji}>
{this.emojiDropDown()}
</select>
<input className="new-card-form__form-button" type="submit" name="submit" value="Add a Card" />
</div>
</form>
);
}
} //end of class
NewCardForm.propTypes = {
addCardCallback: PropTypes.func.isRequired,
};
export default NewCardForm;