0.0.3 • Published 6 years ago

react-native-tag-selector v0.0.3

Weekly downloads
51
License
MIT
Repository
github
Last release
6 years ago

npm version

react-native-tag-selector

Simple React Native tag selector control with folding of overflowed tags

screenshot_1

Installation

$ npm i react-native-tag-selector --save

Basic Usage

import React, {Component} from 'react';
import { StyleSheet, Text, View } from 'react-native';
import TagSelector from 'react-native-tag-selector';

class Example extends React.Component {

	tags = [
		{
			id: 'quick',
			name: 'quick'
		},
		{
			id: 'brown',
			name: 'brown'
		},
		{
			id: 'fox',
			name: 'fox'
		}
	]

	constructor(props) {
		super(props);
		this.state = {
			selectedTags: []
		}
	}

	render() {
		return (
			<View>
				<Text>
					Selected: {this.state.selectedTags.map(tag => `${tag} `)}
				</Text>
				<TagSelector
					maxHeight={70}
					tags={this.tags}
					onChange={(selected) => this.setState({ selectedTags: selected })} />
			</View>
		);
	}
}

With all props:

<TagSelector
    maxHeight={70}
    expandCaptions={['more', 'less']}
    expdandedContainerStyle = {styles.containerExpanded}
    containerStyle = {styles.container}
    selectedTagStyle = {styles.tagSelected}
    tagStyle = {styles.tag}
    separatorStyle = {styles.separator}
    expandBtnStyle = {styles.btnStyle}
    expandTextStyle = {styles.btnText}
    tags={this.tags}
    onChange={ (selected) => this.setState({selectedTags: selected})} />

Props

KeyTypeDefaultDescription
onChangeFunction*requiredcallback on change with one (tagsSelected) param - array of selected tags' id
maxHeightArray0max height of view to allow before appears 'more' text and folding functionality. 0 to disable folding and always show all tags
tagsArray*requiredarray of tags to render - objects of type {id: string, name: string}
expandCaptionsArray'more', 'less'array of expand captions - 'Show more', 'Show less'
expdandedContainerStylestyle-style of expanded container
containerStylestyle-style of default container
selectedTagStylestyle-selected tag style
tagStylestyle-default tag style
separatorStylestyle-separator between tags and expand button style
expandBtnStylestyle-expand button style
expandTextStylestyle-expand button text style

Contribution