Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add showAllEvents Calendar Prop #1808

Merged
merged 2 commits into from
Dec 8, 2020
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
8 changes: 8 additions & 0 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ class Calendar extends React.Component {
*/
onShowMore: PropTypes.func,

/**
* Displays all events on the month view instead of
* having some hidden behind +{count} more. This will
* cause the rows in the month view to be scrollable if
* the number of events exceed the height of the row.
*/
showAllEvents: PropTypes.bool,

/**
* The selected event, if any.
*/
Expand Down
49 changes: 34 additions & 15 deletions src/DateContentRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import * as dates from './utils/dates'
import BackgroundCells from './BackgroundCells'
import EventRow from './EventRow'
import EventEndingRow from './EventEndingRow'
import NoopWrapper from './NoopWrapper'
import ScrollableWeekWrapper from './ScrollableWeekWrapper'
import * as DateSlotMetrics from './utils/DateSlotMetrics'

class DateContentRow extends React.Component {
Expand Down Expand Up @@ -71,10 +73,15 @@ class DateContentRow extends React.Component {
}

renderDummy = () => {
let { className, range, renderHeader } = this.props
let { className, range, renderHeader, showAllEvents } = this.props
return (
<div className={className}>
<div className="rbc-row-content">
<div
className={clsx(
'rbc-row-content',
showAllEvents && 'rbc-row-content-scrollable'
)}
>
{renderHeader && (
<div className="rbc-row" ref={this.createHeadingRef}>
{range.map(this.renderHeadingCell)}
Expand Down Expand Up @@ -118,13 +125,17 @@ class DateContentRow extends React.Component {
longPressThreshold,
isAllDay,
resizable,
showAllEvents,
} = this.props

if (renderForMeasure) return this.renderDummy()

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

let ScrollableWeekComponent = showAllEvents
? ScrollableWeekWrapper
: NoopWrapper
let WeekWrapper = components.weekWrapper

const eventRowProps = {
Expand Down Expand Up @@ -159,24 +170,31 @@ class DateContentRow extends React.Component {
resourceId={resourceId}
/>

<div className="rbc-row-content">
<div
className={clsx(
'rbc-row-content',
showAllEvents && 'rbc-row-content-scrollable'
)}
>
{renderHeader && (
<div className="rbc-row " ref={this.createHeadingRef}>
{range.map(this.renderHeadingCell)}
</div>
)}
<WeekWrapper isAllDay={isAllDay} {...eventRowProps}>
{levels.map((segs, idx) => (
<EventRow key={idx} segments={segs} {...eventRowProps} />
))}
{!!extra.length && (
<EventEndingRow
segments={extra}
onShowMore={this.handleShowMore}
{...eventRowProps}
/>
)}
</WeekWrapper>
<ScrollableWeekComponent>
<WeekWrapper isAllDay={isAllDay} {...eventRowProps}>
{levels.map((segs, idx) => (
<EventRow key={idx} segments={segs} {...eventRowProps} />
))}
{!!extra.length && (
<EventEndingRow
segments={extra}
onShowMore={this.handleShowMore}
{...eventRowProps}
/>
)}
</WeekWrapper>
</ScrollableWeekComponent>
</div>
</div>
)
Expand All @@ -200,6 +218,7 @@ DateContentRow.propTypes = {
longPressThreshold: PropTypes.number,

onShowMore: PropTypes.func,
showAllEvents: PropTypes.bool,
onSelectSlot: PropTypes.func,
onSelect: PropTypes.func,
onSelectEnd: PropTypes.func,
Expand Down
5 changes: 4 additions & 1 deletion src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class MonthView extends React.Component {
longPressThreshold,
accessors,
getters,
showAllEvents,
} = this.props

const { needLimitMeasure, rowLimit } = this.state
Expand All @@ -120,7 +121,7 @@ class MonthView extends React.Component {
date={date}
range={week}
events={events}
maxRows={rowLimit}
maxRows={showAllEvents ? Infinity : rowLimit}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you double check that no code assumes this number is bounded? e.g. uses it as the upper bound in a loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirmed that no code assumes this number is bound. It is only used when determining "extra" segments here

selected={selected}
selectable={selectable}
components={components}
Expand All @@ -137,6 +138,7 @@ class MonthView extends React.Component {
longPressThreshold={longPressThreshold}
rtl={this.props.rtl}
resizable={this.props.resizable}
showAllEvents={showAllEvents}
/>
)
}
Expand Down Expand Up @@ -342,6 +344,7 @@ MonthView.propTypes = {
onDoubleClickEvent: PropTypes.func,
onKeyPressEvent: PropTypes.func,
onShowMore: PropTypes.func,
showAllEvents: PropTypes.bool,
onDrillDown: PropTypes.func,
getDrilldownView: PropTypes.func.isRequired,

Expand Down
7 changes: 7 additions & 0 deletions src/ScrollableWeekWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'

const ScrollableWeekWrapper = ({ children }) => {
return <div className="rbc-row-content-scroll-container">{children}</div>
}

export default ScrollableWeekWrapper
19 changes: 19 additions & 0 deletions src/less/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@
z-index: 4;
}

.rbc-row-content-scrollable {
display: flex;
flex-direction: column;
height: 100%;

.rbc-row-content-scroll-container {
height: 100%;
overflow-y: scroll;

/* Hide scrollbar for Chrome, Safari and Opera */
&::-webkit-scrollbar {
display: none;
}

-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
}

.rbc-today {
background-color: @today-highlight-bg;
}
Expand Down
21 changes: 20 additions & 1 deletion src/sass/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@
z-index: 4;
}

.rbc-row-content-scrollable {
display: flex;
flex-direction: column;
height: 100%;

.rbc-row-content-scroll-container {
height: 100%;
overflow-y: scroll;

/* Hide scrollbar for Chrome, Safari and Opera */
&::-webkit-scrollbar {
display: none;
}

-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
}

.rbc-today {
background-color: $today-highlight-bg;
}
Expand All @@ -88,4 +107,4 @@
@import './event';
@import './month';
@import './agenda';
@import './time-grid';
@import './time-grid';