Skip to content

Commit 545220c

Browse files
authored
Merge pull request #818 from fahad-aot/feature/fwf-5213-date-range-picker
feature/fwf-5213:Added daterangepicker
2 parents c8d9d2a + 6648d44 commit 545220c

File tree

8 files changed

+431
-178
lines changed

8 files changed

+431
-178
lines changed

forms-flow-components/src/components/CustomComponents/ButtonDropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ const { extraActionClass, backgroundColor } = getExtraActionStyles(variant);
159159

160160
<Dropdown.Menu className={(dropdownType === "DROPDOWN_ONLY") && 'dropdown-only'}>
161161
{onSearch && (<CustomSearch
162-
handleClearSearch={handleClearSearch}
162+
// handleClearSearch={handleClearSearch}
163163
search={search}
164164
setSearch={setSearch}
165165
handleSearch={handleSearch}
166166
placeholder={t("Search")}
167-
title={t("Search")}
167+
// title={t("Search")}
168168
dataTestId="search-filter"
169169
/>)}
170170
{dropdownItems.map((item) => (

forms-flow-components/src/components/CustomComponents/DateFilter.tsx

Lines changed: 79 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React, { useState, useRef, useEffect, FC, KeyboardEvent } from "react";
22
import { useTranslation } from "react-i18next";
33
import {
4-
AngleLeftIcon,
5-
AngleRightIcon,
6-
CloseIcon,
74
RightFarIcon,
85
LeftFarIcon,
96
DownArrowIcon,
107
UpArrowIcon,
8+
CalenderLeftIcon,
9+
CalenderRightIcon,
1110
} from "../SvgIcons";
11+
import { V8CustomButton } from "../../formsflow-components";
1212

1313
type DateValue = Date | string | null;
1414
interface DateRange {
@@ -434,6 +434,26 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
434434
);
435435
};
436436

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+
437457
// Handle keyboard navigation
438458
const handleNavKeyDown = (
439459
event: KeyboardEvent<HTMLButtonElement>,
@@ -543,49 +563,40 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
543563
ref={calendarRef}
544564
data-testid="date-range-picker"
545565
>
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
548578
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+
555587
<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}
558592
>
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" />
575597
)}
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>
589600

590601
{isOpen && (
591602
<div
@@ -603,7 +614,8 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
603614
aria-label={t("Previous year")}
604615
type="button"
605616
>
606-
<LeftFarIcon />
617+
<CalenderLeftIcon color="#212529" />
618+
<CalenderLeftIcon color="#212529" />
607619
</button>
608620
<button
609621
className="calendar-prev-month-btn button-as-div"
@@ -613,7 +625,7 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
613625
type="button"
614626
onClick={goToPrevMonth}
615627
>
616-
<AngleLeftIcon />
628+
<CalenderLeftIcon color="#212529" />
617629
</button>
618630
</div>
619631
<span
@@ -631,7 +643,7 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
631643
type="button"
632644
onClick={goToNextMonth}
633645
>
634-
<AngleRightIcon />
646+
<CalenderRightIcon color="#212529" />
635647
</button>
636648
<button
637649
className="calendar-next-year-btn button-as-div"
@@ -641,23 +653,27 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
641653
aria-label={t("Next year")}
642654
type="button"
643655
>
644-
<RightFarIcon />
656+
<CalenderRightIcon color="#212529" />
657+
<CalenderRightIcon color="#212529" />
658+
659+
645660
</button>
646661
</div>
647662
</div>
648663

664+
<div className="calender-week-days-container">
649665
<div
650666
className="calendar-days-header"
651667
data-testid="calendar-days-header"
652668
>
653669
{[
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"),
661677
].map((day) => (
662678
<div
663679
key={day}
@@ -707,6 +723,16 @@ export const DateRangePicker: FC<DateRangePickerProps> = ({
707723
);
708724
})}
709725
</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>
710736
</div>
711737
)}
712738
</div>

forms-flow-components/src/components/CustomComponents/Search.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface CustomSearchProps {
77
handleSearch: () => void;
88
placeholder?: string;
99
dataTestId: string;
10+
disabled?: boolean;
1011
}
1112

1213
export const CustomSearch: FC<CustomSearchProps> = ({
@@ -15,6 +16,7 @@ export const CustomSearch: FC<CustomSearchProps> = ({
1516
handleSearch,
1617
placeholder = "Search",
1718
dataTestId,
19+
disabled = false,
1820
}) => {
1921
const { t } = useTranslation();
2022
return (
@@ -28,6 +30,7 @@ export const CustomSearch: FC<CustomSearchProps> = ({
2830
aria-label={placeholder}
2931
value={search}
3032
role="searchbox"
33+
disabled={disabled}
3134
/>
3235
</div>
3336
);

forms-flow-components/src/components/SvgIcons/index.tsx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,11 @@ export const AngleRightIcon = ({ color = baseColor, ...props }) => (
397397
xmlns="http://www.w3.org/2000/svg"
398398
viewBox="0 0 17 17"
399399
onClick={props.onClick}
400-
className={props.className || "svgIcon-primary"}
400+
className={props.className}
401+
fill="none"
402+
{...props}
401403
>
402-
<path d="M5.24976 15.0003L11.7503 8.49971L5.25034 1.9997"/>
404+
<path stroke={color} d="M5.24976 15.0003L11.7503 8.49971L5.25034 1.9997"/>
403405
</svg>
404406
);
405407

@@ -408,9 +410,11 @@ export const AngleLeftIcon = ({ color = baseColor, ...props }) => (
408410
xmlns="http://www.w3.org/2000/svg"
409411
viewBox="0 0 17 17"
410412
onClick={props.onClick}
411-
className={props.className || "svgIcon-primary"}
413+
className={props.className }
414+
fill="none"
415+
{...props}
412416
>
413-
<path d="M11.7503 1.99971L5.24972 8.50029L11.7497 15.0003"/>
417+
<path stroke={color} d="M11.7503 1.99971L5.24972 8.50029L11.7497 15.0003"/>
414418
</svg>
415419
);
416420

@@ -761,6 +765,7 @@ export const UpArrowIcon = ({ color = baseColor, ...props }) => (
761765
height="10"
762766
viewBox="0 0 16 10"
763767
fill="none"
768+
{...props}
764769
>
765770
<path
766771
d="M14.5003 8.25034L8.00028 1.74976L1.49969 8.24976"
@@ -856,3 +861,33 @@ export const NavbarSubmitIcon = ({
856861
/>
857862
</svg>
858863
);
864+
865+
export const CalenderLeftIcon = ({ color = baseColor, ...props }) => (
866+
<svg
867+
xmlns="http://www.w3.org/2000/svg"
868+
width="7"
869+
height="12"
870+
viewBox="0 0 7 12"
871+
fill="none"
872+
>
873+
<path
874+
d="M0.294026 5.29402C-0.0964468 5.6845 -0.0964468 6.31862 0.294026 6.7091L5.29207 11.7071C5.68255 12.0976 6.31667 12.0976 6.70715 11.7071C7.09762 11.3167 7.09762 10.6825 6.70715 10.2921L2.41507 6L6.70402 1.70793C7.09449 1.31745 7.09449 0.683327 6.70402 0.292854C6.31355 -0.0976181 5.67942 -0.0976182 5.28895 0.292854L0.290902 5.2909L0.294026 5.29402Z"
875+
fill="#4A4A4A"
876+
/>
877+
</svg>
878+
);
879+
880+
export const CalenderRightIcon = ({ color = baseColor, ...props }) => (
881+
<svg
882+
xmlns="http://www.w3.org/2000/svg"
883+
width="7"
884+
height="12"
885+
viewBox="0 0 7 12"
886+
fill="none"
887+
>
888+
<path
889+
d="M6.70597 6.70597C7.09645 6.3155 7.09645 5.68137 6.70597 5.2909L1.70793 0.292854C1.31745 -0.0976182 0.683326 -0.0976181 0.292854 0.292854C-0.0976186 0.683327 -0.0976186 1.31745 0.292854 1.70793L4.58493 6L0.295978 10.2921C-0.0944947 10.6825 -0.0944946 11.3167 0.295978 11.7071C0.68645 12.0976 1.32058 12.0976 1.71105 11.7071L6.7091 6.7091L6.70597 6.70597Z"
890+
fill="#4A4A4A"
891+
/>
892+
</svg>
893+
);

0 commit comments

Comments
 (0)