@octanejs/day-picker 0.0.17 → 0.0.19
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 +5 -5
- package/src/DayPicker.tsrx +9 -10
- 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.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"date-fns": "^4.1.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"octane": "0.1.51"
|
|
56
|
+
"octane": "^0.1.51 || ^0.2.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@tsrx/react": "^0.2.
|
|
59
|
+
"@tsrx/react": "^0.2.67",
|
|
60
60
|
"@types/react": "^19.2.17",
|
|
61
61
|
"@types/react-dom": "^19.2.3",
|
|
62
62
|
"playwright": "^1.61.1",
|
|
@@ -66,8 +66,8 @@
|
|
|
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.50",
|
|
70
|
+
"octane": "0.2.4"
|
|
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';
|
|
@@ -252,7 +251,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
252
251
|
}, [goToMonth, nextMonth, onNextClick]);
|
|
253
252
|
|
|
254
253
|
const handleDayClick = useCallback(
|
|
255
|
-
(day: CalendarDay, m: Modifiers) => (e: MouseEvent) => {
|
|
254
|
+
(day: CalendarDay, m: Modifiers) => (e: MouseEvent<HTMLButtonElement>) => {
|
|
256
255
|
e.preventDefault();
|
|
257
256
|
e.stopPropagation();
|
|
258
257
|
setFocused(day);
|
|
@@ -266,7 +265,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
266
265
|
);
|
|
267
266
|
|
|
268
267
|
const handleDayFocus = useCallback(
|
|
269
|
-
(day: CalendarDay, m: Modifiers) => (e: FocusEvent) => {
|
|
268
|
+
(day: CalendarDay, m: Modifiers) => (e: FocusEvent<HTMLButtonElement>) => {
|
|
270
269
|
setFocused(day);
|
|
271
270
|
onDayFocus?.(day.date, m, e);
|
|
272
271
|
},
|
|
@@ -274,7 +273,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
274
273
|
);
|
|
275
274
|
|
|
276
275
|
const handleDayBlur = useCallback(
|
|
277
|
-
(day: CalendarDay, m: Modifiers) => (e: FocusEvent) => {
|
|
276
|
+
(day: CalendarDay, m: Modifiers) => (e: FocusEvent<HTMLButtonElement>) => {
|
|
278
277
|
blur();
|
|
279
278
|
onDayBlur?.(day.date, m, e);
|
|
280
279
|
},
|
|
@@ -282,7 +281,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
282
281
|
);
|
|
283
282
|
|
|
284
283
|
const handleDayKeyDown = useCallback(
|
|
285
|
-
(day: CalendarDay, modifiers: Modifiers) => (e: KeyboardEvent) => {
|
|
284
|
+
(day: CalendarDay, modifiers: Modifiers) => (e: KeyboardEvent<HTMLButtonElement>) => {
|
|
286
285
|
const keyMap: Record<string, [MoveFocusBy, MoveFocusDir]> = {
|
|
287
286
|
ArrowLeft: [e.shiftKey ? 'month' : 'day', props.dir === 'rtl' ? 'after' : 'before'],
|
|
288
287
|
ArrowRight: [e.shiftKey ? 'month' : 'day', props.dir === 'rtl' ? 'before' : 'after'],
|
|
@@ -305,14 +304,14 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
305
304
|
);
|
|
306
305
|
|
|
307
306
|
const handleDayMouseEnter = useCallback(
|
|
308
|
-
(day: CalendarDay, modifiers: Modifiers) => (e: MouseEvent) => {
|
|
307
|
+
(day: CalendarDay, modifiers: Modifiers) => (e: MouseEvent<HTMLButtonElement>) => {
|
|
309
308
|
onDayMouseEnter?.(day.date, modifiers, e);
|
|
310
309
|
},
|
|
311
310
|
[onDayMouseEnter],
|
|
312
311
|
);
|
|
313
312
|
|
|
314
313
|
const handleDayMouseLeave = useCallback(
|
|
315
|
-
(day: CalendarDay, modifiers: Modifiers) => (e: MouseEvent) => {
|
|
314
|
+
(day: CalendarDay, modifiers: Modifiers) => (e: MouseEvent<HTMLButtonElement>) => {
|
|
316
315
|
onDayMouseLeave?.(day.date, modifiers, e);
|
|
317
316
|
},
|
|
318
317
|
[onDayMouseLeave],
|
|
@@ -320,7 +319,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
320
319
|
|
|
321
320
|
const handleMonthChange = useCallback(
|
|
322
321
|
(date: Date, monthOffset: number) => (e: ChangeEvent<HTMLSelectElement>) => {
|
|
323
|
-
const selectedMonth = Number(e.
|
|
322
|
+
const selectedMonth = Number(e.currentTarget.value);
|
|
324
323
|
const month = dateLib.setMonth(dateLib.startOfMonth(date), selectedMonth);
|
|
325
324
|
goToMonth(dateLib.addMonths(month, -monthOffset));
|
|
326
325
|
},
|
|
@@ -329,7 +328,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
329
328
|
|
|
330
329
|
const handleYearChange = useCallback(
|
|
331
330
|
(date: Date, monthOffset: number) => (e: ChangeEvent<HTMLSelectElement>) => {
|
|
332
|
-
const selectedYear = Number(e.
|
|
331
|
+
const selectedYear = Number(e.currentTarget.value);
|
|
333
332
|
const month = dateLib.setYear(dateLib.startOfMonth(date), selectedYear);
|
|
334
333
|
goToMonth(dateLib.addMonths(month, -monthOffset));
|
|
335
334
|
},
|
|
@@ -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
|
*
|