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

fix: update to current react-overlays #2217

Merged
merged 2 commits into from
Jul 8, 2022
Merged
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"moment": "^2.29.4",
"moment-timezone": "^0.5.34",
"prop-types": "^15.8.1",
"react-overlays": "^4.1.1",
"react-overlays": "^5.2.0",
"uncontrollable": "^7.2.1"
},
"bugs": {
Expand Down
42 changes: 36 additions & 6 deletions src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { notify } from './utils/helpers'
import getPosition from 'dom-helpers/position'
import * as animationFrame from 'dom-helpers/animationFrame'

import Popup from './Popup'
import Overlay from 'react-overlays/Overlay'
/* import Popup from './Popup'
import Overlay from 'react-overlays/Overlay' */
import PopOverlay from './PopOverlay'
import DateContentRow from './DateContentRow'
import Header from './Header'
import DateHeader from './DateHeader'
Expand Down Expand Up @@ -204,11 +205,40 @@ class MonthView extends React.Component {
}

renderOverlay() {
let overlay = (this.state && this.state.overlay) || {}
let { accessors, localizer, components, getters, selected, popupOffset } =
this.props
let overlay = this.state?.overlay ?? {}
let {
accessors,
localizer,
components,
getters,
selected,
popupOffset,
handleDragStart,
} = this.props

const onHide = () => this.setState({ overlay: null })

return (
<PopOverlay
overlay={overlay}
accessors={accessors}
localizer={localizer}
components={components}
getters={getters}
selected={selected}
popupOffset={popupOffset}
ref={this.containerRef}
handleKeyPressEvent={this.handleKeyPressEvent}
handleSelectEvent={this.handleSelectEvent}
handleDoubleClickEvent={this.handleDoubleClickEvent}
handleDragStart={handleDragStart}
show={!!overlay.position}
overlayDisplay={this.overlayDisplay}
onHide={onHide}
/>
)

/* return (
<Overlay
rootClose
placement="bottom"
Expand Down Expand Up @@ -237,7 +267,7 @@ class MonthView extends React.Component {
/>
)}
</Overlay>
)
) */
}

measureRowLimit() {
Expand Down
95 changes: 95 additions & 0 deletions src/PopOverlay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React, { useRef } from 'react'
import PropTypes from 'prop-types'
import { Overlay } from 'react-overlays'
import Popup from './Popup'

function CalOverlay({
containerRef,
popupOffset = 5,
overlay,
accessors,
localizer,
components,
getters,
selected,
handleSelectEvent,
handleDoubleClickEvent,
handleKeyPressEvent,
handleDragStart,
onHide,
overlayDisplay,
}) {
const popperRef = useRef(null)
if (!overlay.position) return null

let offset
if (!isNaN(popupOffset)) {
offset = { x: popupOffset, y: popupOffset }
}

const { position, events, date, end } = overlay
return (
<Overlay
rootClose
flip
show
placement="bottom"
onHide={onHide}
target={overlay.target}
>
{({ props }) => (
<Popup
{...props}
containerRef={containerRef}
ref={popperRef}
target={overlay.target}
offset={offset}
accessors={accessors}
getters={getters}
selected={selected}
components={components}
localizer={localizer}
position={position}
show={overlayDisplay}
events={events}
slotStart={date}
slotEnd={end}
onSelect={handleSelectEvent}
onDoubleClick={handleDoubleClickEvent}
onKeyPress={handleKeyPressEvent}
handleDragStart={handleDragStart}
/>
)}
</Overlay>
)
}

const PopOverlay = React.forwardRef((props, ref) => (
<CalOverlay {...props} containerRef={ref} />
))

PopOverlay.propTypes = {
popupOffset: PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({ x: PropTypes.number, y: PropTypes.number }),
]),
overlay: PropTypes.shape({
position: PropTypes.object,
events: PropTypes.array,
date: PropTypes.instanceOf(Date),
end: PropTypes.instanceOf(Date),
}),
accessors: PropTypes.object.isRequired,
localizer: PropTypes.object.isRequired,
components: PropTypes.object.isRequired,
getters: PropTypes.object.isRequired,
selected: PropTypes.object,
handleSelectEvent: PropTypes.func,
handleDoubleClickEvent: PropTypes.func,
handleKeyPressEvent: PropTypes.func,
handleDragStart: PropTypes.func,
onHide: PropTypes.func,
overlayDisplay: PropTypes.func,
}

export default PopOverlay
Loading