forked from aws-samples/aws-amplify-quick-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecording-Editor.js
123 lines (108 loc) · 2.79 KB
/
Recording-Editor.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import React from "react";
import styled from "@emotion/styled";
import { Button } from "@rebass/emotion";
import { Label, Input } from "@rebass/forms";
import { Formik } from "formik";
import Dialog from "./Dialog";
const StyledButton = styled(Button)`
background-color: #74b49b;
cursor: pointer;
`;
const StyledLabel = styled(Label)`
color: #74b49b;
margin-bottom: 4px;
`;
const StyledInput = styled(Input)`
color: #74b49b;
border-radius: 3px;
background-color: #f4f9f4;
`;
const StyledTextarea = styled("textarea")`
color: #74b49b;
background-color: #f4f9f4;
width: 100%;
min-height: 80px;
border-radius: 3px;
resize: vertical;
`;
const FormInputs = styled("div")`
max-height: 450px;
overflow: scroll;
padding: 16px;
@media (max-height: 570px) {
max-height: 300px;
}
@media (max-height: 675px) {
max-height: 350px;
}
`;
const Actions = styled("div")`
display: flex;
justify-content: flex-end;
align-items: center;
margin-top: 24px;
`;
const InputContainer = styled("div")`
margin-bottom: 16px;
`;
const Title = styled("h2")`
color: #74b49b;
`;
const RecordingEditor = props => (
<Dialog onDismiss={props.onDismiss}>
<Title>{props.title ? "Edit Note" : "Create Note"}</Title>
<Formik
initialValues={{
title: props.title || "",
text: props.text
}}
onSubmit={(values, { setSubmitting, resetForm }) => {
props.onSave({
title: values.title || `${values.text.substr(0, 20)}...`,
text: values.text
});
setSubmitting(false);
resetForm();
props.onDismiss();
}}
>
{({ values, handleSubmit, isSubmitting, handleChange }) => (
<form onSubmit={handleSubmit}>
<FormInputs>
<InputContainer>
<StyledLabel htmlFor="title">Title</StyledLabel>
<StyledInput
type="text"
name="title"
value={values.title}
onChange={handleChange}
/>
</InputContainer>
<InputContainer>
<StyledLabel htmlFor="text">Note</StyledLabel>
<StyledTextarea
name="text"
value={values.text}
onChange={handleChange}
/>
</InputContainer>
</FormInputs>
<Actions>
<StyledButton
onClick={() => {
props.onDismiss();
}}
style={{ marginRight: "8px" }}
>
Cancel
</StyledButton>
<StyledButton type="submit" disabled={isSubmitting}>
{isSubmitting ? "Saving..." : "Save"}
</StyledButton>
</Actions>
</form>
)}
</Formik>
</Dialog>
);
export default RecordingEditor;