From d98af8dcd748a241cefc1b3a02e475a1bcb0baeb Mon Sep 17 00:00:00 2001 From: jquense Date: Thu, 29 Oct 2015 13:05:48 +0700 Subject: [PATCH] [added] edge detection for event popup --- src/Month.jsx | 6 +----- src/Popup.jsx | 50 ++++++++++++++++++++++++++++++++++++++------- src/less/month.less | 7 ++++++- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/Month.jsx b/src/Month.jsx index 8050712d8..185921839 100644 --- a/src/Month.jsx +++ b/src/Month.jsx @@ -288,16 +288,12 @@ let MonthView = React.createClass({ onHide={() => this.setState({ overlay: null })} > ) diff --git a/src/Popup.jsx b/src/Popup.jsx index 56df621f5..48bfcd550 100644 --- a/src/Popup.jsx +++ b/src/Popup.jsx @@ -1,22 +1,58 @@ import React from 'react'; import EventCell from './EventCell'; import { isSelected } from './utils/selection'; +import localizer from './localizer'; +import getOffset from 'dom-helpers/query/offset'; +import getScrollTop from 'dom-helpers/query/scrollTop'; +import getScrollLeft from 'dom-helpers/query/scrollLeft'; class Popup extends React.Component { - render() { - let { events, selected, ...props } = this.props; - let { left, width, top } = this.props.position; + componentDidMount(){ + let { top, left, width, height } = getOffset(this.refs.root) + , viewBottom = window.innerHeight + getScrollTop(window) + , viewRight = window.innerWidth + getScrollLeft(window) + , bottom = top + height + , right = left + width + + if (bottom > viewBottom || right > viewRight) { + let topOffset, leftOffset; + + if (bottom > viewBottom) + topOffset = bottom - viewBottom + 5 + if (right > viewRight) + leftOffset = right - viewRight + 5 + + this.setState({ topOffset, leftOffset }) + } + } + + render() { + let { events, selected, eventComponent, ...props } = this.props; - top += 20; + let { left, width, top } = this.props.position + , topOffset = (this.state || {}).topOffset || 0 + , leftOffset = (this.state || {}).leftOffset || 0; - let style = { left, top, minWidth: width + (width / 2) } + let style = { + top: top - topOffset, + left: left - leftOffset, + minWidth: width + (width / 2) + } return ( -
+
+
+ { localizer.format(props.slotStart, props.dayHeaderFormat, props.culture) } +
{ events.map((event, idx) => - + ) }
diff --git a/src/less/month.less b/src/less/month.less index 480985542..92185d07a 100644 --- a/src/less/month.less +++ b/src/less/month.less @@ -108,7 +108,6 @@ .rbc-overlay { position: absolute; - //width: 400; z-index: @event-zindex + 1; border: 1px solid #e5e5e5; background-color: #fff; @@ -119,3 +118,9 @@ margin-top: 1px; } } + +.rbc-overlay-header { + border-bottom: 1px solid #e5e5e5; + margin: -10px -10px 5px -10px ; + padding: 2px 10px; +}