-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathAddCommentForm.jsx
More file actions
67 lines (63 loc) · 1.66 KB
/
AddCommentForm.jsx
File metadata and controls
67 lines (63 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
import React, { Component } from "react";
import styles from "./AddCommentForm.css";
import PropTypes from "prop-types";
class AddCommentForm extends Component {
state = {
formCommentText: "",
formCommentName: "",
};
handleCommentText = (text) => {
this.setState({
formCommentText: text,
});
};
handleCommentName = (text) => {
this.setState({
formCommentName: text,
});
};
onSubmitForm = (e) => {
e.preventDefault();
this.props.onAddComment(
this.state.formCommentName,
this.state.formCommentText
);
this.setState({
formCommentName: "",
formCommentText: "",
});
};
render() {
return (
<form onSubmit={this.onSubmitForm} className={styles["add-comment-form"]}>
<label htmlFor="text-comment">Text of Your comment</label>
<textarea
className={styles["comment-filed"]}
name=""
id="text-comment"
onChange={(e) => this.handleCommentText(e.target.value)}
value={this.state.formCommentText}
></textarea>
<label htmlFor="name">Your Name</label>
<input
onChange={(e) => this.handleCommentName(e.target.value)}
value={this.state.formCommentName}
id="name"
className={styles["name-field"]}
type="text"
/>
<button
disabled={!this.state.formCommentName || !this.state.formCommentText}
className={styles["btn-add-comment"]}
type="submit"
>
Add Comment
</button>
</form>
);
}
}
AddCommentForm.propTypes = {
onAddComment: PropTypes.func.isRequired,
};
export default AddCommentForm;