Skip to content

Commit

Permalink
Add tooltipAccessor prop to calendar to disable tooltip if needed (#701)
Browse files Browse the repository at this point in the history
* add tooltip accessor

* fix pr reviews
  • Loading branch information
ginifizz authored and jquense committed Feb 5, 2018
1 parent 2c5a7a5 commit 9c9490f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Agenda.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Agenda extends React.Component {
date: PropTypes.instanceOf(Date),
length: PropTypes.number.isRequired,
titleAccessor: accessor.isRequired,
tooltipAccessor: accessor.isRequired,
allDayAccessor: accessor.isRequired,
startAccessor: accessor.isRequired,
endAccessor: accessor.isRequired,
Expand Down
13 changes: 13 additions & 0 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ class Calendar extends React.Component {
*/
titleAccessor: accessor,

/**
* Accessor for the event tooltip. Should
* resolve to a `renderable` value. Removes the tooltip if null.
*
* ```js
* string | (event: Object) => string
* ```
*
* @type {(func|string)}
*/
tooltipAccessor: accessor,

/**
* Determines whether the event should be considered an "all day" event and ignore time.
* Must resolve to a `boolean` value.
Expand Down Expand Up @@ -658,6 +670,7 @@ class Calendar extends React.Component {
drilldownView: views.DAY,

titleAccessor: 'title',
tooltipAccessor: 'title',
allDayAccessor: 'allDay',
startAccessor: 'start',
endAccessor: 'end',
Expand Down
9 changes: 8 additions & 1 deletion src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DayColumn extends React.Component {

rtl: PropTypes.bool,
titleAccessor: accessor,
tooltipAccessor: accessor,
allDayAccessor: accessor.isRequired,
startAccessor: accessor.isRequired,
endAccessor: accessor.isRequired,
Expand Down Expand Up @@ -166,6 +167,7 @@ class DayColumn extends React.Component {
step,
timeslots,
titleAccessor,
tooltipAccessor,
} = this.props

let styledEvents = getStyledEvents({
Expand Down Expand Up @@ -202,6 +204,7 @@ class DayColumn extends React.Component {
let continuesAfter = startsAfter(end, max)

let title = get(event, titleAccessor)
let tooltip = get(event, tooltipAccessor)
let label
if (_continuesPrior && _continuesAfter) {
label = messages.allDay
Expand Down Expand Up @@ -231,7 +234,11 @@ class DayColumn extends React.Component {
[isRtl ? 'right' : 'left']: `${Math.max(0, xOffset)}%`,
width: `${width}%`,
}}
title={(typeof label === 'string' ? label + ': ' : '') + title}
title={
tooltip
? (typeof label === 'string' ? label + ': ' : '') + tooltip
: undefined
}
onClick={e => this._select(event, e)}
onDoubleClick={e => this._doubleClick(event, e)}
className={cn('rbc-event', className, {
Expand Down
5 changes: 4 additions & 1 deletion src/EventCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let propTypes = {
isAllDay: PropTypes.bool,
eventPropGetter: PropTypes.func,
titleAccessor: accessor,
tooltipAccessor: accessor,
allDayAccessor: accessor,
startAccessor: accessor,
endAccessor: accessor,
Expand All @@ -35,6 +36,7 @@ class EventCell extends React.Component {
startAccessor,
endAccessor,
titleAccessor,
tooltipAccessor,
slotStart,
slotEnd,
onSelect,
Expand All @@ -45,6 +47,7 @@ class EventCell extends React.Component {
} = this.props

let title = get(event, titleAccessor),
tooltip = get(event, tooltipAccessor),
end = get(event, endAccessor),
start = get(event, startAccessor),
isAllDayEvent =
Expand Down Expand Up @@ -75,7 +78,7 @@ class EventCell extends React.Component {
onClick={e => onSelect(event, e)}
onDoubleClick={e => onDoubleClick(event, e)}
>
<div className="rbc-event-content" title={title}>
<div className="rbc-event-content" title={tooltip || undefined}>
{Event ? (
<Event event={event} title={title} isAllDay={isAllDayEvent} />
) : (
Expand Down
3 changes: 3 additions & 0 deletions src/EventRowMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
isAllDay: PropTypes.bool,
eventPropGetter: PropTypes.func,
titleAccessor: accessor,
tooltipAccessor: accessor,
allDayAccessor: accessor,
startAccessor: accessor,
endAccessor: accessor,
Expand All @@ -44,6 +45,7 @@ export default {
startAccessor,
endAccessor,
titleAccessor,
tooltipAccessor,
allDayAccessor,
eventComponent,
eventWrapperComponent,
Expand All @@ -63,6 +65,7 @@ export default {
startAccessor={startAccessor}
endAccessor={endAccessor}
titleAccessor={titleAccessor}
tooltipAccessor={tooltipAccessor}
allDayAccessor={allDayAccessor}
slotStart={start}
slotEnd={end}
Expand Down
3 changes: 3 additions & 0 deletions src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ let propTypes = {
width: PropTypes.number,

titleAccessor: accessor.isRequired,
tooltipAccessor: accessor.isRequired,
allDayAccessor: accessor.isRequired,
startAccessor: accessor.isRequired,
endAccessor: accessor.isRequired,
Expand Down Expand Up @@ -153,6 +154,7 @@ class MonthView extends React.Component {
components,
selectable,
titleAccessor,
tooltipAccessor,
startAccessor,
endAccessor,
allDayAccessor,
Expand Down Expand Up @@ -185,6 +187,7 @@ class MonthView extends React.Component {
selectable={selectable}
messages={messages}
titleAccessor={titleAccessor}
tooltipAccessor={tooltipAccessor}
startAccessor={startAccessor}
endAccessor={endAccessor}
allDayAccessor={allDayAccessor}
Expand Down
2 changes: 2 additions & 0 deletions src/TimeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default class TimeGrid extends Component {
width: PropTypes.number,

titleAccessor: accessor.isRequired,
tooltipAccessor: accessor.isRequired,
allDayAccessor: accessor.isRequired,
startAccessor: accessor.isRequired,
endAccessor: accessor.isRequired,
Expand Down Expand Up @@ -310,6 +311,7 @@ export default class TimeGrid extends Component {
eventComponent={this.props.components.event}
eventWrapperComponent={this.props.components.eventWrapper}
titleAccessor={this.props.titleAccessor}
tooltipAccessor={this.props.tooltipAccessor}
startAccessor={this.props.startAccessor}
endAccessor={this.props.endAccessor}
allDayAccessor={this.props.allDayAccessor}
Expand Down

0 comments on commit 9c9490f

Please sign in to comment.