react-native-tag-select
A simple tag component to act as radio button / checkbox
Features
- Max itens selected
- Plain simple and flexible API
- Listeners for actions
Demo
You can try on expo: https://expo.io/@rafaelmotta021/react-native-tag-select-demo
or just check the image bellow:
Setup
yarn add react-native-tag-select
or
npm install --save react-native-tag-select
Usage
;; ; Component { const data = id: 1 label: 'Money' id: 2 label: 'Credit card' id: 3 label: 'Debit card' id: 4 label: 'Online payment' id: 5 label: 'Bitcoin' ; return <View style=stylescontainer> <Text style=styleslabelText>Payment:</Text> <TagSelect data=data max=3 ref= { thistag = tag; } onMaxError= { Alert; } /> <View style=stylesbuttonContainer> <View style=stylesbuttonInner> <Button title="Get selected count" style=stylesbutton onPress= { Alert; } /> </View> <View> <Button title="Get selected" onPress= { Alert; } /> </View> </View> <Text style=styleslabelText>With custom style:</Text> <TagSelect data=data itemStyle=stylesitem itemLabelStyle=styleslabel itemStyleSelected=stylesitemSelected itemLabelStyleSelected=styleslabelSelected /> </View> ; } const styles = StyleSheet;
Available props
Name | Type | Default | Description |
---|---|---|---|
value | array | [] | Array with pre-defined values |
labelAttr | string | 'label' | Key attribute name to render label text |
keyAttr | string | 'id' | Key attribute name to render key property to the list |
data | array | [] | Data to render |
max | number | null | Max itens permitted |
onMaxError | func | null | Callback after user reach max itens |
onItemPress | func | null | Callback after user press on item |
itemStyle | any | {} | Style of item container |
itemStyleSelected | any | {} | Style of item container selected |
itemLabelStyle | any | {} | Style of item label |
itemLabelStyleSelected | any | {} | Style of item label selected |
Methods
To access tag select methods you must get the ref property first.
- Get the number of itens selected. Returns a boolean.
thisreftotalSelected
- Get itens selected. Returns an array.
thisrefitemsSelected