rn-tags-input
v0.0.4
Published
Input component for React Native for Tags Items.
Downloads
7
Maintainers
Readme
rn-tags-input
Fully customizable React Native input-component to add tags to an array. The tags are displayed as chips that can be deleted.
Npm repo
https://www.npmjs.com/package/rn-tags-input
Git repo
https://github.com/JohnnyScript/rn-tags-input
Getting started
$ yarn add rn-tags-input
Standard example
import React, { Component } from 'react';
import {
Dimensions,
StyleSheet,
View
} from 'react-native';
import TagInput from 'rn-tags-input';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
tags: {
tag: '',
tagsArray: []
},
};
}
updateTagState = (state) => {
this.setState({
tags: state
})
};
render() {
return (
<View style={styles.container}>
<TagInput
updateState={this.updateTagState}
tags={this.state.tags}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
Custom example
import React, { Component } from 'react';
import {
Dimensions,
StyleSheet,
View
} from 'react-native';
import {Icon} from 'react-native-elements';
import TagInput from 'rn-tags-input';
const mainColor = '#3ca897';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
tags: {
tag: '',
tagsArray: []
},
tagsColor: mainColor,
tagsText: '#fff',
};
}
updateTagState = (state) => {
this.setState({
tags: state
})
};
render() {
return (
<View style={styles.container}>
<TagInput
updateState={this.updateTagState}
tags={this.state.tags}
placeholder="Tags..."
label='Press comma & space to add a tag'
labelStyle={{color: '#fff'}}
leftElement={<Icon name={'tag-multiple'} type={'material-community'} color={this.state.tagsText}/>}
leftElementContainerStyle={{marginLeft: 3}}
containerStyle={{width: (Dimensions.get('window').width - 40)}}
inputContainerStyle={[styles.textInput, {backgroundColor: this.state.tagsColor}]}
inputStyle={{color: this.state.tagsText}}
onFocus={() => this.setState({tagsColor: '#fff', tagsText: mainColor})}
onBlur={() => this.setState({tagsColor: mainColor, tagsText: '#fff'})}
autoCorrect={false}
tagStyle={styles.tag}
tagTextStyle={styles.tagText}
keysForTag={', '}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: mainColor,
},
textInput: {
height: 40,
borderColor: 'white',
borderWidth: 1,
marginTop: 8,
borderRadius: 5,
padding: 3,
},
tag: {
backgroundColor: '#fff'
},
tagText: {
color: mainColor
},
});
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
rn-tags-input is MIT License @ Johnny Pacheco