1.1.5 • Published 8 months ago

react-native-custom-select v1.1.5

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

React native custom select

A customizable React Native dropdown/select component supporting single and multiple selection modes, with features like search, select all, and flexible styling options for seamless integration

Codacy Badge git workflow NPM Version code style: prettier

Sample code here

Expo snack

Screenshot

Installation

npm i react-native-custom-select
yarn add react-native-custom-select

Usage

import { useState } from 'react';
import { Text, SafeAreaView, StyleSheet } from 'react-native';
import { SelectList, MultipleSelect } from 'react-native-custom-select';

export default function App() {
  const [selectedValue, setSelectedValue] = useState('');
  const [selectedValues, setSelectedValues] = useState([]);

  const data = [
    { key: '1', value: 'Option 1' },
    { key: '2', value: 'Option 2' },
    { key: '3', value: 'Option 3' },
    { key: '4', value: 'Option 4' },
  ];

  const handleChange = value => {
    setSelectedValue(value);
  };

  const handleMultipleChange = values => {
    setSelectedValues(values);
  };

  return (
    <SafeAreaView style={styles.container}>
      <Text style={styles.paragraph}>
        Change code in the editor and watch it change on your phone! Save to get
        a shareable url.
      </Text>

      <SelectList
        data={data}
        value={selectedValue}
        onChange={handleChange}
        placeholder="Select an option"
        borderColor="#444"
      />

      <MultipleSelect
        data={data}
        value={selectedValues}
        onChange={handleMultipleChange}
        placeholder="Choose multiple options"
        searchResult="No results found"
      />
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
    margin: 10,
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});

SelectList Properties

SelectList

PropertyTypeDefaultDescription
dataSelectItem[][]The list of items for the select dropdown.
valuestringundefinedThe selected value.
placeholderstringundefinedPlaceholder text when no item is selected.
searchResultstringundefinedDisplays the search results.
fontSizenumber14Font size of the text within the select component.
backgroundColorstring'transparent'Border color of the select component.
borderColorstring'#000'Border color of the select component.
borderRadiusnumber10Border radius of the select component.
defaultPaddingnumber14Default padding within the select component.
containerStyleStyleProp<ViewStyle>{marginBottom: 15}Custom styles for the container view.
indexValuestringundefinedThe value of the item used for indexing in the dropdown.
caretIconReactNodeundefinedCustom icon for the caret in the dropdown.
closeIconReactNodeundefinedCustom icon for the close button in the dropdown.
onChange(value: string) => voidrequiredCallback function triggered when a selection is made.

MultipleSelect

PropertyTypeDefaultDescription
dataSelectItem[][]The list of items for the select dropdown.
valuestring[]undefinedThe array of selected values.
placeholderstringundefinedPlaceholder text when no item is selected.
searchResultstringundefinedDisplays the search results.
fontSizenumber14Font size of the text within the select component.
backgroundColorstring'transparent'Border color of the select component.
borderColorstring'#000'Border color of the select component.
borderRadiusnumber10Border radius of the select component.
defaultPaddingnumber14Default padding within the select component.
containerStyleStyleProp<ViewStyle>{marginBottom: 15}Custom styles for the container view.
indexValuestringundefinedThe value of the item used for indexing in the dropdown.
caretIconReactNodeundefinedCustom icon for the caret in the dropdown.
closeIconReactNodeundefinedCustom icon for the close button in the dropdown.
onChange(value: string) => voidrequiredCallback function triggered when multiple selections are made.

Maintainers

@kimolalekan

1.1.5

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

2.0.3

2 years ago