@octanejs/day-picker 0.0.18 → 0.0.20
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 +7 -7
- package/src/DayPicker.tsrx +15 -13
- package/src/components/custom-components.tsrx +5 -6
- package/src/selection/useMulti.ts +8 -8
- package/src/selection/useRange.ts +8 -8
- package/src/selection/useSingle.ts +2 -7
- package/src/types/props.ts +10 -8
- package/src/types/selection.ts +4 -5
- package/src/types/shared.ts +5 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/day-picker",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -53,21 +53,21 @@
|
|
|
53
53
|
"date-fns": "^4.1.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"octane": "^0.1.51 || ^0.2.0"
|
|
56
|
+
"octane": "^0.1.51 || ^0.2.0 || ^0.3.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@tsrx/react": "^0.
|
|
59
|
+
"@tsrx/react": "^0.3.0",
|
|
60
60
|
"@types/react": "^19.2.17",
|
|
61
61
|
"@types/react-dom": "^19.2.3",
|
|
62
62
|
"playwright": "^1.61.1",
|
|
63
|
-
"react": "
|
|
64
|
-
"react-dom": "
|
|
63
|
+
"react": "19.2.7",
|
|
64
|
+
"react-dom": "19.2.7",
|
|
65
65
|
"react-day-picker": "10.0.1",
|
|
66
66
|
"typescript": "^5.9.3",
|
|
67
67
|
"vite": "^8.1.5",
|
|
68
68
|
"vitest": "^4.1.10",
|
|
69
|
-
"@octanejs/testing-library": "0.1.
|
|
70
|
-
"octane": "0.
|
|
69
|
+
"@octanejs/testing-library": "0.1.52",
|
|
70
|
+
"octane": "0.3.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"test": "pnpm upstream:check && vitest run --root ../.. --project day-picker --project day-picker-ssr --project day-picker-browser --project day-picker-differential",
|
package/src/DayPicker.tsrx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// @ts-nocheck -- React-compatible DOM props cross Octane's stricter event boundary here.
|
|
2
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'octane';
|
|
3
|
-
import type { ChangeEvent, FocusEvent, KeyboardEvent, MouseEvent } from '
|
|
2
|
+
import type { ChangeEvent, FocusEvent, KeyboardEvent, MouseEvent } from 'octane';
|
|
4
3
|
import type { CalendarDay } from './classes/CalendarDay.js';
|
|
5
4
|
import { DateLib, defaultLocale } from './classes/DateLib.js';
|
|
6
5
|
import { createGetModifiers } from './helpers/createGetModifiers.js';
|
|
@@ -28,7 +27,10 @@ import type {
|
|
|
28
27
|
import { DayFlag, SelectionState, UI } from './UI.js';
|
|
29
28
|
import { useAnimation } from './useAnimation.js';
|
|
30
29
|
import { useCalendar } from './useCalendar.js';
|
|
31
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
type DayPickerContext,
|
|
32
|
+
dayPickerContext as DayPickerContextProvider,
|
|
33
|
+
} from './useDayPicker.js';
|
|
32
34
|
import { useFocus } from './useFocus.js';
|
|
33
35
|
import { useSelection } from './useSelection.js';
|
|
34
36
|
import { convertMatchersToTimeZone } from './utils/convertMatchersToTimeZone.js';
|
|
@@ -252,7 +254,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
252
254
|
}, [goToMonth, nextMonth, onNextClick]);
|
|
253
255
|
|
|
254
256
|
const handleDayClick = useCallback(
|
|
255
|
-
(day: CalendarDay, m: Modifiers) => (e: MouseEvent) => {
|
|
257
|
+
(day: CalendarDay, m: Modifiers) => (e: MouseEvent<HTMLButtonElement>) => {
|
|
256
258
|
e.preventDefault();
|
|
257
259
|
e.stopPropagation();
|
|
258
260
|
setFocused(day);
|
|
@@ -266,7 +268,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
266
268
|
);
|
|
267
269
|
|
|
268
270
|
const handleDayFocus = useCallback(
|
|
269
|
-
(day: CalendarDay, m: Modifiers) => (e: FocusEvent) => {
|
|
271
|
+
(day: CalendarDay, m: Modifiers) => (e: FocusEvent<HTMLButtonElement>) => {
|
|
270
272
|
setFocused(day);
|
|
271
273
|
onDayFocus?.(day.date, m, e);
|
|
272
274
|
},
|
|
@@ -274,7 +276,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
274
276
|
);
|
|
275
277
|
|
|
276
278
|
const handleDayBlur = useCallback(
|
|
277
|
-
(day: CalendarDay, m: Modifiers) => (e: FocusEvent) => {
|
|
279
|
+
(day: CalendarDay, m: Modifiers) => (e: FocusEvent<HTMLButtonElement>) => {
|
|
278
280
|
blur();
|
|
279
281
|
onDayBlur?.(day.date, m, e);
|
|
280
282
|
},
|
|
@@ -282,7 +284,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
282
284
|
);
|
|
283
285
|
|
|
284
286
|
const handleDayKeyDown = useCallback(
|
|
285
|
-
(day: CalendarDay, modifiers: Modifiers) => (e: KeyboardEvent) => {
|
|
287
|
+
(day: CalendarDay, modifiers: Modifiers) => (e: KeyboardEvent<HTMLButtonElement>) => {
|
|
286
288
|
const keyMap: Record<string, [MoveFocusBy, MoveFocusDir]> = {
|
|
287
289
|
ArrowLeft: [e.shiftKey ? 'month' : 'day', props.dir === 'rtl' ? 'after' : 'before'],
|
|
288
290
|
ArrowRight: [e.shiftKey ? 'month' : 'day', props.dir === 'rtl' ? 'before' : 'after'],
|
|
@@ -305,14 +307,14 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
305
307
|
);
|
|
306
308
|
|
|
307
309
|
const handleDayMouseEnter = useCallback(
|
|
308
|
-
(day: CalendarDay, modifiers: Modifiers) => (e: MouseEvent) => {
|
|
310
|
+
(day: CalendarDay, modifiers: Modifiers) => (e: MouseEvent<HTMLButtonElement>) => {
|
|
309
311
|
onDayMouseEnter?.(day.date, modifiers, e);
|
|
310
312
|
},
|
|
311
313
|
[onDayMouseEnter],
|
|
312
314
|
);
|
|
313
315
|
|
|
314
316
|
const handleDayMouseLeave = useCallback(
|
|
315
|
-
(day: CalendarDay, modifiers: Modifiers) => (e: MouseEvent) => {
|
|
317
|
+
(day: CalendarDay, modifiers: Modifiers) => (e: MouseEvent<HTMLButtonElement>) => {
|
|
316
318
|
onDayMouseLeave?.(day.date, modifiers, e);
|
|
317
319
|
},
|
|
318
320
|
[onDayMouseLeave],
|
|
@@ -320,7 +322,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
320
322
|
|
|
321
323
|
const handleMonthChange = useCallback(
|
|
322
324
|
(date: Date, monthOffset: number) => (e: ChangeEvent<HTMLSelectElement>) => {
|
|
323
|
-
const selectedMonth = Number(e.
|
|
325
|
+
const selectedMonth = Number(e.currentTarget.value);
|
|
324
326
|
const month = dateLib.setMonth(dateLib.startOfMonth(date), selectedMonth);
|
|
325
327
|
goToMonth(dateLib.addMonths(month, -monthOffset));
|
|
326
328
|
},
|
|
@@ -329,7 +331,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
329
331
|
|
|
330
332
|
const handleYearChange = useCallback(
|
|
331
333
|
(date: Date, monthOffset: number) => (e: ChangeEvent<HTMLSelectElement>) => {
|
|
332
|
-
const selectedYear = Number(e.
|
|
334
|
+
const selectedYear = Number(e.currentTarget.value);
|
|
333
335
|
const month = dateLib.setYear(dateLib.startOfMonth(date), selectedYear);
|
|
334
336
|
goToMonth(dateLib.addMonths(month, -monthOffset));
|
|
335
337
|
},
|
|
@@ -385,7 +387,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
385
387
|
formatters,
|
|
386
388
|
};
|
|
387
389
|
|
|
388
|
-
<
|
|
390
|
+
<DayPickerContextProvider value={contextValue}>
|
|
389
391
|
<components.Root
|
|
390
392
|
rootRef={props.animate ? rootElRef : undefined}
|
|
391
393
|
className={className}
|
|
@@ -713,5 +715,5 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
713
715
|
aria-live="polite"
|
|
714
716
|
>{props.footer}</components.Footer>}
|
|
715
717
|
</components.Root>
|
|
716
|
-
</
|
|
718
|
+
</DayPickerContextProvider>
|
|
717
719
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
// @ts-nocheck -- public props retain React DOM compatibility at the Octane render boundary.
|
|
2
1
|
import { useCallback, useEffect, useRef } from 'octane';
|
|
3
2
|
import type {
|
|
4
3
|
ButtonHTMLAttributes,
|
|
5
4
|
CSSProperties,
|
|
6
5
|
HTMLAttributes,
|
|
7
|
-
MouseEvent
|
|
6
|
+
MouseEvent,
|
|
8
7
|
MouseEventHandler,
|
|
9
8
|
OptionHTMLAttributes,
|
|
10
|
-
Ref,
|
|
11
9
|
SelectHTMLAttributes,
|
|
12
10
|
TableHTMLAttributes,
|
|
13
11
|
ThHTMLAttributes,
|
|
14
|
-
} from '
|
|
12
|
+
} from 'octane';
|
|
13
|
+
import type { Ref } from 'react';
|
|
15
14
|
import type { CalendarDay, CalendarMonth, CalendarWeek } from '../classes/index.js';
|
|
16
15
|
import type { Modifiers } from '../types/index.js';
|
|
17
16
|
import { UI } from '../UI.js';
|
|
@@ -143,10 +142,10 @@ export type NavProps =
|
|
|
143
142
|
export function Nav(props: NavProps) @{
|
|
144
143
|
const { onPreviousClick, onNextClick, previousMonth, nextMonth, ...navProps } = props;
|
|
145
144
|
const { components, classNames, styles, labels: { labelPrevious, labelNext } } = useDayPicker();
|
|
146
|
-
const handleNextClick = useCallback((event:
|
|
145
|
+
const handleNextClick = useCallback((event: MouseEvent<HTMLButtonElement>) => {
|
|
147
146
|
if (nextMonth) onNextClick?.(event);
|
|
148
147
|
}, [nextMonth, onNextClick]);
|
|
149
|
-
const handlePreviousClick = useCallback((event:
|
|
148
|
+
const handlePreviousClick = useCallback((event: MouseEvent<HTMLButtonElement>) => {
|
|
150
149
|
if (previousMonth) onPreviousClick?.(event);
|
|
151
150
|
}, [previousMonth, onPreviousClick]);
|
|
152
151
|
<nav {...navProps}>
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
|
|
3
1
|
import type { DateLib } from '../classes/DateLib.js';
|
|
4
2
|
import { useControlledValue } from '../helpers/useControlledValue.js';
|
|
5
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
DayPickerProps,
|
|
5
|
+
DaySelectionEvent,
|
|
6
|
+
Modifiers,
|
|
7
|
+
PropsMulti,
|
|
8
|
+
Selection,
|
|
9
|
+
} from '../types/index.js';
|
|
6
10
|
|
|
7
11
|
const multiSelectionSlot = Symbol.for('@octanejs/day-picker/useMulti/selection');
|
|
8
12
|
|
|
@@ -34,11 +38,7 @@ export function useMulti<T extends DayPickerProps>(props: T, dateLib: DateLib):
|
|
|
34
38
|
|
|
35
39
|
const { min, max } = props as PropsMulti;
|
|
36
40
|
|
|
37
|
-
const select = (
|
|
38
|
-
triggerDate: Date,
|
|
39
|
-
modifiers: Modifiers,
|
|
40
|
-
e: React.MouseEvent | React.KeyboardEvent,
|
|
41
|
-
) => {
|
|
41
|
+
const select = (triggerDate: Date, modifiers: Modifiers, e: DaySelectionEvent) => {
|
|
42
42
|
let newDates: Date[] | undefined = [...(selected ?? [])];
|
|
43
43
|
if (isSelected(triggerDate)) {
|
|
44
44
|
if (selected?.length === min) {
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
|
|
3
1
|
import type { DateLib } from '../classes/DateLib.js';
|
|
4
2
|
import { useControlledValue } from '../helpers/useControlledValue.js';
|
|
5
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
DayPickerProps,
|
|
5
|
+
DaySelectionEvent,
|
|
6
|
+
Modifiers,
|
|
7
|
+
PropsRange,
|
|
8
|
+
Selection,
|
|
9
|
+
} from '../types/index.js';
|
|
6
10
|
import { addToRange, rangeContainsModifiers } from '../utils/index.js';
|
|
7
11
|
import { rangeIncludesDate } from '../utils/rangeIncludesDate.js';
|
|
8
12
|
|
|
@@ -37,11 +41,7 @@ export function useRange<T extends DayPickerProps>(props: T, dateLib: DateLib):
|
|
|
37
41
|
|
|
38
42
|
const isSelected = (date: Date) => selected && rangeIncludesDate(selected, date, false, dateLib);
|
|
39
43
|
|
|
40
|
-
const select = (
|
|
41
|
-
triggerDate: Date,
|
|
42
|
-
modifiers: Modifiers,
|
|
43
|
-
e: React.MouseEvent | React.KeyboardEvent,
|
|
44
|
-
) => {
|
|
44
|
+
const select = (triggerDate: Date, modifiers: Modifiers, e: DaySelectionEvent) => {
|
|
45
45
|
const { min, max } = props as PropsRange;
|
|
46
46
|
let newRange: ReturnType<typeof addToRange>;
|
|
47
47
|
if (triggerDate) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
|
|
3
1
|
import type { DateLib } from '../classes/DateLib.js';
|
|
4
2
|
import { useControlledValue } from '../helpers/useControlledValue.js';
|
|
5
3
|
import type {
|
|
6
4
|
DayPickerProps,
|
|
5
|
+
DaySelectionEvent,
|
|
7
6
|
Modifiers,
|
|
8
7
|
PropsSingle,
|
|
9
8
|
SelectedValue,
|
|
@@ -48,11 +47,7 @@ export function useSingle<T extends DayPickerProps>(
|
|
|
48
47
|
return selected ? isSameDay(selected, compareDate) : false;
|
|
49
48
|
};
|
|
50
49
|
|
|
51
|
-
const select = (
|
|
52
|
-
triggerDate: Date,
|
|
53
|
-
modifiers: Modifiers,
|
|
54
|
-
e: React.MouseEvent | React.KeyboardEvent,
|
|
55
|
-
) => {
|
|
50
|
+
const select = (triggerDate: Date, modifiers: Modifiers, e: DaySelectionEvent) => {
|
|
56
51
|
let newDate: Date | undefined = triggerDate;
|
|
57
52
|
if (!required && selected && selected && isSameDay(triggerDate, selected)) {
|
|
58
53
|
// If the date is the same, clear the selection.
|
package/src/types/props.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FocusEvent, KeyboardEvent, MouseEvent } from 'octane';
|
|
1
2
|
import type React from 'react';
|
|
2
3
|
import type { DateLib, DayPickerLocale } from '../classes/DateLib.js';
|
|
3
4
|
|
|
@@ -6,6 +7,7 @@ import type {
|
|
|
6
7
|
CustomComponents,
|
|
7
8
|
DateRange,
|
|
8
9
|
DayEventHandler,
|
|
10
|
+
DaySelectionEvent,
|
|
9
11
|
Formatters,
|
|
10
12
|
Labels,
|
|
11
13
|
Matcher,
|
|
@@ -469,17 +471,17 @@ export interface PropsBase {
|
|
|
469
471
|
*/
|
|
470
472
|
onPrevClick?: MonthChangeEventHandler;
|
|
471
473
|
/** Event handler when a day is clicked. */
|
|
472
|
-
onDayClick?: DayEventHandler<
|
|
474
|
+
onDayClick?: DayEventHandler<MouseEvent<HTMLButtonElement>>;
|
|
473
475
|
/** Event handler when a day is focused. */
|
|
474
|
-
onDayFocus?: DayEventHandler<
|
|
476
|
+
onDayFocus?: DayEventHandler<FocusEvent<HTMLButtonElement>>;
|
|
475
477
|
/** Event handler when a day is blurred. */
|
|
476
|
-
onDayBlur?: DayEventHandler<
|
|
478
|
+
onDayBlur?: DayEventHandler<FocusEvent<HTMLButtonElement>>;
|
|
477
479
|
/** Event handler when a key is pressed on a day. */
|
|
478
|
-
onDayKeyDown?: DayEventHandler<
|
|
480
|
+
onDayKeyDown?: DayEventHandler<KeyboardEvent<HTMLButtonElement>>;
|
|
479
481
|
/** Event handler when the mouse enters a day. */
|
|
480
|
-
onDayMouseEnter?: DayEventHandler<
|
|
482
|
+
onDayMouseEnter?: DayEventHandler<MouseEvent<HTMLButtonElement>>;
|
|
481
483
|
/** Event handler when the mouse leaves a day. */
|
|
482
|
-
onDayMouseLeave?: DayEventHandler<
|
|
484
|
+
onDayMouseLeave?: DayEventHandler<MouseEvent<HTMLButtonElement>>;
|
|
483
485
|
|
|
484
486
|
/**
|
|
485
487
|
* Replace the default date library with a custom one. Experimental: not
|
|
@@ -511,13 +513,13 @@ export interface PropsBase {
|
|
|
511
513
|
* @param {Date} triggerDate - The date when the event was triggered. This is
|
|
512
514
|
* typically the day clicked or interacted with.
|
|
513
515
|
* @param {Modifiers} modifiers - The modifiers associated with the event.
|
|
514
|
-
* @param {
|
|
516
|
+
* @param {DaySelectionEvent} e - The native event object.
|
|
515
517
|
*/
|
|
516
518
|
export type OnSelectHandler<T> = (
|
|
517
519
|
selected: T,
|
|
518
520
|
triggerDate: Date,
|
|
519
521
|
modifiers: Modifiers,
|
|
520
|
-
e:
|
|
522
|
+
e: DaySelectionEvent,
|
|
521
523
|
) => void;
|
|
522
524
|
|
|
523
525
|
/**
|
package/src/types/selection.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
1
|
import type { DayPickerProps } from './props.js';
|
|
3
|
-
import type { DateRange, Mode, Modifiers } from './shared.js';
|
|
2
|
+
import type { DateRange, DaySelectionEvent, Mode, Modifiers } from './shared.js';
|
|
4
3
|
|
|
5
4
|
/** Selection state and helpers for the active selection mode. */
|
|
6
5
|
export type Selection<T extends DayPickerProps> = {
|
|
@@ -56,21 +55,21 @@ export type SelectedValue<T> = T extends { mode: 'single'; required?: boolean }
|
|
|
56
55
|
export type SelectHandlerSingle<T extends { required?: boolean | undefined }> = (
|
|
57
56
|
triggerDate: Date,
|
|
58
57
|
modifiers: Modifiers,
|
|
59
|
-
e:
|
|
58
|
+
e: DaySelectionEvent,
|
|
60
59
|
) => T['required'] extends true ? Date : Date | undefined;
|
|
61
60
|
|
|
62
61
|
/** Selection handler for multiple selection mode. */
|
|
63
62
|
export type SelectHandlerMulti<T extends { required?: boolean | undefined }> = (
|
|
64
63
|
triggerDate: Date,
|
|
65
64
|
modifiers: Modifiers,
|
|
66
|
-
e:
|
|
65
|
+
e: DaySelectionEvent,
|
|
67
66
|
) => T['required'] extends true ? Date[] : Date[] | undefined;
|
|
68
67
|
|
|
69
68
|
/** Selection handler for range selection mode. */
|
|
70
69
|
export type SelectHandlerRange<T extends { required?: boolean | undefined }> = (
|
|
71
70
|
triggerDate: Date,
|
|
72
71
|
modifiers: Modifiers,
|
|
73
|
-
e:
|
|
72
|
+
e: DaySelectionEvent,
|
|
74
73
|
) => T['required'] extends true ? DateRange : DateRange | undefined;
|
|
75
74
|
|
|
76
75
|
/**
|
package/src/types/shared.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KeyboardEvent, MouseEvent } from 'octane';
|
|
1
2
|
import type { CSSProperties } from 'react';
|
|
2
3
|
import type * as components from '../components/custom-components.tsrx';
|
|
3
4
|
import type {
|
|
@@ -215,14 +216,16 @@ export type DayOfWeek = { dayOfWeek: number | number[] };
|
|
|
215
216
|
/**
|
|
216
217
|
* The event handler triggered when clicking or interacting with a day.
|
|
217
218
|
*
|
|
218
|
-
* @template EventType - The event type that triggered the event
|
|
219
|
-
* `React.MouseEvent`, `React.KeyboardEvent`, etc.).
|
|
219
|
+
* @template EventType - The native event type that triggered the event.
|
|
220
220
|
* @param date - The date that has triggered the event.
|
|
221
221
|
* @param modifiers - The modifiers belonging to the date.
|
|
222
222
|
* @param e - The DOM event that triggered the event.
|
|
223
223
|
*/
|
|
224
224
|
export type DayEventHandler<EventType> = (date: Date, modifiers: Modifiers, e: EventType) => void;
|
|
225
225
|
|
|
226
|
+
/** Native button event delivered to a selection callback. */
|
|
227
|
+
export type DaySelectionEvent = MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>;
|
|
228
|
+
|
|
226
229
|
/**
|
|
227
230
|
* The event handler when a month is changed in the calendar.
|
|
228
231
|
*
|