Skip to content
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
6 changes: 5 additions & 1 deletion src/addons/dragAndDrop/DraggableEventWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { accessor } from '../../utils/propTypes'
import { accessor as get } from '../../utils/accessors'

import BigCalendar from '../../index'
const EventWrapper = BigCalendar.components.eventWrapper

class DraggableEventWrapper extends React.Component {
static contextTypes = {
components: PropTypes.object,
draggableAccessor: accessor,
resizableAccessor: accessor,
}
Expand Down Expand Up @@ -51,6 +51,10 @@ class DraggableEventWrapper extends React.Component {
}

render() {
const { components } = this.context
const EventWrapper =
components.eventWrapper || BigCalendar.components.eventWrapper

let {
connectDragSource,
connectTopDragSource,
Expand Down
4 changes: 0 additions & 4 deletions src/addons/dragAndDrop/withDragAndDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ try {
* If you care about these corner cases, you can examine the `allDay` param suppled
* in the callback to determine how the user dropped or resized the event.
*
* Note: you cannot use custom `EventWrapper` components when using this HOC as it
* is overwritten here.
*
*
* @param {*} Calendar
* @param {*} backend
*/
Expand Down
31 changes: 31 additions & 0 deletions stories/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,19 @@ storiesOf('module.Calendar.week', module)
</div>
)
})
.add('add custom eventWrapper', () => {
return (
<div style={{ height: 600 }}>
<Calendar
defaultView={Calendar.Views.DAY}
events={events}
components={{
eventWrapper: customComponents.eventWrapper,
}}
/>
</div>
)
})
.add('no duration', () => {
return (
<div style={{ height: 600 }}>
Expand Down Expand Up @@ -624,3 +637,21 @@ storiesOf('module.Calendar.week', module)
</div>
)
})
.add('draggable and resizable with custom eventWrapper', () => {
return (
<div style={{ height: 600 }}>
<DragAndDropCalendar
components={{
eventWrapper: customComponents.eventWrapper,
}}
defaultDate={new Date()}
defaultView={Calendar.Views.WEEK}
events={events}
resizable
showMultiDayTimes
onEventDrop={action('event dropped')}
onEventResize={action('event resized')}
/>
</div>
)
})
9 changes: 9 additions & 0 deletions stories/customComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ const customComponents = {
</div>
)
},
eventWrapper: eventWrapperProps => {
const style = {
border: '4px solid',
borderColor:
eventWrapperProps.event.start.getHours() % 2 === 0 ? 'green' : 'red',
padding: '5px',
}
return <div style={style}>{eventWrapperProps.children}</div>
},
}

export default customComponents