Maison > Questions et réponses > le corps du texte
P粉8183062802023-08-31 11:54:52
Comme Steve l'a dit, l'attribut renderDay n'est pas accepté dans la nouvelle version. Des emplacements doivent être utilisés à la place. Code pour StaticDatePicker
import React, { useState } from "react"; import dayjs from "dayjs"; import { useReadAllEvent } from "../hooks/useEvent.mjs"; import { Box } from "@mui/material"; import { styled } from "@mui/material/styles"; import { Loading } from "../pages/index.mjs"; import { EventCard } from "./index.mjs"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"; import { PickersDay } from "@mui/x-date-pickers/PickersDay"; import { StaticDatePicker } from "@mui/x-date-pickers/StaticDatePicker"; const HighlightedDay = styled(PickersDay)(({ theme }) => ({ "&.Mui-selected": { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, }, })); //higlight the dates in highlightedDays arra const ServerDay = (props) => { const { highlightedDays = [], day, outsideCurrentMonth, ...other } = props; const isSelected = !props.outsideCurrentMonth && highlightedDays.includes(day.format("YYYY-MM-DD")); return ( <HighlightedDay {...other} outsideCurrentMonth={outsideCurrentMonth} day={day} selected={isSelected} /> ); }; const SessionBooking = ({ doctor }) => { const [value, setValue] = useState(""); const [highlightedDays, setHighlitedDays] = useState([ "2023-07-01", "2023-07-09", "2023-07-21", "2024-07-12", ]); const today = dayjs(); return ( <Box> <LocalizationProvider dateAdapter={AdapterDayjs}> <StaticDatePicker defaultValue={today} minDate={today} maxDate={today.add(1, "month")} slots={{ day: ServerDay, }} slotProps={{ day: { highlightedDays, }, }} /> </LocalizationProvider> </Box> ); }; export default SessionBooking;