admin管理员组文章数量:1202776
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.
slotPropGetter = date => {
const CURRENT_DATE = moment().toDate();
let backgroundColor;
if (moment(date).isBefore(CURRENT_DATE, "month")) {
backgroundColor = "#f7f8f9";
}
var style = {
backgroundColor
};
return {
style: style
};
};
So the "solution" is the DateCellWrapper, it either doesn't work for me, or I've implemented it in the wrong way
const DateCellWrapper = ({ value, children }) => {
console.log("DateCellWrapper")
const style = {
backgroundColor: "#000",
};
return (
<div style={style}>{children}</div>
);
}
It doesn't even output my console.log, so.. anyone an idea? :p
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.
slotPropGetter = date => {
const CURRENT_DATE = moment().toDate();
let backgroundColor;
if (moment(date).isBefore(CURRENT_DATE, "month")) {
backgroundColor = "#f7f8f9";
}
var style = {
backgroundColor
};
return {
style: style
};
};
So the "solution" is the DateCellWrapper, it either doesn't work for me, or I've implemented it in the wrong way
const DateCellWrapper = ({ value, children }) => {
console.log("DateCellWrapper")
const style = {
backgroundColor: "#000",
};
return (
<div style={style}>{children}</div>
);
}
It doesn't even output my console.log, so.. anyone an idea? :p
Share Improve this question edited Apr 19, 2018 at 14:29 Ignacio Ara 2,5822 gold badges27 silver badges37 bronze badges asked Apr 19, 2018 at 13:01 mokimomokimo 731 gold badge1 silver badge3 bronze badges 1- So if its not outputting your console log code, it means; app doesnt even recognize DataCellWrapper and its not rendering it. You should start to solve this render problem first. I think if you can make your app render DataCellWrapper which must be easy, you can solve your problem on your own. – jrSakizci Commented Apr 19, 2018 at 13:14
1 Answer
Reset to default 23The 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 => (
<div style={{height: '100vh', margin: '10px'}}>
<BigCalendar
events={[]}
startAccessor="startDate"
endAccessor="endDate"
components={{
// you have to pass your custom wrapper here
// so that it actually gets used
dateCellWrapper: ColoredDateCellWrapper,
}}
/>
</div>
);
Working Example:
It has the following type definition:
{
event?: ReactClass<any>,
eventWrapper?: ReactClass<any>,
dayWrapper?: ReactClass<any>,
dateCellWrapper?: ReactClass<any>,
toolbar?: ReactClass<any>,
agenda?: {
date?: ReactClass<any>,
time?: ReactClass<any>,
event?: ReactClass<any>
},
day?: {
header?: ReactClass<any>,
event?: ReactClass<any>
},
week?: {
header?: ReactClass<any>,
event?: ReactClass<any>
},
month?: {
header?: ReactClass<any>,
dateHeader?: ReactClass<any>,
event?: ReactClass<any>
}
}
本文标签: javascriptReact Big Calendar how to style a single day in the month viewStack Overflow
版权声明:本文标题:javascript - React Big Calendar how to style a single day in the month view - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738637931a2104145.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论