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

Make month event min height customizable and fix for custom events #534

Merged
merged 4 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions src/components/CalendarBodyForMonthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface CalendarBodyForMonthViewProps<T> {
renderEvent?: EventRenderer<T>
maxVisibleEventCount: number
weekStartsOn: WeekNum
eventMinHeight: number
}

function _CalendarBodyForMonthView<T>({
Expand All @@ -45,6 +46,7 @@ function _CalendarBodyForMonthView<T>({
renderEvent,
maxVisibleEventCount,
weekStartsOn,
eventMinHeight,
}: CalendarBodyForMonthViewProps<T>) {
const { now } = useNow(!hideNowIndicator)
const [calendarWidth, setCalendarWidth] = React.useState<number>(0)
Expand Down Expand Up @@ -160,6 +162,7 @@ function _CalendarBodyForMonthView<T>({
dayOfTheWeek={ii}
calendarWidth={calendarWidth}
isRTL={theme.isRTL}
eventMinHeight={eventMinHeight}
/>
),
],
Expand Down
3 changes: 3 additions & 0 deletions src/components/CalendarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface CalendarContainerProps<T> {
onPressEvent?: (event: ICalendarEvent<T>) => void
weekEndsOn?: WeekNum
maxVisibleEventCount?: number
eventMinHeight?: number
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename it to eventMinHeightForMonthView as it affects only for the month view?

}

function _CalendarContainer<T>({
Expand Down Expand Up @@ -100,6 +101,7 @@ function _CalendarContainer<T>({
renderHeaderForMonthView: HeaderComponentForMonthView = CalendarHeaderForMonthView,
weekEndsOn = 6,
maxVisibleEventCount = 3,
eventMinHeight = 22,
}: CalendarContainerProps<T>) {
const [targetDate, setTargetDate] = React.useState(dayjs(date))

Expand Down Expand Up @@ -191,6 +193,7 @@ function _CalendarContainer<T>({
renderEvent={renderEvent}
targetDate={targetDate}
maxVisibleEventCount={maxVisibleEventCount}
eventMinHeight={eventMinHeight}
/>
</React.Fragment>
)
Expand Down
44 changes: 23 additions & 21 deletions src/components/CalendarEventForMonthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface CalendarEventProps<T> {
dayOfTheWeek: number
calendarWidth: number
isRTL: boolean
eventMinHeight: number
}

function _CalendarEventForMonthView<T>({
Expand All @@ -28,6 +29,7 @@ function _CalendarEventForMonthView<T>({
dayOfTheWeek,
calendarWidth,
isRTL,
eventMinHeight,
}: CalendarEventProps<T>) {
const theme = useTheme()

Expand All @@ -54,28 +56,28 @@ function _CalendarEventForMonthView<T>({
],
})

if (renderEvent) {
return renderEvent(event, touchableOpacityProps)
}

return (
<View style={{ minHeight: 22 }}>
{((!isMultipleDays && date.isSame(event.start, 'day')) ||
(isMultipleDays && isMultipleDaysStart)) && (
<TouchableOpacity {...touchableOpacityProps}>
<Text
style={[
{ color: theme.palette.primary.contrastText },
theme.typography.xs,
u['truncate'],
isRTL && { textAlign: 'right' },
]}
numberOfLines={1}
>
{event.title}
</Text>
</TouchableOpacity>
)}
<View style={{ minHeight: eventMinHeight }}>
{(!isMultipleDays && date.isSame(event.start, 'day')) ||
(isMultipleDays && isMultipleDaysStart) ? (
renderEvent ? (
renderEvent(event, touchableOpacityProps)
) : (
<TouchableOpacity {...touchableOpacityProps}>
<Text
style={[
{ color: theme.palette.primary.contrastText },
theme.typography.xs,
u['truncate'],
isRTL && { textAlign: 'right' },
]}
numberOfLines={1}
>
{event.title}
</Text>
</TouchableOpacity>
)
) : null}
</View>
)
}
Expand Down