Skip to content

Commit

Permalink
Pr/959 (#985)
Browse files Browse the repository at this point in the history
* Now adding a new class to the dragged event

( rbc-addons-dnd-drag-dragged-event )

* Renamed the dragging style to rbc-addons-dnd-dragged-event

* Removed touch-action: manipulation

* Fixed lint errors

* tweak
  • Loading branch information
jquense committed Sep 9, 2018
1 parent d1e90b1 commit 1d62c43
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 61 deletions.
7 changes: 6 additions & 1 deletion examples/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,18 @@ class Example extends React.Component {
</strong>
</a>
</div>
<Dropdown className="examples--dropdown" pullRight>
<Dropdown
pullRight
id="examples-dropdown"
className="examples--dropdown"
>
<Dropdown.Toggle bsStyle="link" className="dropdown--toggle ">
{EXAMPLES[selected]}
</Dropdown.Toggle>
<Dropdown.Menu>
{Object.entries(EXAMPLES).map(([key, title]) => (
<MenuItem
key={key}
href={`#${key}`}
onClick={() => this.select(key)}
>
Expand Down
2 changes: 1 addition & 1 deletion src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class DayColumn extends React.Component {
events,
accessors,
slotMetrics,
minimumStartDifference: Math.ceil((step * timeslots) / 2),
minimumStartDifference: Math.ceil(step * timeslots / 2),
})

return styledEvents.map(({ event, style }, idx) => {
Expand Down
5 changes: 1 addition & 4 deletions src/EventEndingRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ class EventEndingRow extends React.Component {
}

render() {
let {
segments,
slotMetrics: { slots },
} = this.props
let { segments, slotMetrics: { slots } } = this.props
let rowSegments = eventLevels(segments).levels[0]

let current = 1,
Expand Down
6 changes: 1 addition & 5 deletions src/EventRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ class EventRow extends React.Component {
...EventRowMixin.defaultProps,
}
render() {
let {
segments,
slotMetrics: { slots },
className,
} = this.props
let { segments, slotMetrics: { slots }, className } = this.props

let lastEnd = 1

Expand Down
2 changes: 1 addition & 1 deletion src/EventRowMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
},

renderSpan(slots, len, key, content = ' ') {
let per = (Math.abs(len) / slots) * 100 + '%'
let per = Math.abs(len) / slots * 100 + '%'

return (
<div
Expand Down
4 changes: 2 additions & 2 deletions src/TimeGridEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function TimeGridEvent(props) {
return (
<EventWrapper type="time" {...props}>
<div
onClick={props.onClick}
onDoubleClick={props.onDoubleClick}
onClick={onClick}
onDoubleClick={onDoubleClick}
style={{
...userProps.style,
top: `${top}%`,
Expand Down
5 changes: 1 addition & 4 deletions src/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ class Toolbar extends React.Component {
}

render() {
let {
localizer: { messages },
label,
} = this.props
let { localizer: { messages }, label } = this.props

return (
<div className="rbc-toolbar">
Expand Down
87 changes: 53 additions & 34 deletions src/addons/dragAndDrop/EventWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,51 @@ class EventWrapper extends React.Component {
}

render() {
let { children, event, type, continuesPrior, continuesAfter } = this.props
const { event, type, continuesPrior, continuesAfter } = this.props

let { children } = this.props

if (event.__isPreview)
return React.cloneElement(children, {
className: cn(children.props.className, 'rbc-addons-dnd-drag-preview'),
})

let { draggableAccessor, resizableAccessor } = this.context
const { draggableAccessor, resizableAccessor, draggable } = this.context

let isDraggable = draggableAccessor ? !!get(event, draggableAccessor) : true
const isDraggable = draggableAccessor
? !!get(event, draggableAccessor)
: true

/* Event is not draggable, no need to wrap it */
if (!isDraggable) {
return children
}

let StartAnchor = null,
EndAnchor = null
let StartAnchor = null
let EndAnchor = null

/*
* The resizability of events depends on whether they are
* allDay events and how they are displayed.
*
* 1. If the event is being shown in an event row (because
* it is an allDay event shown in the header row or because as
* in month view the view is showing all events as rows) then we
* allow east-west resizing.
*
* 2. Otherwise the event is being displayed
* normally, we can drag it north-south to resize the times.
*
* See `DropWrappers` for handling of the drop of such events.
*
* Notwithstanding the above, we never show drag anchors for
* events which continue beyond current component. This happens
* in the middle of events when showMultiDay is true, and to
* events at the edges of the calendar's min/max location.
*/

let isResizable = resizableAccessor ? !!get(event, resizableAccessor) : true
* The resizability of events depends on whether they are
* allDay events and how they are displayed.
*
* 1. If the event is being shown in an event row (because
* it is an allDay event shown in the header row or because as
* in month view the view is showing all events as rows) then we
* allow east-west resizing.
*
* 2. Otherwise the event is being displayed
* normally, we can drag it north-south to resize the times.
*
* See `DropWrappers` for handling of the drop of such events.
*
* Notwithstanding the above, we never show drag anchors for
* events which continue beyond current component. This happens
* in the middle of events when showMultiDay is true, and to
* events at the edges of the calendar's min/max location.
*/
const isResizable = resizableAccessor
? !!get(event, resizableAccessor)
: true

if (isResizable) {
if (type === 'date') {
Expand All @@ -119,25 +124,39 @@ class EventWrapper extends React.Component {
}

/*
* props.children is the singular <Event> component.
* BigCalendar positions the Event abolutely and we
* need the anchors to be part of that positioning.
* So we insert the anchors inside the Event's children
* rather than wrap the Event here as the latter approach
* would lose the positioning.
*/
children = React.cloneElement(children, {
* props.children is the singular <Event> component.
* BigCalendar positions the Event abolutely and we
* need the anchors to be part of that positioning.
* So we insert the anchors inside the Event's children
* rather than wrap the Event here as the latter approach
* would lose the positioning.
*/
const newProps = {
onMouseDown: this.handleStartDragging,
onTouchStart: this.handleStartDragging,
// replace original event child with anchor-embellished child

children: (
<div className="rbc-addons-dnd-resizable">
{StartAnchor}
{children.props.children}
{EndAnchor}
</div>
),
})
}

if (
draggable.dragAndDropAction.interacting && // if an event is being dragged right now
draggable.dragAndDropAction.event === event // and it's the current event
) {
// add a new class to it
newProps.className = cn(
children.props.className,
'rbc-addons-dnd-dragged-event'
)
}

children = React.cloneElement(children, newProps)
}

return children
Expand Down
11 changes: 5 additions & 6 deletions src/addons/dragAndDrop/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
right: 0;
}

.rbc-addons-dnd-dragging {
opacity: .25;
touch-action: manipulation;
}


.rbc-addons-dnd-over {
background-color: rgba(
Expand All @@ -34,7 +29,11 @@
}
}

&.rbc-addons-dnd-is-dragging .rbc-event:not(.rbc-addons-dnd-dragging):not(.rbc-addons-dnd-drag-preview) {
.rbc-addons-dnd-dragged-event {
opacity: 0;
}

&.rbc-addons-dnd-is-dragging .rbc-event:not(.rbc-addons-dnd-dragged-event):not(.rbc-addons-dnd-drag-preview) {
opacity: .50;
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/TimeSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function getSlotMetrics({ min: start, max: end, step, timeslots }) {
if (dates.lt(date, start, 'minutes')) return slots[0]

const diffMins = dates.diff(start, date, 'minutes')
return slots[(diffMins - (diffMins % step)) / step + offset]
return slots[(diffMins - diffMins % step) / step + offset]
},

startsBeforeDay(date) {
Expand All @@ -129,11 +129,11 @@ export function getSlotMetrics({ min: start, max: end, step, timeslots }) {

const rangeStartMin = positionFromDate(rangeStart)
const rangeEndMin = positionFromDate(rangeEnd)
const top = (rangeStartMin / totalMin) * 100
const top = rangeStartMin / totalMin * 100

return {
top,
height: (rangeEndMin / totalMin) * 100 - top,
height: rangeEndMin / totalMin * 100 - top,
start: positionFromDate(rangeStart),
startDate: rangeStart,
end: positionFromDate(rangeEnd),
Expand Down

0 comments on commit 1d62c43

Please sign in to comment.