link-stack/packages/ui/components/Autocomplete.tsx

43 lines
966 B
TypeScript
Raw Permalink Normal View History

2024-05-09 07:42:44 +02:00
import { FC } from "react";
import { TextField, Autocomplete as AutocompleteInternal } from "@mui/material";
import { colors } from "../styles/theme";
type AutocompleteProps = {
name: string;
label: string;
options: any[];
formState: Record<string, any>;
updateFormState: (name: string, value: any) => void;
2024-05-09 07:42:44 +02:00
disabled?: boolean;
required?: boolean;
};
export const Autocomplete: FC<AutocompleteProps> = ({
name,
label,
options,
formState,
updateFormState,
2024-05-09 07:42:44 +02:00
disabled = false,
required = false,
}) => (
<AutocompleteInternal
disablePortal
options={options}
value={formState.values[name] || ""}
onChange={(e: any) => updateFormState?.(name, e.target.id)}
2024-05-09 07:42:44 +02:00
fullWidth
size="small"
renderInput={(params) => (
<TextField
{...params}
name={name}
2024-05-09 07:42:44 +02:00
label={label}
disabled={disabled}
required={required}
sx={{ backgroundColor: colors.white }}
/>
)}
/>
);