import "./InputList.css"; import FormHelperText from "@mui/material/FormHelperText"; import InputLabel from "@mui/material/InputLabel"; import MenuItem from "@mui/material/MenuItem"; import FormControl from "@mui/material/FormControl"; import Select from "@mui/material/Select"; import { prettyName } from "utils/formatting"; import { ReactNode } from "react"; import { useLang } from "services/lang"; export type Props = { current?: T; options: readonly T[]; onChange: (n: T) => void; label: string; id?: string; className?: string; prettyOptionLabels?: boolean; getKey?: (n: T) => string; getLabel?: (n: T) => string; getDescription?: (n: T) => string; placeholder?: any; title?: string; helperText?: string; endAdornment?: ReactNode; disabled?: boolean; fullWidth?: boolean; }; export function InputList({ current, options, onChange, label, id, className, prettyOptionLabels = true, getKey = String, getLabel: _getLabel, getDescription, placeholder, title, helperText, endAdornment, disabled, fullWidth = true, }: Props) { const langStore = useLang(); const invalidCurrent = current && !options.map(getKey).includes(getKey(current)); const getLabel = _getLabel ?? function (x: T) { return typeof x === "string" ? prettyName(langStore.get(x.toUpperCase())) : getKey(x); }; return ( {label} {invalidCurrent ? `'${current}' is not a valid selection` : helperText} ); }