1 import type { CSSProperties, ComponentPropsWithoutRef, ReactNode, Ref } from 'react';
2 import { forwardRef } from 'react';
4 import { MINUTE } from '@proton/shared/lib/constants';
5 import clsx from '@proton/utils/clsx';
10 CalendarViewEventTemporaryEvent,
11 } from '../../containers/calendar/interface';
12 import { isBusySlotEvent } from '../../helpers/busySlots';
13 import PartDayBusyEvent from './PartDayBusyEvent';
14 import PartDayRegularEvent from './PartDayRegularEvent';
16 export type EventSize = 'sm' | 'xs' | '2xs';
18 interface PartDayEventViewProps extends ComponentPropsWithoutRef<'div'> {
21 isUnanswered?: boolean;
22 isCancelled?: boolean;
27 eventPartDuration?: number;
29 export const PartDayEventView = forwardRef<HTMLDivElement, PartDayEventViewProps>(function PartDayEventViewComponent(
41 }: PartDayEventViewProps,
42 ref: Ref<HTMLDivElement>
44 const canDisplayOnlyOneLine = eventPartDuration ? eventPartDuration < 75 * MINUTE : false;
47 // eslint-disable-next-line jsx-a11y/prefer-tag-over-role
52 'calendar-eventcell overflow-hidden',
53 isLoaded && 'isLoaded',
55 isSelected && 'isSelected',
56 isUnanswered && 'isUnanswered',
57 isCancelled && 'isCancelled',
58 size && `calendar-eventcell--${size}`,
59 canDisplayOnlyOneLine && 'calendar-eventcell--title-small-fit',
70 export interface PartDayEventProps {
73 formatTime: (date: Date) => string;
74 event: CalendarViewEvent | CalendarViewEventTemporaryEvent | CalendarViewBusyEvent;
75 eventPartDuration: number;
78 eventRef?: Ref<HTMLDivElement>;
81 const PartDayEvent = ({ event, ...rest }: PartDayEventProps) => {
82 return isBusySlotEvent(event) ? (
83 <PartDayBusyEvent event={event} {...rest} />
85 <PartDayRegularEvent event={event} {...rest} />
89 export default PartDayEvent;