繁体   English   中英

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

[英]Change color of react-big-calendar events

我需要制作一个包含事件的日历,我决定使用react-big-calendar 但我需要制作不同颜色的事件。 所以每个事件都会有一些类别,每个类别都有相应的颜色。 如何通过反应更改事件的颜色? react-big-calendar 同色示例

结果应该是这样的react-big-calendar 不同颜色的例子

抱歉,我没有很好地阅读文档。 它可以在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
      };
    }
  }
/>

这个解决方案很简单!

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

根据您的需要更改条件并完成。

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

border: "black",
borderStyle: "solid"

我需要制作带有事件的日历,因此决定使用react-big-calendar 但是我需要制作不同颜色的事件。 因此,每个事件将具有某个类别,并且每个类别具有对应的颜色。 如何使用react更改事件的颜色? react-big-calendar相同颜色的示例

结果应该是这样的react-big-calendar不同颜色的示例

Siva Surya 的解决方案是最快的,我也添加了颜色属性。 谢谢...

import React, {useEffect, useLayoutEffect} from 'react';
import { Calendar, momentLocalizer,globalizeLocalizer } from 'react-big-calendar'
import moment from 'moment';
import { connect } from 'frontity';
import BackgroundWrapper from 'react-big-calendar/lib/BackgroundWrapper';

const MyCalendar = ({ actions, state, objetoBloque, formato }) => {

const localizer = momentLocalizer(moment);
const myEventsList = [
  {
    title: 'My Event',
    start: '2022-06-21T13:45:00-05:00',
    end: '2022-06-25T14:00:00-05:00',
    // elcolor:'red'
    colorEvento:'red'
  },
  {
    title: 'Otro',
    start: '2022-06-15T13:45:00-05:00',
    end: '2022-06-23T14:00:00-05:00',
    colorEvento:'green',
    color:'white'
  }
];
    return(
        <div>
        <Calendar
        // defaultDate = {defaultDate}
          localizer={localizer}
          events={myEventsList}
          startAccessor="start"
          endAccessor="end"
          style={{ height: 500 }}
          BackgroundWrapper = "red"
          eventPropGetter={(myEventsList) => {
            const backgroundColor = myEventsList.colorEvento ? myEventsList.colorEvento : 'blue';
            const color = myEventsList.color ? myEventsList.color : 'blue';
            return { style: { backgroundColor ,color} }
          }}
          
        />
      </div>

    )

}
export default connect(MyCalendar);

暂无
暂无

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

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