mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 19:51:53 +00:00
Changed to MAJOR.MINOR version and added test code
This commit is contained in:
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Type definitions for React-Tags (react-tag-input) 4.7.2
|
||||
// Type definitions for React-Tags (react-tag-input) 4.7
|
||||
// Project: https://github.com/prakhar1989/react-tags
|
||||
// Definitions by: Ogglas <https://stackoverflow.com/users/3850405/ogglas>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import * as React from "react";
|
||||
import { WithContext as ReactTags, TagItem } from "react-tag-input";
|
||||
|
||||
export interface IState {
|
||||
tags: TagItem[];
|
||||
suggestions: string[];
|
||||
}
|
||||
|
||||
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"];
|
||||
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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user