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: allDayEventCellStyle #1020

Merged
merged 1 commit into from
Mar 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface CalendarProps<T extends ICalendarEventBase> {
| `onPressDateHeader` | no | `(date: Date) => void` | Event handler which will be fired when the user clicks a date from the header. |
| `mode` | no | `'month' \| 'week' \| '3days' \| 'day' \| 'schedule' \| 'custom'` | |
| `eventCellStyle` | no | `ViewStyle \| (event: ICalendarEvent<T>) => ViewStyle` | The style of Event cell. Accepts either style object (static) or function (dynamic). |
| `allDayEventCellStyle` | no | `ViewStyle \| (event: ICalendarEvent<T>) => ViewStyle` | The style of all day Event cell. Accepts either style object (static) or function (dynamic). |
| `headerContentStyle` | no | `ViewStyle` | The style of the Header's content. Accepts a style object (static). |
| `dayHeaderStyle` | no | `ViewStyle` | The style of the Header's day numbers. Accepts a style object (static). |
| `dayHeaderHighlightColor` | no | `string` | The style of the Header's highlighted day number. Accepts a style object (static). |
Expand Down
4 changes: 4 additions & 0 deletions src/components/CalendarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TextStyle, ViewStyle } from 'react-native'

import { MIN_HEIGHT } from '../commonStyles'
import {
AllDayEventCellStyle,
CalendarCellStyle,
CalendarCellTextStyle,
DateRangeHandler,
Expand Down Expand Up @@ -62,6 +63,7 @@ export interface CalendarContainerProps<T extends ICalendarEventBase> {
* Custom style. It accepts styles or an array of styles, or a function that returns styles or an array of styles.
*/
eventCellStyle?: EventCellStyle<T>
allDayEventCellStyle?: AllDayEventCellStyle<T>
calendarCellStyle?: CalendarCellStyle
calendarCellTextStyle?: CalendarCellTextStyle
calendarContainerStyle?: ViewStyle
Expand Down Expand Up @@ -143,6 +145,7 @@ function _CalendarContainer<T extends ICalendarEventBase>({
hourRowHeight,
ampm = false,
date,
allDayEventCellStyle = {},
eventCellStyle,
calendarCellStyle,
calendarCellTextStyle,
Expand Down Expand Up @@ -331,6 +334,7 @@ function _CalendarContainer<T extends ICalendarEventBase>({
const headerProps = {
...commonProps,
style: headerContainerStyle,
allDayEventCellStyle,
allDayEvents: allDayEvents,
onPressDateHeader: onPressDateHeader,
activeDate,
Expand Down
10 changes: 9 additions & 1 deletion src/components/CalendarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface CalendarHeaderProps<T extends ICalendarEventBase> {
dateRange: dayjs.Dayjs[]
cellHeight: number
style: ViewStyle
allDayEventCellStyle: ViewStyle | ((event: T) => ViewStyle)
allDayEvents: T[]
onPressDateHeader?: (date: Date) => void
onPressEvent?: (event: T) => void
Expand All @@ -31,6 +32,7 @@ function _CalendarHeader<T extends ICalendarEventBase>({
dateRange,
cellHeight,
style,
allDayEventCellStyle,
allDayEvents,
onPressDateHeader,
onPressEvent,
Expand Down Expand Up @@ -194,9 +196,15 @@ function _CalendarHeader<T extends ICalendarEventBase>({
if (!dayjs(date).isBetween(event.start, event.end, 'day', '[]')) {
return null
}

const getEventStyle =
typeof allDayEventCellStyle === 'function'
? allDayEventCellStyle
: () => allDayEventCellStyle

return (
<TouchableOpacity
style={[eventCellCss.style, primaryBg, u['mt-2']]}
style={[eventCellCss.style, primaryBg, u['mt-2'], getEventStyle(event)]}
key={index}
onPress={() => _onPressEvent(event)}
>
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export type EventCellStyle<T extends ICalendarEventBase> =
| ViewStyle[]
| ((event: T) => ViewStyle | ViewStyle[])

export type AllDayEventCellStyle<T extends ICalendarEventBase> =
| ViewStyle
| ((event: T) => ViewStyle)

export type CalendarCellStyle = ViewStyle | ((date?: Date, hourRowIndex?: number) => ViewStyle)

export type CalendarCellTextStyle = TextStyle | ((date?: Date, hourRowIndex?: number) => TextStyle)
Expand Down