更改 react-big-calendar 事件的颜色

Change color of react-big-calendar events

我需要制作一个包含活动的日历,因此我决定使用 react-big-calendar. But I need to make events of different colors. So each event will have some category and each category has corresponding color. How can I change the color of the event with react?

结果应该是这样的

抱歉,我没有仔细阅读文档。它可以在 eventPropGetter 属性的帮助下完成。我是这样做的:

eventStyleGetter: function(event, start, end, isSelected) {
    console.log(event);
    var backgroundColor = '#' + event.hexColor;
    var style = {
        backgroundColor: backgroundColor,
        borderRadius: '0px',
        opacity: 0.8,
        color: 'black',
        border: '0px',
        display: 'block'
    };
    return {
        style: style
    };
},

render: function () {

    return (
        <Layout active="plan" title="Planning">
            <div className="content-app fixed-header">
                <div className="app-body">
                    <div className="box">
                        <BigCalendar
                            events={this.events}
                            defaultDate={new Date()}
                            defaultView='week'
                            views={[]}
                            onSelectSlot={(this.slotSelected)}
                            onSelectEvent={(this.eventSelected)}
                            eventPropGetter={(this.eventStyleGetter)}
                            />
                    </div>
                </div>
            </div>
        </Layout>
    );
}

关于如何设置不同类型事件样式的其他提示:在 myEvents 事件对象数组中,我给每个对象一个布尔值 属性 isMine,然后我定义了:

<BigCalendar

  // other props here

  eventPropGetter={
    (event, start, end, isSelected) => {
      let newStyle = {
        backgroundColor: "lightgrey",
        color: 'black',
        borderRadius: "0px",
        border: "none"
      };

      if (event.isMine){
        newStyle.backgroundColor = "lightgreen"
      }

      return {
        className: "",
        style: newStyle
      };
    }
  }
/>

搜索如何更改事件的边框颜色也把我带到了这里,我在其他地方找不到答案,但发现添加以下内容就可以了:

border: "black",
borderStyle: "solid"

这个解决方案很简单!

eventPropGetter={(event) => {
  const backgroundColor = event.allday ? 'yellow' : 'blue';
  return { style: { backgroundColor } }
}}

根据需要更改条件,完成。