import React from "react"; import { View, StyleSheet, StyleProp, ViewStyle, TextStyle, } from "react-native"; import omit from "lodash.omit"; import { extractPositionStyles, extractFlexItemStyles, extractBorderAndMarginStyles, } from "../../utilities"; import TextField from "../TextField"; import Touchable from "../Touchable"; import { PickerInputContainerProps as ExposedPickerInputContainerProps, PickerOption, } from "./PickerCommon"; interface PickerInputContainerProps extends ExposedPickerInputContainerProps { selectedValue?: string | number | (string | number)[]; options: PickerOption[]; zIndex?: number; onPress?: () => void; testID?: string; } const PickerInputContainer: React.FC< React.PropsWithChildren > = ({ options = [], onPress, Icon, className, style, selectedValue, disabled = false, zIndex, children, testID, ...rest }) => { const containerStyle = StyleSheet.flatten([ extractPositionStyles(style), extractFlexItemStyles(style), extractBorderAndMarginStyles(style).marginStyles, ]); const textFieldStyle = omit( StyleSheet.flatten(style), Object.keys(containerStyle) ); let selectedLabel: string | number | undefined = ""; if (Array.isArray(selectedValue)) { selectedLabel = selectedValue .map( (value) => options .find((option) => option.value.toString() === value.toString()) ?.label.toString() || value ) .join(", "); } else { selectedLabel = options .find((option) => option.value.toString() === selectedValue?.toString()) ?.label.toString() || selectedValue; } return ( {}} value={selectedLabel?.toString()} editable={false} disabled={disabled} style={textFieldStyle as StyleProp} {...rest} /> {children} ); }; export default PickerInputContainer;