Skip to content

Commit 172c316

Browse files
spacetagjquense
authored andcommitted
feat: add custom timeSlotWrapper support (jquense#930)
* feat: pass components through to TimeGutter and TimeSlotGroup * feat: allow timeSlotWrapper to be passed through * Add story for custom timeSlotWrapper
1 parent 06e08e2 commit 172c316

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

src/Calendar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ class Calendar extends React.Component {
649649
eventContainerWrapper: elementType,
650650
dayWrapper: elementType,
651651
dateCellWrapper: elementType,
652+
timeSlotWrapper: elementType,
652653
timeGutterHeader: elementType,
653654

654655
toolbar: elementType,
@@ -767,6 +768,7 @@ class Calendar extends React.Component {
767768
dayWrapper: NoopWrapper,
768769
dateCellWrapper: NoopWrapper,
769770
weekWrapper: NoopWrapper,
771+
timeSlotWrapper: NoopWrapper,
770772
}),
771773
accessors: {
772774
start: wrapAccessor(startAccessor),

src/TimeGrid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export default class TimeGrid extends Component {
247247
step={this.props.step}
248248
getNow={this.props.getNow}
249249
timeslots={this.props.timeslots}
250+
components={components}
250251
className="rbc-time-gutter"
251252
/>
252253
{this.renderEvents(range, rangeEvents, getNow(), resources || [null])}

src/TimeGutter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class TimeGutter extends Component {
1212
timeslots: PropTypes.number.isRequired,
1313
step: PropTypes.number.isRequired,
1414
getNow: PropTypes.func.isRequired,
15+
components: PropTypes.object.isRequired,
1516

1617
localizer: PropTypes.object.isRequired,
1718
resource: PropTypes.string,
@@ -47,7 +48,7 @@ export default class TimeGutter extends Component {
4748
}
4849

4950
render() {
50-
const { resource } = this.props
51+
const { resource, components } = this.props
5152

5253
return (
5354
<div className="rbc-time-gutter rbc-time-column">
@@ -57,6 +58,7 @@ export default class TimeGutter extends Component {
5758
key={idx}
5859
group={grp}
5960
resource={resource}
61+
components={components}
6062
renderSlot={this.renderSlot}
6163
/>
6264
)

stories/Calendar.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,14 @@ storiesOf('Big Calendar', module)
197197
/>
198198
)
199199
})
200+
.add('add custom timeSlotWrapper', () => {
201+
return (
202+
<Calendar
203+
defaultView={Calendar.Views.WEEK}
204+
events={events}
205+
components={{
206+
timeSlotWrapper: customComponents.timeSlotWrapper,
207+
}}
208+
/>
209+
)
210+
})

stories/helpers/customComponents.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ const customComponents = {
5353
}
5454
return <div style={style}>{eventWrapperProps.children}</div>
5555
},
56+
timeSlotWrapper: timeSlotWrapperProps => {
57+
const style =
58+
timeSlotWrapperProps.resource === null ||
59+
timeSlotWrapperProps.value.getMinutes() !== 0
60+
? {}
61+
: {
62+
border: '4px solid',
63+
backgroundColor:
64+
timeSlotWrapperProps.value.getHours() >= 8 &&
65+
timeSlotWrapperProps.value.getHours() <= 17
66+
? 'green'
67+
: 'red',
68+
padding: '5px',
69+
}
70+
return <div style={style}>{timeSlotWrapperProps.children}</div>
71+
},
5672
}
5773

5874
export default customComponents

0 commit comments

Comments
 (0)