import { Box, TextField } from "@mui/material"; import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; import dayjs, { Dayjs } from "dayjs"; import "dayjs/locale/fr"; import { TimepickerSpecificProps } from "interface"; import React, { memo, useCallback, useEffect } from "react"; import { makeStylesEdt } from "../../theme"; export type DatepickerProps = { value?: string; onChange(value: string | null): void; label?: string; tipsLabel?: string; id?: string; min?: string; max?: string; componentSpecificProps?: TimepickerSpecificProps; }; const Datepicker = memo((props: DatepickerProps) => { let { id, onChange, value, tipsLabel, componentSpecificProps } = props; const { classes } = useStyles(); const [valueLocal, setValueLocal] = React.useState(dayjs(value ?? dayjs())); useEffect(() => { onChange(valueLocal?.format("YYYY-MM-DD") || null); }, []); function setValueLunatic(newValue: Dayjs) { setValueLocal(newValue); onChange(newValue?.format("YYYY-MM-DD") || null); } return ( <> {tipsLabel && ( )} { setValueLunatic(newValue ? dayjs(newValue) : dayjs()); }, [])} renderInput={useCallback( params => ( ), [], )} componentsProps={{ actionBar: { actions: ["accept"], }, }} className={classes.input} showToolbar={false} /> ); }); const useStyles = makeStylesEdt({ "name": { Datepicker } })(() => ({ input: { width: "100%", legend: { display: "none", }, }, labelSpacer: { marginBottom: "1rem", }, })); export default Datepicker;