改变反应大日历事件的颜色

时间:2016-01-04 08:19:28

标签: javascript reactjs calendar

我需要制作一个包含活动的日历,我决定使用react-big-calendar。但我需要制作不同颜色的活动。因此每个事件都有一些类别,每个类别都有相应的颜色。如何通过反应改变事件的颜色? react-big-calendar same color example

结果应该类似于react-big-calendar different colors example

5 个答案:

答案 0 :(得分:40)

抱歉,我还没有读好文档。可以在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>
    );
}

答案 1 :(得分:8)

关于如何设置不同类型事件样式的附加提示:在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
      };
    }
  }
/>

答案 2 :(得分:0)

搜索如何更改事件的边框颜色也将我引到了这里,我在其他任何地方都找不到答案,但是发现添加以下内容可以解决问题:

border: "black",
borderStyle: "solid"

答案 3 :(得分:0)

您甚至可以在eventPropGetter中返回className以获取特定类的特定样式。

答案 4 :(得分:0)

这个解决方案很简单!

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

根据您的需要更改条件即可。