dptoot / react-event-calendar

A React calendar component to display events
131 stars 55 forks source link

Display more than 10 events per day #2

Closed optilude closed 8 years ago

optilude commented 8 years ago

Appreciate this isn't supported yet, but it's something I need ;)

Any hints on how to go about implementing this?

optilude commented 8 years ago

There is a pretty crude way to do this:

If we introduce a new prop maxSlots that defaults to 10 and then change getCalendarDays() as below, it's possible to pass maxSlots={100} and get up to 100 events per day.

    getCalendarDays() {
        let maxSlots = this.props.maxSlots || defaultProps.maxSlots;
        return this.calendar.getCalendar(this.props.year, this.props.month).map((day) => {
            day.eventSlots = []
            for(var i = 0; i < maxSlots; ++i) {
                day.eventSlots.push(false);
            }

            return day;
        });
    }

It'd be nicer if the calendar worked out the required max slots itself though!

dptoot commented 8 years ago

Originally I had Array.fill doing the hard work for us here butit seemed like overkill to require an ES6 polyfill just for that. I agree that hardcoding to 10 is not a great idea. Your solution is a good enough replacement for now to alow a maxSlots if you want to vary it. Ideally there should be no maxSlot only maxVisibleSlots. I am just not sure how to address displaying consecutive days with hidden events. There is no real reason that we can't allow the component to determine number of slots required and then let you limit with your suggested prop. I will look to add maxSlots functionality shortly.

optilude commented 8 years ago

See above for my slightly hacky implementation.

dptoot commented 8 years ago

6 months seems like a good enough time for me to revisit this. :smile: Let me see how I think we should handle a dynamic set of slots.

dptoot commented 8 years ago

I have addressed this in version 0.2.7. A user can declare a maxEventSlot parameter that defaults to 10. Caveat is that currently any event after that index is removed from all event displays.