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
102 lines (74 loc) · 2.17 KB
/
NewCardForm.js
File metadata and controls
102 lines (74 loc) · 2.17 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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", "poop", "cookie", "doughnut" ];
class NewCardForm extends Component {
constructor(props) {
super(props);
this.state = {
text: '',
emoji: '',
};
};
onInputChange = (event) => {
const field = event.target.name;
const value = event.target.value;
const conditionalValue = field === "emoji" ? emoji.getName(value) : value;
const newState = {};
newState[field] = conditionalValue;
this.setState(newState);
};
onFormSubmit = (event) => {
event.preventDefault();
const { id, text, emoji } = this.state;
this.props.addCardCallback(this.state);
this.setState({
text: '',
});
};
render() {
const dropDownEmoji = EMOJI_LIST.map((emojiIcon, i) => {
return (
<option key={i}>{emoji.getUnicode(emojiIcon)}</option>
);
});
return (
<div className="new-card-form">
<h3 className="new-card-form__header">Give me some inspo!</h3>
<div>
<form
className="new-card-form__form"
onSubmit={this.onFormSubmit}
>
<div>
<label htmlFor="text" className="new-card-form__form-label">
Text
</label>
</div>
<textarea
name="text"
value={this.state.text}
className="new-card-form__form-textarea"
onChange={this.onInputChange}
/>
<label htmlFor="emoji-select">Emoji</label>
<select
id="emoji-select"
className="new-card-form__form-select"
onChange={this.onInputChange}
name="emoji"
>
{dropDownEmoji}
</select>
<input className="new-card-form__form-button" type="submit" name="submit" value="Add Card" />
</form>
</div>
</div>
)
};
};
NewCardForm.propTypes = {
addCardCallback: PropTypes.func.isRequired,
};
export default NewCardForm;