Skip to content

Commit

Permalink
feat(components): showMore component customization
Browse files Browse the repository at this point in the history
I'm trying to render a custom component for the `show more` button. I
know there are a few recommended ways to do this through the `onShowMore`
callback and the `messages.showMore` prop as suggested in jquense#1147.

But that doesn't cover all use cases. For example, I want to access the
events that are being hidden by the `show more` button. I also want to
render a custom popup right next to the `show more` button.

Resolves jquense#2391
  • Loading branch information
davidmh committed Mar 14, 2024
1 parent 12d81f0 commit 770be8b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ class Calendar extends React.Component {
* timeGutterHeader: MyTimeGutterWrapper,
* timeGutterWrapper: MyTimeGutterWrapper,
* resourceHeader: MyResourceHeader,
* showMore: MyShowMoreEvent,
* toolbar: MyToolbar,
* agenda: {
* event: MyAgendaEvent, // with the agenda view use a different component to render events
Expand Down Expand Up @@ -783,6 +784,7 @@ class Calendar extends React.Component {
timeGutterHeader: PropTypes.elementType,
timeGutterWrapper: PropTypes.elementType,
resourceHeader: PropTypes.elementType,
showMore: PropTypes.elementType,

toolbar: PropTypes.elementType,

Expand Down
20 changes: 19 additions & 1 deletion src/EventEndingRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,28 @@ class EventEndingRow extends React.Component {
}

renderShowMore(segments, slot) {
let { localizer, slotMetrics } = this.props
let { localizer, slotMetrics, components } = this.props
const events = slotMetrics.getEventsForSlot(slot)
const remainingEvents = eventsInSlot(segments, slot)
const count = remainingEvents.length

if (components && components.showMore) {
const ShowMore = components.showMore

return count ? (
<ShowMore
localizer={localizer}
slotDate={slotMetrics.getDateForSlot(slot - 1)}
slot={slot}
count={count}
events={events}
remainingEvents={remainingEvents}
/>
) : (
false
)
}

return count ? (
<button
type="button"
Expand Down
10 changes: 10 additions & 0 deletions stories/Calendar.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,13 @@ CustomNoAgendaEventsLabel.args = {
noEventsInRange: 'There are no special events in this range [test message]',
},
}

export const CustomShowMore = Template.bind({})
CustomShowMore.storyName = 'add custom showMore'
CustomShowMore.args = {
defaultView: Views.MONTH,
events,
components: {
showMore: customComponents.showMore,
},
}
19 changes: 19 additions & 0 deletions stories/resources/customComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ const customComponents = {
</div>
)
},
showMore: (showMoreProps) => {
return (
<button
id="my-custom-show-more"
style={{ border: '4px solid red', cursor: 'pointer' }}
onClick={() => {
action(
`custom showMore component clicked with props: ${JSON.stringify(
showMoreProps,
null,
2
)}`
)
}}
>
{showMoreProps.count} more!
</button>
)
},
}

export default customComponents

0 comments on commit 770be8b

Please sign in to comment.