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-tree-band

v1.0.4

Published

TreeView and DoubleChoce for react-native for tree structured data

Downloads

23

Readme

React Native Tree Band

A Tree Band is a data lifeline for a tree structured data, The TreeBand Components will help you to easily navigate in your data. RNTreeBand uses Promises to move from a node to another one. Want a Component to trace you tree line? You've got choice between TreeView band and DoubleChoice band

Installation

To install run commands:

$ npm i -s react-native-tree-band

or

$ yarn add react-native-tree-band

Tests

Default Test

import {DoubleChoice, TreeView} from 'react-native-tree-band'
render(){
    return(
    // ...
        <DoubleChoice />
        <TreeView />
    // ...
    )
}

Simple Test

const stuffs = {
    'foods': [
        {label: 'Donut'},
        {label: 'Hot Dog'},
        {label: 'Pizza'},
    ],
    cars: [
        {label: 'Mc Lauren'},
        {label: 'Nissan', type: 'nissan'},
    ],
    nissan: [
        {label: 'FS 0004'},
        {label: 'FS 008'},
    ],
}
const options = [
 {label: 'Food', type: 'foods', key: 0},
 {label: 'Cars', type: 'cars', key: 1},
 {label: 'Pizza', type: 'pizzas', key: 2} 
]
const getOptionsForDoubleChoice = async ({item, options, index}) => {
    return item.type ? [] : (stuffs[item.type] || [])
}
const getOptionsForTreeView = async ({item, index}) => {
    // maybe await for something
    return item.type ? [] : (stuffs[item.type] || [])
}
class MyComponent extends Component {
    render(){
        return(
        // ...
            <DoubleChoice
                initialOptions = {options}
                getOptions = {getOptionsForDoubleChoice}
            />
            <TreeView
                initialOptions = {options}
                getOptions = {getOptionsForTreeView}
            />
        // ...
        )
    }
}

Use of Components

RNTB was built as every part of the componennt can be stylized the way you want, just by passing some style props.

List Of props

| name | Type |default | Details | With | |-|-|-|-|-| |style|StyleSheet Object| none | Stylize the bandParent (see Component tructure) | Both |bandHeight|number| 30 | Height of the band | Both |bandStyle|StyleSheet Object| none | Band style ex: {top:70, width: '100%'} | Both |initialOptions|Array of Option (see Option structure)| default | Array of main options show on start | Both |dropdownCollapse|number|5|Margin around Dropdowns | Both |getOptions|function|default| Function to call to determine subOptions (next Options) | Both |dropdownStyle|Object | none | Main dropdown style (see dropdownStyle) | Both |itemDropdownStyle|Object | none | Sub-item dropdown style (see dropdownStyle) | DoubleChoice |optionLabels|Object | none | Labels for delete and Modify Buttons (see optionLabels)|DoubleChoice | single | boolean (or just presence) | false | Make List of Choice unique for use | DoubleChoice | autoPress | boolean (or just presence) | false | Make subchoice open after main choice is done | DoubleChoice

Options (getOptions and initialOptions)

If you read the previous Simple Test section, you can see there are async functions that are called each time the tree changes, and the returned list are used in dropdown to compute the next tree level, these are options computed by the passed getOption function prop. Thus, at the begining the Component needs a start point, the initial list of choice initialOptions.

Options is an array of object with label property, and eventualy with key property. Otherwise you can add any other properties as you want.

  • label is used in for displaying on dropdown and others and is required,
  • key is used only on DoubleChoice if you use single prop.
const options = [
 {label: 'Food', key: 0, ...},
 {label: 'Cars', key: 1, ...},
 {label: 'Pizza', key: 2, ...} 
]

dropdownStyle and itemDropdownStyle

These props are object with some keys used to stylize the dropdown. There are ssseven keys

render = () => (<TreeView
dropdownStyle = {{
  dropdown : {backgroundColor: '#444'},
  item : {borderBottomWidth: 0},
  itemText : {color: 'white'},
  remove : {backgroundColor: 'darkred'},
  removeText : {color: 'white'},
  modify : {backgroundColor: 'blue'},
  modifyText :{color: 'white', fontSize: 30}
}}/>)
  • dropdown : For the dropdown element View
  • item : For the dropdown item View
  • itemText : For the dropdown item Text
  • remove : For remove button (only with DoubleChoice)
  • removeText : For remove button text (only with DoubleChoice)
  • modify : For modify button (only with DoubleChoice)
  • modifyText : For modify button text (only with DoubleChoice)

optionLabels (DoubleChoice only)

optionLabels is an Object label props for options in DoubleChoice.

// ...
optionLabels = {{
  remove: "Remove it bro 😣",
  confirmRemove: "Please don't 😥",
  modify: "Change it bro! 😆"
}}