Change test

This commit is contained in:
Oscar Andersson
2017-06-28 10:07:42 +02:00
parent aa0986dec0
commit 682fb04a84
+13 -59
View File
@@ -1,64 +1,18 @@
import * as React from "react";
import { WithContext as ReactTags, TagItem } from "react-tag-input";
export interface IState {
tags: TagItem[];
suggestions: string[];
}
let tags = [
{ id: 0, text: "test" }, { id: 1, text: "testing" }
];
export class Tags extends React.Component<any, IState> {
constructor(props: any) {
super(props);
let tags: TagItem[] = [];
let tag: TagItem = {
id: 0,
text: "Test"
};
tags.push(tag);
let suggestions = ["test", "testar"];
let suggestions = ["test", "testar"];
this.state = {
tags: tags,
suggestions: suggestions
}
}
//Not complete
handleDelete(i: number) {
let tags = this.state.tags;
tags.splice(i, 1);
this.setState({ tags: tags });
}
handleAddition(tag: string) {
let tags = this.state.tags;
let tagItem: TagItem = {
id: tags.length,
text: tag
};
tags.push(tagItem);
this.setState({ tags: tags });
}
//Not complete
handleDrag(tag: TagItem, currPos: number, newPos: number) {
let tags = this.state.tags;
// mutate array
tags.splice(currPos, 1);
tags.splice(newPos, 0, tag);
// re-render
this.setState({ tags: tags });
}
render() {
return (
<div>
<ReactTags tags={this.state.tags}
suggestions={this.state.suggestions}
handleDelete={(i: number) => this.handleDelete(i)}
handleAddition={(tag: string) => this.handleAddition(tag)}
handleDrag={(tag: TagItem, currPos: number, newPos: number) => this.handleDrag(tag, currPos, newPos)} />
</div>
);
}
}
ReactDOM.render(
<ReactTags tags={tags}
suggestions={suggestions}
handleDelete={(i: number) => console.log("Delete: " + i)}
handleAddition={(tag: string) => console.log("Add: " + tag)}
handleDrag={(tag: TagItem, currPos: number, newPos: number) => console.log("Drag: " + tag.text)} />
document.getElementById("tag-input")
);