Skip to content
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

onRangeChange: new argument #1100

Merged
merged 1 commit into from
Nov 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,14 @@ class Calendar extends React.Component {
onDrillDown: PropTypes.func,

/**
*
* ```js
* (dates: Date[] | { start: Date; end: Date }, view?: 'month'|'week'|'work_week'|'day'|'agenda') => void
* ```
*
* Callback fired when the visible date range changes. Returns an Array of dates
* or an object with start and end dates for BUILTIN views.
* or an object with start and end dates for BUILTIN views. Optionally new `view`
* will be returned when callback called after view change.
*
* Custom views may return something different.
*/
Expand Down Expand Up @@ -903,12 +909,21 @@ class Calendar extends React.Component {
)
}

handleRangeChange = (date, view) => {
/**
*
* @param date
* @param viewComponent
* @param {'month'|'week'|'work_week'|'day'|'agenda'} [view] - optional
* parameter. It appears when range change on view changing. It could be handy
* when you need to have both: range and view type at once, i.e. for manage rbc
* state via url
*/
handleRangeChange = (date, viewComponent, view) => {
let { onRangeChange, localizer } = this.props

if (onRangeChange) {
if (view.range) {
onRangeChange(view.range(date, { localizer }))
if (viewComponent.range) {
onRangeChange(viewComponent.range(date, { localizer }), view)
} else {
warning(true, 'onRangeChange prop not supported for this view')
}
Expand Down Expand Up @@ -937,7 +952,7 @@ class Calendar extends React.Component {
}

let views = this.getViews()
this.handleRangeChange(this.props.date, views[view])
this.handleRangeChange(this.props.date, views[view], view)
}

handleSelectEvent = (...args) => {
Expand Down