Skip to content

Commit

Permalink
feat: add showAllEvents Calendar Prop (jquense#1808)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
jkhoang313 and jhoangatl authored Dec 8, 2020
1 parent 5490207 commit 8ffe39d
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 17 deletions.
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}
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';

0 comments on commit 8ffe39d

Please sign in to comment.