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

Move onItemEnter/onItemLeave listeners onto the items. #206

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ See http://bhp-react-timeline-9k.s3-website-ap-southeast-2.amazonaws.com/docs fo
| onRowClick |
| onRowContext |
| onRowDoubleClick |
| onRowHover |
| onRowLeave |
| onItemHover |
| onItemLeave |

Expand Down
22 changes: 17 additions & 5 deletions src/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export default class Timeline extends React.Component {
onRowClick: PropTypes.func,
onRowContext: PropTypes.func,
onRowDoubleClick: PropTypes.func,
onRowHover: PropTypes.func,
onRowLeave: PropTypes.func,
onItemHover: PropTypes.func,
onItemLeave: PropTypes.func,
itemRenderer: PropTypes.func,
Expand Down Expand Up @@ -676,8 +678,8 @@ export default class Timeline extends React.Component {
if (this.selecting) {
return;
}
if (e.target.hasAttribute('data-item-index') || e.target.parentElement.hasAttribute('data-item-index')) {
let itemKey = e.target.getAttribute('data-item-index') || e.target.parentElement.getAttribute('data-item-index');
if (e.currentTarget.hasAttribute('data-item-index') || e.currentTarget.parentElement.hasAttribute('data-item-index')) {
let itemKey = e.currentTarget.getAttribute('data-item-index') || e.currentTarget.parentElement.getAttribute('data-item-index');
itemCallback && itemCallback(e, Number(itemKey));
} else {
let row = e.target.getAttribute('data-row-index');
Expand Down Expand Up @@ -705,7 +707,7 @@ export default class Timeline extends React.Component {
* @param {} rowIndex Vertical (row) index of cell
* @param {} style Style object to be applied to cell (to position it);
*/
const {timelineMode, onItemHover, onItemLeave, rowLayers} = this.props;
const {timelineMode, onItemHover, onItemLeave, onRowHover, onRowLeave, rowLayers} = this.props;
const canSelect = Timeline.isBitSet(Timeline.TIMELINE_MODES.SELECT, timelineMode);
return ({columnIndex, key, parent, rowIndex, style}) => {
let itemCol = 1;
Expand All @@ -727,11 +729,11 @@ export default class Timeline extends React.Component {
onMouseMove={e => (this.selecting = true)}
onMouseOver={e => {
this.selecting = false;
return this._handleItemRowEvent(e, onItemHover, null);
return this._handleItemRowEvent(e, onRowHover, null);
}}
onMouseLeave={e => {
this.selecting = false;
return this._handleItemRowEvent(e, onItemLeave, null);
return this._handleItemRowEvent(e, onRowLeave, null);
}}
onContextMenu={e =>
this._handleItemRowEvent(e, this.props.onItemContextClick, this.props.onRowContextClick)
Expand All @@ -744,6 +746,16 @@ export default class Timeline extends React.Component {
width,
this.props.itemHeight,
this.props.itemRenderer,
function onMouseOver(e) {
e.preventDefault();
this.selecting = false;
return this._handleItemRowEvent(e, onItemHover, null);
},
function onMouseLeave(e) {
e.preventDefault()
this.selecting = false;
return this._handleItemRowEvent(e, onItemLeave, null);
},
canSelect ? this.props.selectedItems : []
)}
{rowLayerRenderer(layersInRow, this.props.startDate, this.props.endDate, width, rowHeight)}
Expand Down
7 changes: 5 additions & 2 deletions src/utils/itemUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import moment from 'moment';
* @param {moment} vis_end The visible end of the timeline
* @param {number} total_width pixel width of the timeline
*/
export function rowItemsRenderer(items, vis_start, vis_end, total_width, itemHeight, itemRenderer, selectedItems = []) {
export function rowItemsRenderer(items, vis_start, vis_end, total_width, itemHeight, itemRenderer, onMouseOver, onMouseLeave, onItemLeaveselectedItems = []) {
const start_end_min = vis_end.diff(vis_start, 'minutes');
const pixels_per_min = total_width / start_end_min;
let filtered_items = _.sortBy(
Expand Down Expand Up @@ -61,7 +61,10 @@ export function rowItemsRenderer(items, vis_start, vis_end, total_width, itemHei
key={i.key}
data-item-index={i.key}
className={outerClassnames}
style={{left, width, top, backgroundColor: 'transparent'}}>
style={{left, width, top, backgroundColor: 'transparent'}}
onMouseOver={onMouseOver}
onMouseOver={onMouseLeave}
>
<Comp key={i.key} item={i} className={compClassnames} style={style} />
</span>
);
Expand Down