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
79 lines (64 loc) · 1.98 KB
/
NewCardForm.js
File metadata and controls
79 lines (64 loc) · 1.98 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
79
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"]
class NewCardForm extends Component {
constructor(props) {
super(props);
this.state = {
text: '',
emoji: ''
};
}
resetState = () => {
this.setState({
text: '',
emoji: ''
});
}
onFormChange = (event) => {
const field = event.target.name;
const value = event.target.value;
const updatedState = {};
updatedState[field] = value;
this.setState(updatedState);
}
onSubmit = (event) => {
event.preventDefault();
const { text } = this.state;
if (text === '') return;
this.props.addCardCallback(this.state);
this.resetState();
}
generateSelectEmojis = () => {
const emojiOptions = EMOJI_LIST.map((thisEmoji, index) => {
return <option key={index} value={thisEmoji}>{emoji.getUnicode(thisEmoji)}</option>
});
return <select className="new-card-form__form-select" name="emoji" value={this.state.emoji} onChange={this.onFormChange}>
{emojiOptions}
</select>
}
render() {
return (
<form onSubmit={this.onSubmit} name="new-card-form__form" id="new-card-form" className="new-card-form">
<div className="new-card-form__header">Add a new Card</div>
<div>
<label className="new-card-form__form-label" htmlFor="text">Text</label>
<input className="new-card-form__form-textarea" name="text" placeholder="text" onChange={this.onFormChange} value={this.state.text}/>
</div>
<div>
<label>
Select an Emoji:
{this.generateSelectEmojis()}
</label>
</div>
<input className="new-card-form__form-button" type="submit" name="submit" value="Add a Card" />
</form>
);
}
}
NewCardForm.propTypes = {
addCardCallback: PropTypes.func.isRequired
};
export default NewCardForm;