简体   繁体   English

更改日历日期的颜色(反应大日历)

[英]Change the color of calendar dates (react big calendar)

I'm using react big calendar and need to change the color of the text for dark mode.我正在使用反应大日历,需要更改暗模式文本的颜色。 The background color changes of the calendar changes, however the text color of date doesn't change.日历的背景颜色会发生变化,但日期的文本颜色不会发生变化。 How to make it work?如何使它工作?

const calendarStyle = () => {
    return {
      style: {
        backgroundColor: 'red', //this works
        color: 'green' //but why doesn't this work?
      }
    }
}   

<Calendar
      localizer={localizer}
      events={eventsData}
      startAccessor="start"
      endAccessor="end"
      style={{ height: 500 }}
      views={{ month: true }}
      step={155}
      dayPropGetter={calendarStyle}
/>

Moreover how to change the color of the headers like sun, mon etc and back, next button as well.此外,如何更改太阳、星期一等标题的颜色,以及返回、下一个按钮的颜色。

在此处输入图片说明

Use style property of calendar使用日历的样式属性

<Calendar
      style={{ height: 500 ,color:'#fff' }}
      localizer={localizer}
      events={eventsData}
      startAccessor="start"
      endAccessor="end"
      views={{ month: true }}
      step={155}
      dayPropGetter={calendarStyle}
/>

You can change them via passing components with the components prop of the react-big-calendar.您可以通过使用 react-big-calendar 的 components 属性传递组件来更改它们。 For example:例如:

<Calendar
  className={classes.calendar}
  localizer={localizer}
  events={events}
  startAccessor="start"
  endAccessor="end"
  dayPropGetter={getDayProps}
  eventPropGetter={getEventProps}
  components={{
    event: CalendarEvent,
    month: {
      header: HeaderCellContent,
      dateHeader: DateCellContent,
    },
  }}
/>

Example of the HeaderCellContent component: HeaderCellContent组件的示例:

const HeaderCellContent: React.FC<any> = (props: any) => {
  const { date } = props;
  const classes = useStyles();
  const dayOfWeek = date.getDay();

  const className = dayOfWeek === 0 || dayOfWeek === 6 ? classes.day_weekend : classes.day_working;
  return (
    <Box component="span" className={className}>
      {props.label}
    </Box>
  );
};

With the className or style props in the example above you can pass your own styles to the content of each header cells, and dateHeader is for customizing the content of the calendar days.使用上面示例中的classNamestyle道具,您可以将自己的样式传递给每个标题单元格的内容,而dateHeader用于自定义日历日的内容。

I couldn't find much info about components prop but since I'm using typescript I found the details through inspecting the types file, I'm including the link below.我找不到关于 components prop 的太多信息,但是由于我使用的是 typescript,所以我通过检查类型文件找到了详细信息,我在下面包含了链接。

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM