Files
GeneIT/geneit_app/src/widgets/forms/PropEdit.tsx
Pierre HUBERT 1a890844ef
All checks were successful
continuous-integration/drone/push Build is passing
Add an accommodations reservations module (#188)
Add a new module to enable accommodations reservation

![](https://gitea.communiquons.org/attachments/de1f5b12-0a93-40f8-b29d-97665daa6fd5)

Reviewed-on: #188
2024-06-22 21:30:26 +00:00

52 lines
1.2 KiB
TypeScript

import { TextField } from "@mui/material";
import { LenConstraint } from "../../api/ServerApi";
/**
* Couple / Member property edition
*/
export function PropEdit(p: {
label: string;
editable: boolean;
value?: string;
onValueChange?: (newVal: string | undefined) => void;
size?: LenConstraint;
checkValue?: (s: string) => boolean;
multiline?: boolean;
minRows?: number;
maxRows?: number;
helperText?: string;
}): React.ReactElement {
if (((!p.editable && p.value) ?? "") === "") return <></>;
return (
<TextField
label={p.label}
value={p.value}
onChange={(e) =>
p.onValueChange?.(
e.target.value.length === 0 ? undefined : e.target.value
)
}
inputProps={{
maxLength: p.size?.max,
}}
InputProps={{
readOnly: !p.editable,
}}
variant={p.editable ? "filled" : "standard"}
style={{ width: "100%", marginBottom: "15px" }}
multiline={p.multiline}
minRows={p.minRows}
maxRows={p.maxRows}
error={
(p.checkValue &&
p.value &&
p.value.length > 0 &&
!p.checkValue(p.value)) ||
false
}
helperText={p.helperText}
/>
);
}