p5.js-web-editor/client/modules/IDE/components/NewFolderForm.jsx
Nitesh Sawant 121bf94007 fixes #726 (#728)
* fixes #726

* Disabled Sumit butto nif form is not touched & used tri function instead of replace
2018-10-22 15:41:35 -04:00

58 lines
1.6 KiB
JavaScript

import PropTypes from 'prop-types';
import React from 'react';
import { domOnlyProps } from '../../../utils/reduxFormUtils';
class NewFolderForm extends React.Component {
constructor(props) {
super(props);
this.createFolder = this.props.createFolder.bind(this);
}
componentDidMount() {
this.fileName.focus();
}
render() {
const {
fields: { name }, handleSubmit, submitting, pristine
} = this.props;
return (
<form
className="new-folder-form"
onSubmit={(data) => {
if (handleSubmit(this.createFolder)(data)) {
this.props.closeModal();
}
}}
>
<label className="new-folder-form__name-label" htmlFor="name">Name:</label>
<input
className="new-folder-form__name-input"
id="name"
type="text"
placeholder="Name"
ref={(element) => { this.fileName = element; }}
{...domOnlyProps(name)}
/>
<input type="submit" value="Add Folder" disabled={submitting || pristine} aria-label="add folder" />
{name.touched && name.error && <span className="form-error">{name.error}</span>}
</form>
);
}
}
NewFolderForm.propTypes = {
fields: PropTypes.shape({
name: PropTypes.object.isRequired
}).isRequired,
handleSubmit: PropTypes.func.isRequired,
createFolder: PropTypes.func.isRequired,
closeModal: PropTypes.func.isRequired,
submitting: PropTypes.bool,
pristine: PropTypes.bool
};
NewFolderForm.defaultProps = {
submitting: false,
pristine: true
};
export default NewFolderForm;