1.1.6 • Published 7 months ago

react-native-dropdown-multi v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

react-native-dropdown-multi

react-native-dropdown-multi is supported on both Android and iOS, making it a versatile solution for cross-platform dropdown functionality in React Native applications. Here's a breakdown of its key features

Key Features

  • Multi-Select & Single Select
  • Searchable
  • Customizable Styling
  • Modal Interface
  • Clear Selection Option
  • Cross-Platform

Screenshots

Installation

Use the package manager npm to install react-native-dropdown-multi.

npm i react-native-dropdown-multi

OR

yarn add react-native-dropdown-multi

Installation Steps

The library has specified dedicated steps for each platform. Please follow their installation guide in order to properly use icon fonts.

npm i react-native-vector-icons

IOS Installation

Please refer linked document react-native-vector-icons

Android Installation

Please refer linked document react-native-vector-icons

Usage

import React, { useState } from 'react';
import CustomDropdown from 'react-native-dropdown-multi';

const [selectedEmployee, setSelectedEmployee] = useState({ label: '', value: '' });
const [selectedEmployees, setSelectedEmployees] = useState([]);
const [isReportForVisible, setIsReportForVisible] = useState(false);
const [isAssignVisible, setIsAssignVisible] = useState(false);

const employees = Array.from({ length: 100 }, (_, i) => ({
    label: `Employee ${i + 1}`,
    value: i + 1,
  }));

const toggleReportForDropdown = () => setIsReportForVisible(!isReportForVisible);
const toggleAssignDropdown = () => setIsAssignVisible(!isAssignVisible);

const updateAssignedEmployees = (value) => {
    setSelectedEmployees(value.map((val) => val));
};

<View style={{ padding: 15, gap: 10 }}>
        <Text>Example 1 </Text>
        <CustomDropdown
          isClearable={true}
          selectedValue={selectedEmployee}
          isSearchEnabled={true}
          data={employees}
          isVisible={isReportForVisible}
          onClose={toggleReportForDropdown}
          onSelect={setSelectedEmployee}
          onPress={toggleReportForDropdown}
          customStyles={{
            pickerWrapper: { borderColor: 'blue' },
            itemText: { color: 'darkblue' },
            buttonText: { color: 'white', fontWeight: 'bold' },
          }}
          customButtonLabels={{ submit: 'Confirm', close: 'Cancel' }}
          dropdownHeight={500}
          searchPlaceholder="Type to search..."
          loading={false}
        />

        <Text>Example 2 (Multiselect)</Text>
        <CustomDropdown
          isClearable={true}
          selectedValue={selectedEmployees}
          isSearchEnabled={true}
          isMultiSelect={true}
          data={employees}
          isVisible={isAssignVisible}
          onClose={toggleAssignDropdown}
          onSelect={updateAssignedEmployees}
          onPress={toggleAssignDropdown}
        />
</View>

Props & Styling

Props

Certainly! Below is a table summarizing all the props, their types, whether they are required, and default values (if applicable). Additionally, I'll include the corresponding styling properties for each prop:

PropTypeDescriptionRequiredDefault Value
dataArray<Object>The data array to populate the dropdown. Each object must have a value and label property.YesRequired. No default value.
isVisiblebooleanControls whether the dropdown modal is visible or not.YesRequired. No default value.
onCloseFunctionA function to handle closing the dropdown.YesRequired. No default value.
onSelectFunctionA function to handle item selection. Receives the selected item or items.YesRequired. No default value.
isSearchEnabledbooleanIf true, the search bar will be enabled in the dropdown.Nofalse
selectedValueObjectThe initially selected item. The object should have a value and label.No{} (empty object)
onPressFunctionA function to be called when the dropdown is pressed (to open the modal).YesRequired. No default value.
isClearablebooleanIf true, a clear icon will be displayed to clear the selection.Nofalse
placeholderstringPlaceholder text for the dropdown input when no item is selected.No"Select an item"
isMultiSelectbooleanIf true, the dropdown will allow multiple selections.Nofalse
customStylesObjectA set of custom styles to override default styles. Custom styles can include pickerWrapper, item, modalContainer, and more.No{} (empty object)
customButtonLabelsObjectCustom labels for the buttons. Supports submit and close.No{ submit: "Submit", close: "Close" }
customIconsObjectCustom icons for the dropdown button and clear icon. Supports dropdown and clear.No{ dropdown: <FontAwesomeIcon>, clear: <FontAwesomeIcon> }
dropdownHeightnumberDefines the height of the dropdown modal.Noheight * 0.7
searchPlaceholderstringPlaceholder text for the search input.No"Search..."
loadingbooleanIf true, a loading indicator will be shown instead of the dropdown items.Nofalse

Custom Styles (for the customStyles prop)

Here are the available custom styles that can be passed within the customStyles prop:

PropTypeDescriptionRequiredDefault Value
pickerWrapperObjectCustom styles for the wrapper of the dropdown input. This affects the overall outer container of the dropdown.No{} (empty object)
contentWrapperObjectCustom styles for the wrapper inside the dropdown input, usually for the layout (row, alignment, etc.).No{} (empty object)
itemObjectCustom styles for individual dropdown items (each option). Can adjust padding, borders, etc.No{} (empty object)
itemTextObjectCustom styles for the text inside each dropdown item.No{} (empty object)
selectedColorstringThe color applied to the item circle when it's selected.No'green'
selectedTextColorstringCustom text color for selected items (multi-select).No'black'
modalContainerObjectCustom styles for the outer container of the dropdown modal.No{} (empty object)
modalViewObjectCustom styles for the modal view, where the dropdown list and buttons reside.No{} (empty object)
searchContainerObjectCustom styles for the search bar container inside the dropdown modal.No{} (empty object)
searchInputObjectCustom styles for the text input inside the search bar of the dropdown modal.No{} (empty object)
clearButtonObjectCustom styles for the clear button (appears when the search input is not empty).No{} (empty object)
buttonContainerObjectCustom styles for the container holding the submit and close buttons.No{} (empty object)
buttonObjectCustom styles for the individual buttons (submit or close).No{} (empty object)
buttonTextObjectCustom styles for the text inside the submit and close buttons.No{} (empty object)
multiselectTextObjectCustom styles for the text inside the multi-select dropdown (when multiple items are selected).No{} (empty object)
placeholderTextObjectCustom styles for the placeholder text when no item is selected in the dropdown.No{} (empty object)
clearIconObjectCustom styles for the clear icon (for clearing the selection).No{} (empty object)
dropdownIconObjectCustom styles for the dropdown icon (the arrow indicator).No{} (empty object)
loadingContainerObjectCustom styles for the loading spinner container when the dropdown is in a loading state.No{} (empty object)
emptyListTextObjectCustom styles for the "No data found" text when the filtered list is empty.No{} (empty object)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

1.1.6

7 months ago

1.1.5

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago