-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateArea.jsx
73 lines (67 loc) · 1.53 KB
/
CreateArea.jsx
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
import React, { useState } from "react";
import AddIcon from "@material-ui/icons/Add";
import Fab from "@material-ui/core/Fab";
import Zoom from "@material-ui/core/Zoom";
function CreateArea(props) {
const [isExpanded, setExpanded] = useState(false);
const [note, setNote] = useState({
title: "",
content: ""
});
function handleChange(event) {
const { name, value } = event.target;
setNote(prevNote => {
return {
...prevNote,
[name]: value
};
});
}
function submitNote(event) {
props.onAdd(note);
setNote({
title: "",
content: ""
});
event.preventDefault();
}
function expand() {
setExpanded(true);
}
return (
<div>
<form className="create-note">
{/* {isExpanded ? (
<input
name="title"
onChange={handleChange}
value={note.title}
placeholder="Title"
/>
) : null} */}
{isExpanded && (
<input
name="title"
onChange={handleChange}
value={note.title}
placeholder="Title"
/>
)}
<textarea
name="content"
onClick={expand}
onChange={handleChange}
value={note.content}
placeholder="Take a note..."
rows={isExpanded ? "3" : "1"}
/>
<Zoom in={isExpanded}>
<Fab onClick={submitNote}>
<AddIcon />
</Fab>
</Zoom>
</form>
</div>
);
}
export default CreateArea;