From 81a762e522b08a1e1529f830b4f7cee565bcf749 Mon Sep 17 00:00:00 2001 From: dkmiecik Date: Fri, 12 Nov 2021 09:43:22 +0100 Subject: [PATCH] Rename props. Add Readme. --- README.md | 150 ++++++++++++++++++++++++++++++++++++++++++++++++ example/App.tsx | 8 +-- src/index.tsx | 14 ++--- 3 files changed, 161 insertions(+), 11 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..3aa6b66 --- /dev/null +++ b/README.md @@ -0,0 +1,150 @@ +
+ +

React Native Collapsible Tree

+ +
+ +# Install + +```sh +yarn add @productbrew/react-native-collapsible-tree + +npm i @productbrew/react-native-collapsible-tree +``` + +# Usage + +./Button.tsx +```js +import React from "react"; +import { Text, TouchableHighlight, View } from "react-native"; + +type ButtonProps = { + onPress: () => void; + isSelected: boolean; + title: string; +}; + +export default function Button(props: ButtonProps) { + return ( + + + {props.title} + + + ); +} +``` + +./App.tsx +```js +import React, { useState } from "react"; +import { StatusBar } from 'expo-status-bar'; +import { StyleSheet, View } from 'react-native'; + +import Pill, { DataStructure } from '@productbrew/react-native-collapsible-tree'; + +import Button from "./Button"; + +const dataStructure: DataStructure[] = [ + { + id: 1, + name: "Parent1", + children: [ + { id: 11, name: "child1" }, + { id: 12, name: "child2" }, + { id: 13, name: "child3" }, + { id: 14, name: "child4" }, + ], + }, + { + id: 2, + name: "Parent2", + children: [ + { id: 21, name: "child1" }, + { id: 22, name: "child2" }, + { id: 23, name: "child3" }, + { id: 24, name: "child4" }, + ], + } +]; + +export default function App() { + const [selected, setSelected] = useState([]); + + return ( + + + treeData={dataStructure} + selectedItemId={selected} + buttonComponent={(itemData: DataStructure, level: number) => { + const isSelected = !!(selected.find(s => s === itemData.id)); + + return ( +