1
1
import React , { useState , useRef , useEffect , FC , KeyboardEvent } from "react" ;
2
2
import { useTranslation } from "react-i18next" ;
3
3
import {
4
- AngleLeftIcon ,
5
- AngleRightIcon ,
6
- CloseIcon ,
7
4
RightFarIcon ,
8
5
LeftFarIcon ,
9
6
DownArrowIcon ,
10
7
UpArrowIcon ,
8
+ CalenderLeftIcon ,
9
+ CalenderRightIcon ,
11
10
} from "../SvgIcons" ;
11
+ import { V8CustomButton } from "../../formsflow-components" ;
12
12
13
13
type DateValue = Date | string | null ;
14
14
interface DateRange {
@@ -434,6 +434,26 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
434
434
) ;
435
435
} ;
436
436
437
+ // Select today's date
438
+ const handleTodayClick = ( ) : void => {
439
+ const today = new Date ( ) ;
440
+ const normalizedToday = new Date (
441
+ today . getFullYear ( ) ,
442
+ today . getMonth ( ) ,
443
+ today . getDate ( )
444
+ ) ;
445
+ const filterRange = createFilterDateRange ( normalizedToday , normalizedToday ) ;
446
+ setDateRange ( {
447
+ startDate : filterRange . startDate ,
448
+ endDate : filterRange . endDate ,
449
+ } ) ;
450
+ setCurrentMonth ( normalizedToday ) ;
451
+ onChange ( {
452
+ startDate : filterRange . startDate ,
453
+ endDate : filterRange . endDate ,
454
+ } ) ;
455
+ } ;
456
+
437
457
// Handle keyboard navigation
438
458
const handleNavKeyDown = (
439
459
event : KeyboardEvent < HTMLButtonElement > ,
@@ -543,49 +563,40 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
543
563
ref = { calendarRef }
544
564
data-testid = "date-range-picker"
545
565
>
546
- < button
547
- className = { `date-range-display ${ isOpen ? "open" : "" } button-as-div` }
566
+ < div className = "drp-input-container" >
567
+ < input
568
+ onClick = { toggleCalendar }
569
+ type = "text"
570
+ className = "drp-date-input"
571
+ value = { formatDateValue ( dateRange . startDate ) }
572
+ readOnly
573
+ aria-label = "Start date"
574
+ placeholder = "Start date"
575
+ />
576
+ < span className = "drp-separator" > to</ span >
577
+ < input
548
578
onClick = { toggleCalendar }
549
- onKeyDown = { ( e ) => handleNavKeyDown ( e , toggleCalendar ) }
550
- data-testid = "date-range-display"
551
- aria-label = { t ( "Date range selector" ) }
552
- aria-expanded = { isOpen }
553
- type = "button"
554
- >
579
+ type = "text"
580
+ className = "drp-date-input"
581
+ value = { formatDateValue ( dateRange . endDate ) }
582
+ readOnly
583
+ aria-label = "End date"
584
+ placeholder = "End date"
585
+ />
586
+
555
587
< span
556
- className = { `date-range-text ${ isOpen ? "open" : "" } ` }
557
- data-testid = "date-range-text"
588
+ className = { `date-range-toggle-icon cursor-pointer ${ isOpen ? "open" : "" } ` }
589
+ data-testid = "date-range-toggle-icon"
590
+ aria-hidden = "true"
591
+ onClick = { toggleCalendar }
558
592
>
559
- { formatDateRange ( ) }
560
- </ span >
561
- < div className = "date-range-controls" >
562
- { isOpen && (
563
- < button
564
- className = "date-range-close button-as-div"
565
- data-testid = "date-range-close-btn"
566
- aria-label = { t ( "Close calendar" ) }
567
- type = "button"
568
- onClick = { ( e ) => handleCloseCalendar ( e ) }
569
- onKeyDown = { ( e ) =>
570
- handleNavKeyDown ( e , ( ) => handleCloseCalendar ( ) )
571
- }
572
- >
573
- < CloseIcon />
574
- </ button >
593
+ { isOpen ? (
594
+ < UpArrowIcon color = "#4A4A4A" />
595
+ ) : (
596
+ < DownArrowIcon color = "#4A4A4A" />
575
597
) }
576
- < span
577
- className = { `date-range-toggle-icon ${ isOpen ? "open" : "" } ` }
578
- data-testid = "date-range-toggle-icon"
579
- aria-hidden = "true"
580
- >
581
- { isOpen ? (
582
- < UpArrowIcon color = "white" />
583
- ) : (
584
- < DownArrowIcon color = "white" />
585
- ) }
586
- </ span >
587
- </ div >
588
- </ button >
598
+ </ span >
599
+ </ div >
589
600
590
601
{ isOpen && (
591
602
< div
@@ -603,7 +614,8 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
603
614
aria-label = { t ( "Previous year" ) }
604
615
type = "button"
605
616
>
606
- < LeftFarIcon />
617
+ < CalenderLeftIcon color = "#212529" />
618
+ < CalenderLeftIcon color = "#212529" />
607
619
</ button >
608
620
< button
609
621
className = "calendar-prev-month-btn button-as-div"
@@ -613,7 +625,7 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
613
625
type = "button"
614
626
onClick = { goToPrevMonth }
615
627
>
616
- < AngleLeftIcon />
628
+ < CalenderLeftIcon color = "#212529" />
617
629
</ button >
618
630
</ div >
619
631
< span
@@ -631,7 +643,7 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
631
643
type = "button"
632
644
onClick = { goToNextMonth }
633
645
>
634
- < AngleRightIcon />
646
+ < CalenderRightIcon color = "#212529" />
635
647
</ button >
636
648
< button
637
649
className = "calendar-next-year-btn button-as-div"
@@ -641,23 +653,27 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
641
653
aria-label = { t ( "Next year" ) }
642
654
type = "button"
643
655
>
644
- < RightFarIcon />
656
+ < CalenderRightIcon color = "#212529" />
657
+ < CalenderRightIcon color = "#212529" />
658
+
659
+
645
660
</ button >
646
661
</ div >
647
662
</ div >
648
663
664
+ < div className = "calender-week-days-container" >
649
665
< div
650
666
className = "calendar-days-header"
651
667
data-testid = "calendar-days-header"
652
668
>
653
669
{ [
654
- t ( "MO " ) ,
655
- t ( "TU " ) ,
656
- t ( "WE " ) ,
657
- t ( "TH " ) ,
658
- t ( "FR " ) ,
659
- t ( "SA " ) ,
660
- t ( "SU " ) ,
670
+ t ( "Mon " ) ,
671
+ t ( "Tue " ) ,
672
+ t ( "Wed " ) ,
673
+ t ( "Thu " ) ,
674
+ t ( "Fri " ) ,
675
+ t ( "Sat " ) ,
676
+ t ( "Sun " ) ,
661
677
] . map ( ( day ) => (
662
678
< div
663
679
key = { day }
@@ -707,6 +723,16 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
707
723
) ;
708
724
} ) }
709
725
</ div >
726
+ < div className = "calendar-today-container" >
727
+ < V8CustomButton
728
+ label = "Today"
729
+ onClick = { handleTodayClick }
730
+ ariaLabel = "Today"
731
+ dataTestId = "calendar-today-btn"
732
+ variant = "secondary"
733
+ />
734
+ </ div >
735
+ </ div >
710
736
</ div >
711
737
) }
712
738
</ div >
0 commit comments