-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add background events feature #1851
Changes from 14 commits
11bcbc8
6b92983
e029e77
458bb99
84164ea
b0079bf
841a436
f6f7f92
0a00e77
4c196ee
e62b716
c9ed1e8
16e2100
0df77cb
559663e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default [ | ||
{ | ||
id: 0, | ||
title: 'Available for Clients', | ||
start: new Date(2015, 3, 13, 6), | ||
end: new Date(2015, 3, 13, 18), | ||
}, | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react' | ||
import { Calendar, Views } from 'react-big-calendar' | ||
import events from '../events' | ||
import backgroundEvents from '../backgroundEvents' | ||
import * as dates from '../../src/utils/dates' | ||
|
||
let allViews = Object.keys(Views).map(k => Views[k]) | ||
|
||
let Basic = ({ localizer }) => ( | ||
<Calendar | ||
events={events} | ||
defaultView={Views.DAY} | ||
views={allViews} | ||
step={60} | ||
showMultiDayTimes | ||
max={dates.add(dates.endOf(new Date(2015, 17, 1), 'day'), -1, 'hours')} | ||
defaultDate={new Date(2015, 3, 13)} | ||
localizer={localizer} | ||
backgroundEvents={backgroundEvents} | ||
dayLayoutAlgorithm={'no-overlap'} | ||
/> | ||
) | ||
|
||
export default Basic |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ function TimeGridEvent(props) { | |
getters, | ||
onClick, | ||
onDoubleClick, | ||
isBackgroundEvent, | ||
onKeyPress, | ||
components: { event: Event, eventWrapper: EventWrapper }, | ||
} = props | ||
|
@@ -40,29 +41,44 @@ function TimeGridEvent(props) { | |
</div>, | ||
] | ||
|
||
const eventStyle = isBackgroundEvent | ||
? { | ||
...userProps.style, | ||
top: stringifyPercent(top), | ||
height: stringifyPercent(height), | ||
width: `calc(${width}% + 10px)`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the additional 10px here to compensate for the right margin on events? It might be worth adding a comment to explain why we need this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Also, there was a small inconsistency causing these events to not render at 100% width of the column. I'll add a comment and fix this behavior. Also, I'll update the examples screenshots. |
||
[rtl ? 'right' : 'left']: stringifyPercent(Math.max(0, xOffset)), | ||
} | ||
: { | ||
...userProps.style, | ||
top: stringifyPercent(top), | ||
width: stringifyPercent(width), | ||
height: stringifyPercent(height), | ||
[rtl ? 'right' : 'left']: stringifyPercent(xOffset), | ||
} | ||
|
||
return ( | ||
<EventWrapper type="time" {...props}> | ||
<div | ||
onClick={onClick} | ||
onDoubleClick={onDoubleClick} | ||
style={eventStyle} | ||
onKeyPress={onKeyPress} | ||
style={{ | ||
...userProps.style, | ||
top: stringifyPercent(top), | ||
[rtl ? 'right' : 'left']: stringifyPercent(xOffset), | ||
width: stringifyPercent(width), | ||
height: stringifyPercent(height), | ||
}} | ||
title={ | ||
tooltip | ||
? (typeof label === 'string' ? label + ': ' : '') + tooltip | ||
: undefined | ||
} | ||
className={clsx('rbc-event', className, userProps.className, { | ||
'rbc-selected': selected, | ||
'rbc-event-continues-earlier': continuesEarlier, | ||
'rbc-event-continues-later': continuesLater, | ||
})} | ||
className={clsx( | ||
isBackgroundEvent ? 'rbc-background-event' : 'rbc-event', | ||
className, | ||
userProps.className, | ||
{ | ||
'rbc-selected': selected, | ||
'rbc-event-continues-earlier': continuesEarlier, | ||
'rbc-event-continues-later': continuesLater, | ||
} | ||
)} | ||
> | ||
{inner} | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observation/Suggestion: It feels like the
isBackgroundEvent
property here may be confusing since the name is singular, but it applies to all events passed in.How do we feel about keeping the current state where
renderEvents
doesn't accept arguments, and instead we get bothevents
andbackgroundEvents
from the props withinrenderEvents
and merge them into a single collection of events such that background events have a propertyisBackgroundEvent
set to true?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merging
events
andbackgroundEvents
will causeno-overlap
algorithm to treat them as colliding events, and place them next to each other instead of one on top of each other.