Skip to content

Commit 8ffe39d

Browse files
feat: add showAllEvents Calendar Prop (jquense#1808)
* Add `showAllEvents` Calendar Prop This prop will allow the rows in the `month` view to display all events in a scrollable container, rather than use the `show more` capability. * fixup! Add `showAllEvents` Calendar Prop Co-authored-by: Jackson Hoang <[email protected]>
1 parent 5490207 commit 8ffe39d

File tree

6 files changed

+92
-17
lines changed

6 files changed

+92
-17
lines changed

src/Calendar.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ class Calendar extends React.Component {
341341
*/
342342
onShowMore: PropTypes.func,
343343

344+
/**
345+
* Displays all events on the month view instead of
346+
* having some hidden behind +{count} more. This will
347+
* cause the rows in the month view to be scrollable if
348+
* the number of events exceed the height of the row.
349+
*/
350+
showAllEvents: PropTypes.bool,
351+
344352
/**
345353
* The selected event, if any.
346354
*/

src/DateContentRow.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import * as dates from './utils/dates'
99
import BackgroundCells from './BackgroundCells'
1010
import EventRow from './EventRow'
1111
import EventEndingRow from './EventEndingRow'
12+
import NoopWrapper from './NoopWrapper'
13+
import ScrollableWeekWrapper from './ScrollableWeekWrapper'
1214
import * as DateSlotMetrics from './utils/DateSlotMetrics'
1315

1416
class DateContentRow extends React.Component {
@@ -71,10 +73,15 @@ class DateContentRow extends React.Component {
7173
}
7274

7375
renderDummy = () => {
74-
let { className, range, renderHeader } = this.props
76+
let { className, range, renderHeader, showAllEvents } = this.props
7577
return (
7678
<div className={className}>
77-
<div className="rbc-row-content">
79+
<div
80+
className={clsx(
81+
'rbc-row-content',
82+
showAllEvents && 'rbc-row-content-scrollable'
83+
)}
84+
>
7885
{renderHeader && (
7986
<div className="rbc-row" ref={this.createHeadingRef}>
8087
{range.map(this.renderHeadingCell)}
@@ -118,13 +125,17 @@ class DateContentRow extends React.Component {
118125
longPressThreshold,
119126
isAllDay,
120127
resizable,
128+
showAllEvents,
121129
} = this.props
122130

123131
if (renderForMeasure) return this.renderDummy()
124132

125133
let metrics = this.slotMetrics(this.props)
126134
let { levels, extra } = metrics
127135

136+
let ScrollableWeekComponent = showAllEvents
137+
? ScrollableWeekWrapper
138+
: NoopWrapper
128139
let WeekWrapper = components.weekWrapper
129140

130141
const eventRowProps = {
@@ -159,24 +170,31 @@ class DateContentRow extends React.Component {
159170
resourceId={resourceId}
160171
/>
161172

162-
<div className="rbc-row-content">
173+
<div
174+
className={clsx(
175+
'rbc-row-content',
176+
showAllEvents && 'rbc-row-content-scrollable'
177+
)}
178+
>
163179
{renderHeader && (
164180
<div className="rbc-row " ref={this.createHeadingRef}>
165181
{range.map(this.renderHeadingCell)}
166182
</div>
167183
)}
168-
<WeekWrapper isAllDay={isAllDay} {...eventRowProps}>
169-
{levels.map((segs, idx) => (
170-
<EventRow key={idx} segments={segs} {...eventRowProps} />
171-
))}
172-
{!!extra.length && (
173-
<EventEndingRow
174-
segments={extra}
175-
onShowMore={this.handleShowMore}
176-
{...eventRowProps}
177-
/>
178-
)}
179-
</WeekWrapper>
184+
<ScrollableWeekComponent>
185+
<WeekWrapper isAllDay={isAllDay} {...eventRowProps}>
186+
{levels.map((segs, idx) => (
187+
<EventRow key={idx} segments={segs} {...eventRowProps} />
188+
))}
189+
{!!extra.length && (
190+
<EventEndingRow
191+
segments={extra}
192+
onShowMore={this.handleShowMore}
193+
{...eventRowProps}
194+
/>
195+
)}
196+
</WeekWrapper>
197+
</ScrollableWeekComponent>
180198
</div>
181199
</div>
182200
)
@@ -200,6 +218,7 @@ DateContentRow.propTypes = {
200218
longPressThreshold: PropTypes.number,
201219

202220
onShowMore: PropTypes.func,
221+
showAllEvents: PropTypes.bool,
203222
onSelectSlot: PropTypes.func,
204223
onSelect: PropTypes.func,
205224
onSelectEnd: PropTypes.func,

src/Month.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class MonthView extends React.Component {
102102
longPressThreshold,
103103
accessors,
104104
getters,
105+
showAllEvents,
105106
} = this.props
106107

107108
const { needLimitMeasure, rowLimit } = this.state
@@ -120,7 +121,7 @@ class MonthView extends React.Component {
120121
date={date}
121122
range={week}
122123
events={events}
123-
maxRows={rowLimit}
124+
maxRows={showAllEvents ? Infinity : rowLimit}
124125
selected={selected}
125126
selectable={selectable}
126127
components={components}
@@ -137,6 +138,7 @@ class MonthView extends React.Component {
137138
longPressThreshold={longPressThreshold}
138139
rtl={this.props.rtl}
139140
resizable={this.props.resizable}
141+
showAllEvents={showAllEvents}
140142
/>
141143
)
142144
}
@@ -342,6 +344,7 @@ MonthView.propTypes = {
342344
onDoubleClickEvent: PropTypes.func,
343345
onKeyPressEvent: PropTypes.func,
344346
onShowMore: PropTypes.func,
347+
showAllEvents: PropTypes.bool,
345348
onDrillDown: PropTypes.func,
346349
getDrilldownView: PropTypes.func.isRequired,
347350

src/ScrollableWeekWrapper.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react'
2+
3+
const ScrollableWeekWrapper = ({ children }) => {
4+
return <div className="rbc-row-content-scroll-container">{children}</div>
5+
}
6+
7+
export default ScrollableWeekWrapper

src/less/styles.less

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@
8181
z-index: 4;
8282
}
8383

84+
.rbc-row-content-scrollable {
85+
display: flex;
86+
flex-direction: column;
87+
height: 100%;
88+
89+
.rbc-row-content-scroll-container {
90+
height: 100%;
91+
overflow-y: scroll;
92+
93+
/* Hide scrollbar for Chrome, Safari and Opera */
94+
&::-webkit-scrollbar {
95+
display: none;
96+
}
97+
98+
-ms-overflow-style: none; /* IE and Edge */
99+
scrollbar-width: none; /* Firefox */
100+
}
101+
}
102+
84103
.rbc-today {
85104
background-color: @today-highlight-bg;
86105
}

src/sass/styles.scss

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@
8080
z-index: 4;
8181
}
8282

83+
.rbc-row-content-scrollable {
84+
display: flex;
85+
flex-direction: column;
86+
height: 100%;
87+
88+
.rbc-row-content-scroll-container {
89+
height: 100%;
90+
overflow-y: scroll;
91+
92+
/* Hide scrollbar for Chrome, Safari and Opera */
93+
&::-webkit-scrollbar {
94+
display: none;
95+
}
96+
97+
-ms-overflow-style: none; /* IE and Edge */
98+
scrollbar-width: none; /* Firefox */
99+
}
100+
}
101+
83102
.rbc-today {
84103
background-color: $today-highlight-bg;
85104
}
@@ -88,4 +107,4 @@
88107
@import './event';
89108
@import './month';
90109
@import './agenda';
91-
@import './time-grid';
110+
@import './time-grid';

0 commit comments

Comments
 (0)