Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-paper-select

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-paper-select

Material Design Select Dropdown Component using React Native Paper

  • 0.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.5K
decreased by-0.62%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Paper Select 🔽

Version Dependency Status License Github Typescript React Native

  • This module includes a customizable multi-select and a single select component for React Native Paper.
  • The package is both Android and iOS compatible.
  • The package is well-typed and supports TypeScript.
  • Smooth and fast.
  • Type-safe

Go to Customizable Properties

Give us a GitHub star 🌟, if you found this package useful. GitHub stars

React Native Paper Select (NPM Link)

Demo/Screenshots

React Native Paper Select React Native Paper Select React Native Paper Select React Native Paper Select React Native Paper Select React Native Paper Select

Dependencies

react-native-paper
react-native-vector-icons

Installation

npm install react-native-paper-select

or

yarn add react-native-paper-select

Basic Usage (Multi-Select)

import { PaperSelect } from 'react-native-paper-select';

// ...

const [colors, setColors] = useState({
  value: '',
  list: [
    { _id: '1', value: 'BLUE' },
    { _id: '2', value: 'RED' },
    { _id: '3', value: 'GREEN' },
    { _id: '4', value: 'YELLOW' },
    { _id: '5', value: 'BROWN' },
    { _id: '6', value: 'BLACK' },
    { _id: '7', value: 'WHITE' },
    { _id: '8', value: 'CYAN' },
  ],
  selectedList: [],
  error: '',
});

<PaperSelect
  label="Select Colors"
  value={colors.value}
  onSelection={(value: any) => {
    setColors({
      ...colors,
      value: value.text,
      selectedList: value.selectedList,
      error: '',
    });
  }}
  arrayList={[...colors.list]}
  selectedArrayList={colors.selectedList}
  errorText={colors.error}
  multiEnable={true}
  textInputMode="flat"
  searchStyle={{ iconColor: 'red' }}
/>;

Basic Usage (Single-Select)

import { PaperSelect } from 'react-native-paper-select';

// ...

<PaperSelect
  label="Select Gender"
  value={gender.value}
  onSelection={(value: any) => {
    setGender({
      ...gender,
      value: value.text,
      selectedList: value.selectedList,
      error: '',
    });
  }}
  arrayList={[...gender.list]}
  selectedArrayList={gender.selectedList}
  errorText={gender.error}
  multiEnable={false}
  dialogTitleStyle={{ color: 'red' }}
  checkboxColor="yellow"
  checkboxLabelStyle={{ color: 'red', fontWeight: '700' }}
  textInputBackgroundColor="yellow"
  textInputColor="red"
/>;

Customization Options

The table consists of 5 columns. Please go through the table properly.

propstypedescriptiondefault valuerequired
  labelstringInput Labelset to empty string if you don’t want to displayyes
  arrayListArray<{  _id: string; value: string;}>Array of items. Should be an array of objects with _id and value property.example: [{"_id": 1, "value": "Red"}].there isn't any default value you need to specify a list.yes
  selectedArrayListArray<{  _id: string; value: string;}>selected elements or preselected elementsset empty array as defaultyes
  multiEnablebooleantrue if you want to use multi select, false if you want single selectno default valueyes
  errorTextstringtext to display on errorset to empty string as defaultyes
  valuestringdefault value you want to displaybind it with your variableyes
  dialogStyle{backgroundColor?: ViewStyle['backgroundColor']; borderRadius?: ViewStyle['borderRadius'];}dialog box style{backgroundColor:'white', borderRadius: 5}no
  dialogTitlestringtitle shown in the dialogdefaults to the value of labelno
  dialogTitleStyleTextStyledialog box title styledefault react native paper styleno
  searchStyle{backgroundColor?: ViewStyle['backgroundColor']; textColor?: TextStyle['color']; borderRadius?: number; borderColor?: ViewStyle['borderColor']; iconColor?: string;}search bar style in dialog box{borderRadius:5, borderColor:'#e5e5e5', backgroundColor: '#e5e5e5', color: '#000'}no
  disabledbooleanwhether the input (and dialog) are disabled and cannot be openedfalseno
  checkboxUncheckedColorstringcheckbox unchecked color#000007no
  checkboxColorstringcheckbox checked colorblueno
  checkboxLabelStyleTextStylecheckbox label styledefault react native paper styleno
  errorStyleTextStyleerror styledefault react native paper styleno
  textInputModeflat or outlinedinput style flat or outlinedoutlinedno
  underlineColorstringunderline color (if input mode is flat)blackno
  activeUnderlineColorstringactive underline color (if input mode is flat)blackno
  activeOutlineColorstringactive border color (if input mode is outlined)blackno
  outlineColorstringborder color (if input mode is outlined)blackno
  textInputBackgroundColorstringtext input background colorwhiteno
  textInputColorstringtext input text colorblackno
  textInputHeightnumbertext input heightdefault react native paper styleno
  textInputStyleTextStyletext input text styledefault react native paper styleno
  dialogButtonLabelStyleTextStyledialog button styledefault react native paper styleno
  hideSearchBoxbooleanhide searchbox in modalfalseno
  searchPlaceholderstringsearch placeholderSearchno
  modalCloseButtonTextstringClose button text in modalCloseno
  modalDoneButtonTextstringDone button text in modalDoneno

Callback Methods

  • onSelection - Return the selected item when an item is selected. Example :

    onSelection={(value: any) => {
      setGender({
        ...gender,
        value: value.text,
        selectedList: value.selectedList,
        error: '',
      });
    }}
    

Example

import React, { useState } from 'react';

import { Alert, StyleSheet, View } from 'react-native';
import { Button as PaperButton, Headline } from 'react-native-paper';
import { PaperSelect } from 'react-native-paper-select';

export const selectValidator = (value: any) => {
  if (!value || value.length <= 0) {
    return 'Please select a value.';
  }

  return '';
};

export default function App() {
  const [gender, setGender] = useState({
    value: '',
    list: [
      { _id: '1', value: 'MALE' },
      { _id: '2', value: 'FEMALE' },
      { _id: '3', value: 'OTHERS' },
    ],
    selectedList: [],
    error: '',
  });
  const [colors, setColors] = useState({
    value: '',
    list: [
      { _id: '1', value: 'BLUE' },
      { _id: '2', value: 'RED' },
      { _id: '3', value: 'GREEN' },
      { _id: '4', value: 'YELLOW' },
      { _id: '5', value: 'BROWN' },
      { _id: '6', value: 'BLACK' },
      { _id: '7', value: 'WHITE' },
      { _id: '8', value: 'CYAN' },
    ],
    selectedList: [],
    error: '',
  });

  return (
    <View style={styles.container}>
      <Headline style={{ marginBottom: 10 }}>
        React Native Paper Select
      </Headline>
      <PaperSelect
        label="Select Gender"
        value={gender.value}
        onSelection={(value: any) => {
          setGender({
            ...gender,
            value: value.text,
            selectedList: value.selectedList,
            error: '',
          });
        }}
        arrayList={[...gender.list]}
        selectedArrayList={gender.selectedList}
        errorText={gender.error}
        multiEnable={false}
        dialogTitleStyle={{ color: 'red' }}
        checkboxColor="yellow"
        checkboxLabelStyle={{ color: 'red', fontWeight: '700' }}
        textInputBackgroundColor="yellow"
        textInputColor="red"
      />
      <PaperSelect
        label="Select Colors"
        value={colors.value}
        onSelection={(value: any) => {
          setColors({
            ...colors,
            value: value.text,
            selectedList: value.selectedList,
            error: '',
          });
        }}
        arrayList={[...colors.list]}
        selectedArrayList={colors.selectedList}
        errorText={colors.error}
        multiEnable={true}
        textInputMode="flat"
        searchStyle={{ iconColor: 'red' }}
        searchPlaceholder="Procurar"
        modalCloseButtonText="fechar"
        modalDoneButtonText="terminado"
      />
      <PaperButton
        style={styles.button}
        labelStyle={styles.text}
        mode={'outlined'}
        onPress={() => {
          const genderError = selectValidator(gender.value);
          const colorError = selectValidator(colors.value);
          if (genderError || colorError) {
            setColors({ ...colors, error: colorError });
            setGender({ ...gender, error: genderError });
            return;
          }
          Alert.alert(
            'Selected Values',
            'Gender: ' + gender.value + ' and Colors: ' + colors.value
          );
        }}
      >
        Submit
      </PaperButton>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    paddingHorizontal: 12,
  },
  box: {
    width: 60,
    height: 60,
    marginVertical: 20,
  },

  button: {
    marginVertical: 10,
    width: '100%',
    backgroundColor: 'blue',
  },
  text: {
    fontWeight: 'bold',
    fontSize: 15,
    lineHeight: 26,
    color: 'white',
  },
});

You can check the example source code in example module.

Try it out

You can run the example module by performing these steps:

git clone https://github.com/srivastavaanurag79/react-native-paper-select.git
cd react-native-paper-select && cd example
npm install
cd ios && pod install && cd ..
react-native run-ios
react-native run-android

Author

Contributors

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Keywords

FAQs

Package last updated on 30 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc