@delacour/react-native-ui 0.9.1-alpha.20261120122915 → 0.10.0-alpha.20261120132800

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delacour/react-native-ui",
3
- "version": "0.9.1-alpha.20261120122915",
3
+ "version": "0.10.0-alpha.20261120132800",
4
4
  "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -186,8 +186,8 @@
186
186
  "expo-blur": ">=15",
187
187
  "@maplibre/maplibre-react-native": "^11.5.0",
188
188
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
189
- "@delacour/react-native-bottom-sheet": "0.9.1-alpha.20261120122915",
190
- "@delacour/react-native-charts": "0.9.1-alpha.20261120122915",
189
+ "@delacour/react-native-bottom-sheet": "0.10.0-alpha.20261120132800",
190
+ "@delacour/react-native-charts": "0.10.0-alpha.20261120132800",
191
191
  "@legendapp/list": ">=3.3",
192
192
  "react-native-skia": ">=3.9.0",
193
193
  "expo-linear-gradient": ">=15",
@@ -15,7 +15,7 @@ sheets.
15
15
  | `calendar.tsx` | Root: selection and month state, bounds, the context value, the `Object.assign` surface |
16
16
  | `calendar-header.tsx` | `Calendar.Header` — prev arrow, caption, next arrow by default |
17
17
  | `calendar-nav.tsx` | `Calendar.Nav` — a ghost `Button` that disables itself at a bound |
18
- | `calendar-caption.tsx` | `Calendar.Caption` — label, or the button that cycles days → months → years |
18
+ | `calendar-caption.tsx` | `Calendar.Caption` — label, or the button that cycles days → months → years. `initialView` picks the view the calendar opens on (picker caption only) |
19
19
  | `calendar-weekdays.tsx` | `Calendar.Weekdays` — short names shown, full names spoken |
20
20
  | `calendar-grid.tsx` | `Calendar.Grid` — six weeks, the paging pan and slide, hosts the picker |
21
21
  | `calendar-day.tsx` | `Calendar.Day` — one cell: band, circle, number or custom content |
@@ -61,6 +61,13 @@ sheets.
61
61
  - **Disabled vs read-only.** `isDisabled` makes everything inert and fades the root. `isReadOnly`
62
62
  ignores day taps and leaves paging working — looking at another month changes nothing.
63
63
 
64
+ ## Opening view
65
+
66
+ - **`initialView` seeds the view once, on mount**, like `defaultMonth`. `years` is for a date of
67
+ birth: a year opens its months, a month its days, so a date decades back is three taps rather
68
+ than dozens of swipes. A `label` caption ignores it and opens on the days, because a jump view
69
+ with no caption button has no way back to them.
70
+
64
71
  ## Layout
65
72
 
66
73
  - **Always six weeks** (`CALENDAR_WEEKS`). A month that fits in four or five rows still draws six,
@@ -356,6 +356,44 @@ describe("Calendar", () => {
356
356
  expect(onMonthChange).toHaveBeenLastCalledWith(day(2026, 3, 1));
357
357
  });
358
358
 
359
+ test('initialView="years" opens on the year list, then walks year, month and day', async () => {
360
+ const onSelect = jest.fn();
361
+ await renderWithProviders(
362
+ <Calendar
363
+ initialView="years"
364
+ locale="en"
365
+ maxDate={day(2008, 11, 20)}
366
+ minDate={day(1926, 11, 20)}
367
+ onSelect={onSelect}
368
+ testID="cal"
369
+ />
370
+ );
371
+ expect(screen.getByRole("button", { name: "1926 – 2008" })).toBeOnTheScreen();
372
+ expect(screen.queryByTestId("cal-day-2008-11-01")).not.toBeOnTheScreen();
373
+
374
+ await fireEvent(screen.getByTestId("cal-year-1990"), "accessibilityTap");
375
+ expect(screen.getByRole("button", { name: "1990" })).toBeOnTheScreen();
376
+
377
+ await fireEvent(screen.getByTestId("cal-month-3"), "accessibilityTap");
378
+ expect(screen.getByRole("button", { name: "March 1990" })).toBeOnTheScreen();
379
+
380
+ await press("1990-03-23");
381
+ expect(onSelect).toHaveBeenLastCalledWith(day(1990, 3, 23));
382
+ });
383
+
384
+ test('initialView="months" opens on the months of the visible year', async () => {
385
+ await renderWithProviders(<Calendar initialView="months" locale="en" testID="cal" />);
386
+ expect(screen.getByRole("button", { name: "2026" })).toBeOnTheScreen();
387
+ expect(screen.getByTestId("cal-month-10")).toBeOnTheScreen();
388
+ });
389
+
390
+ test("initialView is ignored by a label caption, which has no way back to the days", async () => {
391
+ await renderWithProviders(<Calendar captionLayout="label" initialView="years" locale="en" testID="cal" />);
392
+ expect(screen.getByRole("adjustable", { name: "October 2026" })).toBeOnTheScreen();
393
+ expect(screen.queryByTestId("cal-year-2026")).not.toBeOnTheScreen();
394
+ expect(screen.getByTestId("cal-day-2026-10-14")).toBeOnTheScreen();
395
+ });
396
+
359
397
  test('captionLayout="label" is an adjustable text, not a button', async () => {
360
398
  await renderWithProviders(<Calendar captionLayout="label" locale="en" testID="cal" />);
361
399
  expect(screen.getByRole("adjustable", { name: "October 2026" })).toBeOnTheScreen();
@@ -127,6 +127,7 @@ function CalendarRoot(props: CalendarProps): ReactElement {
127
127
  locale,
128
128
  weekStartsOn = "auto",
129
129
  captionLayout = "picker",
130
+ initialView = "days",
130
131
  showOutsideDays = true,
131
132
  selectOutsideDays = false,
132
133
  isBordered = false,
@@ -168,7 +169,8 @@ function CalendarRoot(props: CalendarProps): ReactElement {
168
169
  });
169
170
  const visibleMonth = useMemo(() => startOfMonth(visibleMonthRaw), [visibleMonthRaw]);
170
171
 
171
- const [view, setView] = useState<CalendarView>("days");
172
+ // Read on mount only. A label caption cannot leave a jump view, so it always opens on the days.
173
+ const [view, setView] = useState<CalendarView>(captionLayout === "picker" ? initialView : "days");
172
174
  // The direction counts only for the month the calendar paged to. When `month` changes from
173
175
  // outside, the stale page is dropped during render, so the new month never slides in from the
174
176
  // side of an earlier page.
@@ -1,7 +1,7 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { ViewProps } from "react-native";
3
3
  import type { CalendarDate, CalendarDateRange, DateMatcher, Weekday } from "./calendar.date";
4
- import type { CalendarSize, CalendarVariant } from "./calendar.variants";
4
+ import type { CalendarSize, CalendarVariant, CalendarView } from "./calendar.variants";
5
5
 
6
6
  /**
7
7
  * What a calendar selects, and the value it reports — one shape per mode.
@@ -71,6 +71,14 @@ export type CalendarProps = Omit<ViewProps, "children"> &
71
71
  weekStartsOn?: Weekday | "auto";
72
72
  /** `picker` makes the caption open the month and year views. */
73
73
  captionLayout?: CalendarCaptionLayout;
74
+ /**
75
+ * The view the calendar opens on. `years` starts a date of birth at the year list: a year
76
+ * opens its months, a month opens its days. Read on mount only, like `defaultMonth`.
77
+ * A `label` caption always opens on the days, since it has no way back to them.
78
+ *
79
+ * @default "days"
80
+ */
81
+ initialView?: CalendarView;
74
82
  /** Draws the neighbouring months' days in the leading and trailing cells. */
75
83
  showOutsideDays?: boolean;
76
84
  /** Lets an outside day be picked, paging to its month. */
@@ -22,7 +22,7 @@ The subpath imports `BottomSheet`, so an app using it installs the optional
22
22
  | `date-picker-value.tsx` | `DatePicker.Value` — the formatted selection or the placeholder; a half range ends on a muted "End" |
23
23
  | `date-picker-icon.tsx` | `DatePicker.Icon` — `IconCalendar1`, muted or destructive |
24
24
  | `date-picker-content.tsx` | `DatePicker.Content` — the sheet (scrim, close, title, calendar, footer), or the calendar in place when inline |
25
- | `date-picker-calendar.tsx` | `DatePicker.Calendar` — `Calendar` bound to the picker, every tap routed through `select` |
25
+ | `date-picker-calendar.tsx` | `DatePicker.Calendar` — `Calendar` bound to the picker, every tap routed through `select`; keyed by `openCount`, so each opening starts on `initialView` (empty) or the value's days |
26
26
  | `date-picker-done.tsx` | `DatePicker.Done` — closes |
27
27
  | `date-picker-clear.tsx` | `DatePicker.Clear` — empties, reports, stays open |
28
28
  | `date-picker.context.tsx` | `DatePickerProvider`, `useDatePicker()`, `useDatePickerContext()`, `useDatePickerPart()` |
@@ -126,13 +126,19 @@ The subpath imports `BottomSheet`, so an app using it installs the optional
126
126
  anatomy can open near a likely date and bound paging and the year list without a custom
127
127
  `DatePicker.Calendar`. Omitted, the calendar derives `startMonth`/`endMonth` from
128
128
  `minDate`/`maxDate`, and opens on the selection's month, else today's.
129
- - **A date of birth sets `maxDate`.** Without it the picker allows future days and the year list
130
- runs a century ahead:
129
+ - **`initialView` and `defaultMonth` apply only while the picker is empty.** With a value, the
130
+ calendar opens on that value's month of days, so an edit starts where the last pick ended rather
131
+ than at the year list or a month chosen for an empty field. The root counts openings
132
+ (`openCount`) and keys the calendar by it, so every opening starts fresh — including a sheet
133
+ reopened before its close settled, or one kept mounted — rather than where the last one was left.
134
+ - **A date of birth sets `maxDate` and opens on the years.** Without `maxDate` the picker allows
135
+ future days and the year list runs a century ahead:
131
136
 
132
137
  ```tsx
133
138
  const now = today();
134
139
  <DatePicker
135
140
  defaultMonth={{ year: now.year - 30, month: 1, day: 1 }}
141
+ initialView="years"
136
142
  maxDate={addYears(now, -18)}
137
143
  minDate={{ year: now.year - 120, month: 1, day: 1 }}
138
144
  onValueChange={field.onChange}
@@ -16,6 +16,7 @@ export type DatePickerCalendarProps = Omit<
16
16
  | "isDisabled"
17
17
  | "isInvalid"
18
18
  | "isReadOnly"
19
+ | "initialView"
19
20
  >;
20
21
 
21
22
  /**
@@ -25,15 +26,19 @@ export type DatePickerCalendarProps = Omit<
25
26
  * included — and hands every tap to the picker's finish rule rather than straight to the caller:
26
27
  * a single day commits and closes, a range commits and closes once both ends exist, several days
27
28
  * commit on every toggle and stay open. Every other `Calendar` prop passes through.
29
+ *
30
+ * Keyed by the picker's `openCount`, so each opening starts on the root's `initialView` (or the
31
+ * picked value's days) even when the sheet engine keeps its content mounted between openings.
28
32
  */
29
33
  export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement {
30
34
  const picker = useDatePickerPart("DatePicker.Calendar");
31
35
  const { calendar, shown, select } = picker;
32
36
  const common = {
33
37
  captionLayout: calendar.captionLayout,
34
- defaultMonth: calendar.defaultMonth,
38
+ defaultMonth: picker.hasValue ? undefined : calendar.defaultMonth,
35
39
  disabled: calendar.disabled,
36
40
  endMonth: calendar.endMonth,
41
+ initialView: picker.hasValue ? "days" : calendar.initialView,
37
42
  isDisabled: picker.isDisabled,
38
43
  isInvalid: picker.isInvalid,
39
44
  isReadOnly: picker.isReadOnly,
@@ -54,6 +59,7 @@ export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement
54
59
  return (
55
60
  <Calendar
56
61
  {...common}
62
+ key={picker.openCount}
57
63
  mode="range"
58
64
  onSelect={(value) => select({ mode: "range", value })}
59
65
  selected={shown.value}
@@ -63,6 +69,7 @@ export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement
63
69
  return (
64
70
  <Calendar
65
71
  {...common}
72
+ key={picker.openCount}
66
73
  mode="multiple"
67
74
  onSelect={(value) => select({ mode: "multiple", value })}
68
75
  selected={shown.value}
@@ -72,6 +79,7 @@ export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement
72
79
  return (
73
80
  <Calendar
74
81
  {...common}
82
+ key={picker.openCount}
75
83
  mode="single"
76
84
  onSelect={(value) => select({ mode: "single", value })}
77
85
  selected={shown.value}
@@ -1,7 +1,7 @@
1
1
  import { createContext, type ReactElement, type ReactNode, use } from "react";
2
2
  import type { CalendarDate, CalendarSelectionState, DateMatcher, Weekday } from "../calendar/calendar.date";
3
3
  import type { CalendarCaptionLayout } from "../calendar/calendar.types";
4
- import type { CalendarSize } from "../calendar/calendar.variants";
4
+ import type { CalendarSize, CalendarView } from "../calendar/calendar.variants";
5
5
  import type { InputSize, InputVariant } from "../input/input.variants";
6
6
  import type { DatePickerMode, DatePickerPresentation } from "./date-picker.variants";
7
7
 
@@ -48,6 +48,11 @@ export type DatePickerContextValue = {
48
48
  description: string | undefined;
49
49
  doneLabel: string;
50
50
  clearLabel: string;
51
+ /**
52
+ * Counts the sheet's openings. The calendar is keyed by it, so each opening starts on
53
+ * `initialView` and the selection's month, never where the last opening was left.
54
+ */
55
+ openCount: number;
51
56
  calendar: {
52
57
  size: CalendarSize;
53
58
  minDate: CalendarDate | undefined;
@@ -58,6 +63,8 @@ export type DatePickerContextValue = {
58
63
  disabled: readonly DateMatcher[] | undefined;
59
64
  weekStartsOn: Weekday | "auto";
60
65
  captionLayout: CalendarCaptionLayout;
66
+ /** The view an empty picker's calendar opens on. A picked value always opens on its days. */
67
+ initialView: CalendarView;
61
68
  selectOutsideDays: boolean;
62
69
  today: CalendarDate | undefined;
63
70
  };
@@ -430,3 +430,59 @@ describe("DatePicker parts", () => {
430
430
  }
431
431
  });
432
432
  });
433
+
434
+ describe("DatePicker initialView", () => {
435
+ const bounds = { maxDate: { day: 20, month: 11, year: 2008 }, minDate: { day: 20, month: 11, year: 1926 } };
436
+ const year = (y: number) => screen.queryByTestId(`stay-calendar-year-${y}`);
437
+ const caption = () => screen.getByTestId("stay-calendar-caption");
438
+
439
+ test("an empty picker opens on the years, then walks year, month and day to a pick", async () => {
440
+ const onValueChange = jest.fn();
441
+ await renderWithProviders(<Picker defaultOpen initialView="years" onValueChange={onValueChange} {...bounds} />, {
442
+ wrapper: Providers,
443
+ });
444
+ expect(year(1990)).toBeOnTheScreen();
445
+ await tap(screen.getByTestId("stay-calendar-year-1990"));
446
+ await tap(screen.getByTestId("stay-calendar-month-3"));
447
+ await tap(day("1990-03-23"));
448
+ expect(onValueChange).toHaveBeenCalledWith({ day: 23, month: 3, year: 1990 });
449
+ });
450
+
451
+ test("a picked value opens on its month's days, not the years", async () => {
452
+ await renderWithProviders(
453
+ <Picker defaultOpen defaultValue={{ day: 23, month: 3, year: 1990 }} initialView="years" {...bounds} />,
454
+ { wrapper: Providers }
455
+ );
456
+ expect(caption()).toHaveAccessibleName("March 1990");
457
+ expect(year(1990)).not.toBeOnTheScreen();
458
+ });
459
+
460
+ test("reopening after a pick shows the picked month's days, even with a defaultMonth", async () => {
461
+ await renderWithProviders(
462
+ <Picker defaultMonth={{ day: 1, month: 1, year: 1996 }} initialView="years" {...bounds} />,
463
+ { wrapper: Providers }
464
+ );
465
+ await tap(trigger());
466
+ await tap(screen.getByTestId("stay-calendar-year-1990"));
467
+ await tap(screen.getByTestId("stay-calendar-month-3"));
468
+ await tap(day("1990-03-23"));
469
+ await settle();
470
+ expect(trigger()).not.toBeExpanded();
471
+
472
+ await tap(trigger());
473
+ expect(caption()).toHaveAccessibleName("March 1990");
474
+ expect(year(1990)).not.toBeOnTheScreen();
475
+ });
476
+
477
+ test("starts again on the years each time the sheet opens while empty", async () => {
478
+ const { rerender } = await renderWithProviders(<Picker initialView="years" isOpen {...bounds} />, {
479
+ wrapper: Providers,
480
+ });
481
+ await tap(screen.getByTestId("stay-calendar-year-1990"));
482
+ expect(year(1990)).not.toBeOnTheScreen();
483
+
484
+ await rerender(<Picker initialView="years" isOpen={false} {...bounds} />);
485
+ await rerender(<Picker initialView="years" isOpen {...bounds} />);
486
+ expect(year(1990)).toBeOnTheScreen();
487
+ });
488
+ });
@@ -83,6 +83,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
83
83
  locale,
84
84
  weekStartsOn = "auto",
85
85
  captionLayout = "picker",
86
+ initialView = "days",
86
87
  minDate,
87
88
  maxDate,
88
89
  defaultMonth,
@@ -157,6 +158,15 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
157
158
  setRangeDraft(null);
158
159
  }, [cancelPendingClose, isOpen, presentation]);
159
160
 
161
+ // Counted during render, the way React derives state from a prop: each opening, controlled or
162
+ // not, remounts the calendar on `initialView`.
163
+ const [openCount, setOpenCount] = useState(0);
164
+ const [wasOpen, setWasOpen] = useState(isOpen);
165
+ if (isOpen !== wasOpen) {
166
+ setWasOpen(isOpen);
167
+ if (isOpen) setOpenCount((count) => count + 1);
168
+ }
169
+
160
170
  const trigger = resolveTriggerState({ ...axes, isOpen });
161
171
 
162
172
  const open = useCallback(() => {
@@ -248,6 +258,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
248
258
  defaultMonth,
249
259
  disabled: disabledDates,
250
260
  endMonth,
261
+ initialView,
251
262
  maxDate,
252
263
  minDate,
253
264
  selectOutsideDays,
@@ -272,6 +283,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
272
283
  locale,
273
284
  mode,
274
285
  open,
286
+ openCount,
275
287
  placeholder: placeholder ?? resolveDefaultPlaceholder(mode),
276
288
  presentation,
277
289
  select,
@@ -301,6 +313,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
301
313
  doneLabel,
302
314
  endMonth,
303
315
  field?.label,
316
+ initialView,
304
317
  isClearable,
305
318
  isOpen,
306
319
  locale,
@@ -308,6 +321,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
308
321
  minDate,
309
322
  mode,
310
323
  open,
324
+ openCount,
311
325
  placeholder,
312
326
  presentation,
313
327
  select,
@@ -389,9 +403,10 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
389
403
  * <DatePicker disabledDates={[{ type: "weekday", days: [0, 6] }]} mode="multiple" />
390
404
  *
391
405
  * @example
392
- * // A date of birth: no future days, opens near a likely year, the year list bounded.
406
+ * // A date of birth: no future days, opens on the year list near a likely year, bounded.
393
407
  * <DatePicker
394
408
  * defaultMonth={{ year: today().year - 30, month: 1, day: 1 }}
409
+ * initialView="years"
395
410
  * maxDate={addYears(today(), -18)}
396
411
  * minDate={{ year: today().year - 120, month: 1, day: 1 }}
397
412
  * onValueChange={setDob}
@@ -2,7 +2,7 @@ import type { ReactNode } from "react";
2
2
  import type { ViewProps } from "react-native";
3
3
  import type { CalendarDate, CalendarDateRange, DateMatcher, Weekday } from "../calendar/calendar.date";
4
4
  import type { CalendarCaptionLayout } from "../calendar/calendar.types";
5
- import type { CalendarSize } from "../calendar/calendar.variants";
5
+ import type { CalendarSize, CalendarView } from "../calendar/calendar.variants";
6
6
  import type { InputSize, InputVariant } from "../input/input.variants";
7
7
  import type { DatePickerFormat, DatePickerFormatRange, DatePickerPresentation } from "./date-picker.variants";
8
8
 
@@ -57,11 +57,22 @@ export type DatePickerProps = Omit<ViewProps, "children"> &
57
57
  weekStartsOn?: Weekday | "auto";
58
58
  /** `picker` makes the calendar's caption open the month and year views. */
59
59
  captionLayout?: CalendarCaptionLayout;
60
+ /**
61
+ * The view the calendar opens on while nothing is picked. `years` starts a date of birth at
62
+ * the year list: a year opens its months, a month its days. With a value, the calendar opens
63
+ * on that value's days, so an edit starts where the last pick ended.
64
+ *
65
+ * @default "days"
66
+ */
67
+ initialView?: CalendarView;
60
68
  /** The earliest day that can be picked, inclusive. */
61
69
  minDate?: CalendarDate;
62
70
  /** The latest day that can be picked, inclusive. */
63
71
  maxDate?: CalendarDate;
64
- /** The month the calendar opens on. Omitted, the selection's month, else today's. */
72
+ /**
73
+ * The month an empty picker's calendar opens on. Omitted, today's. With a value, the calendar
74
+ * opens on the value's month instead.
75
+ */
65
76
  defaultMonth?: CalendarDate;
66
77
  /** The earliest month paging and the year list reach. Omitted, `minDate`'s month. */
67
78
  startMonth?: CalendarDate;