React Big Calendar how to style a single day in the month view

后端 未结 1 1875
耶瑟儿~
耶瑟儿~ 2021-02-10 05:42

So as seen on the picture, I want to style individual events.

Example of how it should look

With the slotpropgetter it\'s possible to conditionally render styles

1条回答
  •  暖寄归人
    2021-02-10 05:50

    The components prop can be used to individually change how parts of the calendar are rendered:

    import React, {Children} from 'react';
    import BigCalendar from 'react-big-calendar';
    import moment from 'moment';
    
    BigCalendar.momentLocalizer(moment);
    
    const CURRENT_DATE = moment().toDate();
    
    // example implementation of a wrapper
    const ColoredDateCellWrapper = ({children, value}) =>
        React.cloneElement(Children.only(children), {
            style: {
                ...children.style,
                backgroundColor: value < CURRENT_DATE ? 'lightgreen' : 'lightblue',
            },
        });
    
    const MyCalendar = props => (
        
    );

    Working Example:

    It has the following type definition:

    {
      event?: ReactClass,
      eventWrapper?: ReactClass,
      dayWrapper?: ReactClass,
      dateCellWrapper?: ReactClass,
      toolbar?: ReactClass,
      agenda?: {
        date?: ReactClass,
        time?: ReactClass,
        event?: ReactClass
      },
      day?: {
        header?: ReactClass,
        event?: ReactClass
      },
      week?: {
        header?: ReactClass,
        event?: ReactClass
      },
      month?: {
        header?: ReactClass,
        dateHeader?: ReactClass,
        event?: ReactClass
      }
    }
    

    0 讨论(0)
提交回复
热议问题