From 3514314bbca4e1ee629244a3356a8c8082840e89 Mon Sep 17 00:00:00 2001 From: Michael O'Connor Date: Sat, 11 Aug 2018 11:00:02 -0400 Subject: [PATCH] Added the ability to delete on press, and add a maximum number for tags --- .DS_Store | Bin 0 -> 6148 bytes CONTRIBUTORS | 1 + README.md | 5 +++-- Tags/index.js | 28 +++++++++++++++++++++++----- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a1c23bc993687f38fcc54daa58a5fafbecd638a7 GIT binary patch literal 6148 zcmeHK%Wl&^6ur|LYKJ1SsMIdKL1Ga_DUTF{kc^uyvf!b*zyeTf*HP=@dZO4Nln~?% z{{Z{}pTZaLA$$Owd9-RAxbEP}ydgh*S=1gYBLqyCU#_L3NBC_EEts06ym}nP1 zV+*=QG&0%8Hg(CTXS734X0lC%QNSqhzbPQr?lNs+y*|dOJ->dpDd?trKT3Io9I-*% zhu`=m4UyOs63Qs19=)R`9Z_D%|5nLgrapzVPj65jfF(J^DVyf8)e6tS@7kh=)S*Yf zCLL2;VSK7EER03GqwnItO%2=H<08c?jhyXizJKr$mhc>&SgJ= zYOrm`c6RG)<8k}W-G+O!eQ(lm#~T~1hI{)~dopqC)$8jIx_ieb@5dh|AHQHQFovyH z+BJ=*@D;(C5O0G)mh$WXbt2!P69_cG^ff8P6kt-OC6$x?`P^im_G)l$6wrSh`^wym z$PC0NU=;XU3W)u|g$wjFmI~$8fkIvZfEKEyAr_wsg5zrRG?og{0%M8_R8*#~7);So z@9I2HW2sQliRsG+({E<_hQj3A(Z4IxiFpc5X%sLDOe?Uc9_!-#-@5qzKTR@EMggP1 zTq(e;PSEi&Bz?Bd3{IT2E_@FzOyrdcB?W~(j%6T@;x)K5w7DVxdKycGsDYUe0V#ti Ji~|2uf#2>EocjO( literal 0 HcmV?d00001 diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 8e6a91a..f6b987e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1,2 +1,3 @@ Federico Martín Alconada Verzini (https://github.com/fedealconada) Havens (https://github.com/havenS) +Michael O'Connor Havens (https://github.com/seeocon) \ No newline at end of file diff --git a/README.md b/README.md index 4d8f963..727614d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# React-Native-Tags +# React-Native-Tags (with maximum tag and delete on press support) [![Build Status](https://travis-ci.org/peterp/react-native-tags.svg?branch=master)](https://travis-ci.org/peterp/react-native-tags) [![npm](https://img.shields.io/npm/dt/express.svg)](https://www.npmjs.com/package/react-native-tags) @@ -43,10 +43,11 @@ const UselessComponent = () => ( | initialText | The input element's text | | initialTags | ['the', 'initial', 'tags'] | | onChangeTags | Fires when tags are added or removed | -| onTagPress | Fires when tags are pressed | +| maxNumberOfTags | integer: up to you (mandatory) | | readonly | Removes the TextInput | | containerStyle | Style | | style | Style (`containerStyle` alias) | | inputStyle | Style | | tagContainerStyle | Style | | tagTextStyle | Style | +| deleteOnPress | true/false | diff --git a/Tags/index.js b/Tags/index.js index 7af31ba..e10cffc 100644 --- a/Tags/index.js +++ b/Tags/index.js @@ -52,7 +52,7 @@ class Tags extends React.Component { ); } else if ( text.length > 1 && - (text.slice(-1) === " " || text.slice(-1) === ",") + (text.slice(-1) === " " || text.slice(-1) === ",") && !(this.state.tags.indexOf(text.slice(0, -1).trim()) > -1) ) { this.setState( { @@ -67,6 +67,22 @@ class Tags extends React.Component { } }; + + /** + * void arraySplice(tag) + * uses the array.filter() method provided in Javascript to remove the specific tag from the list. + * + * @param {string} tag + */ + arraySplice(tag) { + if (this.props.deleteOnPress == true){ + this.setState({ + tags: this.state.tags.filter(e => e !== tag) + }); + } +} + + render() { return ( this.props.onTagPress(i, tag, e)} + onPress={() => this.arraySplice(tag)} tagContainerStyle={this.props.tagContainerStyle} tagTextStyle={this.props.tagTextStyle} /> ))} - {!this.props.readonly && ( + + {!this.props.readonly && (this.props.maxNumberOfTags > this.state.tags.length) && (