@octanejs/day-picker 0.0.28 → 0.0.29
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 +308 -259
- package/src/components/custom-components.tsrx +53 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/day-picker",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -53,14 +53,14 @@
|
|
|
53
53
|
"date-fns": "^4.1.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"octane": "^0.
|
|
56
|
+
"octane": "^0.11.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@octanejs/testing-library": "0.1.
|
|
60
|
-
"@tsrx/react": "^0.
|
|
59
|
+
"@octanejs/testing-library": "0.1.61",
|
|
60
|
+
"@tsrx/react": "^0.4.5",
|
|
61
61
|
"@types/react": "^19.2.17",
|
|
62
62
|
"@types/react-dom": "^19.2.3",
|
|
63
|
-
"octane": "0.
|
|
63
|
+
"octane": "0.11.0",
|
|
64
64
|
"playwright": "^1.61.1",
|
|
65
65
|
"react": "19.2.7",
|
|
66
66
|
"react-dom": "19.2.7",
|
package/src/DayPicker.tsrx
CHANGED
|
@@ -110,17 +110,20 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
110
110
|
const overrides =
|
|
111
111
|
props.dateLib && noonOverrides
|
|
112
112
|
? { ...noonOverrides, ...props.dateLib }
|
|
113
|
-
: props.dateLib ?? noonOverrides;
|
|
114
|
-
|
|
115
|
-
const dateLib = new DateLib(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
: (props.dateLib ?? noonOverrides);
|
|
114
|
+
|
|
115
|
+
const dateLib = new DateLib(
|
|
116
|
+
{
|
|
117
|
+
locale,
|
|
118
|
+
weekStartsOn,
|
|
119
|
+
firstWeekContainsDate: props.firstWeekContainsDate,
|
|
120
|
+
useAdditionalWeekYearTokens: props.useAdditionalWeekYearTokens,
|
|
121
|
+
useAdditionalDayOfYearTokens: props.useAdditionalDayOfYearTokens,
|
|
122
|
+
timeZone: props.timeZone,
|
|
123
|
+
numerals: props.numerals,
|
|
124
|
+
},
|
|
125
|
+
overrides,
|
|
126
|
+
);
|
|
124
127
|
|
|
125
128
|
return {
|
|
126
129
|
dateLib,
|
|
@@ -198,12 +201,15 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
198
201
|
formatYearDropdown,
|
|
199
202
|
} = formatters;
|
|
200
203
|
|
|
201
|
-
const calendar = useCalendar(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
const calendar = useCalendar(
|
|
205
|
+
props,
|
|
206
|
+
dateLib,
|
|
207
|
+
monthIsControlled ? undefined : uncontrolledMonth,
|
|
208
|
+
(month) => {
|
|
209
|
+
setUncontrolledMonth(month);
|
|
210
|
+
props.onMonthChange?.(month);
|
|
211
|
+
},
|
|
212
|
+
);
|
|
207
213
|
|
|
208
214
|
const { days, months, navStart, navEnd, previousMonth, nextMonth, goToMonth } = calendar;
|
|
209
215
|
|
|
@@ -403,7 +409,7 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
403
409
|
{...dataAttributes}
|
|
404
410
|
>
|
|
405
411
|
<components.Months className={classNames[UI.Months]} style={styles?.[UI.Months]}>
|
|
406
|
-
{!props.hideNavigation && !navLayout &&
|
|
412
|
+
{!props.hideNavigation && !navLayout && (
|
|
407
413
|
<components.Nav
|
|
408
414
|
data-animated-nav={props.animate ? 'true' : undefined}
|
|
409
415
|
className={classNames[UI.Nav]}
|
|
@@ -413,95 +419,98 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
413
419
|
onNextClick={handleNextClick}
|
|
414
420
|
previousMonth={previousMonth}
|
|
415
421
|
nextMonth={nextMonth}
|
|
416
|
-
/>
|
|
422
|
+
/>
|
|
423
|
+
)}
|
|
417
424
|
{months.map((calendarMonth, displayIndex) => {
|
|
418
425
|
const monthOffset = props.reverseMonths ? months.length - 1 - displayIndex : displayIndex;
|
|
419
426
|
|
|
420
|
-
return
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
calendarMonth={calendarMonth}
|
|
428
|
-
>
|
|
429
|
-
{navLayout === 'around' && !props.hideNavigation && displayIndex === 0 &&
|
|
430
|
-
<components.PreviousMonthButton
|
|
431
|
-
type="button"
|
|
432
|
-
className={classNames[UI.PreviousMonthButton]}
|
|
433
|
-
style={styles?.[UI.PreviousMonthButton]}
|
|
434
|
-
tabIndex={previousMonth ? undefined : -1}
|
|
435
|
-
aria-disabled={previousMonth ? undefined : true}
|
|
436
|
-
aria-label={labelPrevious(previousMonth)}
|
|
437
|
-
onClick={handlePreviousClick}
|
|
438
|
-
data-animated-button={props.animate ? 'true' : undefined}
|
|
439
|
-
>
|
|
440
|
-
<components.Chevron
|
|
441
|
-
disabled={previousMonth ? undefined : true}
|
|
442
|
-
className={classNames[UI.Chevron]}
|
|
443
|
-
style={styles?.[UI.Chevron]}
|
|
444
|
-
orientation={props.dir === 'rtl' ? 'right' : 'left'}
|
|
445
|
-
/>
|
|
446
|
-
</components.PreviousMonthButton>}
|
|
447
|
-
<components.MonthCaption
|
|
448
|
-
data-animated-caption={props.animate ? 'true' : undefined}
|
|
449
|
-
className={classNames[UI.MonthCaption]}
|
|
450
|
-
style={styles?.[UI.MonthCaption]}
|
|
451
|
-
calendarMonth={calendarMonth}
|
|
427
|
+
return (
|
|
428
|
+
<components.Month
|
|
429
|
+
data-animated-month={props.animate ? 'true' : undefined}
|
|
430
|
+
className={classNames[UI.Month]}
|
|
431
|
+
style={styles?.[UI.Month]}
|
|
432
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: breaks animation
|
|
433
|
+
key={displayIndex}
|
|
452
434
|
displayIndex={displayIndex}
|
|
435
|
+
calendarMonth={calendarMonth}
|
|
453
436
|
>
|
|
454
|
-
{
|
|
455
|
-
|
|
437
|
+
{navLayout === 'around' && !props.hideNavigation && displayIndex === 0 && (
|
|
438
|
+
<components.PreviousMonthButton
|
|
439
|
+
type="button"
|
|
440
|
+
className={classNames[UI.PreviousMonthButton]}
|
|
441
|
+
style={styles?.[UI.PreviousMonthButton]}
|
|
442
|
+
tabIndex={previousMonth ? undefined : -1}
|
|
443
|
+
aria-disabled={previousMonth ? undefined : true}
|
|
444
|
+
aria-label={labelPrevious(previousMonth)}
|
|
445
|
+
onClick={handlePreviousClick}
|
|
446
|
+
data-animated-button={props.animate ? 'true' : undefined}
|
|
447
|
+
>
|
|
448
|
+
<components.Chevron
|
|
449
|
+
disabled={previousMonth ? undefined : true}
|
|
450
|
+
className={classNames[UI.Chevron]}
|
|
451
|
+
style={styles?.[UI.Chevron]}
|
|
452
|
+
orientation={props.dir === 'rtl' ? 'right' : 'left'}
|
|
453
|
+
/>
|
|
454
|
+
</components.PreviousMonthButton>
|
|
455
|
+
)}
|
|
456
|
+
<components.MonthCaption
|
|
457
|
+
data-animated-caption={props.animate ? 'true' : undefined}
|
|
458
|
+
className={classNames[UI.MonthCaption]}
|
|
459
|
+
style={styles?.[UI.MonthCaption]}
|
|
460
|
+
calendarMonth={calendarMonth}
|
|
461
|
+
displayIndex={displayIndex}
|
|
462
|
+
>
|
|
463
|
+
{captionLayout?.startsWith('dropdown') ? (
|
|
464
|
+
<components.DropdownNav
|
|
456
465
|
className={classNames[UI.Dropdowns]}
|
|
457
466
|
style={styles?.[UI.Dropdowns]}
|
|
458
467
|
>
|
|
459
468
|
{(() => {
|
|
460
469
|
const monthControl =
|
|
461
|
-
captionLayout === 'dropdown' || captionLayout === 'dropdown-months'
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
calendarMonth.date,
|
|
470
|
-
navStart,
|
|
471
|
-
navEnd,
|
|
472
|
-
formatters,
|
|
473
|
-
dateLib,
|
|
474
|
-
)}
|
|
475
|
-
style={getDropdownStyle(UI.MonthsDropdown)}
|
|
476
|
-
value={dateLib.getMonth(calendarMonth.date)}
|
|
477
|
-
/>
|
|
478
|
-
: <span key="month">{formatMonthDropdown(
|
|
470
|
+
captionLayout === 'dropdown' || captionLayout === 'dropdown-months' ? (
|
|
471
|
+
<components.MonthsDropdown
|
|
472
|
+
key="month"
|
|
473
|
+
className={classNames[UI.MonthsDropdown]}
|
|
474
|
+
aria-label={labelMonthDropdown()}
|
|
475
|
+
disabled={Boolean(props.disableNavigation)}
|
|
476
|
+
onChange={handleMonthChange(calendarMonth.date, monthOffset)}
|
|
477
|
+
options={getMonthOptions(
|
|
479
478
|
calendarMonth.date,
|
|
479
|
+
navStart,
|
|
480
|
+
navEnd,
|
|
481
|
+
formatters,
|
|
480
482
|
dateLib,
|
|
481
|
-
)}
|
|
483
|
+
)}
|
|
484
|
+
style={getDropdownStyle(UI.MonthsDropdown)}
|
|
485
|
+
value={dateLib.getMonth(calendarMonth.date)}
|
|
486
|
+
/>
|
|
487
|
+
) : (
|
|
488
|
+
<span key="month">
|
|
489
|
+
{formatMonthDropdown(calendarMonth.date, dateLib)}
|
|
490
|
+
</span>
|
|
491
|
+
);
|
|
482
492
|
|
|
483
493
|
const yearControl =
|
|
484
|
-
captionLayout === 'dropdown' || captionLayout === 'dropdown-years'
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
dateLib,
|
|
496
|
-
Boolean(props.reverseYears),
|
|
497
|
-
)}
|
|
498
|
-
style={getDropdownStyle(UI.YearsDropdown)}
|
|
499
|
-
value={dateLib.getYear(calendarMonth.date)}
|
|
500
|
-
/>
|
|
501
|
-
: <span key="year">{formatYearDropdown(
|
|
502
|
-
calendarMonth.date,
|
|
494
|
+
captionLayout === 'dropdown' || captionLayout === 'dropdown-years' ? (
|
|
495
|
+
<components.YearsDropdown
|
|
496
|
+
key="year"
|
|
497
|
+
className={classNames[UI.YearsDropdown]}
|
|
498
|
+
aria-label={labelYearDropdown(dateLib.options)}
|
|
499
|
+
disabled={Boolean(props.disableNavigation)}
|
|
500
|
+
onChange={handleYearChange(calendarMonth.date, monthOffset)}
|
|
501
|
+
options={getYearOptions(
|
|
502
|
+
navStart,
|
|
503
|
+
navEnd,
|
|
504
|
+
formatters,
|
|
503
505
|
dateLib,
|
|
504
|
-
|
|
506
|
+
Boolean(props.reverseYears),
|
|
507
|
+
)}
|
|
508
|
+
style={getDropdownStyle(UI.YearsDropdown)}
|
|
509
|
+
value={dateLib.getYear(calendarMonth.date)}
|
|
510
|
+
/>
|
|
511
|
+
) : (
|
|
512
|
+
<span key="year">{formatYearDropdown(calendarMonth.date, dateLib)}</span>
|
|
513
|
+
);
|
|
505
514
|
|
|
506
515
|
const controls =
|
|
507
516
|
dateLib.getMonthYearOrder() === 'year-first'
|
|
@@ -525,195 +534,235 @@ export function DayPicker(initialProps: DayPickerProps) @{
|
|
|
525
534
|
whiteSpace: 'nowrap',
|
|
526
535
|
wordWrap: 'normal',
|
|
527
536
|
}}
|
|
528
|
-
>
|
|
537
|
+
>
|
|
538
|
+
{formatCaption(calendarMonth.date, dateLib.options, dateLib)}
|
|
539
|
+
</span>
|
|
529
540
|
</components.DropdownNav>
|
|
530
|
-
:
|
|
541
|
+
) : (
|
|
542
|
+
<components.CaptionLabel
|
|
531
543
|
className={classNames[UI.CaptionLabel]}
|
|
532
544
|
style={styles?.[UI.CaptionLabel]}
|
|
533
545
|
role="status"
|
|
534
546
|
aria-live="polite"
|
|
535
|
-
>
|
|
536
|
-
calendarMonth.date,
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
547
|
+
>
|
|
548
|
+
{formatCaption(calendarMonth.date, dateLib.options, dateLib)}
|
|
549
|
+
</components.CaptionLabel>
|
|
550
|
+
)}
|
|
551
|
+
</components.MonthCaption>
|
|
552
|
+
{navLayout === 'around' &&
|
|
553
|
+
!props.hideNavigation &&
|
|
554
|
+
displayIndex === numberOfMonths - 1 && (
|
|
555
|
+
<components.NextMonthButton
|
|
556
|
+
type="button"
|
|
557
|
+
className={classNames[UI.NextMonthButton]}
|
|
558
|
+
style={styles?.[UI.NextMonthButton]}
|
|
559
|
+
tabIndex={nextMonth ? undefined : -1}
|
|
560
|
+
aria-disabled={nextMonth ? undefined : true}
|
|
561
|
+
aria-label={labelNext(nextMonth)}
|
|
562
|
+
onClick={handleNextClick}
|
|
563
|
+
data-animated-button={props.animate ? 'true' : undefined}
|
|
564
|
+
>
|
|
565
|
+
<components.Chevron
|
|
566
|
+
disabled={nextMonth ? undefined : true}
|
|
567
|
+
className={classNames[UI.Chevron]}
|
|
568
|
+
style={styles?.[UI.Chevron]}
|
|
569
|
+
orientation={props.dir === 'rtl' ? 'left' : 'right'}
|
|
570
|
+
/>
|
|
571
|
+
</components.NextMonthButton>
|
|
572
|
+
)}
|
|
573
|
+
{displayIndex === numberOfMonths - 1 &&
|
|
574
|
+
navLayout === 'after' &&
|
|
575
|
+
!props.hideNavigation && (
|
|
576
|
+
<components.Nav
|
|
577
|
+
data-animated-nav={props.animate ? 'true' : undefined}
|
|
578
|
+
className={classNames[UI.Nav]}
|
|
579
|
+
style={styles?.[UI.Nav]}
|
|
580
|
+
aria-label={labelNav()}
|
|
581
|
+
onPreviousClick={handlePreviousClick}
|
|
582
|
+
onNextClick={handleNextClick}
|
|
583
|
+
previousMonth={previousMonth}
|
|
584
|
+
nextMonth={nextMonth}
|
|
585
|
+
/>
|
|
586
|
+
)}
|
|
587
|
+
|
|
588
|
+
<components.MonthGrid
|
|
589
|
+
role="grid"
|
|
590
|
+
aria-multiselectable={mode === 'multiple' || mode === 'range'}
|
|
591
|
+
aria-label={labelGrid(calendarMonth.date, dateLib.options, dateLib) || undefined}
|
|
592
|
+
className={classNames[UI.MonthGrid]}
|
|
593
|
+
style={styles?.[UI.MonthGrid]}
|
|
552
594
|
>
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
nextMonth={nextMonth}
|
|
571
|
-
/>}
|
|
572
|
-
|
|
573
|
-
<components.MonthGrid
|
|
574
|
-
role="grid"
|
|
575
|
-
aria-multiselectable={mode === 'multiple' || mode === 'range'}
|
|
576
|
-
aria-label={labelGrid(calendarMonth.date, dateLib.options, dateLib) || undefined}
|
|
577
|
-
className={classNames[UI.MonthGrid]}
|
|
578
|
-
style={styles?.[UI.MonthGrid]}
|
|
579
|
-
>
|
|
580
|
-
{!props.hideWeekdays &&
|
|
581
|
-
<components.Weekdays
|
|
582
|
-
data-animated-weekdays={props.animate ? 'true' : undefined}
|
|
583
|
-
className={classNames[UI.Weekdays]}
|
|
584
|
-
style={styles?.[UI.Weekdays]}
|
|
585
|
-
>
|
|
586
|
-
{showWeekNumber &&
|
|
587
|
-
<components.WeekNumberHeader
|
|
588
|
-
aria-label={labelWeekNumberHeader(dateLib.options)}
|
|
589
|
-
className={classNames[UI.WeekNumberHeader]}
|
|
590
|
-
style={styles?.[UI.WeekNumberHeader]}
|
|
591
|
-
scope="col"
|
|
592
|
-
>{formatWeekNumberHeader()}</components.WeekNumberHeader>}
|
|
593
|
-
{weekdays.map(
|
|
594
|
-
(weekday) =>
|
|
595
|
+
{!props.hideWeekdays && (
|
|
596
|
+
<components.Weekdays
|
|
597
|
+
data-animated-weekdays={props.animate ? 'true' : undefined}
|
|
598
|
+
className={classNames[UI.Weekdays]}
|
|
599
|
+
style={styles?.[UI.Weekdays]}
|
|
600
|
+
>
|
|
601
|
+
{showWeekNumber && (
|
|
602
|
+
<components.WeekNumberHeader
|
|
603
|
+
aria-label={labelWeekNumberHeader(dateLib.options)}
|
|
604
|
+
className={classNames[UI.WeekNumberHeader]}
|
|
605
|
+
style={styles?.[UI.WeekNumberHeader]}
|
|
606
|
+
scope="col"
|
|
607
|
+
>
|
|
608
|
+
{formatWeekNumberHeader()}
|
|
609
|
+
</components.WeekNumberHeader>
|
|
610
|
+
)}
|
|
611
|
+
{weekdays.map((weekday) => (
|
|
595
612
|
<components.Weekday
|
|
596
613
|
aria-label={labelWeekday(weekday, dateLib.options, dateLib)}
|
|
597
614
|
className={classNames[UI.Weekday]}
|
|
598
615
|
key={String(weekday)}
|
|
599
616
|
style={styles?.[UI.Weekday]}
|
|
600
617
|
scope="col"
|
|
601
|
-
>
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
key={week.weekNumber}
|
|
612
|
-
style={styles?.[UI.Week]}
|
|
613
|
-
week={week}
|
|
618
|
+
>
|
|
619
|
+
{formatWeekdayName(weekday, dateLib.options, dateLib)}
|
|
620
|
+
</components.Weekday>
|
|
621
|
+
))}
|
|
622
|
+
</components.Weekdays>
|
|
623
|
+
)}
|
|
624
|
+
<components.Weeks
|
|
625
|
+
data-animated-weeks={props.animate ? 'true' : undefined}
|
|
626
|
+
className={classNames[UI.Weeks]}
|
|
627
|
+
style={styles?.[UI.Weeks]}
|
|
614
628
|
>
|
|
615
|
-
{
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
629
|
+
{calendarMonth.weeks.map((week) => {
|
|
630
|
+
return (
|
|
631
|
+
<components.Week
|
|
632
|
+
className={classNames[UI.Week]}
|
|
633
|
+
key={week.weekNumber}
|
|
634
|
+
style={styles?.[UI.Week]}
|
|
635
|
+
week={week}
|
|
636
|
+
>
|
|
637
|
+
{showWeekNumber && (
|
|
638
|
+
<components.WeekNumber
|
|
639
|
+
week={week}
|
|
640
|
+
style={styles?.[UI.WeekNumber]}
|
|
641
|
+
aria-label={labelWeekNumber(week.weekNumber, {
|
|
642
|
+
locale,
|
|
643
|
+
})}
|
|
644
|
+
className={classNames[UI.WeekNumber]}
|
|
645
|
+
scope="row"
|
|
646
|
+
role="rowheader"
|
|
647
|
+
>
|
|
648
|
+
{formatWeekNumber(week.weekNumber, dateLib)}
|
|
649
|
+
</components.WeekNumber>
|
|
650
|
+
)}
|
|
651
|
+
{week.days.map((day: CalendarDay) => {
|
|
652
|
+
const { date } = day;
|
|
653
|
+
const modifiers = getModifiers(day);
|
|
654
|
+
|
|
655
|
+
modifiers[DayFlag.focused] =
|
|
656
|
+
!modifiers.hidden && Boolean(focused?.isEqualTo(day));
|
|
657
|
+
|
|
658
|
+
modifiers[SelectionState.selected] =
|
|
659
|
+
isSelected?.(date) || modifiers.selected;
|
|
660
|
+
|
|
661
|
+
if (isDateRange(selectedValue)) {
|
|
662
|
+
// add range modifiers
|
|
663
|
+
const { from, to } = selectedValue;
|
|
664
|
+
modifiers[SelectionState.range_start] = Boolean(
|
|
665
|
+
from && to && dateLib.isSameDay(date, from),
|
|
666
|
+
);
|
|
667
|
+
modifiers[SelectionState.range_end] = Boolean(
|
|
668
|
+
from && to && dateLib.isSameDay(date, to),
|
|
669
|
+
);
|
|
670
|
+
modifiers[SelectionState.range_middle] = rangeIncludesDate(
|
|
671
|
+
selectedValue,
|
|
672
|
+
date,
|
|
673
|
+
true,
|
|
674
|
+
dateLib,
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
const style = getStyleForModifiers(
|
|
679
|
+
modifiers,
|
|
680
|
+
styles,
|
|
681
|
+
props.modifiersStyles,
|
|
682
|
+
);
|
|
683
|
+
|
|
684
|
+
const className = getClassNamesForModifiers(
|
|
685
|
+
modifiers,
|
|
686
|
+
classNames,
|
|
687
|
+
props.modifiersClassNames,
|
|
688
|
+
);
|
|
689
|
+
|
|
690
|
+
const ariaLabel =
|
|
691
|
+
!isInteractive && !modifiers.hidden
|
|
692
|
+
? labelGridcell(date, modifiers, dateLib.options, dateLib)
|
|
693
|
+
: undefined;
|
|
694
|
+
|
|
695
|
+
return (
|
|
696
|
+
<components.Day
|
|
697
|
+
key={`${day.isoDate}_${day.displayMonthId}`}
|
|
698
|
+
day={day}
|
|
699
|
+
modifiers={modifiers}
|
|
700
|
+
className={className.join(' ')}
|
|
701
|
+
style={style}
|
|
702
|
+
role="gridcell"
|
|
703
|
+
aria-selected={modifiers.selected || undefined}
|
|
704
|
+
aria-label={ariaLabel}
|
|
705
|
+
data-day={day.isoDate}
|
|
706
|
+
data-month={day.outside ? day.dateMonthId : undefined}
|
|
707
|
+
data-selected={modifiers.selected || undefined}
|
|
708
|
+
data-disabled={modifiers.disabled || undefined}
|
|
709
|
+
data-hidden={modifiers.hidden || undefined}
|
|
710
|
+
data-outside={day.outside || undefined}
|
|
711
|
+
data-focused={modifiers.focused || undefined}
|
|
712
|
+
data-today={modifiers.today || undefined}
|
|
713
|
+
>
|
|
714
|
+
{!modifiers.hidden && isInteractive ? (
|
|
715
|
+
<components.DayButton
|
|
716
|
+
className={classNames[UI.DayButton]}
|
|
717
|
+
style={styles?.[UI.DayButton]}
|
|
718
|
+
type="button"
|
|
719
|
+
day={day}
|
|
720
|
+
modifiers={modifiers}
|
|
721
|
+
disabled={(!modifiers.focused && modifiers.disabled) || undefined}
|
|
722
|
+
aria-disabled={
|
|
723
|
+
(modifiers.focused && modifiers.disabled) || undefined
|
|
724
|
+
}
|
|
725
|
+
tabIndex={isFocusTarget(day) ? 0 : -1}
|
|
726
|
+
aria-label={labelDayButton(
|
|
727
|
+
date,
|
|
728
|
+
modifiers,
|
|
729
|
+
dateLib.options,
|
|
730
|
+
dateLib,
|
|
731
|
+
)}
|
|
732
|
+
onClick={handleDayClick(day, modifiers)}
|
|
733
|
+
onBlur={handleDayBlur(day, modifiers)}
|
|
734
|
+
onFocus={handleDayFocus(day, modifiers)}
|
|
735
|
+
onKeyDown={handleDayKeyDown(day, modifiers)}
|
|
736
|
+
onMouseEnter={handleDayMouseEnter(day, modifiers)}
|
|
737
|
+
onMouseLeave={handleDayMouseLeave(day, modifiers)}
|
|
738
|
+
>
|
|
739
|
+
{formatDay(date, dateLib.options, dateLib)}
|
|
740
|
+
</components.DayButton>
|
|
741
|
+
) : (
|
|
742
|
+
!modifiers.hidden && formatDay(day.date, dateLib.options, dateLib)
|
|
743
|
+
)}
|
|
744
|
+
</components.Day>
|
|
745
|
+
);
|
|
746
|
+
})}
|
|
747
|
+
</components.Week>
|
|
658
748
|
);
|
|
659
|
-
|
|
660
|
-
const ariaLabel =
|
|
661
|
-
!isInteractive && !modifiers.hidden
|
|
662
|
-
? labelGridcell(date, modifiers, dateLib.options, dateLib)
|
|
663
|
-
: undefined;
|
|
664
|
-
|
|
665
|
-
return <components.Day
|
|
666
|
-
key={`${day.isoDate}_${day.displayMonthId}`}
|
|
667
|
-
day={day}
|
|
668
|
-
modifiers={modifiers}
|
|
669
|
-
className={className.join(' ')}
|
|
670
|
-
style={style}
|
|
671
|
-
role="gridcell"
|
|
672
|
-
aria-selected={modifiers.selected || undefined}
|
|
673
|
-
aria-label={ariaLabel}
|
|
674
|
-
data-day={day.isoDate}
|
|
675
|
-
data-month={day.outside ? day.dateMonthId : undefined}
|
|
676
|
-
data-selected={modifiers.selected || undefined}
|
|
677
|
-
data-disabled={modifiers.disabled || undefined}
|
|
678
|
-
data-hidden={modifiers.hidden || undefined}
|
|
679
|
-
data-outside={day.outside || undefined}
|
|
680
|
-
data-focused={modifiers.focused || undefined}
|
|
681
|
-
data-today={modifiers.today || undefined}
|
|
682
|
-
>
|
|
683
|
-
{!modifiers.hidden && isInteractive
|
|
684
|
-
? <components.DayButton
|
|
685
|
-
className={classNames[UI.DayButton]}
|
|
686
|
-
style={styles?.[UI.DayButton]}
|
|
687
|
-
type="button"
|
|
688
|
-
day={day}
|
|
689
|
-
modifiers={modifiers}
|
|
690
|
-
disabled={!modifiers.focused && modifiers.disabled || undefined}
|
|
691
|
-
aria-disabled={modifiers.focused && modifiers.disabled || undefined}
|
|
692
|
-
tabIndex={isFocusTarget(day) ? 0 : -1}
|
|
693
|
-
aria-label={labelDayButton(date, modifiers, dateLib.options, dateLib)}
|
|
694
|
-
onClick={handleDayClick(day, modifiers)}
|
|
695
|
-
onBlur={handleDayBlur(day, modifiers)}
|
|
696
|
-
onFocus={handleDayFocus(day, modifiers)}
|
|
697
|
-
onKeyDown={handleDayKeyDown(day, modifiers)}
|
|
698
|
-
onMouseEnter={handleDayMouseEnter(day, modifiers)}
|
|
699
|
-
onMouseLeave={handleDayMouseLeave(day, modifiers)}
|
|
700
|
-
>{formatDay(date, dateLib.options, dateLib)}</components.DayButton>
|
|
701
|
-
: !modifiers.hidden && formatDay(day.date, dateLib.options, dateLib)}
|
|
702
|
-
</components.Day>;
|
|
703
749
|
})}
|
|
704
|
-
</components.
|
|
705
|
-
|
|
706
|
-
</components.
|
|
707
|
-
|
|
750
|
+
</components.Weeks>
|
|
751
|
+
</components.MonthGrid>
|
|
752
|
+
</components.Month>
|
|
753
|
+
);
|
|
708
754
|
})}
|
|
709
755
|
</components.Months>
|
|
710
|
-
{props.footer &&
|
|
756
|
+
{props.footer && (
|
|
711
757
|
<components.Footer
|
|
712
758
|
className={classNames[UI.Footer]}
|
|
713
759
|
style={styles?.[UI.Footer]}
|
|
714
760
|
role="status"
|
|
715
761
|
aria-live="polite"
|
|
716
|
-
>
|
|
762
|
+
>
|
|
763
|
+
{props.footer}
|
|
764
|
+
</components.Footer>
|
|
765
|
+
)}
|
|
717
766
|
</components.Root>
|
|
718
767
|
</DayPickerContextProvider>
|
|
719
768
|
}
|
|
@@ -30,14 +30,18 @@ export function Chevron(props: {
|
|
|
30
30
|
}) @{
|
|
31
31
|
const { size = 24, orientation = 'left', className, style } = props;
|
|
32
32
|
<svg className={className} style={style} width={size} height={size} viewBox="0 0 24 24">
|
|
33
|
-
{orientation === 'up' &&
|
|
34
|
-
<polygon points="6.77 17 12.5 11.43 18.24 17 20 15.28 12.5 8 5 15.28" />
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
{orientation === '
|
|
40
|
-
<polygon points="
|
|
33
|
+
{orientation === 'up' && (
|
|
34
|
+
<polygon points="6.77 17 12.5 11.43 18.24 17 20 15.28 12.5 8 5 15.28" />
|
|
35
|
+
)}
|
|
36
|
+
{orientation === 'down' && (
|
|
37
|
+
<polygon points="6.77 8 12.5 13.57 18.24 8 20 9.72 12.5 17 5 9.72" />
|
|
38
|
+
)}
|
|
39
|
+
{orientation === 'left' && (
|
|
40
|
+
<polygon points="16 18.112 9.81111111 12 16 5.87733333 14.0888889 4 6 12 14.0888889 20" />
|
|
41
|
+
)}
|
|
42
|
+
{orientation === 'right' && (
|
|
43
|
+
<polygon points="8 18.112 14.18888889 12 8 5.87733333 9.91111111 4 18 12 9.91111111 20" />
|
|
44
|
+
)}
|
|
41
45
|
</svg>
|
|
42
46
|
}
|
|
43
47
|
export type ChevronProps = Parameters<typeof Chevron>[0];
|
|
@@ -48,8 +52,10 @@ export function Day(props: DayProps) @{
|
|
|
48
52
|
<td {...cellProps} />
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
export type DayButtonProps =
|
|
52
|
-
|
|
55
|
+
export type DayButtonProps = {
|
|
56
|
+
day: CalendarDay;
|
|
57
|
+
modifiers: Modifiers;
|
|
58
|
+
} & ButtonHTMLAttributes<HTMLButtonElement>;
|
|
53
59
|
export function DayButton(props: DayButtonProps) @{
|
|
54
60
|
const { day: _day, modifiers, ...buttonProps } = props;
|
|
55
61
|
const ref = useRef<HTMLButtonElement | null>(null);
|
|
@@ -60,8 +66,10 @@ export function DayButton(props: DayButtonProps) @{
|
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
export type DropdownOption = { value: number; label: string; disabled: boolean };
|
|
63
|
-
export type DropdownProps =
|
|
64
|
-
|
|
69
|
+
export type DropdownProps = { options?: DropdownOption[] } & Omit<
|
|
70
|
+
SelectHTMLAttributes<HTMLSelectElement>,
|
|
71
|
+
'children'
|
|
72
|
+
>;
|
|
65
73
|
export function Dropdown(props: DropdownProps) @{
|
|
66
74
|
const { options, className, ...selectProps } = props;
|
|
67
75
|
const { classNames, components, styles } = useDayPicker();
|
|
@@ -73,14 +81,11 @@ export function Dropdown(props: DropdownProps) @{
|
|
|
73
81
|
style={styles?.[UI.DropdownRoot]}
|
|
74
82
|
>
|
|
75
83
|
<components.Select className={cssClassSelect} {...selectProps}>
|
|
76
|
-
{options?.map(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
disabled={disabled}
|
|
82
|
-
>{label}</components.Option>,
|
|
83
|
-
)}
|
|
84
|
+
{options?.map(({ value, label, disabled }) => (
|
|
85
|
+
<components.Option key={value} value={value} disabled={disabled}>
|
|
86
|
+
{label}
|
|
87
|
+
</components.Option>
|
|
88
|
+
))}
|
|
84
89
|
</components.Select>
|
|
85
90
|
<span className={classNames[UI.CaptionLabel]} style={styles?.[UI.CaptionLabel]} aria-hidden>
|
|
86
91
|
{selectedOption?.label}
|
|
@@ -103,8 +108,10 @@ export function Footer(props: HTMLAttributes<HTMLDivElement>) @{
|
|
|
103
108
|
}
|
|
104
109
|
export type FooterProps = Parameters<typeof Footer>[0];
|
|
105
110
|
|
|
106
|
-
export type MonthProps =
|
|
107
|
-
|
|
111
|
+
export type MonthProps = {
|
|
112
|
+
calendarMonth: CalendarMonth;
|
|
113
|
+
displayIndex: number;
|
|
114
|
+
} & HTMLAttributes<HTMLDivElement>;
|
|
108
115
|
export function Month(props: MonthProps) @{
|
|
109
116
|
const { calendarMonth: _calendarMonth, displayIndex: _displayIndex, ...divProps } = props;
|
|
110
117
|
<div {...divProps}>{props.children}</div>
|
|
@@ -132,22 +139,32 @@ export function YearsDropdown(props: DropdownProps) @{
|
|
|
132
139
|
<components.Dropdown {...props} />
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
export type NavProps =
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
} & HTMLAttributes<HTMLElement>;
|
|
142
|
+
export type NavProps = {
|
|
143
|
+
onPreviousClick?: MouseEventHandler<HTMLButtonElement>;
|
|
144
|
+
onNextClick?: MouseEventHandler<HTMLButtonElement>;
|
|
145
|
+
previousMonth?: Date;
|
|
146
|
+
nextMonth?: Date;
|
|
147
|
+
} & HTMLAttributes<HTMLElement>;
|
|
142
148
|
export function Nav(props: NavProps) @{
|
|
143
149
|
const { onPreviousClick, onNextClick, previousMonth, nextMonth, ...navProps } = props;
|
|
144
|
-
const {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
const {
|
|
151
|
+
components,
|
|
152
|
+
classNames,
|
|
153
|
+
styles,
|
|
154
|
+
labels: { labelPrevious, labelNext },
|
|
155
|
+
} = useDayPicker();
|
|
156
|
+
const handleNextClick = useCallback(
|
|
157
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
158
|
+
if (nextMonth) onNextClick?.(event);
|
|
159
|
+
},
|
|
160
|
+
[nextMonth, onNextClick],
|
|
161
|
+
);
|
|
162
|
+
const handlePreviousClick = useCallback(
|
|
163
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
164
|
+
if (previousMonth) onPreviousClick?.(event);
|
|
165
|
+
},
|
|
166
|
+
[previousMonth, onPreviousClick],
|
|
167
|
+
);
|
|
151
168
|
<nav {...navProps}>
|
|
152
169
|
<components.PreviousMonthButton
|
|
153
170
|
type="button"
|