@super-calendar/dom 2.12.1 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/dist/index.d.mts +29 -9
- package/dist/index.d.ts +29 -9
- package/dist/index.js +200 -42
- package/dist/index.mjs +201 -43
- package/package.json +2 -2
- package/src/Calendar.tsx +112 -75
- package/src/MonthList.tsx +11 -4
- package/src/MonthView.tsx +26 -16
- package/src/TimeGrid.tsx +271 -74
- package/src/index.ts +2 -0
- package/src/touch.ts +61 -0
package/src/Calendar.tsx
CHANGED
|
@@ -14,10 +14,15 @@ import {
|
|
|
14
14
|
} from "date-fns";
|
|
15
15
|
import {
|
|
16
16
|
type CSSProperties,
|
|
17
|
+
type ForwardedRef,
|
|
18
|
+
forwardRef,
|
|
17
19
|
type KeyboardEvent as ReactKeyboardEvent,
|
|
18
20
|
type ReactElement,
|
|
19
21
|
type ReactNode,
|
|
22
|
+
type RefAttributes,
|
|
23
|
+
useImperativeHandle,
|
|
20
24
|
useMemo,
|
|
25
|
+
useRef,
|
|
21
26
|
} from "react";
|
|
22
27
|
import {
|
|
23
28
|
type CalendarMode,
|
|
@@ -33,7 +38,7 @@ import {
|
|
|
33
38
|
type WeekdayFormat,
|
|
34
39
|
type WeekStartsOn,
|
|
35
40
|
} from "@super-calendar/core";
|
|
36
|
-
import type { CalendarLabels } from "@super-calendar/core";
|
|
41
|
+
import type { CalendarHandle, CalendarLabels } from "@super-calendar/core";
|
|
37
42
|
import { Agenda, type AgendaSlot, type DomAgendaEvent } from "./Agenda";
|
|
38
43
|
import { YearView, type YearViewSlot } from "./YearView";
|
|
39
44
|
import { type DomMonthEvent, MonthView, type MonthViewSlot } from "./MonthView";
|
|
@@ -127,7 +132,7 @@ export interface CalendarProps<T = unknown>
|
|
|
127
132
|
* Default 1; pass 0 to let events fill their column.
|
|
128
133
|
*/
|
|
129
134
|
eventGap?: number;
|
|
130
|
-
/**
|
|
135
|
+
/** Vertical scroll, in minutes from midnight. Applied on mount and whenever it changes. */
|
|
131
136
|
scrollOffsetMinutes?: number;
|
|
132
137
|
/** Sub-divisions per hour for the grid lines. */
|
|
133
138
|
timeslots?: number;
|
|
@@ -171,6 +176,10 @@ export interface CalendarProps<T = unknown>
|
|
|
171
176
|
eventOverlap?: boolean;
|
|
172
177
|
/** Snap dragged/created events to this many minutes. */
|
|
173
178
|
dragStepMinutes?: number;
|
|
179
|
+
/** DOM touch/pen hold duration in ms (default 300). */
|
|
180
|
+
touchDragDelay?: number;
|
|
181
|
+
/** DOM touch/pen movement tolerance in px (default 8). */
|
|
182
|
+
touchDragThreshold?: number;
|
|
174
183
|
/**
|
|
175
184
|
* Tap empty space: the date+time pressed on the week/day grid, or the tapped
|
|
176
185
|
* day at midnight in `month` mode (where it fires alongside `onPressDay`).
|
|
@@ -205,6 +214,10 @@ export interface CalendarProps<T = unknown>
|
|
|
205
214
|
// --- Month mode ---
|
|
206
215
|
/** Max chips per day before a "+N more" row. */
|
|
207
216
|
maxVisibleEventCount?: number;
|
|
217
|
+
/** Month chip height in pixels; omit to keep the renderer default. */
|
|
218
|
+
chipHeight?: number;
|
|
219
|
+
/** Gap between month chip rows in pixels (default 2). */
|
|
220
|
+
chipGap?: number;
|
|
208
221
|
/** Overflow row template; `{moreCount}` is replaced. */
|
|
209
222
|
moreLabel?: string;
|
|
210
223
|
/** Translations for the screen-reader words and gutter text; omitted keys use English. */
|
|
@@ -311,79 +324,98 @@ function pageStep(
|
|
|
311
324
|
* <Calendar mode="week" date={new Date()} events={events} />
|
|
312
325
|
* ```
|
|
313
326
|
*/
|
|
314
|
-
export
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
327
|
+
export const Calendar = forwardRef(CalendarInner) as <T = unknown>(
|
|
328
|
+
props: CalendarProps<T> & RefAttributes<CalendarHandle>,
|
|
329
|
+
) => ReactElement;
|
|
330
|
+
|
|
331
|
+
function CalendarInner<T = unknown>(
|
|
332
|
+
{
|
|
333
|
+
mode = "week",
|
|
334
|
+
date,
|
|
335
|
+
events,
|
|
336
|
+
onChangeDate,
|
|
337
|
+
weekStartsOn = 0,
|
|
338
|
+
hiddenDays,
|
|
339
|
+
now,
|
|
340
|
+
numberOfDays,
|
|
341
|
+
locale,
|
|
342
|
+
timeZone,
|
|
343
|
+
theme,
|
|
344
|
+
height,
|
|
345
|
+
className,
|
|
346
|
+
style,
|
|
347
|
+
onPressEvent,
|
|
348
|
+
eventAccessibilityLabel,
|
|
349
|
+
// time grid
|
|
350
|
+
ampm,
|
|
351
|
+
hourHeight,
|
|
352
|
+
minEventHeight,
|
|
353
|
+
eventGap,
|
|
354
|
+
scrollOffsetMinutes,
|
|
355
|
+
timeslots,
|
|
356
|
+
minHour,
|
|
357
|
+
maxHour,
|
|
358
|
+
hideHours,
|
|
359
|
+
showWeekNumber,
|
|
360
|
+
weekNumberPrefix,
|
|
361
|
+
businessHours,
|
|
362
|
+
renderBusinessHours,
|
|
363
|
+
renderBackgroundEvent,
|
|
364
|
+
showNowIndicator,
|
|
365
|
+
showAllDayEventCell,
|
|
366
|
+
showAllDayLabel,
|
|
367
|
+
highlightWeekends,
|
|
368
|
+
eventStartEditable,
|
|
369
|
+
eventDurationEditable,
|
|
370
|
+
eventOverlap,
|
|
371
|
+
dragStepMinutes,
|
|
372
|
+
touchDragDelay,
|
|
373
|
+
touchDragThreshold,
|
|
374
|
+
onPressCell,
|
|
375
|
+
onCreateEvent,
|
|
376
|
+
onDragStart,
|
|
377
|
+
onDragEvent,
|
|
378
|
+
onPressDateHeader,
|
|
379
|
+
renderTimeEvent,
|
|
380
|
+
hourComponent,
|
|
381
|
+
keyboardEventNavigation,
|
|
382
|
+
// month
|
|
383
|
+
maxVisibleEventCount,
|
|
384
|
+
chipHeight,
|
|
385
|
+
chipGap,
|
|
386
|
+
moreLabel,
|
|
387
|
+
labels,
|
|
388
|
+
showAdjacentMonths,
|
|
389
|
+
showTitle,
|
|
390
|
+
weekdayFormat,
|
|
391
|
+
fillCellOnSelection,
|
|
392
|
+
selectedRange,
|
|
393
|
+
selectedDates,
|
|
394
|
+
minDate,
|
|
395
|
+
maxDate,
|
|
396
|
+
isDateDisabled,
|
|
397
|
+
keyboardDayNavigation,
|
|
398
|
+
onPressDay,
|
|
399
|
+
onSelectDrag,
|
|
400
|
+
onPressMonth,
|
|
401
|
+
onPressMore,
|
|
402
|
+
renderMonthEvent,
|
|
403
|
+
// schedule
|
|
404
|
+
renderScheduleEvent,
|
|
405
|
+
// styling
|
|
406
|
+
classNames,
|
|
407
|
+
styles,
|
|
408
|
+
}: CalendarProps<T>,
|
|
409
|
+
ref: ForwardedRef<CalendarHandle>,
|
|
410
|
+
): ReactElement {
|
|
411
|
+
const timeGridRef = useRef<CalendarHandle>(null);
|
|
412
|
+
useImperativeHandle(
|
|
413
|
+
ref,
|
|
414
|
+
() => ({
|
|
415
|
+
scrollToTime: (minutes, options) => timeGridRef.current?.scrollToTime(minutes, options),
|
|
416
|
+
}),
|
|
417
|
+
[],
|
|
418
|
+
);
|
|
387
419
|
// Materialise recurring events over the range this mode renders, then apply the
|
|
388
420
|
// display zone. Non-recurring and already-expanded events pass through
|
|
389
421
|
// untouched, so identity is preserved for the common (no-recurrence) case.
|
|
@@ -476,6 +508,8 @@ export function Calendar<T = unknown>({
|
|
|
476
508
|
classNames={classNames}
|
|
477
509
|
styles={styles}
|
|
478
510
|
maxVisibleEventCount={maxVisibleEventCount}
|
|
511
|
+
chipHeight={chipHeight}
|
|
512
|
+
chipGap={chipGap}
|
|
479
513
|
moreLabel={moreLabel}
|
|
480
514
|
showAdjacentMonths={showAdjacentMonths}
|
|
481
515
|
showTitle={showTitle}
|
|
@@ -503,6 +537,7 @@ export function Calendar<T = unknown>({
|
|
|
503
537
|
} else {
|
|
504
538
|
view = (
|
|
505
539
|
<TimeGrid<T>
|
|
540
|
+
ref={timeGridRef}
|
|
506
541
|
date={date}
|
|
507
542
|
mode={mode}
|
|
508
543
|
events={displayEvents}
|
|
@@ -542,6 +577,8 @@ export function Calendar<T = unknown>({
|
|
|
542
577
|
eventDurationEditable={eventDurationEditable}
|
|
543
578
|
eventOverlap={eventOverlap}
|
|
544
579
|
dragStepMinutes={dragStepMinutes}
|
|
580
|
+
touchDragDelay={touchDragDelay}
|
|
581
|
+
touchDragThreshold={touchDragThreshold}
|
|
545
582
|
onPressEvent={onPressEvent}
|
|
546
583
|
onPressCell={onPressCell}
|
|
547
584
|
onCreateEvent={onCreateEvent}
|
package/src/MonthList.tsx
CHANGED
|
@@ -52,6 +52,10 @@ export interface MonthListProps<T = unknown>
|
|
|
52
52
|
eventAccessibilityLabel?: EventAccessibilityLabeler<T>;
|
|
53
53
|
/** Max chips shown per day before a "+N more" row (default 3). */
|
|
54
54
|
maxVisibleEventCount?: number;
|
|
55
|
+
/** Month chip height in pixels; omit to keep the renderer default. */
|
|
56
|
+
chipHeight?: number;
|
|
57
|
+
/** Gap between month chip rows in pixels (default 2). */
|
|
58
|
+
chipGap?: number;
|
|
55
59
|
/** Template for the overflow row; `{moreCount}` is replaced. */
|
|
56
60
|
moreLabel?: string;
|
|
57
61
|
/** Translations for the screen-reader words and gutter text; omitted keys use English. */
|
|
@@ -102,6 +106,8 @@ export function MonthList<T = unknown>({
|
|
|
102
106
|
renderEvent,
|
|
103
107
|
eventAccessibilityLabel,
|
|
104
108
|
maxVisibleEventCount,
|
|
109
|
+
chipHeight,
|
|
110
|
+
chipGap,
|
|
105
111
|
moreLabel,
|
|
106
112
|
labels,
|
|
107
113
|
onPressEvent,
|
|
@@ -148,11 +154,10 @@ export function MonthList<T = unknown>({
|
|
|
148
154
|
return map;
|
|
149
155
|
}, [events]);
|
|
150
156
|
|
|
151
|
-
//
|
|
152
|
-
// actually change, not on every parent render.
|
|
157
|
+
// Cached rows refresh when selection, events, or chip dimensions change.
|
|
153
158
|
const extraData = useMemo(
|
|
154
|
-
() => [selectedRange, selectedDates, events] as const,
|
|
155
|
-
[selectedRange, selectedDates, events],
|
|
159
|
+
() => [selectedRange, selectedDates, events, chipHeight, chipGap] as const,
|
|
160
|
+
[selectedRange, selectedDates, events, chipHeight, chipGap],
|
|
156
161
|
);
|
|
157
162
|
|
|
158
163
|
return (
|
|
@@ -202,6 +207,8 @@ export function MonthList<T = unknown>({
|
|
|
202
207
|
renderEvent={renderEvent}
|
|
203
208
|
eventAccessibilityLabel={eventAccessibilityLabel}
|
|
204
209
|
maxVisibleEventCount={maxVisibleEventCount}
|
|
210
|
+
chipHeight={chipHeight}
|
|
211
|
+
chipGap={chipGap}
|
|
205
212
|
moreLabel={moreLabel}
|
|
206
213
|
labels={labels}
|
|
207
214
|
onPressEvent={onPressEvent}
|
package/src/MonthView.tsx
CHANGED
|
@@ -127,6 +127,10 @@ export interface MonthViewProps<T = unknown>
|
|
|
127
127
|
* per day, so a long bar can push a lightly-booked day's own events into "+N more".
|
|
128
128
|
*/
|
|
129
129
|
maxVisibleEventCount?: number;
|
|
130
|
+
/** Height of an event chip and of the "+N more" row, in px (default 18). */
|
|
131
|
+
chipHeight?: number;
|
|
132
|
+
/** Vertical gap between event chips, in px (default 2). */
|
|
133
|
+
chipGap?: number;
|
|
130
134
|
/** Template for the overflow row; `{moreCount}` is replaced (default "{moreCount} More"). */
|
|
131
135
|
moreLabel?: string;
|
|
132
136
|
/** Translations for the screen-reader words and gutter text; omitted keys use English. */
|
|
@@ -328,6 +332,7 @@ function eventCellDefault(
|
|
|
328
332
|
// True while a drag is over this day: a create sweep covering it, or a move
|
|
329
333
|
// about to land on it. Tinted over the weekend shading so the drag reads live.
|
|
330
334
|
isDragTarget: boolean,
|
|
335
|
+
chipGap: number,
|
|
331
336
|
): SlotDefault {
|
|
332
337
|
return {
|
|
333
338
|
base: {
|
|
@@ -338,7 +343,7 @@ function eventCellDefault(
|
|
|
338
343
|
cursor: day.isDisabled ? "default" : "pointer",
|
|
339
344
|
display: "flex",
|
|
340
345
|
flexDirection: "column",
|
|
341
|
-
gap:
|
|
346
|
+
gap: chipGap,
|
|
342
347
|
padding: CELL_PAD,
|
|
343
348
|
boxSizing: "border-box",
|
|
344
349
|
textAlign: "left",
|
|
@@ -397,12 +402,12 @@ const chipButtonDefault: SlotDefault = {
|
|
|
397
402
|
},
|
|
398
403
|
};
|
|
399
404
|
|
|
400
|
-
function chipDefault(theme: DomCalendarTheme): SlotDefault {
|
|
405
|
+
function chipDefault(theme: DomCalendarTheme, chipHeight: number): SlotDefault {
|
|
401
406
|
return {
|
|
402
407
|
base: {
|
|
403
408
|
display: "block",
|
|
404
|
-
height:
|
|
405
|
-
lineHeight: `${
|
|
409
|
+
height: chipHeight,
|
|
410
|
+
lineHeight: `${chipHeight}px`,
|
|
406
411
|
whiteSpace: "nowrap",
|
|
407
412
|
overflow: "hidden",
|
|
408
413
|
textOverflow: "ellipsis",
|
|
@@ -418,7 +423,7 @@ function chipDefault(theme: DomCalendarTheme): SlotDefault {
|
|
|
418
423
|
};
|
|
419
424
|
}
|
|
420
425
|
|
|
421
|
-
function moreButtonDefault(theme: DomCalendarTheme): SlotDefault {
|
|
426
|
+
function moreButtonDefault(theme: DomCalendarTheme, chipHeight: number): SlotDefault {
|
|
422
427
|
return {
|
|
423
428
|
base: {
|
|
424
429
|
position: "relative",
|
|
@@ -427,8 +432,8 @@ function moreButtonDefault(theme: DomCalendarTheme): SlotDefault {
|
|
|
427
432
|
background: "transparent",
|
|
428
433
|
cursor: "pointer",
|
|
429
434
|
textAlign: "left",
|
|
430
|
-
height:
|
|
431
|
-
lineHeight: `${
|
|
435
|
+
height: chipHeight,
|
|
436
|
+
lineHeight: `${chipHeight}px`,
|
|
432
437
|
fontFamily: "inherit",
|
|
433
438
|
},
|
|
434
439
|
themed: {
|
|
@@ -487,6 +492,8 @@ export function MonthView<T = unknown>({
|
|
|
487
492
|
renderEvent,
|
|
488
493
|
eventAccessibilityLabel,
|
|
489
494
|
maxVisibleEventCount = 3,
|
|
495
|
+
chipHeight = CHIP_HEIGHT,
|
|
496
|
+
chipGap = CHIP_GAP,
|
|
490
497
|
moreLabel = "{moreCount} More",
|
|
491
498
|
labels: labelsProp,
|
|
492
499
|
onPressEvent,
|
|
@@ -579,7 +586,7 @@ export function MonthView<T = unknown>({
|
|
|
579
586
|
}, [moreOpenFor]);
|
|
580
587
|
// Reserve `maxVisibleEventCount` rows below the date so every cell is uniform;
|
|
581
588
|
// when a day overflows, the last row becomes the "+N more" affordance.
|
|
582
|
-
const eventRowHeight = CELL_PAD * 2 + DATE_ROW + maxVisibleEventCount * (
|
|
589
|
+
const eventRowHeight = CELL_PAD * 2 + DATE_ROW + maxVisibleEventCount * (chipHeight + chipGap);
|
|
583
590
|
const { weeks, weekdays } = useMemo(
|
|
584
591
|
() =>
|
|
585
592
|
buildMonthGrid(date, {
|
|
@@ -833,7 +840,7 @@ export function MonthView<T = unknown>({
|
|
|
833
840
|
})
|
|
834
841
|
.filter((b) => b.startCol <= b.endCol);
|
|
835
842
|
const barChipButton = slot("chipButton", chipButtonDefault);
|
|
836
|
-
const barChip = slot("chip", chipDefault(theme));
|
|
843
|
+
const barChip = slot("chip", chipDefault(theme, chipHeight));
|
|
837
844
|
return (
|
|
838
845
|
<div
|
|
839
846
|
key={week.id}
|
|
@@ -897,6 +904,7 @@ export function MonthView<T = unknown>({
|
|
|
897
904
|
cellHeight,
|
|
898
905
|
highlightWeekends,
|
|
899
906
|
inCreate || isDropTarget,
|
|
907
|
+
chipGap,
|
|
900
908
|
),
|
|
901
909
|
);
|
|
902
910
|
return (
|
|
@@ -1019,9 +1027,9 @@ export function MonthView<T = unknown>({
|
|
|
1019
1027
|
top:
|
|
1020
1028
|
CELL_PAD +
|
|
1021
1029
|
DATE_ROW +
|
|
1022
|
-
|
|
1023
|
-
b.seg.lane * (
|
|
1024
|
-
height:
|
|
1030
|
+
chipGap +
|
|
1031
|
+
b.seg.lane * (chipHeight + chipGap),
|
|
1032
|
+
height: chipHeight,
|
|
1025
1033
|
pointerEvents: isDragging ? "none" : "auto",
|
|
1026
1034
|
// Fade the bar being carried, so the tinted drop
|
|
1027
1035
|
// target reads as where it is going.
|
|
@@ -1057,13 +1065,13 @@ export function MonthView<T = unknown>({
|
|
|
1057
1065
|
})}
|
|
1058
1066
|
<div
|
|
1059
1067
|
{...slot("events", {
|
|
1060
|
-
base: { display: "flex", flexDirection: "column", gap:
|
|
1068
|
+
base: { display: "flex", flexDirection: "column", gap: chipGap },
|
|
1061
1069
|
})}
|
|
1062
1070
|
>
|
|
1063
1071
|
{/* Reserve one row per visible lane so the absolute bars have
|
|
1064
1072
|
space and "+more" sits below them. */}
|
|
1065
1073
|
{Array.from({ length: visibleLanes }, (_, i) => (
|
|
1066
|
-
<div key={`lane-${i}`} aria-hidden style={{ height:
|
|
1074
|
+
<div key={`lane-${i}`} aria-hidden style={{ height: chipHeight }} />
|
|
1067
1075
|
))}
|
|
1068
1076
|
{hiddenEvents.length > 0 ? (
|
|
1069
1077
|
<button
|
|
@@ -1080,7 +1088,7 @@ export function MonthView<T = unknown>({
|
|
|
1080
1088
|
setMoreOpenFor((open) => (open === day.id ? null : day.id));
|
|
1081
1089
|
}
|
|
1082
1090
|
}}
|
|
1083
|
-
{...slot("more", moreButtonDefault(theme))}
|
|
1091
|
+
{...slot("more", moreButtonDefault(theme, chipHeight))}
|
|
1084
1092
|
aria-label={`${labels.moreEvents(hiddenEvents.length)}, ${dayLabel}`}
|
|
1085
1093
|
aria-expanded={onPressMore ? undefined : moreOpenFor === day.id}
|
|
1086
1094
|
>
|
|
@@ -1160,7 +1168,9 @@ export function MonthView<T = unknown>({
|
|
|
1160
1168
|
{Chip ? (
|
|
1161
1169
|
<Chip event={event} onPress={() => onPressEvent?.(event)} />
|
|
1162
1170
|
) : (
|
|
1163
|
-
<span {...slot("chip", chipDefault(theme))}>
|
|
1171
|
+
<span {...slot("chip", chipDefault(theme, chipHeight))}>
|
|
1172
|
+
{event.title}
|
|
1173
|
+
</span>
|
|
1164
1174
|
)}
|
|
1165
1175
|
</button>
|
|
1166
1176
|
))}
|