Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
feat(time-gutter-wrapper): expose time gutter wrapper component (jque…
Browse files Browse the repository at this point in the history
…nse#2236)

Allows clients to override the time gutter wrapper.
  • Loading branch information
dhruvgoel92 authored Jul 19, 2022
1 parent 85e3769 commit 39ff8a1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ class Calendar extends React.Component {
* dateCellWrapper: MyDateCellWrapper,
* timeSlotWrapper: MyTimeSlotWrapper,
* timeGutterHeader: MyTimeGutterWrapper,
* timeGutterWrapper: MyTimeGutterWrapper,
* resourceHeader: MyResourceHeader,
* toolbar: MyToolbar,
* agenda: {
Expand Down Expand Up @@ -762,6 +763,7 @@ class Calendar extends React.Component {
dayColumnWrapper: PropTypes.elementType,
timeSlotWrapper: PropTypes.elementType,
timeGutterHeader: PropTypes.elementType,
timeGutterWrapper: PropTypes.elementType,
resourceHeader: PropTypes.elementType,

toolbar: PropTypes.elementType,
Expand Down Expand Up @@ -930,6 +932,7 @@ class Calendar extends React.Component {
dateCellWrapper: NoopWrapper,
weekWrapper: NoopWrapper,
timeSlotWrapper: NoopWrapper,
timeGutterWrapper: NoopWrapper,
}),
accessors: {
start: wrapAccessor(startAccessor),
Expand Down
31 changes: 17 additions & 14 deletions src/TimeGutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const TimeGutter = ({
getters,
gutterRef,
}) => {
const { timeGutterWrapper: TimeGutterWrapper } = components
const { start, end } = useMemo(
() => adjustForDST({ min, max, localizer }),
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -81,20 +82,22 @@ const TimeGutter = ({
)

return (
<div className="rbc-time-gutter rbc-time-column" ref={gutterRef}>
{slotMetrics.groups.map((grp, idx) => {
return (
<TimeSlotGroup
key={idx}
group={grp}
resource={resource}
components={components}
renderSlot={renderSlot}
getters={getters}
/>
)
})}
</div>
<TimeGutterWrapper slotMetrics={slotMetrics}>
<div className="rbc-time-gutter rbc-time-column" ref={gutterRef}>
{slotMetrics.groups.map((grp, idx) => {
return (
<TimeSlotGroup
key={idx}
group={grp}
resource={resource}
components={components}
renderSlot={renderSlot}
getters={getters}
/>
)
})}
</div>
</TimeGutterWrapper>
)
}

Expand Down
14 changes: 14 additions & 0 deletions stories/Calendar.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ CustomTimeGutterHeader.args = {
},
}

export const CustomTimeGutterWrapper = Template.bind({})
CustomTimeGutterWrapper.storyName = 'custom TimeGutter wrapper'
CustomTimeGutterWrapper.args = {
popup: true,
events: demoEvents,
onSelectEvent: action('event selected'),
defaultDate: new Date(2015, 3, 1),
defaultView: Views.WEEK,
views: [Views.WEEK, Views.DAY],
components: {
timeGutterWrapper: customComponents.timeGutterWrapper,
},
}

export const CustomDateCellWrapper = Template.bind({})
CustomDateCellWrapper.storyName = 'add custom dateCellWrapper'
CustomDateCellWrapper.args = {
Expand Down
10 changes: 10 additions & 0 deletions stories/resources/customComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ const customComponents = {
}
return <div style={style}>{timeSlotWrapperProps.children}</div>
},
timeGutterWrapper: (timeGutterWrapperProps) => {
return (
<div
id="my-custom-time-gutter-wrapper"
style={{ backgroundColor: 'gray' }}
>
{timeGutterWrapperProps.children}
</div>
)
},
}

export default customComponents

0 comments on commit 39ff8a1

Please sign in to comment.