import { useMemo } from "react"; import { Box, Container, Flex, HoverCard, Text, useMantineTheme } from "@mantine/core"; import { useRequiredBoard } from "@homarr/boards/context"; import type { CalendarEvent } from "@homarr/integrations/types"; import { CalendarEventList } from "./calendar-event-list"; interface CalendarDayProps { date: Date; events: CalendarEvent[]; disabled: boolean; rootWidth: number; rootHeight: number; } const fallbackDayScale = { textSize: "xs" as const, indicatorSize: 3, indicatorMarginTop: 2 }; const dayScaleTiers = [ { minAxisSize: 700, textSize: "lg" as const, indicatorSize: 6, indicatorMarginTop: 6 }, { minAxisSize: 450, textSize: "md" as const, indicatorSize: 5, indicatorMarginTop: 4 }, { minAxisSize: 250, textSize: "sm" as const, indicatorSize: 4, indicatorMarginTop: 3 }, { minAxisSize: 0, ...fallbackDayScale }, ]; const getDayScale = (minAxisSize: number) => dayScaleTiers.find((tier) => minAxisSize >= tier.minAxisSize) ?? fallbackDayScale; export const CalendarDay = ({ date, events, disabled, rootHeight, rootWidth }: CalendarDayProps) => { const board = useRequiredBoard(); const mantineTheme = useMantineTheme(); const actualItemRadius = mantineTheme.radius[board.itemRadius]; const minAxisSize = Math.min(rootWidth, rootHeight); const shouldShowIndicators = rootHeight >= 256; const { textSize, indicatorSize, indicatorMarginTop } = useMemo(() => getDayScale(minAxisSize), [minAxisSize]); const cell = ( {date.getDate()} ); if (disabled) return cell; return ( {cell} ); }; interface NotificationIndicatorProps { events: CalendarEvent[]; size: number; marginTop: number; visible: boolean; } const NotificationIndicator = ({ events, size, marginTop, visible }: NotificationIndicatorProps) => { const notificationEvents = [...new Set(events.map((event) => event.indicatorColor))].filter( (color): color is string => Boolean(color), ); if (!visible) return null; return ( {notificationEvents.map((notificationEvent) => { return ( ); })} ); };