From c81da44fc5bde38d8845f1cc445254062d97d5fc Mon Sep 17 00:00:00 2001 From: Pavel Gordienko Date: Wed, 25 Sep 2024 05:58:21 +0300 Subject: [PATCH] feat: add enter date for date picker --- app/src/components/Filters/Filters.css | 56 +++++++++++++-- app/src/components/Filters/Filters.tsx | 96 ++++++++++++++++++++++++++ app/src/pages/AppPage.tsx | 12 ++++ 3 files changed, 157 insertions(+), 7 deletions(-) diff --git a/app/src/components/Filters/Filters.css b/app/src/components/Filters/Filters.css index 0039ea0..b8ff88d 100644 --- a/app/src/components/Filters/Filters.css +++ b/app/src/components/Filters/Filters.css @@ -50,11 +50,6 @@ .arrow-icon { padding: 0px 4px; - transition: transform 0.2s; -} - -.filter-arrow-icon:hover .arrow-icon { - transform: scale(1.1); } .dropdown-menu { @@ -119,9 +114,56 @@ border: 1px solid #bbb; box-shadow: 0px 4px 20px 0px rgba(0, 0, 0, 0.08); z-index: 1000; - margin-top: 150px; + margin-top: 220px; border-radius: 8px; - width: 133px; + width: 204px; text-align: left; color: #2b2d33; } + +.custom-date-range { + display: flex; + justify-content: center; + color: rgb(173, 191, 223); + font-size: 14px; + font-weight: 400; + letter-spacing: 0.04em; +} + +.date-input { + display: flex; + align-items: baseline; +} + +.date-field { + width: 18px; + padding-bottom: 20px; + border: none; + outline: none; +} + +.date-field-year { + width: 28px; + padding-bottom: 20px; + border: none; + outline: none; +} + +.date-separator { + font-size: 14px; +} + +.date-range-separator { + font-size: 14px; + padding-right: 10px; +} + +.calendar-icon { + width: 16px; + height: 17.6px; + cursor: pointer; +} + +.custom-date-range.active .date-field { + border-bottom: 2px solid #2563eb; +} diff --git a/app/src/components/Filters/Filters.tsx b/app/src/components/Filters/Filters.tsx index b177757..26afde6 100644 --- a/app/src/components/Filters/Filters.tsx +++ b/app/src/components/Filters/Filters.tsx @@ -6,6 +6,7 @@ interface FiltersProps { onDateRangeChange: (range: string) => void; onLeftArrowClick: () => void; onRightArrowClick: () => void; + onCustomDateRangeChange: (startDate: string, endDate: string) => void; } const Filters: React.FC = ({ @@ -13,16 +14,25 @@ const Filters: React.FC = ({ onDateRangeChange, onLeftArrowClick, onRightArrowClick, + onCustomDateRangeChange, }) => { const [isMenuOpen, setMenuOpen] = useState(false); const [currentFilter, setCurrentFilter] = useState('Все типы'); const [isDateMenuOpen, setDateMenuOpen] = useState(false); const [currentDateRange, setCurrentDateRange] = useState('3 дня'); + const [isCustomDateRange, setIsCustomDateRange] = useState(false); const menuRef = useRef(null); const [isLeftHovered, setIsLeftHovered] = useState(false); const [isRightHovered, setIsRightHovered] = useState(false); const [isCalendarHovered, setIsCalendarHovered] = useState(false); + const [startDay, setStartDay] = useState(''); + const [startMonth, setStartMonth] = useState(''); + const [startYear, setStartYear] = useState(''); + const [endDay, setEndDay] = useState(''); + const [endMonth, setEndMonth] = useState(''); + const [endYear, setEndYear] = useState(''); + const handleFilterChange = (filter: string) => { const filterNames: { [key: string]: string } = { '': 'Все типы', @@ -49,6 +59,7 @@ const Filters: React.FC = ({ setCurrentDateRange(range); onDateRangeChange(range); setDateMenuOpen(false); + setIsCustomDateRange(false); }; const handleToggleDateMenu = () => { @@ -62,6 +73,23 @@ const Filters: React.FC = ({ } }; + const handleCustomDateRangeChange = () => { + const startDate = `${startYear}-${startMonth}-${startDay}`; + const endDate = `${endYear}-${endMonth}-${endDay}`; + + if (startDate && endDate) { + onCustomDateRangeChange(startDate, endDate); + setStartDay(''); + setStartMonth(''); + setStartYear(''); + setEndDay(''); + setEndMonth(''); + setEndYear(''); + setIsCustomDateRange(false); + setCurrentDateRange('Диапазон'); + } + }; + useEffect(() => { document.addEventListener('mousedown', handleClickOutside); return () => { @@ -195,6 +223,74 @@ const Filters: React.FC = ({ > Год +
setIsCustomDateRange((prev) => !prev)} + > + Указать даты +
+ +
+
+ setStartDay(e.target.value)} + className="date-field" + placeholder="_ _" + /> + . + setStartMonth(e.target.value)} + className="date-field" + placeholder="_ _" + /> + . + setStartYear(e.target.value)} + className="date-field-year" + placeholder="_ _" + /> +
+ - +
+ setEndDay(e.target.value)} + className="date-field" + placeholder="_ _" + /> + . + setEndMonth(e.target.value)} + className="date-field" + placeholder="_ _" + /> + . + setEndYear(e.target.value)} + className="date-field-year" + placeholder="_ _" + /> +
+ calendar +
)} diff --git a/app/src/pages/AppPage.tsx b/app/src/pages/AppPage.tsx index b208049..2cf14c5 100644 --- a/app/src/pages/AppPage.tsx +++ b/app/src/pages/AppPage.tsx @@ -114,6 +114,17 @@ const AppPage = () => { setCustomDateRange({ startDate, endDate }); }; + const handleCustomDateRangeChange = (startDate: string, endDate: string) => { + const start = new Date(startDate); + const end = new Date(endDate); + + if (!isNaN(start.getTime()) && !isNaN(end.getTime()) && start <= end) { + setCustomDateRange({ startDate: start, endDate: end }); + } else { + console.error('Invalid date range selected'); + } + }; + return (
{ onDateRangeChange={setDateRange} onLeftArrowClick={handleLeftArrowClick} onRightArrowClick={handleRightArrowClick} + onCustomDateRangeChange={handleCustomDateRangeChange} />