import type { FieldProps } from "formik"; import { Field } from "formik"; import Select, { components, ControlProps, InputProps, MenuProps, OptionProps } from "react-select"; import { OptionBasicTyped } from "../../domain/constants"; import CreatableSelect from "react-select/creatable"; import { CustomTooltip } from "../tooltips/CustomTooltip"; interface SelectFieldProps { name: string; label: string; help?: string; placeholder?: string; defaultValue?: OptionBasicTyped; tooltip?: JSX.Element; options: OptionBasicTyped[]; } export function SelectFieldCreatable({ name, label, help, placeholder, tooltip, options }: SelectFieldProps) { return (
{({ field, form: { setFieldValue } }: FieldProps) => ( ({ ...base, color: "unset" }) }} theme={(theme) => ({ ...theme, spacing: { ...theme.spacing, controlHeight: 30, baseUnit: 2 } })} // value={field?.value ? field.value : options.find(o => o.value == field?.value)} value={field?.value ? { value: field.value, label: field.value } : field.value} onChange={(option) => { if (option === null) { setFieldValue(field.name, ""); return; } else { setFieldValue(field.name, option.value ?? ""); } }} options={[...[...options, { value: field.value, label: field.value }].reduce((map, obj) => map.set(obj.value, obj), new Map()).values()]} /> )} {help && (

{help}

)}
); } const Input = (props: InputProps) => { return ( ); }; const Control = (props: ControlProps) => { return ( ); }; const Menu = (props: MenuProps) => { return ( ); }; const Option = (props: OptionProps) => { return ( ); }; export function SelectField({ name, label, help, placeholder, options }: SelectFieldProps) { return (
{({ field, form: { setFieldValue } }: FieldProps) => ( ({ ...base, color: "unset" }) }} theme={(theme) => ({ ...theme, spacing: { ...theme.spacing, controlHeight: 30, baseUnit: 2 } })} defaultValue={defaultValue} value={field?.value && options.find(o => o.value == field?.value)} onChange={(option) => { if (option === null) { setFieldValue(field.name, ""); return; } else { setFieldValue(field.name, option.value ?? ""); } }} options={options} /> )} {help && (

{help}

)}
); }