import React from 'react'; import FormControl from '@mui/material/FormControl'; import Grid from '@mui/material/Grid'; import InputLabel from '@mui/material/InputLabel'; import MenuItem from '@mui/material/MenuItem'; import Select from '@mui/material/Select'; import TextField from '@mui/material/TextField'; function isCustomOption(value, options) { for (let o of options) { if (o.value === value) { return false; } } return true; } export default function Component(props) { const [$value, setValue] = React.useState({ value: props.value, isCustom: isCustomOption(props.value, props.options), custom: isCustomOption(props.value, props.options) === true ? props.value : '', }); const handleChange = (event) => { const v = event.target.value; const value = $value; value.isCustom = v === props.customKey ? true : false; if (value.isCustom === true) { value.custom = value.value; } value.value = v; setValue({ ...$value, value: v, isCustom: v === props.customKey ? true : false, }); props.onChange(event); }; const handleCustomChange = (event) => { setValue({ ...$value, custom: event.target.value, }); props.onChange(event); }; const options = []; for (let o of props.options) { options.push( {o.label} ); } return ( {props.allowCustom === true ? ( {$value.isCustom === true ? ( {props.label} ) : ( {props.label} )} ) : ( {props.label} )} ); } Component.defaultProps = { variant: 'outlined', label: '', value: '', disabled: false, customKey: 'custom', allowCustom: false, onChange: function (event) {}, };