0.4.0 • Published 2 years ago

react-native-actions-sheet-picker-serial-luncher v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Native Actions Sheet Picker

A React Native component that provides a filterable select dropdown/picker.

Preview

Installation Guide

yarn add react-native-actions-sheet-picker

or

npm install react-native-actions-sheet-picker

Usage

import React, { useState, useMemo, useEffect } from 'react';

import { StyleSheet, Text, TouchableOpacity, SafeAreaView } from 'react-native';
import { Picker, onOpen } from 'react-native-actions-sheet-picker';

/*
 **Example data:
 */
import countries from './countries.json';

export default function App() {
  const [data, setData] = useState([]);
  const [selected, setSelected] = useState(undefined);
  const [query, setQuery] = useState('');

  useEffect(() => {
    setData(countries);
  }, []);

  /*
   **Example filter function
   * @param {string} filter
   */
  const filteredData = useMemo(() => {
    if (data && data.length > 0) {
      return data.filter((item) =>
        item.name
          .toLocaleLowerCase('en')
          .includes(query.toLocaleLowerCase('en'))
      );
    }
  }, [data, query]);

  /*
   **Input search
   *@param {string} text
   */
  const onSearch = (text) => {
    setQuery(text);
  };

  return (
    <SafeAreaView style={styles.container}>
      <TouchableOpacity
        style={styles.button}
        onPress={() => {
          onOpen('country');
        }}
      >
        <Text>Open ActionSheet</Text>
      </TouchableOpacity>
      <Text style={{ padding: 10 }}>Chosen : {JSON.stringify(selected)}</Text>
      <Picker
        id="country"
        data={filteredData}
        inputValue={query}
        searchable={true}
        label="Select Country"
        setSelected={setSelected}
        onSearch={onSearch}
      />
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
  },
  button: {
    backgroundColor: '#8B93A5',
    padding: 10,
    borderRadius: 6,
    marginTop: 50,
  },
});

Options

PropertiesTypeDescriptionDefault
id *requiredstringA unique id for the ActionSheet
dataarrayArray of list items{name: string, ...props}[]
inputValuestringThe value to show for the text input.
searchablebooleanSearchable statefalse
loadingbooleanLoading statefalse
labelstringFlatlist label
heightstringActionSheet heightDimensions.get('window').height * 0.5
closeTextstringClose text"Close"
placeholderTextstringPlaceholder text"Search"
noDataFoundTextstringNo data found text"No Data Found."
placeholderTextColorstringPlaceholder text color#8B93A5
setSelectedfunctionSelected function
onSearchfunctionTextinput search function
renderListItemfunctionRender List item

Style options

PropertiesTypeDescriptionDefault
actionSheetViewStyleCustom style for the action sheetundefined
activityIndicator{color?: string, style?: ViewStyle}Custom style for the activity indicatorundefined
close{text?: TextStyle, container?: ViewStyle}Custom style for the close text and containerundefined
inputTextStyleCustom style for the search inputundefined
item{text?: TextStyle, container?: ViewStyle}Custom style for the item text and containerundefined
label{text?: TextStyle, container?: ViewStyle}Custom style for the label text and containerundefined
noDataFound{text?: TextStyle, container?: ViewStyle}Custom style for the "no data found" text and containerundefined

Method

PropertiesTypeDescription
onOpenfunctionSheetManager show
onClosefunctionSheetManager hide

Core Props of using packages

PropertiesTypeDescription
actionsSheetPropsobjectreact-native-actions-sheet
flatListPropsobjectFlatListProps
searchInputPropsobjectTextInputProps

Roadmap

Contributing

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

License

MIT