Skip to content

Commit

Permalink
feat(components): showMore component customization (#2537)
Browse files Browse the repository at this point in the history
Closes #2391
  • Loading branch information
davidmh authored Oct 1, 2024
1 parent 856dddf commit afb3138
Show file tree
Hide file tree
Showing 6 changed files with 85 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
22 changes: 21 additions & 1 deletion src/EventEndingRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,30 @@ 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?.showMore) {
const ShowMore = components.showMore
// The received slot seems to be 1-based, but the range we use to pull the date is 0-based
const slotDate = slotMetrics.getDateForSlot(slot - 1)

return count ? (
<ShowMore
localizer={localizer}
slotDate={slotDate}
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 @@ -129,3 +129,13 @@ CustomDayColumnWrapper.parameters = {
},
},
}

export const CustomShowMore = Template.bind({})
CustomShowMore.storyName = 'add custom showMore'
CustomShowMore.args = {
defaultView: Views.MONTH,
events,
components: {
showMore: customComponents.showMore,
},
}
30 changes: 30 additions & 0 deletions stories/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ export const DragableCalendar = (props) => {
}

export const events = [
{
title: 'example 1',
start: moment().startOf('month').add(1, 'hours').toDate(),
end: moment().startOf('month').add(2, 'hours').toDate(),
allDay: false,
},
{
title: 'example 2',
start: moment().startOf('month').add(1, 'hours').toDate(),
end: moment().startOf('month').add(2, 'hours').toDate(),
allDay: false,
},
{
title: 'example 3',
start: moment().startOf('month').add(1, 'hours').toDate(),
end: moment().startOf('month').add(2, 'hours').toDate(),
allDay: false,
},
{
title: 'example 4',
start: moment().startOf('month').add(1, 'hours').toDate(),
end: moment().startOf('month').add(2, 'hours').toDate(),
allDay: false,
},
{
title: 'example 5',
start: moment().startOf('month').add(1, 'hours').toDate(),
end: moment().startOf('month').add(2, 'hours').toDate(),
allDay: false,
},
{
title: 'test',
start: moment().add(1, 'days').subtract(5, 'hours').toDate(),
Expand Down
1 change: 1 addition & 0 deletions stories/props/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const components = useMemo(() => ({
timeGutterHeader: MyTimeGutterWrapper,
resourceHeader: MyResourceHeader,
toolbar: MyToolbar,
showMore: MyShowMoreButton,
agenda: {
event: MyAgendaEvent, // with the agenda view use a different component to render events
time: MyAgendaTime,
Expand Down
21 changes: 21 additions & 0 deletions stories/resources/customComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ const customComponents = {
</div>
)
},
showMore: (showMoreProps) => {
return (
<button
id="my-custom-show-more"
style={{ border: '4px solid red', cursor: 'pointer' }}
onClick={() => {
console.log('showMoreProps', showMoreProps)
window.alert(`
Clicked ${showMoreProps.slotDate
.toISOString()
.substr(0, 10)} with ${
showMoreProps.remainingEvents.length
} remaining events.
Open the console for the full set of props.
`)
}}
>
{showMoreProps.count} more!
</button>
)
},
}

export default customComponents

0 comments on commit afb3138

Please sign in to comment.