npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-nested-selects

v1.0.2

Published

This package allows you to easily create nested selects. Supported are static and dynamic selects. For own behaviour you can create your own components by subclassing and implementing only three required functions!

Downloads

2

Readme

react-native-nested-selects

This package allows you to easily create nested selects. Supported are static and dynamic selects. For own behaviour you can create your own components by subclassing and implementing only three required functions!

Documentation

Preview

Preview

Installation

Install the package using npm:

npm i --save react-native-nested-selects

Usage

Example

This is the code for the app used in preview.


import React, { useState } from "react";
import {
    Button,
    Text,
    View
} from "react-native";
import {
    DynamicSelect,
    StaticSelect
} from "react-native-nested-selects";

const App = () => {
    const [staticVisible, setStaticVisible] = useState(false),
        [dynamicVisible, setDynamicVisible] = useState(false),
        [text, setText] = useState("");
    let select;

    return (
        <View style={{
            flex: 1
        }}>
            <View style={{
                flex: 1,
                justifyContent: "center",
                alignItems: "center"
            }}>
                <View style={{ marginBottom: 10 }}>
                    <Button title="Show static" onPress={() => setStaticVisible(true)} color="#e34323" />
                </View>
                <View>
                    <Button title="Show dynamic" onPress={() => setDynamicVisible(true)} color="#43df08" />
                </View>
                <Text>{text}</Text>
            </View>
            <StaticSelect
                onAbort={() => setStaticVisible(false)}
                data={[
                    [
                        {
                            label: "A",
                            value: "a"
                        },
                        {
                            label: "B",
                            value: "b"
                        },
                        {
                            label: "C",
                            value: "c"
                        }
                    ],
                    [
                        {
                            label: "1",
                            value: 1
                        },
                        {
                            label: "2",
                            value: 2
                        }
                    ]
                ]}
                onDone={(args) => {
                    setStaticVisible(false);
                    setText(args);
                }}
                isVisible={staticVisible} />
            <DynamicSelect
                ref={item => select = item}
                onAbort={() => {
                    setDynamicVisible(false);
                    select.reset(); // If no reset call, the user will continue on the place where they aborted.
                }}
                data={[
                    {
                        label: "A",
                        value: "a",
                        nextLevel: [
                            {
                                label: "1",
                                value: 1
                            },
                            {
                                label: "2",
                                value: 2
                            }
                        ]
                    },
                    {
                        label: "B",
                        value: "b",
                        nextLevel: [
                            {
                                label: "3",
                                value: 3
                            },
                            {
                                label: "4",
                                value: 4
                            },
                            {
                                label: "Five",
                                value: 5,
                                nextLevel: [
                                    {
                                        label: "?",
                                        value: "?"
                                    },
                                    {
                                        label: "!",
                                        value: "!"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        label: "End now",
                        value: "d"
                    }
                ]}
                onDone={(args) => {
                    setDynamicVisible(false);
                    setText(args);
                }}
                isVisible={dynamicVisible} />
        </View>
    );
};

Usage

StaticSelect

StaticSelect uses fixed selects. Each layer will be shown no matter what was chosen.

| Code | Description | Type | |-|-|-| | data | The data | Array<Array> | | onAbort | Function executed when user aborts | Function | | onDone | Function executed after the user is done selecting | Function | | isVisible | Whether the select menu is visible | boolean |

DynamicSelect

DynamicSelect uses dynamic selects. Each select object defines whether there is another layer or not. To add another layer to a select, add one of the following values as a nextLayer-key.

Available nextLevel types

| Type | Description | |-|-| | Array<DataObject/Object> | Simple array of objects | | Function | The function will be executed and must return an array of DataObjects. The first (and only) argument is the class instance | | undefined (aka. no key) | The current layer will be used as the last layer and onDone will be called |

Creating own selects

You can create your own subclass (aka. component) by extending DefaultSelect and implementing AbstractBaseInterface. Your class will probably look like this:

class StaticSelect extends DefaultSelect<Props, States> implements AbstractBaseInterface{}

DefaultSelect contains three generic values:

abstract class DefaultSelect<P extends Props, S extends States, T = any>

| Value | Description | |-|-| | P | Props for the component | | S | States for the component | | T | The type of the given values (default: any) |

See JSDoc of AbstractBaseInterface to see how to continue.