123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import React, { useState } from 'react';
- import {View, Text, TextInput, StyleSheet} from 'react-native';
- import { Icon } from 'react-native-elements';
- import TypeHandler from './TypeHandler'
- export default function ArrayEditor(props) {
- let [array, setArray] = useState(props.value || []);
- let [template, setTemplate] = useState(props.template || {});
- let Handler = TypeHandler(template);
- return (
- <View style={styles.container}>
- <View style={styles.row}>
- <Text style={styles.capFirst}>{props.title}</Text>
- <View>
- <Icon name={'plus-one'}
- // type = {}
- // color = {}
- onPress = {() => {
- array.push(null);
- setArray(array);
- props.onChange && props.onChange(array);
- }}/>
- </View>
- </View>
- {array.map((item, index) => {
- let editorProps = {
- title: undefined,
- onChange: (value) => {
- array[index] = value;
- setArray(array);
- props.onChange && props.onChange(array);
- },
- value: array[index]
- };
- return <View style={styles.item}>
- <View style={styles.row}>
- <Text style={styles.itemIndex}># {index}</Text>
- <Icon name={'delete-forever'}
- // type = {}
- // color = {}
- onPress = {() => {
- array.splice(index,1);
- setArray(array);
- props.onChange && props.onChange(array);
- }}/>
- </View>
- <Handler {...editorProps} key={array.length * 100 + index} />
- </View>
- })}
- </View>
- );
- }
- const styles = StyleSheet.create({
- container:{
- flexDirection: 'column'
- },
- row: {
- flexDirection: 'row',
- alignItems: 'baseline',
- justifyContent: 'space-between',
- },
- capFirst: {
- fontSize: 14,
- fontFamily: 'roboto-light',
- textTransform: 'capitalize'
- },
- defaultInput: {
- marginTop:6,
- borderWidth:1,
- backgroundColor: 'white',
- boxShadow: '0px 3px 6px #00000029',
- borderColor: '#FFFFFF66',
- borderRadius: 14
- },
- item: {
- paddingLeft: 8,
- borderLeftWidth: 1,
- borderColor: '#cecece',
- marginBottom: 4,
- marginTop: 4
- },
- itemIndex: {
- fontSize: 12,
- opacity: 0.4
- }
- })
|