Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix(calendar): make view a widget option only and use hover for details (#7266)

Thomas7ded153bd2c6
diff --git a/apps/docs/docs/widgets/calendar/index.mdx b/apps/docs/docs/widgets/calendar/index.mdx
index 33403cfc9..4b151b8f7 100644
--- a/apps/docs/docs/widgets/calendar/index.mdx
+++ b/apps/docs/docs/widgets/calendar/index.mdx
@@ -25,9 +25,7 @@ import { icalIntegration } from "@site/docs/integrations/ical";
The Calendar widget combines events and upcoming media releases. Healthy integrations remain visible when another
source fails.
-View choices are remembered per widget in this browser, including on read-only boards. They do not change the
-configured default or other users' views. Set the shared default in the widget configuration.
-Advanced view starts in Agenda and remembers its own browser-local selection. Timed events without an end time
+Advanced view always shows the Agenda. Timed events without an end time
occupy a 30-minute slot in Day and Week; their details keep the original event time.
### Supported integrations
@@ -51,16 +49,15 @@ occupy a 30-minute slot in Day and Week; their details keep the original event t
| View | Preview |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
-| **Compact month (default)** | <img src="/img/widgets/calendar/current-view.png" width={800} height={560} alt="Default compact month with colored event indicators" /> |
-| Month | <img src="/img/widgets/calendar/month-view.png" width={400} height={280} alt="Month grid with event times, titles, and overflow counts" /> |
-| Week | <img src="/img/widgets/calendar/week-view.png" width={400} height={280} alt="Week time grid with visible all-day events" /> |
-| Day | <img src="/img/widgets/calendar/day-view.png" width={400} height={280} alt="Day time grid with visible all-day and overlapping events" /> |
-| Agenda | <img src="/img/widgets/calendar/advanced-view.png" width={400} height={280} alt="Agenda with grouped events, source labels, and event details" /> |
+| **Compact month (default)** | <img src="/img/widgets/calendar/current-view.png" width={800} height={592} alt="Default compact month with colored event indicators" /> |
+| Month | <img src="/img/widgets/calendar/month-view.png" width={400} height={296} alt="Month grid with event times and titles" /> |
+| Week | <img src="/img/widgets/calendar/week-view.png" width={400} height={296} alt="Week time grid with an all-day row" /> |
+| Day | <img src="/img/widgets/calendar/day-view.png" width={400} height={296} alt="Day time grid with an all-day row" /> |
+| Agenda | <img src="/img/widgets/calendar/advanced-view.png" width={400} height={296} alt="Agenda with grouped events, source labels, and event details" /> |
### Interactions
-- Hover or select a marked date to inspect its events.
-- Month overflow counts open the complete list of events for that date.
+- Hover a date or event to inspect its details.
<WidgetInteractionGuide />
diff --git a/apps/docs/docs/widgets/calendar/index.ts b/apps/docs/docs/widgets/calendar/index.ts
index f39304ae7..9516f5a3b 100644
--- a/apps/docs/docs/widgets/calendar/index.ts
+++ b/apps/docs/docs/widgets/calendar/index.ts
@@ -10,10 +10,16 @@ export const calendarWidget: WidgetDefinition = {
items: [
{
name: "View",
- description: "Shared default view. View menu selections are remembered only in the current browser.",
+ description: "Layout used to display events.",
values: "Compact month, Month, Week, Day, Agenda",
defaultValue: "Compact month",
},
+ {
+ name: "Hide header",
+ description: "Hide the date navigation. Widgets that are too short always hide it.",
+ values: { type: "boolean" },
+ defaultValue: "no",
+ },
{
name: "Radarr release type",
description: "Select what type of release date to see.",
diff --git a/apps/docs/public/img/widgets/calendar/advanced-view.png b/apps/docs/public/img/widgets/calendar/advanced-view.png
index 57addfd01..57d3d33c2 100644
Binary files a/apps/docs/public/img/widgets/calendar/advanced-view.png and b/apps/docs/public/img/widgets/calendar/advanced-view.png differ
diff --git a/apps/docs/public/img/widgets/calendar/current-view.png b/apps/docs/public/img/widgets/calendar/current-view.png
index 502412abe..ef42a80da 100644
Binary files a/apps/docs/public/img/widgets/calendar/current-view.png and b/apps/docs/public/img/widgets/calendar/current-view.png differ
diff --git a/apps/docs/public/img/widgets/calendar/day-view.png b/apps/docs/public/img/widgets/calendar/day-view.png
index b827e356d..8b3da2372 100644
Binary files a/apps/docs/public/img/widgets/calendar/day-view.png and b/apps/docs/public/img/widgets/calendar/day-view.png differ
diff --git a/apps/docs/public/img/widgets/calendar/month-view.png b/apps/docs/public/img/widgets/calendar/month-view.png
index 0af37f313..73863c84e 100644
Binary files a/apps/docs/public/img/widgets/calendar/month-view.png and b/apps/docs/public/img/widgets/calendar/month-view.png differ
diff --git a/apps/docs/public/img/widgets/calendar/week-view.png b/apps/docs/public/img/widgets/calendar/week-view.png
index c82fa168d..55b7ebfee 100644
Binary files a/apps/docs/public/img/widgets/calendar/week-view.png and b/apps/docs/public/img/widgets/calendar/week-view.png differ
diff --git a/packages/translation/src/lang/en.json b/packages/translation/src/lang/en.json
index cc4f5d04b..60c4f76c0 100644
--- a/packages/translation/src/lang/en.json
+++ b/packages/translation/src/lang/en.json
@@ -3228,6 +3228,10 @@
},
"viewMode": {
"label": "View"
+ },
+ "hideHeader": {
+ "label": "Hide header",
+ "description": "Hide the date navigation. Widgets that are too short always hide it."
}
},
"advanced": {
@@ -3245,15 +3249,11 @@
"agenda": "Agenda"
},
"controls": {
- "view": "Calendar view",
"today": "Today",
"previous": "Previous period",
"next": "Next period",
"noEvents": "No events in this period",
"more": "{count} more",
- "moreLabel": "Show {count} more events",
- "eventDetails": "Event details",
- "close": "Close event details",
"timeSlot": "Time slot",
"weekday": "Weekday"
}
diff --git a/packages/widgets/src/calendar/calendar-display.tsx b/packages/widgets/src/calendar/calendar-display.tsx
index 4bd2e2de5..ad5be8fb1 100644
--- a/packages/widgets/src/calendar/calendar-display.tsx
+++ b/packages/widgets/src/calendar/calendar-display.tsx
@@ -1,16 +1,13 @@
"use client";
-import { useEffect, useMemo, useState } from "react";
+import { useMemo } from "react";
import type { CSSProperties } from "react";
import {
ActionIcon,
Box,
- Button,
Center,
Group,
Loader,
- Menu,
- Modal,
Text,
Tooltip,
UnstyledButton,
@@ -20,7 +17,8 @@ import {
import { Calendar } from "@mantine/dates";
import { useElementSize } from "@mantine/hooks";
import { DayView, WeekView } from "@mantine/schedule";
-import { IconCheck, IconChevronDown, IconChevronLeft, IconChevronRight, IconCalendarEvent } from "@tabler/icons-react";
+import type { ScheduleEventData, WeekViewProps } from "@mantine/schedule";
+import { IconChevronLeft, IconChevronRight, IconCalendarEvent } from "@tabler/icons-react";
import dayjs from "dayjs";
import { useI18n } from "@homarr/translation/client";
@@ -32,10 +30,9 @@ import { IntegrationErrorIndicator } from "../common/integration-error-indicator
import { formatLocalizedTime } from "../common/locale";
import { CalendarDay } from "./calender-day";
import { getCalendarAgendaEvents, groupEventsByDate, splitEvents, toCalendarDateKey } from "./calendar-events";
-import { CalendarEventList } from "./calendar-event-list";
+import { CalendarEventList, CalendarEventsHoverCard } from "./calendar-event-list";
import type { CalendarEventWithSource } from "./calendar-event-list";
import { getCalendarScheduleEvents, isCalendarAllDayEvent } from "./calendar-schedule-events";
-import { calendarViews } from "./calendar-view";
import type { CalendarView } from "./calendar-view";
import classes from "./component.module.css";
@@ -47,11 +44,10 @@ interface CalendarDisplayProps {
month: Date;
setMonth: (date: Date) => void;
view: CalendarView;
- setView: (view: CalendarView) => void;
+ hideHeader: boolean;
releaseType: readonly string[];
locale: string;
firstDayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6;
- radius: CSSProperties["borderRadius"];
}
export const CalendarDisplay = ({
@@ -62,17 +58,14 @@ export const CalendarDisplay = ({
month: date,
setMonth: setDate,
view,
- setView,
+ hideHeader,
releaseType,
locale,
firstDayOfWeek,
- radius,
}: CalendarDisplayProps) => {
const t = useI18n("widget.calendar");
- const { ref, width, height } = useElementSize();
+ const { ref, width } = useElementSize();
const { ref: bodyRef, height: bodyHeight } = useElementSize();
- const [details, setDetails] = useState<CalendarEventWithSource[] | null>(null);
- useEffect(() => setDetails(null), [date, view]);
const filteredEvents = useMemo(
() =>
events.filter((event) => event.metadata?.type !== "radarr" || releaseType.includes(event.metadata.releaseType)),
@@ -97,16 +90,11 @@ export const CalendarDisplay = ({
timeSlot: t("controls.timeSlot"),
moreLabel: (count: number) => t("controls.more", { count }),
};
- const openEvent = (event: (typeof scheduleEvents)[number]) => {
- if (isEditMode) return;
- const original = event.payload?.event as CalendarEventWithSource | undefined;
- if (original) setDetails([original]);
- };
- const openDay = (value: string) => {
- if (isEditMode) return;
- const dayEvents = eventsByDate.get(value) as CalendarEventWithSource[] | undefined;
- if (dayEvents?.length) setDetails(dayEvents);
- };
+ const renderEvent: WeekViewProps["renderEvent"] = (event, props) => (
+ <CalendarEventsHoverCard events={getOriginalEvents(event)} disabled={isEditMode}>
+ <UnstyledButton {...props} />
+ </CalendarEventsHoverCard>
+ );
const moveDate = (amount: number) => {
if (view === "day") setDate(dayjs(date).add(amount, "day").toDate());
else if (view === "week") setDate(dayjs(date).add(amount, "week").toDate());
@@ -133,23 +121,36 @@ export const CalendarDisplay = ({
labels,
withHeader: false,
mode: scheduleMode,
- onEventClick: openEvent,
+ renderEvent,
+ renderEventBody: (event: ScheduleEventData) => <span className={classes.scheduleEvent}>{event.title}</span>,
scrollAreaProps: {
- h: bodyHeight,
- mah: bodyHeight,
+ h: "100%",
+ mah: "100%",
type: "auto" as const,
styles: { content: { minWidth: 0, width: "100%" } },
- startScrollPosition: { y: 8 * Math.max(40, bodyHeight / 12) },
+ startScrollPosition: { y: 8 * slotHeight },
},
slotHeight,
- allDaySlotHeight: 48,
+ allDaySlotHeight: 28,
h: "100%",
w: "100%",
slotLabelFormat: (value: string) => formatLocalizedTime(dayjs(value).toDate(), locale),
};
return (
- <Box ref={ref} className={classes.root} h="100%" w="100%" p="xs" data-calendar-view={view}>
+ <Box
+ ref={ref}
+ className={classes.root}
+ h="100%"
+ w="100%"
+ p="xs"
+ data-calendar-view={view}
+ data-hide-header={hideHeader || undefined}
+ style={{ "--calendar-weeks": weekCount } as CSSProperties}
+ >
+ <Box className={classes.floatingError}>
+ <IntegrationErrorIndicator results={failedIntegrations} />
+ </Box>
<Box className={classes.header}>
<Group className={classes.navigation} gap={2} wrap="nowrap">
<ActionIcon
@@ -190,31 +191,6 @@ export const CalendarDisplay = ({
<IconCalendarEvent size={16} />
</ActionIcon>
</Tooltip>
- <Menu withinPortal position="bottom-end" shadow="sm">
- <Menu.Target>
- <Button
- className={actionTargetClasses.root}
- variant="subtle"
- size="compact-xs"
- disabled={isEditMode}
- aria-label={`${t("controls.view")}: ${t(`view.${view}`)}`}
- rightSection={<IconChevronDown size={12} />}
- >
- {t(`view.${view}`)}
- </Button>
- </Menu.Target>
- <Menu.Dropdown>
- {calendarViews.map((mode) => (
- <Menu.Item
- key={mode}
- onClick={() => setView(mode)}
- rightSection={view === mode && <IconCheck size={14} aria-hidden />}
- >
- {t(`view.${mode}`)}
- </Menu.Item>
- ))}
- </Menu.Dropdown>
- </Menu>
</Group>
</Box>
<Box ref={bodyRef} className={classes.body}>
@@ -234,19 +210,16 @@ export const CalendarDisplay = ({
firstDayOfWeek={firstDayOfWeek}
static={view === "month"}
className={classes.calendar}
+ classNames={{ weekday: classes.weekday, weekdaysRow: classes.weekdaysRow }}
w="100%"
h="100%"
- getDayProps={(value) => {
- if (view === "month") return {};
- return { onClick: () => openDay(value), disabled: isEditMode };
- }}
styles={{
calendarHeader: { display: "none" },
levelsGroup: { height: "100%" },
month: { height: "100%", tableLayout: "fixed" },
monthCell: { textAlign: "center", position: "relative", padding: 2 },
day: {
- borderRadius: radius,
+ borderRadius: "var(--mantine-radius-sm)",
width: "100%",
height: "100%",
position: "absolute",
@@ -257,32 +230,13 @@ export const CalendarDisplay = ({
maxWidth: "100%",
overflow: "hidden",
},
- weekday: { padding: 0, fontSize: "var(--mantine-font-size-xs)" },
- weekdaysRow: { height: 22 },
}}
renderDay={(value) => {
const tileDate = dayjs(value).toDate();
const dayEvents = (eventsByDate.get(toCalendarDateKey(tileDate)) ?? []) as CalendarEventWithSource[];
if (view === "month")
- return (
- <DetailedDay
- date={tileDate}
- events={dayEvents}
- locale={locale}
- cellHeight={(bodyHeight - 22) / weekCount}
- disabled={isEditMode}
- onOpen={setDetails}
- />
- );
- return (
- <CalendarDay
- date={tileDate}
- events={dayEvents}
- disabled={dayEvents.length === 0 || isEditMode}
- rootWidth={width}
- rootHeight={height}
- />
- );
+ return <DetailedDay date={tileDate} events={dayEvents} locale={locale} disabled={isEditMode} />;
+ return <CalendarDay date={tileDate} events={dayEvents} disabled={dayEvents.length === 0 || isEditMode} />;
}}
/>
)}
@@ -313,13 +267,9 @@ export const CalendarDisplay = ({
{...scheduleProps}
firstDayOfWeek={firstDayOfWeek}
withWeekNumber={false}
+ withCurrentTimeBubble={false}
classNames={{ weekViewAllDaySlots: classes.weekAllDay }}
- style={
- {
- "--week-view-min-slot-width": "0px",
- "--week-view-slots-label-width": width < 350 ? "2rem" : "3.5rem",
- } as CSSProperties
- }
+ className={classes.week}
styles={{
weekViewRoot: { height: "100%" },
weekViewScrollArea: { height: "100%" },
@@ -337,77 +287,51 @@ export const CalendarDisplay = ({
onDateChange={(value) => {
if (!isEditMode) setDate(dayjs(value).toDate());
}}
- onViewChange={(value) => {
- if (!isEditMode && value === "day") setView("day");
- }}
/>
)}
</Box>
- <Modal
- opened={details !== null}
- onClose={() => setDetails(null)}
- title={t("controls.eventDetails")}
- closeButtonProps={{ "aria-label": t("controls.close") }}
- centered
- size="lg"
- >
- {details && <CalendarEventList events={details} advanced locale={locale} />}
- </Modal>
</Box>
);
};
+const getOriginalEvents = (event: ScheduleEventData): CalendarEventWithSource[] => {
+ const original = event.payload?.event as CalendarEventWithSource | undefined;
+ if (!original) return [];
+ return [original];
+};
+
interface DetailedDayProps {
date: Date;
events: CalendarEventWithSource[];
locale: string;
- cellHeight: number;
disabled: boolean;
- onOpen: (events: CalendarEventWithSource[]) => void;
}
-const DetailedDay = ({ date, events, locale, cellHeight, disabled, onOpen }: DetailedDayProps) => {
+const DetailedDay = ({ date, events, locale, disabled }: DetailedDayProps) => {
const theme = useMantineTheme();
- const t = useI18n("widget.calendar");
- const maxRows = Math.max(0, Math.floor((cellHeight - 20) / 18));
+ const { ref, height } = useElementSize();
+ const maxRows = Math.max(0, Math.floor((height - 20) / 18));
let visibleCount = Math.min(events.length, maxRows);
if (events.length > maxRows) visibleCount = Math.max(0, maxRows - 1);
const hiddenCount = events.length - visibleCount;
return (
- <Box className={classes.detailedDay} data-compact={maxRows === 0 || undefined}>
- <UnstyledButton
- className={classes.dayNumber}
- aria-label={new Intl.DateTimeFormat(locale, { dateStyle: "full" }).format(date)}
- disabled={disabled || events.length === 0}
- onClick={() => onOpen(events)}
- >
- {date.getDate()}
- </UnstyledButton>
- {events.slice(0, visibleCount).map((event, index) => (
- <UnstyledButton
- key={index}
- disabled={disabled}
- className={classes.monthEvent}
- onClick={() => onOpen([event])}
- style={{ "--event-color": getThemeColor(event.indicatorColor ?? "blue", theme) } as CSSProperties}
- title={event.title}
- >
- {!isCalendarAllDayEvent(event) && (
- <span className={classes.eventTime}>{formatLocalizedTime(event.startDate, locale)} </span>
- )}
- {event.title}
- </UnstyledButton>
- ))}
- {hiddenCount > 0 && (
- <UnstyledButton
- disabled={disabled}
- className={classes.moreEvents}
- aria-label={t("controls.moreLabel", { count: hiddenCount })}
- onClick={() => onOpen(events)}
- >
- +{hiddenCount}
- </UnstyledButton>
- )}
- </Box>
+ <CalendarEventsHoverCard events={events} disabled={disabled}>
+ <Box ref={ref} className={classes.detailedDay} data-compact={maxRows === 0 || undefined}>
+ <span className={classes.dayNumber}>{date.getDate()}</span>
+ {events.slice(0, visibleCount).map((event, index) => (
+ <span
+ key={index}
+ className={classes.monthEvent}
+ style={{ "--event-color": getThemeColor(event.indicatorColor, theme) } as CSSProperties}
+ >
+ {!isCalendarAllDayEvent(event) && (
+ <span className={classes.eventTime}>{formatLocalizedTime(event.startDate, locale)} </span>
+ )}
+ {event.title}
+ </span>
+ ))}
+ {hiddenCount > 0 && <span className={classes.moreEvents}>+{hiddenCount}</span>}
+ </Box>
+ </CalendarEventsHoverCard>
);
};
diff --git a/packages/widgets/src/calendar/calendar-event-list.tsx b/packages/widgets/src/calendar/calendar-event-list.tsx
index 1385ae650..aa41ac00a 100644
--- a/packages/widgets/src/calendar/calendar-event-list.tsx
+++ b/packages/widgets/src/calendar/calendar-event-list.tsx
@@ -1,10 +1,12 @@
import { useId } from "react";
+import type { ReactNode } from "react";
import {
Badge,
Box,
Button,
darken,
Group,
+ HoverCard,
Image,
lighten,
ScrollArea,
@@ -28,6 +30,31 @@ export type CalendarEventWithSource = CalendarEvent & {
source?: { integrationId: string; integrationName: string };
};
+interface CalendarEventsHoverCardProps {
+ events: CalendarEvent[];
+ disabled: boolean;
+ children: ReactNode;
+}
+
+export const CalendarEventsHoverCard = ({ events, disabled, children }: CalendarEventsHoverCardProps) => (
+ <HoverCard
+ disabled={disabled || events.length === 0}
+ position="bottom"
+ withArrow
+ withinPortal
+ radius="lg"
+ shadow="sm"
+ transitionProps={{ transition: "pop" }}
+ openDelay={350}
+ closeDelay={400}
+ >
+ <HoverCard.Target>{children}</HoverCard.Target>
+ <HoverCard.Dropdown maw="calc(100vw - 24px)" w={512} ps={4} pe={4} pt={4} pb={0} style={{ overflow: "hidden" }}>
+ <CalendarEventList events={events} />
+ </HoverCard.Dropdown>
+ </HoverCard>
+);
+
interface CalendarEventListProps {
events: CalendarEventWithSource[];
advanced?: boolean;
diff --git a/packages/widgets/src/calendar/calendar-view.ts b/packages/widgets/src/calendar/calendar-view.ts
index 2ffb6eca6..3bd24b427 100644
--- a/packages/widgets/src/calendar/calendar-view.ts
+++ b/packages/widgets/src/calendar/calendar-view.ts
@@ -1,4 +1,2 @@
export const calendarViews = ["compact", "month", "week", "day", "agenda"] as const;
export type CalendarView = (typeof calendarViews)[number];
-
-export const isCalendarView = (value: unknown): value is CalendarView => calendarViews.some((view) => view === value);
diff --git a/packages/widgets/src/calendar/calender-day.tsx b/packages/widgets/src/calendar/calender-day.tsx
index 13ccf2dff..fad19cdef 100644
--- a/packages/widgets/src/calendar/calender-day.tsx
+++ b/packages/widgets/src/calendar/calender-day.tsx
@@ -1,121 +1,37 @@
-import { useMemo } from "react";
-import { Box, Container, HoverCard, Text, useMantineTheme } from "@mantine/core";
+import { Box } from "@mantine/core";
-import { useRequiredBoard } from "@homarr/boards/context";
import type { CalendarEvent } from "@homarr/integrations/types";
-import { CalendarEventList } from "./calendar-event-list";
+import { CalendarEventsHoverCard } from "./calendar-event-list";
+import classes from "./component.module.css";
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 = (
- <Container
- h="100%"
- w="100%"
- p={0}
- m={0}
- pos="relative"
- style={{
- alignItems: "center",
- borderRadius: actualItemRadius,
- cursor: disabled ? "default" : "pointer",
- display: "flex",
- flexDirection: "column",
- justifyContent: "center",
- }}
- >
- <Text ta={"center"} size={textSize} lh={1}>
- {date.getDate()}
- </Text>
- <NotificationIndicator
- events={events}
- size={indicatorSize}
- marginTop={indicatorMarginTop}
- visible={shouldShowIndicators}
- />
- </Container>
- );
-
- if (disabled) return cell;
-
- return (
- <HoverCard
- position="bottom"
- withArrow
- withinPortal
- radius="lg"
- shadow="sm"
- transitionProps={{ transition: "pop" }}
- openDelay={350}
- closeDelay={400}
- >
- <HoverCard.Target>{cell}</HoverCard.Target>
- <HoverCard.Dropdown maw="calc(100vw - 24px)" w={512} ps={4} pe={4} pt={4} pb={0} style={{ overflow: "hidden" }}>
- <CalendarEventList events={events} />
- </HoverCard.Dropdown>
- </HoverCard>
- );
-};
-
-interface NotificationIndicatorProps {
- events: CalendarEvent[];
- size: number;
- marginTop: number;
- visible: boolean;
-}
+export const CalendarDay = ({ date, events, disabled }: CalendarDayProps) => (
+ <CalendarEventsHoverCard events={events} disabled={disabled}>
+ <Box className={classes.compactDay} data-disabled={disabled || undefined}>
+ <span className={classes.compactDayNumber}>{date.getDate()}</span>
+ <NotificationIndicator events={events} />
+ </Box>
+ </CalendarEventsHoverCard>
+);
-const NotificationIndicator = ({ events, size, marginTop, visible }: NotificationIndicatorProps) => {
- const notificationEvents = [...new Set(events.map((event) => event.indicatorColor))].filter(
- (color): color is string => Boolean(color),
+const NotificationIndicator = ({ events }: { events: CalendarEvent[] }) => {
+ const colors = [...new Set(events.map((event) => event.indicatorColor))].filter((color): color is string =>
+ Boolean(color),
);
- if (!visible || notificationEvents.length === 0) return null;
+ if (colors.length === 0) return null;
return (
- <Box
- mt={marginTop}
- w="fit-content"
- maw="75%"
- p={0}
- style={{
- display: "grid",
- gridTemplateColumns: `repeat(${Math.min(notificationEvents.length, 3)}, ${size}px)`,
- gap: 2,
- justifyContent: "center",
- }}
- aria-hidden
- >
- {notificationEvents.map((notificationEvent) => {
- return (
- <Box key={notificationEvent} bg={notificationEvent} h={size} w={size} p={0} style={{ borderRadius: 999 }} />
- );
- })}
+ <Box className={classes.indicators} aria-hidden>
+ {colors.map((color) => (
+ <Box key={color} bg={color} className={classes.indicator} />
+ ))}
</Box>
);
};
diff --git a/packages/widgets/src/calendar/component.module.css b/packages/widgets/src/calendar/component.module.css
index 7346d93d1..615931264 100644
--- a/packages/widgets/src/calendar/component.module.css
+++ b/packages/widgets/src/calendar/component.module.css
@@ -1,20 +1,27 @@
.root {
+ position: relative;
display: flex;
flex-direction: column;
gap: 4px;
overflow: hidden;
- container-type: inline-size;
+ container-type: size;
+}
+.floatingError {
+ display: none;
+ position: absolute;
+ top: 4px;
+ inset-inline-end: 4px;
+ z-index: 1;
}
.header {
display: flex;
align-items: center;
- flex-wrap: wrap;
gap: 4px;
flex-shrink: 0;
}
.navigation {
flex: 1;
- min-width: 120px;
+ min-width: 0;
}
.dateLabel {
flex: 1;
@@ -29,6 +36,75 @@
min-height: 0;
min-width: 0;
overflow: hidden;
+ --calendar-header-rows: 1;
+ --calendar-weekday-rows: 1;
+ --calendar-cell: min(
+ 100cqw / 7,
+ 100cqh / (var(--calendar-weeks) + var(--calendar-header-rows) + var(--calendar-weekday-rows))
+ );
+}
+.root[data-hide-header] .header {
+ display: none;
+}
+.root[data-hide-header] .floatingError {
+ display: block;
+}
+.root[data-hide-header] .body {
+ --calendar-header-rows: 0;
+}
+.root .weekdaysRow {
+ height: calc(var(--calendar-cell) * 0.6);
+}
+.root .weekday {
+ padding: 0;
+ font-size: clamp(8px, calc(var(--calendar-cell) * 0.4), 20px);
+}
+.compactDay {
+ --calendar-font: clamp(8px, calc(var(--calendar-cell) * 0.6), 36px);
+ --indicator-size: clamp(3px, calc(var(--calendar-font) * 0.28), 10px);
+ position: relative;
+ width: 100%;
+ height: 100%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border-radius: var(--mantine-radius-sm);
+ cursor: pointer;
+}
+.compactDay[data-disabled] {
+ cursor: default;
+}
+.compactDayNumber {
+ font-size: var(--calendar-font);
+ line-height: 1;
+}
+.indicators {
+ position: absolute;
+ top: calc(50% + var(--calendar-font) * 0.48);
+ inset-inline: 12.5%;
+ display: flex;
+ justify-content: center;
+ gap: calc(var(--indicator-size) * 0.4);
+ overflow: hidden;
+}
+.indicator {
+ flex-shrink: 0;
+ width: var(--indicator-size);
+ height: var(--indicator-size);
+ border-radius: 999px;
+}
+@container (max-height: 220px) {
+ .header,
+ .weekdaysRow {
+ display: none;
+ }
+ .floatingError {
+ display: block;
+ }
+ .body {
+ --calendar-header-rows: 0;
+ --calendar-weekday-rows: 0;
+ }
}
.calendar div[data-month-level] {
width: 100%;
@@ -77,10 +153,9 @@
margin-top: auto;
}
.detailedDay[data-compact] {
- flex-direction: row;
+ position: relative;
align-items: center;
justify-content: center;
- gap: 2px;
}
.detailedDay[data-compact] .dayNumber,
.detailedDay[data-compact] .moreEvents {
@@ -88,6 +163,26 @@
line-height: 12px;
margin: 0;
}
+.detailedDay[data-compact] .moreEvents {
+ position: absolute;
+ top: 1px;
+ inset-inline-end: 2px;
+ font-size: 8px;
+ line-height: 10px;
+}
+.root .week {
+ --week-view-min-slot-width: 0px;
+ --week-view-slots-label-width: 3.5rem;
+ --week-view-week-day-height: 2.5rem;
+}
+.scheduleEvent {
+ display: block;
+ font-size: 10px;
+ line-height: 1.2;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
.dayAllDay,
.weekAllDay,
.daySlotLabel[data-all-day] {
@@ -99,14 +194,12 @@
.weekAllDay {
top: var(--week-view-week-day-height);
}
-@container (max-width: 340px) {
- .navigation {
- flex-basis: 100%;
- }
-}
-
@container (max-width: 350px) {
.eventTime {
display: none;
}
+ .root .week {
+ --week-view-slots-label-width: 2rem;
+ --week-view-week-day-height: 2rem;
+ }
}
diff --git a/packages/widgets/src/calendar/component.tsx b/packages/widgets/src/calendar/component.tsx
index 286753ad4..790310c32 100644
--- a/packages/widgets/src/calendar/component.tsx
+++ b/packages/widgets/src/calendar/component.tsx
@@ -1,22 +1,17 @@
"use client";
import { useMemo, useState } from "react";
-import { useMantineTheme } from "@mantine/core";
import { getQueryKey } from "@trpc/react-query";
import { clientApi } from "@homarr/api/client";
-import { useRequiredBoard } from "@homarr/boards/context";
import { useSettings } from "@homarr/settings";
import { useCurrentIntlLocale } from "@homarr/translation/client";
import type { WidgetComponentProps } from "../definition";
import { getUsableWidgetQueryData } from "../common/query-state";
-import { useLocalWidgetState } from "../common/use-local-widget-state";
import { useWidgetRuntimeQueries } from "../runtime-hooks";
import type { CalendarEventWithSource } from "./calendar-event-list";
import { CalendarDisplay } from "./calendar-display";
-import type { CalendarView } from "./calendar-view";
-import { isCalendarView } from "./calendar-view";
export default function CalendarWidget(props: WidgetComponentProps<"calendar">) {
const [month, setMonth] = useState(() => new Date());
@@ -107,31 +102,18 @@ interface CalendarBaseProps extends WidgetComponentProps<"calendar"> {
setMonth: (date: Date) => void;
}
-const CalendarBase = ({ options, boardId, itemId, displayMode, ...props }: CalendarBaseProps) => {
+const CalendarBase = ({ options, displayMode, ...props }: CalendarBaseProps) => {
const locale = useCurrentIntlLocale();
const { firstDayOfWeek } = useSettings();
- const board = useRequiredBoard();
- const theme = useMantineTheme();
- const defaultView = displayMode === "advanced" ? "agenda" : options.viewMode;
- const [selectedView, setSelectedView] = useLocalWidgetState<CalendarView | null>({
- key: boardId && itemId ? `homarr:calendar:${boardId}:${itemId}:view:${displayMode ?? "compact"}` : undefined,
- version: 1,
- defaultValue: null,
- validate: (value): value is CalendarView | null => value === null || isCalendarView(value),
- });
- const setView = (view: CalendarView) => {
- if (!props.isEditMode) setSelectedView(view);
- };
return (
<CalendarDisplay
{...props}
releaseType={options.releaseType}
- view={props.isEditMode ? defaultView : (selectedView ?? defaultView)}
- setView={setView}
+ view={displayMode === "advanced" ? "agenda" : options.viewMode}
+ hideHeader={displayMode !== "advanced" && options.hideHeader}
locale={locale}
firstDayOfWeek={firstDayOfWeek}
- radius={theme.radius[board.itemRadius]}
/>
);
};
diff --git a/packages/widgets/src/calendar/index.ts b/packages/widgets/src/calendar/index.ts
index 3e035f2a8..055dbb77d 100644
--- a/packages/widgets/src/calendar/index.ts
+++ b/packages/widgets/src/calendar/index.ts
@@ -22,6 +22,10 @@ export const { definition, componentLoader } = createWidgetDefinition("calendar"
label: (t) => t(`widget.calendar.view.${value}`),
})),
}),
+ hideHeader: factory.switch({
+ defaultValue: false,
+ withDescription: true,
+ }),
releaseType: factory.multiSelect({
defaultValue: ["inCinemas", "digitalRelease"],
options: radarrReleaseTypes.map((value) => ({