1.3.1 • Published 11 months ago

rn-multi-selected-modal v1.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

rn-multi-selected-modal

npm version npm downloads

A modal to select multi items from a list of data for React native. Platform Android/ios.

Getting started

Installation

Install the package in your React Native project:

yarn add rn-multi-selected-modal

OR

npm install rn-multi-selected-modal

Installing dependencies

Install the package we need as a dependency

yarn add react-native-svg

OR

npm install react-native-svg

Link native code

If yoy want yo use it for ios platform

cd ios && pod install

Usage

import React, { useState } from 'react'
import {  Text, SafeAreaView, Pressable, StyleSheet } from 'react-native'
import {MultiSelected} from 'rn-multi-selected-modal';

const App = () => {

    interface List {
        id: string,
        title: string,
    }

    const [modalVisible, setModalVisible] = useState(false)

    const data = [
        { id: 1, title: "John Smith" },
        { id: 2, title: "Jane Doe" },
        { id: 3, title: "Adam Johnson" },
        { id: 4, title: "Emily Davis" },
        { id: 5, title: "Michael Wilson" }
    ]

    const [selectedItems, setSelectedItems] = useState<List[]>([])

    const onSelectHandler = (item: any) => {

        if (selectedItems.some((i) => i.id === item.id)) {
            let newSelectedItems = [...selectedItems]
            const index = selectedItems.findIndex((i) => i.id === item.id)
            if (index > -1) {
                newSelectedItems.splice(index, 1)
                setSelectedItems(newSelectedItems)
            }

        } else {
            setSelectedItems([...selectedItems, item])
        }
    }

    return (
        <SafeAreaView>
            <Pressable
                onPress={() => setModalVisible(true)}>
                <Text style={styles.textStyle}>Show Modal</Text>
            </Pressable>
            <MultiSelected
                data={data}
                modalVisible={modalVisible}
                selectedItems={selectedItems}
                onChangeSelect={onSelectHandler}
                onClose={() => setModalVisible(false)}
            />
        </SafeAreaView>
    )
}

Properties

We have the props as following for customizing and pass data:

Required

PropDescriptionDefault
dataList of data with an id:string or number & title:string.Empty Array
onCloseA function that make the modal visible falseNone
modalVisibleValue that shows the visibility of modal.false
selectedItemsList of items that are selected.Empty Array
onChangeSelectA function that describe what you want to do on selecting an item (we retuen the selected item for you).None

Optional

PropDescriptionDefault
modalStyleThe style of Modal ViewView style
checkBoxColorThe color of checkbox when the item is selected. It should be a string value"#5850EC"
listEmptyTitleThe title that is shown when we don't have any result of searching or the data is empty. It should be a string value.No Item match!
itemTitleStyleStyle of the item's title.Text style
confirmBtnTitleThe title of button that close the modal. It should be a string valueConfirm
confirmBtnStyleStyle of the confirm buttonView style
confirmTxtStyleStyle of the confirm button title.Text style
searchPlaceHolderThe text as a placeholder in search input. It should be a string valueSearch by name
listEmptyTitleStyleThe style of list empty title.Text style
checkBoxContainerStyleStyle of the check boxesView style
checkBoxSelectedIconThe Icon in the check box when it is selectedReact Node
checkBoxNotSelectedIconThe Icon in the check box when it is not selectedReact Node
1.3.1

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.1.0

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago