@super-calendar/native 2.11.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.
@@ -32,9 +32,13 @@ import type {
32
32
  } from "../types";
33
33
  import { createSlots, type SlotStyleProps } from "../utils/slots";
34
34
  import { withEventAccessibilityLabel } from "../utils/withEventAccessibilityLabel";
35
+ import { CalendarLabelsContext } from "../utils/labels";
35
36
  import {
37
+ type CalendarLabels,
36
38
  type DateRange,
37
39
  type EventAccessibilityLabeler,
40
+ dayAccessibilityLabel,
41
+ resolveCalendarLabels,
38
42
  type WeekdayFormat,
39
43
  daySelectionState,
40
44
  isDateSelectable,
@@ -167,6 +171,8 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
167
171
  sortedMonthView?: boolean;
168
172
  /** Template for the overflow label; `{moreCount}` is replaced. Default "{moreCount} More". */
169
173
  moreLabel?: string;
174
+ /** Translations for the screen-reader words and gutter text; omitted keys use English. */
175
+ labels?: Partial<CalendarLabels>;
170
176
  /** Show dimmed days from adjacent months in the grid. Default true. */
171
177
  showAdjacentMonths?: boolean;
172
178
  /** Tint weekend day cells with the theme's weekend background. Default true. */
@@ -272,6 +278,7 @@ function MonthViewInner<T>({
272
278
  locale,
273
279
  sortedMonthView = true,
274
280
  moreLabel = "{moreCount} More",
281
+ labels: labelsProp,
275
282
  showAdjacentMonths = true,
276
283
  highlightWeekends = true,
277
284
  disableMonthEventCellPress = false,
@@ -310,6 +317,7 @@ function MonthViewInner<T>({
310
317
  }: MonthViewProps<T>): ReactElement {
311
318
  const theme = useCalendarTheme();
312
319
  const slot = createSlots<MonthViewSlot>({ classNames, styles: styleOverrides });
320
+ const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
313
321
  // Selection comes from context (so cached pages still repaint), but explicit
314
322
  // props win for direct/standalone use of MonthView.
315
323
  const selection = useCalendarSelection();
@@ -694,7 +702,14 @@ function MonthViewInner<T>({
694
702
  // Summarise the cell for screen readers: full date, today marker, and how
695
703
  // many events it holds (the chips inside are grouped under this cell).
696
704
  const eventCount = dayEvents.length;
697
- const accessibilityLabel = `${format(day, "EEEE, d LLLL yyyy", { locale })}${isToday ? ", today" : ""}${isSelected ? ", selected" : ""}${isDisabled ? ", unavailable" : ""}, ${eventCount} ${eventCount === 1 ? "event" : "events"}`;
705
+ const accessibilityLabel = dayAccessibilityLabel({
706
+ dateLabel: format(day, "EEEE, d LLLL yyyy", { locale }),
707
+ isToday,
708
+ isSelected,
709
+ isDisabled,
710
+ eventCount,
711
+ labels,
712
+ });
698
713
 
699
714
  const daySlot = slot("day", {
700
715
  // Events mode mirrors the dom renderer: left-aligned cell content with
@@ -856,7 +871,7 @@ function MonthViewInner<T>({
856
871
  : () => setMoreOpenFor({ day, events: dayEvents })
857
872
  }
858
873
  accessibilityRole="button"
859
- accessibilityLabel={`Show ${hiddenCount} more events`}
874
+ accessibilityLabel={`${labels.moreEvents(hiddenCount)}, ${format(day, "d MMMM", { locale })}`}
860
875
  allowFontScaling={false}
861
876
  >
862
877
  {moreLabel.replace("{moreCount}", String(hiddenCount))}
@@ -874,183 +889,191 @@ function MonthViewInner<T>({
874
889
  };
875
890
 
876
891
  return (
877
- <View style={styles.root}>
878
- {showTitle ? (
879
- <Text
880
- {...slot<TextStyle>("title", {
881
- base: styles.title,
882
- themed: [theme.text.monthTitle, { color: theme.colors.text }],
883
- })}
884
- allowFontScaling={false}
885
- >
886
- {format(date, "MMMM yyyy", locale ? { locale } : undefined)}
887
- </Text>
888
- ) : null}
889
- {showWeekdays ? (
890
- <View
891
- {...slot("weekdays", {
892
- base: styles.weekdayHeader,
893
- themed: theme.containers.weekdayHeader,
894
- })}
895
- >
896
- {weekdayLabels.map((day) => (
897
- <Text
898
- key={day.toISOString()}
899
- {...slot<TextStyle>("weekday", {
900
- base: styles.weekdayLabel,
901
- themed: [theme.text.weekday, { color: theme.colors.textMuted }],
902
- })}
903
- allowFontScaling={false}
904
- >
905
- {format(day, weekdayFormatToken(weekdayFormat), { locale })}
906
- </Text>
907
- ))}
908
- </View>
909
- ) : null}
910
- {moreOpenFor ? (
911
- <Modal transparent animationType="fade" visible onRequestClose={() => setMoreOpenFor(null)}>
912
- <Pressable
913
- style={styles.moreBackdrop}
914
- accessibilityLabel="Close"
915
- onPress={() => setMoreOpenFor(null)}
892
+ <CalendarLabelsContext.Provider value={labels}>
893
+ <View style={styles.root}>
894
+ {showTitle ? (
895
+ <Text
896
+ {...slot<TextStyle>("title", {
897
+ base: styles.title,
898
+ themed: [theme.text.monthTitle, { color: theme.colors.text }],
899
+ })}
900
+ allowFontScaling={false}
916
901
  >
917
- <Pressable
918
- // Swallow taps on the card so only the backdrop dismisses.
919
- onPress={() => {}}
920
- {...slot("morePopover", {
921
- base: styles.moreCard,
922
- themed: {
923
- backgroundColor: theme.colors.surface,
924
- borderColor: theme.colors.gridLine,
925
- },
926
- })}
927
- >
902
+ {format(date, "MMMM yyyy", locale ? { locale } : undefined)}
903
+ </Text>
904
+ ) : null}
905
+ {showWeekdays ? (
906
+ <View
907
+ {...slot("weekdays", {
908
+ base: styles.weekdayHeader,
909
+ themed: theme.containers.weekdayHeader,
910
+ })}
911
+ >
912
+ {weekdayLabels.map((day) => (
928
913
  <Text
929
- accessibilityRole="header"
930
- style={[styles.moreCardTitle, { color: theme.colors.text }]}
914
+ key={day.toISOString()}
915
+ {...slot<TextStyle>("weekday", {
916
+ base: styles.weekdayLabel,
917
+ themed: [theme.text.weekday, { color: theme.colors.textMuted }],
918
+ })}
931
919
  allowFontScaling={false}
932
920
  >
933
- {format(moreOpenFor.day, "EEEE, d LLLL yyyy", { locale })}
921
+ {format(day, weekdayFormatToken(weekdayFormat), { locale })}
934
922
  </Text>
935
- <ScrollView>
936
- {moreOpenFor.events.map((event, index) => (
937
- <View key={keyExtractor(event, index)} style={styles.moreCardRow}>
938
- <RenderEventComponent
939
- event={event}
940
- mode="month"
941
- isAllDay={isAllDayEvent(event)}
942
- onPress={() => {
943
- setMoreOpenFor(null);
944
- onPressEvent(event);
945
- }}
946
- />
947
- </View>
948
- ))}
949
- </ScrollView>
923
+ ))}
924
+ </View>
925
+ ) : null}
926
+ {moreOpenFor ? (
927
+ <Modal
928
+ transparent
929
+ animationType="fade"
930
+ visible
931
+ onRequestClose={() => setMoreOpenFor(null)}
932
+ >
933
+ <Pressable
934
+ style={styles.moreBackdrop}
935
+ accessibilityLabel={labels.close}
936
+ onPress={() => setMoreOpenFor(null)}
937
+ >
938
+ <Pressable
939
+ // Swallow taps on the card so only the backdrop dismisses.
940
+ onPress={() => {}}
941
+ {...slot("morePopover", {
942
+ base: styles.moreCard,
943
+ themed: {
944
+ backgroundColor: theme.colors.surface,
945
+ borderColor: theme.colors.gridLine,
946
+ },
947
+ })}
948
+ >
949
+ <Text
950
+ accessibilityRole="header"
951
+ style={[styles.moreCardTitle, { color: theme.colors.text }]}
952
+ allowFontScaling={false}
953
+ >
954
+ {format(moreOpenFor.day, "EEEE, d LLLL yyyy", { locale })}
955
+ </Text>
956
+ <ScrollView>
957
+ {moreOpenFor.events.map((event, index) => (
958
+ <View key={keyExtractor(event, index)} style={styles.moreCardRow}>
959
+ <RenderEventComponent
960
+ event={event}
961
+ mode="month"
962
+ isAllDay={isAllDayEvent(event)}
963
+ onPress={() => {
964
+ setMoreOpenFor(null);
965
+ onPressEvent(event);
966
+ }}
967
+ />
968
+ </View>
969
+ ))}
970
+ </ScrollView>
971
+ </Pressable>
950
972
  </Pressable>
951
- </Pressable>
952
- </Modal>
953
- ) : null}
954
- <MonthGridSurface gesture={dragGesture}>
955
- <View
956
- ref={gridRef}
957
- testID="month-grid"
958
- {...slot("grid", { base: styles.container })}
959
- onLayout={handleLayout}
960
- {...(isWeb && dragEnabled
961
- ? {
962
- onPointerDown: (event: RNPointerEvent) => {
963
- const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
964
- if (point) beginDrag(point.x, point.y);
965
- },
966
- onPointerMove: (event: RNPointerEvent) => {
967
- if (!dragRef.current) return;
968
- const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
969
- if (point) extendDrag(point.x, point.y);
970
- },
971
- }
972
- : null)}
973
- >
974
- {weeks.map((week, weekIndex) => {
975
- // Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
976
- // event is one bar across its columns, stacked into lanes; the bars render
977
- // in an overlay so they can span cells, and the cells reserve the lane rows
978
- // so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
979
- const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
980
- const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
981
- const cols = week.length;
982
- // With adjacent months hidden, clamp bars to the current-month columns so
983
- // none draw over the blank leading/trailing cells.
984
- let firstVisCol = 0;
985
- let lastVisCol = cols - 1;
986
- if (showGrid && !showAdjacentMonths) {
987
- const first = week.findIndex((d) => isSameMonth(d, date));
988
- if (first !== -1) {
989
- firstVisCol = first;
990
- lastVisCol = cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
973
+ </Modal>
974
+ ) : null}
975
+ <MonthGridSurface gesture={dragGesture}>
976
+ <View
977
+ ref={gridRef}
978
+ testID="month-grid"
979
+ {...slot("grid", { base: styles.container })}
980
+ onLayout={handleLayout}
981
+ {...(isWeb && dragEnabled
982
+ ? {
983
+ onPointerDown: (event: RNPointerEvent) => {
984
+ const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
985
+ if (point) beginDrag(point.x, point.y);
986
+ },
987
+ onPointerMove: (event: RNPointerEvent) => {
988
+ if (!dragRef.current) return;
989
+ const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
990
+ if (point) extendDrag(point.x, point.y);
991
+ },
992
+ }
993
+ : null)}
994
+ >
995
+ {weeks.map((week, weekIndex) => {
996
+ // Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
997
+ // event is one bar across its columns, stacked into lanes; the bars render
998
+ // in an overlay so they can span cells, and the cells reserve the lane rows
999
+ // so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
1000
+ const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
1001
+ const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
1002
+ const cols = week.length;
1003
+ // With adjacent months hidden, clamp bars to the current-month columns so
1004
+ // none draw over the blank leading/trailing cells.
1005
+ let firstVisCol = 0;
1006
+ let lastVisCol = cols - 1;
1007
+ if (showGrid && !showAdjacentMonths) {
1008
+ const first = week.findIndex((d) => isSameMonth(d, date));
1009
+ if (first !== -1) {
1010
+ firstVisCol = first;
1011
+ lastVisCol =
1012
+ cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
1013
+ }
991
1014
  }
992
- }
993
- return (
994
- <View
995
- {...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
996
- key={week[0].toISOString()}
997
- >
998
- {week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes))}
999
- {showGrid ? (
1000
- <View style={[StyleSheet.absoluteFill, { pointerEvents: "box-none" }]}>
1001
- {rowLayout.segments
1002
- .filter((seg) => seg.lane < visibleLanes)
1003
- .map((seg) => {
1004
- const startCol = Math.max(seg.startCol, firstVisCol);
1005
- const endCol = Math.min(seg.endCol, lastVisCol);
1006
- if (startCol > endCol) return null;
1007
- // Fade the bar being carried, so the tinted drop target reads
1008
- // as where it is going and this as where it came from.
1009
- const isDragged = drag?.kind === "move" && drag.event === seg.event;
1010
- return (
1011
- <View
1012
- key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`}
1013
- style={{
1014
- position: "absolute",
1015
- left: pct((startCol / cols) * 100),
1016
- width: pct(((endCol - startCol + 1) / cols) * 100),
1017
- top: BADGE_AREA + seg.lane * chipMetrics.chipRowHeight,
1018
- height: chipMetrics.chipHeight,
1019
- paddingHorizontal: CHIP_INSET_H,
1020
- // Let a sweep in progress reach the cells underneath.
1021
- pointerEvents: drag ? "none" : "box-none",
1022
- opacity: isDragged ? DRAGGED_BAR_OPACITY : 1,
1023
- }}
1024
- >
1025
- <RenderEventComponent
1026
- event={seg.event}
1027
- mode="month"
1028
- isAllDay={isAllDayEvent(seg.event)}
1029
- onPress={
1030
- disableMonthEventCellPress
1031
- ? () => {}
1032
- : () => {
1033
- if (consumeSuppressedPress()) return;
1034
- onPressEvent(seg.event);
1035
- }
1036
- }
1037
- onLongPress={
1038
- disableMonthEventCellPress || !onLongPressEvent
1039
- ? undefined
1040
- : () => onLongPressEvent(seg.event)
1041
- }
1042
- />
1043
- </View>
1044
- );
1045
- })}
1046
- </View>
1047
- ) : null}
1048
- </View>
1049
- );
1050
- })}
1051
- </View>
1052
- </MonthGridSurface>
1053
- </View>
1015
+ return (
1016
+ <View
1017
+ {...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
1018
+ key={week[0].toISOString()}
1019
+ >
1020
+ {week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes))}
1021
+ {showGrid ? (
1022
+ <View style={[StyleSheet.absoluteFill, { pointerEvents: "box-none" }]}>
1023
+ {rowLayout.segments
1024
+ .filter((seg) => seg.lane < visibleLanes)
1025
+ .map((seg) => {
1026
+ const startCol = Math.max(seg.startCol, firstVisCol);
1027
+ const endCol = Math.min(seg.endCol, lastVisCol);
1028
+ if (startCol > endCol) return null;
1029
+ // Fade the bar being carried, so the tinted drop target reads
1030
+ // as where it is going and this as where it came from.
1031
+ const isDragged = drag?.kind === "move" && drag.event === seg.event;
1032
+ return (
1033
+ <View
1034
+ key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`}
1035
+ style={{
1036
+ position: "absolute",
1037
+ left: pct((startCol / cols) * 100),
1038
+ width: pct(((endCol - startCol + 1) / cols) * 100),
1039
+ top: BADGE_AREA + seg.lane * chipMetrics.chipRowHeight,
1040
+ height: chipMetrics.chipHeight,
1041
+ paddingHorizontal: CHIP_INSET_H,
1042
+ // Let a sweep in progress reach the cells underneath.
1043
+ pointerEvents: drag ? "none" : "box-none",
1044
+ opacity: isDragged ? DRAGGED_BAR_OPACITY : 1,
1045
+ }}
1046
+ >
1047
+ <RenderEventComponent
1048
+ event={seg.event}
1049
+ mode="month"
1050
+ isAllDay={isAllDayEvent(seg.event)}
1051
+ onPress={
1052
+ disableMonthEventCellPress
1053
+ ? () => {}
1054
+ : () => {
1055
+ if (consumeSuppressedPress()) return;
1056
+ onPressEvent(seg.event);
1057
+ }
1058
+ }
1059
+ onLongPress={
1060
+ disableMonthEventCellPress || !onLongPressEvent
1061
+ ? undefined
1062
+ : () => onLongPressEvent(seg.event)
1063
+ }
1064
+ />
1065
+ </View>
1066
+ );
1067
+ })}
1068
+ </View>
1069
+ ) : null}
1070
+ </View>
1071
+ );
1072
+ })}
1073
+ </View>
1074
+ </MonthGridSurface>
1075
+ </View>
1076
+ </CalendarLabelsContext.Provider>
1054
1077
  );
1055
1078
  }
1056
1079
 
@@ -27,6 +27,8 @@ import {
27
27
  type PositionedEvent,
28
28
  resolveDraggedBounds,
29
29
  snapDeltaMinutes,
30
+ type CalendarLabels,
31
+ resolveCalendarLabels,
30
32
  } from "@super-calendar/core";
31
33
  import { useCalendarTheme } from "../theme";
32
34
 
@@ -167,6 +169,8 @@ export interface ResourceTimelineProps<T = unknown> {
167
169
  now?: Date;
168
170
  /** Shift the now indicator into this IANA zone (pair with `eventsInTimeZone`). */
169
171
  timeZone?: string;
172
+ /** Translations for the screen-reader drag actions; omitted keys use English. */
173
+ labels?: Partial<CalendarLabels>;
170
174
  }
171
175
 
172
176
  const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
@@ -250,6 +254,7 @@ type ResourceBarProps<T> = {
250
254
  /** Raise this bar's lane above its siblings while a drag is live. */
251
255
  onDragActiveChange: (laneId: string | null) => void;
252
256
  theme: ReturnType<typeof useCalendarTheme>;
257
+ labels: CalendarLabels;
253
258
  };
254
259
 
255
260
  // A bar with drag-to-move (long-press) and edge resize along the time axis
@@ -276,6 +281,7 @@ function ResourceBar<T>({
276
281
  dragActive,
277
282
  onDragActiveChange,
278
283
  theme,
284
+ labels,
279
285
  }: ResourceBarProps<T>): ReactElement {
280
286
  const moveX = useSharedValue(0);
281
287
  const moveCross = useSharedValue(0);
@@ -330,18 +336,19 @@ function ResourceBar<T>({
330
336
  // the same `commit` path. They all live on the bar's accessible Pressable (the
331
337
  // resize grip is a non-focusable visual/gesture affordance, so an `adjustable`
332
338
  // role there would never receive focus on a real device).
333
- const unit = (n: number) => `${n} minute${n === 1 ? "" : "s"}`;
334
339
  const laneTitle = (lane?: Resource) => lane && (lane.title || lane.id);
335
340
  const nextLane = laneTitle(resources[laneIndex + 1]);
336
341
  const previousLane = laneTitle(resources[laneIndex - 1]);
337
342
  const barActions = draggable
338
343
  ? [
339
- { name: "move-later", label: `Move ${unit(snapMinutes)} later` },
340
- { name: "move-earlier", label: `Move ${unit(snapMinutes)} earlier` },
341
- { name: "extend", label: `Extend by ${unit(snapMinutes)}` },
342
- { name: "shrink", label: `Shorten by ${unit(snapMinutes)}` },
343
- ...(nextLane ? [{ name: "move-next-lane", label: `Move to ${nextLane}` }] : []),
344
- ...(previousLane ? [{ name: "move-previous-lane", label: `Move to ${previousLane}` }] : []),
344
+ { name: "move-later", label: labels.moveLater(snapMinutes) },
345
+ { name: "move-earlier", label: labels.moveEarlier(snapMinutes) },
346
+ { name: "extend", label: labels.extend(snapMinutes) },
347
+ { name: "shrink", label: labels.shorten(snapMinutes) },
348
+ ...(nextLane ? [{ name: "move-next-lane", label: labels.moveToResource(nextLane) }] : []),
349
+ ...(previousLane
350
+ ? [{ name: "move-previous-lane", label: labels.moveToResource(previousLane) }]
351
+ : []),
345
352
  ]
346
353
  : undefined;
347
354
  const onBarAction = draggable
@@ -720,8 +727,10 @@ export function ResourceTimeline<T = unknown>({
720
727
  showNowIndicator = true,
721
728
  now: nowProp,
722
729
  timeZone,
730
+ labels: labelsProp,
723
731
  }: ResourceTimelineProps<T>): ReactElement {
724
732
  const theme = useCalendarTheme();
733
+ const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
725
734
  // Window the lanes to the requested page when resourcesPerPage caps them.
726
735
  const resources = useMemo(() => {
727
736
  if (!resourcesPerPage || resourcesPerPage <= 0) return allResources;
@@ -960,6 +969,7 @@ export function ResourceTimeline<T = unknown>({
960
969
  }
961
970
  onDragEvent={onDragEvent}
962
971
  theme={theme}
972
+ labels={labels}
963
973
  />
964
974
  );
965
975
  }
@@ -1139,6 +1149,7 @@ export function ResourceTimeline<T = unknown>({
1139
1149
  }
1140
1150
  onDragEvent={onDragEvent}
1141
1151
  theme={theme}
1152
+ labels={labels}
1142
1153
  />
1143
1154
  );
1144
1155
  }