1.0.10 • Published 4 years ago

react-native-tags-input v1.0.10

Weekly downloads
276
License
MIT
Repository
github
Last release
4 years ago

react-native-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/react-native-tags-input

Git repo

https://github.com/jimmybengtsson/react-native-tags-input

Getting started

$ npm install react-native-tags-input --save

Props

necessarytypesabout
tagsobjectObject containing a empty string called tag and a empty array called tagsArray
updateStatefuncFunction to pass for component to be able to update parents state
keysForTagstringString to decide when a tag will be added. Space for standard
containerStylestylesStyles for the most outer view component
labelstringText to appear on top of input
labelStylestylesStyles for label text
inputContainerStylestylesStyles for the outer input component
inputStylestylesStyles for the inner input component
leftElementelementElement to be passed to input. Such as an icon.
leftElementContainerStylestylesStyles for the left element inside input
rightElementelementElement to be passed to input. Such as an icon.
rightElementContainerStylestylesStyles for the right element inside input
tagsViewStylestylesStyles for the view component containing the tag-chips
tagStylestylesStyles for the tag-chips
tagTextStylestylesStyles for the text inside a tag-chip
disabledbooleanActive input or not? false for standard
disabledInputStylestylesStyles for when the input is disabled
deleteElementelementIf this is included, the delete icon will be replaced by the element provided. (Thanks to periabyte)
deleteIconStylesstylesStyles for the delete icon
customElementelementElement to be displayed between input and tags. For example suggestions. (Auto suggestions will be implemented in a future release)

This component also inherits all native TextInput props that come with a standard React Native TextInput element.

Examples

Standard and Custom example

Auto suggest example by using customElement-prop

Standard example

import React, { Component } from 'react';
import {
  Dimensions,
  StyleSheet,
  View
} from 'react-native';

import TagInput from 'react-native-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 'react-native-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

react-native-tags-input is MIT License @ Jimmy Bengtsson

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago