From aa0986dec09d780193846e9e411fca31e109e2da Mon Sep 17 00:00:00 2001 From: Oscar Andersson Date: Wed, 28 Jun 2017 09:51:50 +0200 Subject: [PATCH] Changed to MAJOR.MINOR version and added test code --- types/react-tag-input/index.d.ts | 2 +- .../react-tag-input/react-tag-input-tests.ts | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/types/react-tag-input/index.d.ts b/types/react-tag-input/index.d.ts index 96ed2b0268..922e5083b4 100644 --- a/types/react-tag-input/index.d.ts +++ b/types/react-tag-input/index.d.ts @@ -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 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/types/react-tag-input/react-tag-input-tests.ts b/types/react-tag-input/react-tag-input-tests.ts index e69de29bb2..bdcdbc37ed 100644 --- a/types/react-tag-input/react-tag-input-tests.ts +++ b/types/react-tag-input/react-tag-input-tests.ts @@ -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 { + 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 ( +
+ this.handleDelete(i)} + handleAddition={(tag: string) => this.handleAddition(tag)} + handleDrag={(tag: TagItem, currPos: number, newPos: number) => this.handleDrag(tag, currPos, newPos)} /> +
+ ); + } +}