-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFileForm.js
69 lines (64 loc) · 2.22 KB
/
FileForm.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
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import {
Paper, TextField, Button,
} from '@material-ui/core';
function FileForm({
branch: _branch,
filepath: _filepath,
defaultContent: _defaultContent,
submitText,
onSubmit,
}) {
const [branch, setBranch] = useState(_branch);
const [filepath, setFilepath] = useState(_filepath);
const [defaultContent, setDefaultContent] = useState(_defaultContent);
const disabled = !(filepath);
return (
<Paper
style={{ marginBottom: '1em', padding: '1.3em' }}
data-test="component-fileForm"
>
<form>
<button type="submit" disabled style={{ display: 'none' }} aria-hidden="true"></button>
<TextField
name='branch' label='branch' type='text' autoComplete={null}
variant="outlined" margin="normal" fullWidth defaultValue={'branch'}
onChange={(e) => setBranch(e.target.value)}
data-test="branch-textField"
/>
<TextField
name='filepath' label='filepath' type='text' autoComplete={null}
variant="outlined" margin="normal" fullWidth defaultValue={filepath}
onChange={(e) => setFilepath(e.target.value)}
data-test="filepath-textField"
/>
<TextField
name='defaultContent' label='defaultContent' type='text' multiline={true} autoComplete={null}
variant="outlined" margin="normal" fullWidth defaultValue={defaultContent}
onChange={(e) => setDefaultContent(e.target.value)}
data-test="defaultContent-textField"
/>
<Button type="button" disabled={disabled} fullWidth variant="contained" color="primary"
onClick={() => onSubmit({
branch, filepath, defaultContent,
})}
data-test="submit-button"
>
{submitText}
</Button>
</form>
</Paper>
);
};
FileForm.propTypes = {
/** text to display on the submit button */
submitText: PropTypes.string,
/** Function run when submit button is clicked */
onSubmit: PropTypes.func.isRequired,
branch: PropTypes.string,
filepath: PropTypes.string,
defaultContent: PropTypes.string,
};
FileForm.defaultProps = { submitText: 'Submit' };
export default FileForm;