This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
commonEdit.js
111 lines (101 loc) · 3.92 KB
/
commonEdit.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
import React, { Component }from "react";
import {FormGroup, Label, Input, Col} from 'reactstrap'
import { WithContext as ReactTags } from 'react-tag-input';
import './tagbox.css'
const KeyCodes = {
comma: 188,
enter: 13,
};
const delimiters = [KeyCodes.comma, KeyCodes.enter];
export default class CommonEdit extends React.Component{
constructor(props) {
super(props);
this.state = {
title : "Untitled",
authors : "",
publishDate : "",
published : "",
link : "",
tags: [],
suggestions: this.props.suggestions
};
}
onInputChange = event => {
const target = event.target;
const name = target.name;
const value = target.value;
this.setState({
[name]: value
}, () => this.props.handleEdit(this.state))
};
handleDelete = (i) => {
const { tags } = this.state;
this.setState({
tags: tags.filter((tag, index) => index !== i),
}, ()=>this.props.handleEdit(this.state));
}
handleAddition = (tag) => {
this.setState(state => (
{ tags: [...state.tags, tag] }),
() => this.props.handleEdit(this.state)
);
}
render() {
//console.log(this.state)
return(
<div>
<div style={{background:"white", padding:"5px"}}>
<FormGroup row>
<Label sm={2} size="lg" style={{textAlign:"right"}}>Title</Label>
<Col sm={10}>
<Input type="text" name="title" bsSize="lg" onChange={this.onInputChange}></Input>
</Col>
</FormGroup>
<FormGroup row>
<Label sm={2} size="lg" style={{textAlign:"right"}}>Authors</Label>
<Col sm={10}>
<Input type="text" name="authors" bsSize="lg" onChange={this.onInputChange}/>
</Col>
</FormGroup>
<FormGroup row>
<Label sm={2} size="lg" style={{textAlign:"right"}}>Date</Label>
<Col sm={10}>
<Input type="text" name="publishDate" bsSize="lg" onChange={this.onInputChange}/>
</Col>
</FormGroup>
<FormGroup row>
<Label sm={2} size="lg" style={{textAlign:"right"}}>Published</Label>
<Col sm={10}>
<Input type="text" name="published" bsSize="lg" onChange={this.onInputChange}/>
</Col>
</FormGroup>
<FormGroup row>
<Label sm={2} size="lg" style={{textAlign:"right"}}>Link</Label>
<Col sm={10}>
<Input type="url" name="link" bsSize="lg" onChange={this.onInputChange}/>
</Col>
</FormGroup>
</div>
<div style={{background:"white", marginTop:"10px", padding:"5px"}}>
<FormGroup row>
<Label sm={2} size="lg" style={{textAlign:"right"}}>Tags</Label>
<ReactTags
classNames={{
tags: "col-sm-10",
tagInputField: 'form-control-lg form-control',
}}
tags={this.state.tags}
suggestions={this.state.suggestions}
handleDelete={this.handleDelete}
handleAddition={this.handleAddition}
allowDeleteFromEmptyInput={false}
allowDragDrop={false}
delimiters={delimiters}
labelField="name"
inputFieldPosition="inline"
inline/>
</FormGroup>
</div>
</div>
)}
}