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]: add support for a callback for activeDayFiller #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/flash-calendar/src/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const BaseCalendar = memo(function BaseCalendar(props: CalendarProps) {
daySpacing={calendarRowHorizontalSpacing}
isStartOfWeek={dayProps.isStartOfWeek}
key={dayProps.id}
metadata={dayProps}
theme={theme?.itemDayContainer}
>
<CalendarItemEmpty
Expand Down
12 changes: 9 additions & 3 deletions packages/flash-calendar/src/components/CalendarItemDay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ interface CalendarItemDayContainerTheme {
spacer?: ViewStyle;
/** An absolute positioned filler to join the active days together in a single
* complete range. */
activeDayFiller?: ViewStyle;
activeDayFiller?: ViewStyle | ((params: CalendarDayMetadata) => ViewStyle);
}

export interface CalendarItemDayContainerProps {
Expand All @@ -266,6 +266,7 @@ export interface CalendarItemDayContainerProps {
daySpacing: number;
/** The day's height */
dayHeight: number;
metadata?: CalendarDayMetadata;
}

export const CalendarItemDayContainer = ({
Expand All @@ -275,6 +276,7 @@ export const CalendarItemDayContainer = ({
theme,
daySpacing,
dayHeight,
metadata,
}: CalendarItemDayContainerProps) => {
const baseTheme = useTheme();
const spacerStyles = useMemo<ViewStyle>(() => {
Expand All @@ -299,13 +301,16 @@ export const CalendarItemDayContainer = ({
right: -(daySpacing + 1), // +1 to cover the 1px gap
width: daySpacing + 2, // +2 to cover the 1px gap (distributes evenly on both sides)
backgroundColor: baseTheme.colors.background.inverse.primary,
...theme?.activeDayFiller,
...(typeof theme?.activeDayFiller === "function" && !!metadata
? theme.activeDayFiller(metadata)
: theme?.activeDayFiller),
};
}, [
baseTheme.colors.background.inverse.primary,
daySpacing,
metadata,
shouldShowActiveDayFiller,
theme?.activeDayFiller,
theme,
]);

return (
Expand Down Expand Up @@ -351,6 +356,7 @@ export const CalendarItemDayWithContainer = ({
dayHeight={dayHeight}
daySpacing={daySpacing}
isStartOfWeek={metadata.isStartOfWeek}
metadata={metadata}
shouldShowActiveDayFiller={
metadata.isRangeValid && !metadata.isEndOfWeek
? !metadata.isEndOfRange
Expand Down
Loading