@super-calendar/dom 2.10.0 → 2.11.1
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/dist/index.d.mts +42 -14
- package/dist/index.d.ts +42 -14
- package/dist/index.js +118 -46
- package/dist/index.mjs +114 -48
- package/package.json +2 -2
- package/src/Calendar.tsx +18 -0
- package/src/MonthList.tsx +5 -0
- package/src/MonthView.tsx +19 -3
- package/src/TimeGrid.tsx +100 -28
- package/src/YearView.tsx +17 -5
- package/src/index.ts +2 -0
package/src/TimeGrid.tsx
CHANGED
|
@@ -32,6 +32,8 @@ import {
|
|
|
32
32
|
isBackgroundEvent,
|
|
33
33
|
eventAccessibilityLabel as defaultEventAccessibilityLabel,
|
|
34
34
|
type EventAccessibilityLabeler,
|
|
35
|
+
type CalendarLabels,
|
|
36
|
+
resolveCalendarLabels,
|
|
35
37
|
eventChipLayout,
|
|
36
38
|
eventTimeLabel,
|
|
37
39
|
formatHour,
|
|
@@ -195,6 +197,15 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
|
|
|
195
197
|
* band stays non-interactive and hidden from assistive tech.
|
|
196
198
|
*/
|
|
197
199
|
renderBusinessHours?: (band: BusinessHoursBand) => ReactNode;
|
|
200
|
+
/**
|
|
201
|
+
* A component that draws a `display: "background"` event's band in place of
|
|
202
|
+
* the themed shade. Rendered like `renderEvent`, it receives the event, the
|
|
203
|
+
* mode, `continuesBefore` / `continuesAfter` for a multi-day event, and
|
|
204
|
+
* `onPress`, which fires `onPressEvent`. The band then takes pointer events and
|
|
205
|
+
* is no longer hidden from assistive tech; cell clicks and drag-to-create are
|
|
206
|
+
* unreachable underneath it. Without it the band stays a shaded, inert range.
|
|
207
|
+
*/
|
|
208
|
+
renderBackgroundEvent?: DomRenderEvent<T>;
|
|
198
209
|
/** Show the current-time indicator on today's column (default true). */
|
|
199
210
|
showNowIndicator?: boolean;
|
|
200
211
|
/** Fixed "now" instant for the indicator (doesn't tick). Defaults to the device clock. */
|
|
@@ -203,6 +214,10 @@ export interface TimeGridProps<T = unknown> extends SlotStyleProps<TimeGridSlot>
|
|
|
203
214
|
timeZone?: string;
|
|
204
215
|
/** Show the all-day lane above the grid (default true). */
|
|
205
216
|
showAllDayEventCell?: boolean;
|
|
217
|
+
/** Show the "all-day" text beside the lane (default false). */
|
|
218
|
+
showAllDayLabel?: boolean;
|
|
219
|
+
/** Translations for the screen-reader words and gutter text; omitted keys use English. */
|
|
220
|
+
labels?: Partial<CalendarLabels>;
|
|
206
221
|
/** Tint Saturday/Sunday columns with the weekend background (default true). Set
|
|
207
222
|
* false to treat weekends like any other day. */
|
|
208
223
|
highlightWeekends?: boolean;
|
|
@@ -423,6 +438,7 @@ export function TimeGrid<T = unknown>({
|
|
|
423
438
|
keyboardEventNavigation = false,
|
|
424
439
|
businessHours,
|
|
425
440
|
renderBusinessHours,
|
|
441
|
+
renderBackgroundEvent,
|
|
426
442
|
showNowIndicator = true,
|
|
427
443
|
highlightWeekends = true,
|
|
428
444
|
eventStartEditable = true,
|
|
@@ -431,6 +447,8 @@ export function TimeGrid<T = unknown>({
|
|
|
431
447
|
now: nowProp,
|
|
432
448
|
timeZone,
|
|
433
449
|
showAllDayEventCell = true,
|
|
450
|
+
showAllDayLabel = false,
|
|
451
|
+
labels: labelsProp,
|
|
434
452
|
locale,
|
|
435
453
|
theme: themeOverrides,
|
|
436
454
|
height = 600,
|
|
@@ -450,6 +468,7 @@ export function TimeGrid<T = unknown>({
|
|
|
450
468
|
styles,
|
|
451
469
|
}: TimeGridProps<T>): ReactElement {
|
|
452
470
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
471
|
+
const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
|
|
453
472
|
const slot = createSlots<TimeGridSlot>({ classNames, styles });
|
|
454
473
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
455
474
|
const dfns = locale ? { locale } : undefined;
|
|
@@ -464,6 +483,7 @@ export function TimeGrid<T = unknown>({
|
|
|
464
483
|
const windowEnd = Math.max(windowStart + 1, Math.min(maxHour, 24));
|
|
465
484
|
const windowHours = windowEnd - windowStart;
|
|
466
485
|
const gutterWidth = hideHours ? 0 : GUTTER_WIDTH;
|
|
486
|
+
const RenderBackground = renderBackgroundEvent;
|
|
467
487
|
const visibleHours = useMemo(
|
|
468
488
|
() => Array.from({ length: windowHours }, (_, i) => windowStart + i),
|
|
469
489
|
[windowStart, windowHours],
|
|
@@ -1110,15 +1130,22 @@ export function TimeGrid<T = unknown>({
|
|
|
1110
1130
|
// `display: "background"` events, sliced per day and clipped to the window.
|
|
1111
1131
|
const backgroundByDay = useMemo(
|
|
1112
1132
|
() =>
|
|
1113
|
-
days.map((day) =>
|
|
1114
|
-
|
|
1133
|
+
days.map((day) => {
|
|
1134
|
+
const seen = new Map<string, number>();
|
|
1135
|
+
return backgroundBandsForDay(events, day)
|
|
1115
1136
|
.map((b) => ({
|
|
1116
1137
|
...b,
|
|
1117
1138
|
startHours: Math.max(b.startHours, windowStart),
|
|
1118
1139
|
endHours: Math.min(b.endHours, windowEnd),
|
|
1119
1140
|
}))
|
|
1120
|
-
.filter((b) => b.endHours > b.startHours)
|
|
1121
|
-
|
|
1141
|
+
.filter((b) => b.endHours > b.startHours)
|
|
1142
|
+
.map((b) => {
|
|
1143
|
+
const base = `bg-${b.event.start.toISOString()}-${b.event.end.toISOString()}`;
|
|
1144
|
+
const nth = (seen.get(base) ?? 0) + 1;
|
|
1145
|
+
seen.set(base, nth);
|
|
1146
|
+
return { ...b, key: nth === 1 ? base : `${base}-${nth}` };
|
|
1147
|
+
});
|
|
1148
|
+
}),
|
|
1122
1149
|
[days, events, windowStart, windowEnd],
|
|
1123
1150
|
);
|
|
1124
1151
|
const gridLines = useMemo(() => {
|
|
@@ -1187,7 +1214,9 @@ export function TimeGrid<T = unknown>({
|
|
|
1187
1214
|
});
|
|
1188
1215
|
const inner = (
|
|
1189
1216
|
<>
|
|
1190
|
-
<span style={VISUALLY_HIDDEN}>
|
|
1217
|
+
<span style={VISUALLY_HIDDEN}>
|
|
1218
|
+
{today ? `${dateLabel}, ${labels.today}` : dateLabel}
|
|
1219
|
+
</span>
|
|
1191
1220
|
<span
|
|
1192
1221
|
aria-hidden
|
|
1193
1222
|
{...slot("columnHeaderWeekday", { themed: { fontSize: 11, fontWeight: 600 } })}
|
|
@@ -1261,7 +1290,7 @@ export function TimeGrid<T = unknown>({
|
|
|
1261
1290
|
themed: { fontSize: 10, color: theme.textMuted, padding: "4px 6px 0 0" },
|
|
1262
1291
|
})}
|
|
1263
1292
|
>
|
|
1264
|
-
|
|
1293
|
+
{showAllDayLabel ? labels.allDay : null}
|
|
1265
1294
|
</div>
|
|
1266
1295
|
{allDayByDay.map((list, i) => {
|
|
1267
1296
|
const dayStart = startOfDay(days[i]);
|
|
@@ -1310,6 +1339,7 @@ export function TimeGrid<T = unknown>({
|
|
|
1310
1339
|
start: event.start,
|
|
1311
1340
|
end: event.end,
|
|
1312
1341
|
ampm,
|
|
1342
|
+
labels,
|
|
1313
1343
|
})
|
|
1314
1344
|
}
|
|
1315
1345
|
{...slot("allDayEvent", {
|
|
@@ -1449,26 +1479,50 @@ export function TimeGrid<T = unknown>({
|
|
|
1449
1479
|
{renderBusinessHours?.({ date: day, start: b.start, end: b.end })}
|
|
1450
1480
|
</div>
|
|
1451
1481
|
))}
|
|
1452
|
-
{/* Background events: shaded,
|
|
1453
|
-
{backgroundByDay[dayIndex].map((b
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1482
|
+
{/* Background events: shaded time ranges, or the consumer's own band. */}
|
|
1483
|
+
{backgroundByDay[dayIndex].map((b) => {
|
|
1484
|
+
const { key } = b;
|
|
1485
|
+
const geometry = {
|
|
1486
|
+
position: "absolute" as const,
|
|
1487
|
+
left: 0,
|
|
1488
|
+
right: 0,
|
|
1489
|
+
top: (b.startHours - windowStart) * hourHeight,
|
|
1490
|
+
height: (b.endHours - b.startHours) * hourHeight,
|
|
1491
|
+
zIndex: 0,
|
|
1492
|
+
overflow: "hidden" as const,
|
|
1493
|
+
};
|
|
1494
|
+
if (!RenderBackground) {
|
|
1495
|
+
return (
|
|
1496
|
+
<div
|
|
1497
|
+
key={key}
|
|
1498
|
+
aria-hidden
|
|
1499
|
+
title={b.event.title}
|
|
1500
|
+
{...slot("backgroundEvent", {
|
|
1501
|
+
base: { ...geometry, pointerEvents: "none" },
|
|
1502
|
+
themed: { background: theme.backgroundEvent },
|
|
1503
|
+
})}
|
|
1504
|
+
/>
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
const dayStart = startOfDay(days[dayIndex]);
|
|
1508
|
+
return (
|
|
1509
|
+
<div
|
|
1510
|
+
key={key}
|
|
1511
|
+
{...slot("backgroundEvent", { base: { ...geometry, pointerEvents: "auto" } })}
|
|
1512
|
+
>
|
|
1513
|
+
<RenderBackground
|
|
1514
|
+
event={b.event}
|
|
1515
|
+
mode={mode}
|
|
1516
|
+
isAllDay={false}
|
|
1517
|
+
boxHeight={geometry.height}
|
|
1518
|
+
continuesBefore={b.event.start < dayStart}
|
|
1519
|
+
continuesAfter={b.event.end > addDays(dayStart, 1)}
|
|
1520
|
+
ampm={ampm}
|
|
1521
|
+
onPress={() => onPressEvent?.(b.event)}
|
|
1522
|
+
/>
|
|
1523
|
+
</div>
|
|
1524
|
+
);
|
|
1525
|
+
})}
|
|
1472
1526
|
{/* Grid lines, painted over the shade so they stay visible. */}
|
|
1473
1527
|
<div
|
|
1474
1528
|
aria-hidden
|
|
@@ -1542,6 +1596,7 @@ export function TimeGrid<T = unknown>({
|
|
|
1542
1596
|
start: pe.event.start,
|
|
1543
1597
|
end: pe.event.end,
|
|
1544
1598
|
ampm,
|
|
1599
|
+
labels,
|
|
1545
1600
|
})
|
|
1546
1601
|
}
|
|
1547
1602
|
onKeyDown={(e) => {
|
|
@@ -1591,11 +1646,21 @@ export function TimeGrid<T = unknown>({
|
|
|
1591
1646
|
) : (
|
|
1592
1647
|
<DefaultDomEvent {...args} theme={theme} boxProps={slot("eventBox")} />
|
|
1593
1648
|
)}
|
|
1649
|
+
{/* A release without movement on a handle presses the event, like
|
|
1650
|
+
the box itself. Only when the box can move: otherwise it carries
|
|
1651
|
+
its own `onClick`, which would press the event a second time. */}
|
|
1594
1652
|
{canResize && !pe.continuesBefore ? (
|
|
1595
1653
|
<div
|
|
1596
1654
|
onPointerDown={(e) => {
|
|
1597
1655
|
e.stopPropagation();
|
|
1598
|
-
beginDrag(
|
|
1656
|
+
beginDrag(
|
|
1657
|
+
e,
|
|
1658
|
+
pe,
|
|
1659
|
+
key,
|
|
1660
|
+
"resize-start",
|
|
1661
|
+
dayIndex,
|
|
1662
|
+
canMove ? onPress : undefined,
|
|
1663
|
+
);
|
|
1599
1664
|
}}
|
|
1600
1665
|
style={{
|
|
1601
1666
|
position: "absolute",
|
|
@@ -1617,7 +1682,14 @@ export function TimeGrid<T = unknown>({
|
|
|
1617
1682
|
<div
|
|
1618
1683
|
onPointerDown={(e) => {
|
|
1619
1684
|
e.stopPropagation();
|
|
1620
|
-
beginDrag(
|
|
1685
|
+
beginDrag(
|
|
1686
|
+
e,
|
|
1687
|
+
pe,
|
|
1688
|
+
key,
|
|
1689
|
+
"resize",
|
|
1690
|
+
dayIndex,
|
|
1691
|
+
canMove ? onPress : undefined,
|
|
1692
|
+
);
|
|
1621
1693
|
}}
|
|
1622
1694
|
style={{
|
|
1623
1695
|
position: "absolute",
|
package/src/YearView.tsx
CHANGED
|
@@ -21,6 +21,11 @@ import {
|
|
|
21
21
|
type WeekStartsOn,
|
|
22
22
|
weekdayFormatToken,
|
|
23
23
|
} from "@super-calendar/core";
|
|
24
|
+
import {
|
|
25
|
+
type CalendarLabels,
|
|
26
|
+
dayAccessibilityLabel,
|
|
27
|
+
resolveCalendarLabels,
|
|
28
|
+
} from "@super-calendar/core";
|
|
24
29
|
import { createSlots, dataState, type SlotStyleProps } from "./slots";
|
|
25
30
|
import { type DomCalendarTheme, mergeDomTheme } from "./theme";
|
|
26
31
|
|
|
@@ -54,6 +59,8 @@ export interface YearViewProps<T = unknown>
|
|
|
54
59
|
/** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
|
|
55
60
|
hiddenDays?: number[];
|
|
56
61
|
locale?: Locale;
|
|
62
|
+
/** Translations for the screen-reader words; omitted keys use English. */
|
|
63
|
+
labels?: Partial<CalendarLabels>;
|
|
57
64
|
/** Highlight this date instead of the real "today". */
|
|
58
65
|
activeDate?: Date;
|
|
59
66
|
/** A selected span: endpoints get a filled badge, the days between get the range band. */
|
|
@@ -104,6 +111,7 @@ export function YearView<T = unknown>({
|
|
|
104
111
|
weekStartsOn = 0,
|
|
105
112
|
hiddenDays,
|
|
106
113
|
locale,
|
|
114
|
+
labels: labelsProp,
|
|
107
115
|
activeDate,
|
|
108
116
|
selectedRange,
|
|
109
117
|
selectedDates,
|
|
@@ -122,6 +130,7 @@ export function YearView<T = unknown>({
|
|
|
122
130
|
styles,
|
|
123
131
|
}: YearViewProps<T>): ReactElement {
|
|
124
132
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
133
|
+
const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
|
|
125
134
|
const slot = createSlots<YearViewSlot>({ classNames, styles });
|
|
126
135
|
|
|
127
136
|
// Drag-to-select / drag-to-create: press a day and sweep across others (mini
|
|
@@ -302,11 +311,14 @@ export function YearView<T = unknown>({
|
|
|
302
311
|
creating != null &&
|
|
303
312
|
dayTime >= Math.min(creating.anchor, creating.hover) &&
|
|
304
313
|
dayTime <= Math.max(creating.anchor, creating.hover);
|
|
305
|
-
const label =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
state.
|
|
309
|
-
|
|
314
|
+
const label = dayAccessibilityLabel({
|
|
315
|
+
dateLabel: format(day, "EEEE, d LLLL yyyy", { locale }),
|
|
316
|
+
isToday,
|
|
317
|
+
isSelected: state.isSelected,
|
|
318
|
+
isDisabled: state.isDisabled,
|
|
319
|
+
hasEvents,
|
|
320
|
+
labels,
|
|
321
|
+
});
|
|
310
322
|
// Today wins over a selection, matching the month grid.
|
|
311
323
|
const badge = dayBadgeKind(state, isHighlighted);
|
|
312
324
|
const daySlot = slot("day", {
|