从“react”导入 { React, useState }; 从“dayjs”导入dayjs; 从“@mui/material”导入{Box,TextField}; 从“../pages/index.mjs”导入{加载}; 从“./index.mjs”导入{EventCard}; 从“@mui/x-date-pickers/AdapterDayjs”导入{ AdapterDayjs }; 从“@mui/x-date-pickers/LocalizationProvider”导入{ LocalizationProvider }; 从“@mui/x-date-pickers/StaticDatePicker”导入{ StaticDatePicker }; 从“../hooks/useEvent.mjs”导入{useReadAllEvent}; 从“@mui/x-date-pickers”导入{ PickersDay }; 从“@mui/material”导入{徽章}; const SessionBooking = ({ 医生 }) =>; { const [值,setValue] = useState(“”); const [highlightDays, setHighlightDays] = useState([ “2023年6月1日”, “2023年6月2日”, “2023年6月4日”, ]); 控制台.log(值); const { 数据: eventSet, isLoading } = useReadAllEvent({ onSuccess: (消息) => {}, onError: (消息) => {}, 会话:{ id:医生,今天:dayjs().format(“YYYY-MM-DD”) }, }); if (isLoading) return <正在加载/>; 控制台.log(事件集); 常量事件 = eventSet.map( ({ key, countPatient, start, end, maxPatients }) =>; ( <活动卡 键={键} 开始={开始} 结束={结束} 患者={countPatient} 最大值={最大患者} >> ) ); 返回 ( <盒子 MT={2} SX={{ 显示:“网格”, 网格模板列:{ xs: "重复(1, 1fr)", sm: "重复(1, 1fr)", md: "重复(2, 1fr)", }, 间隙:1, }} > <盒子> <LocalizationProvider dateAdapter={AdapterDayjs}> <静态日期选择器 方向=“纵向” openTo="日"; 值={值} onChange={(newValue) =>; { 设置值(新值); }} renderInput={(params) =>;} renderDay={(day, _value, DayComponentProps) =>; { const isSelected = !DayComponentProps.outsideCurrentMonth && highlightDays.includes(dayjs(day).format(“YYYY-MM-DD”)); 返回 ( <徽章 key={day.toString()} 重叠=“圆形” 徽章内容={已选择? “-” : 不明确的}颜色=“原色” > /> </徽章> ); }} >> </本地化提供商> </框> {事件} </框> ); }; 导出默认SessionBooking;</pre> <pre class="brush:php;toolbar:false;"></pre></p>
P粉8183062802023-08-31 11:54:52
就像 steve 所说的
在新版本中不接受 renderDay 属性。相反必须使用插槽。 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;