1import React from 'react'; 2import { StyleSheet, View } from 'react-native'; 3 4import ConfiguratorChoice from './ConfiguratorChoice'; 5import { 6 FunctionArgument, 7 FunctionParameter, 8 OnArgumentChangeCallback, 9 PrimitiveArgument, 10} from './index.types'; 11 12type Props = { 13 parameters: FunctionParameter[]; 14 value: FunctionArgument[]; 15 onChange: OnArgumentChangeCallback; 16}; 17 18export default function Configurator({ parameters, value, onChange }: Props) { 19 return ( 20 <View style={styles.container}> 21 {parameters.map((parameter, index) => 22 parameter.type === 'constant' ? null : parameter.type === 'object' ? ( 23 parameter.properties.map(({ name, ...properties }) => ( 24 <ConfiguratorChoice 25 {...properties} 26 name={[parameter.name, name]} 27 key={`${parameter.name}.${name}`} 28 value={(value[index] as Record<string, PrimitiveArgument>)[name]} 29 onChange={onChange} 30 /> 31 )) 32 ) : ( 33 <ConfiguratorChoice 34 {...parameter} 35 key={parameter.name} 36 value={value[index] as PrimitiveArgument} 37 onChange={onChange} 38 /> 39 ) 40 )} 41 </View> 42 ); 43} 44 45const styles = StyleSheet.create({ 46 container: { 47 marginVertical: 5, 48 }, 49}); 50