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

feat(components): showMore component customization #2537

Merged
merged 1 commit into from
Oct 1, 2024
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
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