Skip to content

Commit 10b8041

Browse files
feat(time-indicator-wrapper): expose time indicator wrapper component (jquense#2747)
Co-authored-by: davidju <[email protected]>
1 parent f3df007 commit 10b8041

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

src/Calendar.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ class Calendar extends React.Component {
767767
* timeSlotWrapper: MyTimeSlotWrapper,
768768
* timeGutterHeader: MyTimeGutterWrapper,
769769
* timeGutterWrapper: MyTimeGutterWrapper,
770+
* timeIndicatorWrapper: MyTimeIndicatorWrapper,
770771
* resourceHeader: MyResourceHeader,
771772
* showMore: MyShowMoreEvent,
772773
* toolbar: MyToolbar,
@@ -801,6 +802,7 @@ class Calendar extends React.Component {
801802
timeSlotWrapper: PropTypes.elementType,
802803
timeGutterHeader: PropTypes.elementType,
803804
timeGutterWrapper: PropTypes.elementType,
805+
timeIndicatorWrapper: PropTypes.elementType,
804806
resourceHeader: PropTypes.elementType,
805807
showMore: PropTypes.elementType,
806808

@@ -975,6 +977,7 @@ class Calendar extends React.Component {
975977
weekWrapper: NoopWrapper,
976978
timeSlotWrapper: NoopWrapper,
977979
timeGutterWrapper: NoopWrapper,
980+
timeIndicatorWrapper: NoopWrapper,
978981
}),
979982
accessors: {
980983
start: wrapAccessor(startAccessor),

src/DayColumn.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ class DayColumn extends React.Component {
110110
accessors,
111111
localizer,
112112
getters: { dayProp, ...getters },
113-
components: { eventContainerWrapper: EventContainer, ...components },
113+
components: {
114+
eventContainerWrapper: EventContainer,
115+
timeIndicatorWrapper: TimeIndicatorWrapper,
116+
...components
117+
},
114118
} = this.props
115119

116120
this.slotMetrics = this.slotMetrics.update(this.props)
@@ -122,6 +126,13 @@ class DayColumn extends React.Component {
122126

123127
const { className, style } = dayProp(max, resource)
124128

129+
const timeIndicatorProps = {
130+
className: 'rbc-current-time-indicator',
131+
style: {
132+
top: `${this.state.timeIndicatorPosition}%`,
133+
},
134+
}
135+
125136
const DayColumnWrapperComponent =
126137
components.dayColumnWrapper || DayColumnWrapper
127138

@@ -173,10 +184,9 @@ class DayColumn extends React.Component {
173184
</div>
174185
)}
175186
{isNow && this.intervalTriggered && (
176-
<div
177-
className="rbc-current-time-indicator"
178-
style={{ top: `${this.state.timeIndicatorPosition}%` }}
179-
/>
187+
<TimeIndicatorWrapper {...timeIndicatorProps}>
188+
<div {...timeIndicatorProps} />
189+
</TimeIndicatorWrapper>
180190
)}
181191
</DayColumnWrapperComponent>
182192
)

stories/Calendar.stories.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ CustomTimeGutterWrapper.args = {
6868
},
6969
}
7070

71+
export const CustomTimeIndicatorWrapper = Template.bind({})
72+
CustomTimeIndicatorWrapper.storyName = 'custom TimeIndicator wrapper'
73+
CustomTimeIndicatorWrapper.args = {
74+
popup: true,
75+
events: demoEvents,
76+
onSelectEvent: action('event selected'),
77+
defaultDate: new Date(2015, 3, 1),
78+
defaultView: Views.WEEK,
79+
views: [Views.WEEK, Views.DAY],
80+
components: {
81+
timeIndicatorWrapper: customComponents.timeIndicatorWrapper,
82+
},
83+
}
84+
7185
export const CustomDateCellWrapper = Template.bind({})
7286
CustomDateCellWrapper.storyName = 'add custom dateCellWrapper'
7387
CustomDateCellWrapper.args = {

stories/resources/customComponents.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ const customComponents = {
102102
</button>
103103
)
104104
},
105+
timeIndicatorWrapper: (timeIndicatorWrapperProps) => {
106+
return (
107+
<div
108+
{...timeIndicatorWrapperProps}
109+
style={{
110+
...timeIndicatorWrapperProps.style,
111+
backgroundColor: 'red',
112+
height: '2px',
113+
}}
114+
>
115+
Time Ex
116+
</div>
117+
)
118+
},
105119
}
106120

107121
export default customComponents

0 commit comments

Comments
 (0)