Skip to content

Commit afb3138

Browse files
authored
feat(components): showMore component customization (jquense#2537)
Closes jquense#2391
1 parent 856dddf commit afb3138

File tree

6 files changed

+85
-1
lines changed

6 files changed

+85
-1
lines changed

src/Calendar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ class Calendar extends React.Component {
750750
* timeGutterHeader: MyTimeGutterWrapper,
751751
* timeGutterWrapper: MyTimeGutterWrapper,
752752
* resourceHeader: MyResourceHeader,
753+
* showMore: MyShowMoreEvent,
753754
* toolbar: MyToolbar,
754755
* agenda: {
755756
* event: MyAgendaEvent, // with the agenda view use a different component to render events
@@ -783,6 +784,7 @@ class Calendar extends React.Component {
783784
timeGutterHeader: PropTypes.elementType,
784785
timeGutterWrapper: PropTypes.elementType,
785786
resourceHeader: PropTypes.elementType,
787+
showMore: PropTypes.elementType,
786788

787789
toolbar: PropTypes.elementType,
788790

src/EventEndingRow.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,30 @@ class EventEndingRow extends React.Component {
7575
}
7676

7777
renderShowMore(segments, slot) {
78-
let { localizer, slotMetrics } = this.props
78+
let { localizer, slotMetrics, components } = this.props
7979
const events = slotMetrics.getEventsForSlot(slot)
8080
const remainingEvents = eventsInSlot(segments, slot)
8181
const count = remainingEvents.length
82+
83+
if (components?.showMore) {
84+
const ShowMore = components.showMore
85+
// The received slot seems to be 1-based, but the range we use to pull the date is 0-based
86+
const slotDate = slotMetrics.getDateForSlot(slot - 1)
87+
88+
return count ? (
89+
<ShowMore
90+
localizer={localizer}
91+
slotDate={slotDate}
92+
slot={slot}
93+
count={count}
94+
events={events}
95+
remainingEvents={remainingEvents}
96+
/>
97+
) : (
98+
false
99+
)
100+
}
101+
82102
return count ? (
83103
<button
84104
type="button"

stories/Calendar.stories.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,13 @@ CustomDayColumnWrapper.parameters = {
129129
},
130130
},
131131
}
132+
133+
export const CustomShowMore = Template.bind({})
134+
CustomShowMore.storyName = 'add custom showMore'
135+
CustomShowMore.args = {
136+
defaultView: Views.MONTH,
137+
events,
138+
components: {
139+
showMore: customComponents.showMore,
140+
},
141+
}

stories/helpers/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,36 @@ export const DragableCalendar = (props) => {
4444
}
4545

4646
export const events = [
47+
{
48+
title: 'example 1',
49+
start: moment().startOf('month').add(1, 'hours').toDate(),
50+
end: moment().startOf('month').add(2, 'hours').toDate(),
51+
allDay: false,
52+
},
53+
{
54+
title: 'example 2',
55+
start: moment().startOf('month').add(1, 'hours').toDate(),
56+
end: moment().startOf('month').add(2, 'hours').toDate(),
57+
allDay: false,
58+
},
59+
{
60+
title: 'example 3',
61+
start: moment().startOf('month').add(1, 'hours').toDate(),
62+
end: moment().startOf('month').add(2, 'hours').toDate(),
63+
allDay: false,
64+
},
65+
{
66+
title: 'example 4',
67+
start: moment().startOf('month').add(1, 'hours').toDate(),
68+
end: moment().startOf('month').add(2, 'hours').toDate(),
69+
allDay: false,
70+
},
71+
{
72+
title: 'example 5',
73+
start: moment().startOf('month').add(1, 'hours').toDate(),
74+
end: moment().startOf('month').add(2, 'hours').toDate(),
75+
allDay: false,
76+
},
4777
{
4878
title: 'test',
4979
start: moment().add(1, 'days').subtract(5, 'hours').toDate(),

stories/props/components.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const components = useMemo(() => ({
1818
timeGutterHeader: MyTimeGutterWrapper,
1919
resourceHeader: MyResourceHeader,
2020
toolbar: MyToolbar,
21+
showMore: MyShowMoreButton,
2122
agenda: {
2223
event: MyAgendaEvent, // with the agenda view use a different component to render events
2324
time: MyAgendaTime,

stories/resources/customComponents.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,27 @@ const customComponents = {
8181
</div>
8282
)
8383
},
84+
showMore: (showMoreProps) => {
85+
return (
86+
<button
87+
id="my-custom-show-more"
88+
style={{ border: '4px solid red', cursor: 'pointer' }}
89+
onClick={() => {
90+
console.log('showMoreProps', showMoreProps)
91+
window.alert(`
92+
Clicked ${showMoreProps.slotDate
93+
.toISOString()
94+
.substr(0, 10)} with ${
95+
showMoreProps.remainingEvents.length
96+
} remaining events.
97+
Open the console for the full set of props.
98+
`)
99+
}}
100+
>
101+
{showMoreProps.count} more!
102+
</button>
103+
)
104+
},
84105
}
85106

86107
export default customComponents

0 commit comments

Comments
 (0)