Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Replace Flatpickr with a custom DatePicker component

Blue Mouse1433c0bff9d0
diff --git a/web/app/pages/Captcha/View/ViewCaptcha.tsx b/web/app/pages/Captcha/View/ViewCaptcha.tsx
index 14b41b73b..120a9bb4e 100644
--- a/web/app/pages/Captcha/View/ViewCaptcha.tsx
+++ b/web/app/pages/Captcha/View/ViewCaptcha.tsx
@@ -44,8 +44,8 @@ import { deviceIconMapping, onCSVExportClick } from '~/pages/Project/View/ViewPr
import { useAuth } from '~/providers/AuthProvider'
import { useCurrentProject } from '~/providers/CurrentProjectProvider'
import { useTheme } from '~/providers/ThemeProvider'
+import DatePicker from '~/ui/Datepicker'
import Dropdown from '~/ui/Dropdown'
-import FlatPicker from '~/ui/Flatpicker'
import Loader from '~/ui/Loader'
import routes from '~/utils/routes'
@@ -470,7 +470,7 @@ const ViewCaptcha = () => {
</>
</Link>
) : null}
- <FlatPicker
+ <DatePicker
className='!mx-0 w-0'
ref={refCalendar}
onChange={([from, to]) => {
diff --git a/web/app/pages/Project/Settings/ProjectSettings.tsx b/web/app/pages/Project/Settings/ProjectSettings.tsx
index 7d17743de..5891d114f 100644
--- a/web/app/pages/Project/Settings/ProjectSettings.tsx
+++ b/web/app/pages/Project/Settings/ProjectSettings.tsx
@@ -36,8 +36,8 @@ import { Project } from '~/lib/models/Project'
import { useAuth } from '~/providers/AuthProvider'
import Button from '~/ui/Button'
import Checkbox from '~/ui/Checkbox'
+import DatePicker from '~/ui/Datepicker'
import Dropdown from '~/ui/Dropdown'
-import FlatPicker from '~/ui/Flatpicker'
import Input from '~/ui/Input'
import Loader from '~/ui/Loader'
import Modal from '~/ui/Modal'
@@ -150,7 +150,7 @@ const ModalMessage = ({
type='text'
className='m-0 h-0 w-0 border-0 p-0 focus:border-transparent focus:text-transparent focus:shadow-none focus:ring-transparent'
/>
- <FlatPicker
+ <DatePicker
className='!mx-0 w-0'
onChange={(date) => setDateRange(date)}
options={{
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 1cf667706..dde608a70 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -129,9 +129,9 @@ import ViewProjectHotkeys from '~/modals/ViewProjectHotkeys'
import { useAuth } from '~/providers/AuthProvider'
import { useTheme } from '~/providers/ThemeProvider'
import Checkbox from '~/ui/Checkbox'
+import DatePicker from '~/ui/Datepicker'
import Dropdown from '~/ui/Dropdown'
import Flag from '~/ui/Flag'
-import FlatPicker from '~/ui/Flatpicker'
import Loader from '~/ui/Loader'
import LoadingBar from '~/ui/LoadingBar'
import Select from '~/ui/Select'
@@ -2458,7 +2458,7 @@ const ViewProject = () => {
setSessionsLoading(null)
}
- // We can assume period provided is never custom, as it's handled separately in the Flatpickr callback function
+ // We can assume period provided is never custom, as it's handled separately in the Datepicker callback function
const updatePeriod = ({ period: newPeriod }: { period: Period }) => {
if (period === newPeriod) {
return
@@ -3300,7 +3300,7 @@ const ViewProject = () => {
/>
</>
) : null}
- <FlatPicker
+ <DatePicker
className='!mx-0 w-0'
ref={refCalendar}
onChange={([from, to]) => {
@@ -3314,7 +3314,7 @@ const ViewProject = () => {
maxDateMonths={MAX_MONTHS_IN_PAST}
maxRange={0}
/>
- <FlatPicker
+ <DatePicker
className='!mx-0 w-0'
ref={refCalendarCompare}
onChange={(date) => {
diff --git a/web/app/root.tsx b/web/app/root.tsx
index c49275e6d..bbd6698d1 100644
--- a/web/app/root.tsx
+++ b/web/app/root.tsx
@@ -1,8 +1,6 @@
import { ExclamationTriangleIcon, ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'
import BillboardCss from 'billboard.js/dist/billboard.min.css?url'
import cx from 'clsx'
-import FlatpickrDarkCss from 'flatpickr/dist/themes/dark.css?url'
-import FlatpickrLightCss from 'flatpickr/dist/themes/light.css?url'
import _replace from 'lodash/replace'
import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
@@ -25,7 +23,6 @@ import { LocaleLinks } from '~/components/LocaleLinks'
import SelfhostedApiUrlBanner from '~/components/SelfhostedApiUrlBanner'
import { SEO } from '~/components/SEO'
import { CONTACT_EMAIL, LS_THEME_SETTING, isSelfhosted, I18N_CACHE_BREAKER } from '~/lib/constants'
-import FlatpickerCss from '~/styles/Flatpicker.css?url'
import mainCss from '~/styles/index.css?url'
import tailwindCss from '~/styles/tailwind.css?url'
import { trackViews, trackErrors, trackError } from '~/utils/analytics'
@@ -54,7 +51,6 @@ export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: tailwindCss },
{ rel: 'stylesheet', href: mainCss },
{ rel: 'stylesheet', href: BillboardCss },
- { rel: 'stylesheet', href: FlatpickerCss },
]
export const headers: HeadersFunction = () => ({
@@ -248,9 +244,6 @@ export default function App() {
<Meta />
<meta name='viewport' content='width=device-width,initial-scale=1' />
<Links />
- {/* TODO: We should not load Flatpicker styles globally; load them within the FlatPicker component */}
- {theme === 'dark' ? <link rel='stylesheet' href={FlatpickrDarkCss} /> : null}
- {theme === 'light' ? <link rel='stylesheet' href={FlatpickrLightCss} /> : null}
<LocaleLinks />
<link
rel='preload'
diff --git a/web/app/styles/Flatpicker.css b/web/app/styles/Flatpicker.css
deleted file mode 100644
index dd4fe7f4b..000000000
--- a/web/app/styles/Flatpicker.css
+++ /dev/null
@@ -1,60 +0,0 @@
-.flatpicker-custom .flatpickr-calendar.static {
- position: absolute !important;
-}
-
-.flatpicker-custom .flatpickr-calendar.static.open {
- left: -310px;
- top: 30px;
-}
-
-.flatpicker-custom .flatpickr-day.selected,
-.flatpicker-custom .flatpickr-day.startRange,
-.flatpicker-custom .flatpickr-day.endRange,
-.flatpicker-custom .flatpickr-day.selected.inRange,
-.flatpicker-custom .flatpickr-day.startRange.inRange,
-.flatpicker-custom .flatpickr-day.endRange.inRange,
-.flatpicker-custom .flatpickr-day.selected:focus,
-.flatpicker-custom .flatpickr-day.startRange:focus,
-.flatpicker-custom .flatpickr-day.endRange:focus,
-.flatpicker-custom .flatpickr-day.selected:hover,
-.flatpicker-custom .flatpickr-day.startRange:hover,
-.flatpicker-custom .flatpickr-day.endRange:hover,
-.flatpicker-custom .flatpickr-day.selected.prevMonthDay,
-.flatpicker-custom .flatpickr-day.startRange.prevMonthDay,
-.flatpicker-custom .flatpickr-day.endRange.prevMonthDay,
-.flatpicker-custom .flatpickr-day.selected.nextMonthDay,
-.flatpicker-custom .flatpickr-day.startRange.nextMonthDay,
-.flatpicker-custom .flatpickr-day.endRange.nextMonthDay {
- background: #1d4ed8;
- -webkit-box-shadow: none;
- box-shadow: none;
- color: #fff;
- border-color: #1d4ed8;
-}
-
-/* if you need other color on dark theme */
-
-.dark .flatpicker-custom .flatpickr-day.selected,
-.dark .flatpicker-custom .flatpickr-day.startRange,
-.dark .flatpicker-custom .flatpickr-day.endRange,
-.dark .flatpicker-custom .flatpickr-day.selected.inRange,
-.dark .flatpicker-custom .flatpickr-day.startRange.inRange,
-.dark .flatpicker-custom .flatpickr-day.endRange.inRange,
-.dark .flatpicker-custom .flatpickr-day.selected:focus,
-.dark .flatpicker-custom .flatpickr-day.startRange:focus,
-.dark .flatpicker-custom .flatpickr-day.endRange:focus,
-.dark .flatpicker-custom .flatpickr-day.selected:hover,
-.dark .flatpicker-custom .flatpickr-day.startRange:hover,
-.dark .flatpicker-custom .flatpickr-day.endRange:hover,
-.dark .flatpicker-custom .flatpickr-day.selected.prevMonthDay,
-.dark .flatpicker-custom .flatpickr-day.startRange.prevMonthDay,
-.dark .flatpicker-custom .flatpickr-day.endRange.prevMonthDay,
-.dark .flatpicker-custom .flatpickr-day.selected.nextMonthDay,
-.dark .flatpicker-custom .flatpickr-day.startRange.nextMonthDay,
-.dark .flatpicker-custom .flatpickr-day.endRange.nextMonthDay {
- background: #4f46e5;
- -webkit-box-shadow: none;
- box-shadow: none;
- color: #fff;
- border-color: #4f46e5;
-}
diff --git a/web/app/ui/Datepicker.tsx b/web/app/ui/Datepicker.tsx
new file mode 100644
index 000000000..36b764d41
--- /dev/null
+++ b/web/app/ui/Datepicker.tsx
@@ -0,0 +1,517 @@
+import cx from 'clsx'
+import _clamp from 'lodash/clamp'
+import _isEmpty from 'lodash/isEmpty'
+import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react'
+import React, { memo, useEffect, useImperativeHandle, useMemo, useRef, useState, forwardRef } from 'react'
+import { useTranslation } from 'react-i18next'
+
+import useOnClickOutside from '~/hooks/useOnClickOutside'
+import { MAX_MONTHS_IN_PAST } from '~/lib/constants'
+
+interface DatePickerProps {
+ onChange?: (dates: Date[]) => void
+ value?: Date[]
+ maxDateMonths?: number
+ options?: { altInputClass?: string }
+ maxRange?: number
+ className?: string
+}
+
+type DatePickerHandle = {
+ openCalendar: () => void
+ closeCalendar: () => void
+}
+
+const startOfDay = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate())
+const endOfDay = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59, 999)
+
+const addDays = (d: Date, days: number) => {
+ const res = new Date(d)
+ res.setDate(res.getDate() + days)
+ return res
+}
+
+const removeMonths = (date: Date, months: number) => {
+ const d = date.getDate()
+ date.setMonth(date.getMonth() - months)
+ if (date.getDate() !== d) {
+ date.setDate(0)
+ }
+ return date
+}
+
+const areSameDay = (a: Date, b: Date) =>
+ a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate()
+
+const getDaysMatrix = (anchor: Date) => {
+ const firstDay = new Date(anchor.getFullYear(), anchor.getMonth(), 1)
+ const startWeekday = firstDay.getDay() // 0 Sun .. 6 Sat
+ const daysInMonth = new Date(anchor.getFullYear(), anchor.getMonth() + 1, 0).getDate()
+
+ const days: Date[] = []
+ // Prev month padding
+ for (let i = 0; i < startWeekday; i += 1) {
+ days.push(addDays(firstDay, i - startWeekday))
+ }
+ // Current month
+ for (let d = 1; d <= daysInMonth; d += 1) {
+ days.push(new Date(anchor.getFullYear(), anchor.getMonth(), d))
+ }
+ // Next month padding to complete 42 cells
+ const remaining = 42 - days.length
+ for (let i = 1; i <= remaining; i += 1) {
+ days.push(new Date(anchor.getFullYear(), anchor.getMonth() + 1, i))
+ }
+ return days
+}
+
+const formatRangeLabel = (locale: string, value?: Date[]) => {
+ if (!value || value.length < 1) return ''
+ const formatter = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'short', day: '2-digit' })
+ if (value.length === 1 || !value[1]) return formatter.format(value[0])
+ return `${formatter.format(value[0])} — ${formatter.format(value[1])}`
+}
+
+const DatePicker = forwardRef<DatePickerHandle, DatePickerProps>(function DatePickerInner(
+ { onChange, value = [], maxDateMonths = MAX_MONTHS_IN_PAST, options, maxRange = 0, className },
+ ref,
+) {
+ const { i18n } = useTranslation('common')
+ const locale = i18n.language
+
+ const today = useMemo(() => startOfDay(new Date()), [])
+ const absoluteMinDate = useMemo(() => startOfDay(removeMonths(new Date(), maxDateMonths)), [maxDateMonths])
+
+ const [open, setOpen] = useState(false)
+ const [anchorMonth, setAnchorMonth] = useState<Date>(() => startOfDay(value?.[0] || today))
+ const [start, setStart] = useState<Date | null>(() => (value?.[0] ? startOfDay(value[0]) : null))
+ const [end, setEnd] = useState<Date | null>(() => (value?.[1] ? startOfDay(value[1]) : null))
+ const [hoverDate, setHoverDate] = useState<Date | null>(null)
+ const popoverRef = useRef<HTMLDivElement>(null)
+
+ // Close on outside click
+ useOnClickOutside(popoverRef as React.RefObject<HTMLDivElement | HTMLUListElement>, () => setOpen(false))
+
+ // Imperative API
+ useImperativeHandle(ref, () => ({
+ openCalendar: () => setOpen(true),
+ closeCalendar: () => setOpen(false),
+ }))
+
+ // Sync with external value
+ useEffect(() => {
+ if (!_isEmpty(value)) {
+ setStart(value[0] ? startOfDay(value[0]) : null)
+ setEnd(value[1] ? startOfDay(value[1]) : null)
+ if (value[0]) setAnchorMonth(startOfDay(value[0]))
+ }
+ }, [value])
+
+ const weekFormatter = useMemo(() => new Intl.DateTimeFormat(locale, { weekday: 'short' }), [locale])
+
+ const _monthLabel = useMemo(() => {
+ return `${new Intl.DateTimeFormat(locale, { month: 'long' }).format(anchorMonth)} ${anchorMonth.getFullYear()}`
+ }, [anchorMonth, locale])
+
+ const weekdays = useMemo(() => {
+ const base = new Date(2021, 7, 1) // Sunday
+ return Array.from({ length: 7 }).map((_, i) => weekFormatter.format(addDays(base, i)))
+ }, [weekFormatter])
+
+ const rangeBounds = useMemo(() => {
+ if (!start || maxRange <= 0) {
+ return { min: absoluteMinDate, max: today }
+ }
+ const min = startOfDay(addDays(start, -maxRange))
+ const max = startOfDay(addDays(start, maxRange))
+ return { min: min < absoluteMinDate ? absoluteMinDate : min, max: max > today ? today : max }
+ }, [start, maxRange, absoluteMinDate, today])
+
+ const isDisabled = (d: Date) => {
+ const sd = startOfDay(d)
+ if (sd < rangeBounds.min) return true
+ if (sd > rangeBounds.max) return true
+ return false
+ }
+
+ const isInCurrentMonth = (d: Date) =>
+ d.getMonth() === anchorMonth.getMonth() && d.getFullYear() === anchorMonth.getFullYear()
+
+ const days = useMemo(() => getDaysMatrix(anchorMonth), [anchorMonth])
+
+ const minYear = absoluteMinDate.getFullYear()
+ const maxYear = today.getFullYear()
+ const minMonthOfMinYear = absoluteMinDate.getMonth()
+ const maxMonthOfMaxYear = today.getMonth()
+
+ const monthNames = useMemo(
+ () =>
+ Array.from({ length: 12 }).map((_, idx) =>
+ new Intl.DateTimeFormat(locale, { month: 'short' }).format(new Date(2021, idx, 1)),
+ ),
+ [locale],
+ )
+
+ const setAnchor = (year: number, month: number) => {
+ const clampedYear = Math.max(minYear, Math.min(maxYear, year))
+ let clampedMonth = month
+ if (clampedYear === minYear) clampedMonth = Math.max(minMonthOfMinYear, clampedMonth)
+ if (clampedYear === maxYear) clampedMonth = Math.min(maxMonthOfMaxYear, clampedMonth)
+ setAnchorMonth(new Date(clampedYear, clampedMonth, 1))
+ }
+
+ const handlePrevMonth = () => {
+ const prev = new Date(anchorMonth.getFullYear(), anchorMonth.getMonth() - 1, 1)
+ // Clamp within [absoluteMinDate, today]
+ const minMonth = new Date(absoluteMinDate.getFullYear(), absoluteMinDate.getMonth(), 1)
+ if (prev < minMonth) return
+ setAnchorMonth(prev)
+ }
+
+ const handleNextMonth = () => {
+ const next = new Date(anchorMonth.getFullYear(), anchorMonth.getMonth() + 1, 1)
+ const maxMonth = new Date(today.getFullYear(), today.getMonth(), 1)
+ if (next > maxMonth) return
+ setAnchorMonth(next)
+ }
+
+ const commitRange = (a: Date, b: Date) => {
+ const from = startOfDay(a)
+ const to = startOfDay(b)
+ const startN = from <= to ? from : to
+ const endN = from <= to ? to : from
+ setStart(startN)
+ setEnd(endN)
+ onChange?.([startN, endOfDay(endN)])
+ setOpen(false)
+ }
+
+ const onDayClick = (d: Date) => {
+ const sd = startOfDay(d)
+ if (!start || (start && end)) {
+ setStart(sd)
+ setEnd(null)
+ setHoverDate(null)
+ // Move anchor when clicking other month day
+ setAnchorMonth(new Date(sd.getFullYear(), sd.getMonth(), 1))
+ return
+ }
+ // If second click on the same date -> single-day range
+ if (start && areSameDay(start, sd)) {
+ commitRange(sd, sd)
+ return
+ }
+ // Enforce maxRange
+ if (maxRange > 0) {
+ const minAllowed = startOfDay(addDays(start, -maxRange))
+ const maxAllowed = startOfDay(addDays(start, maxRange))
+ const clamped = startOfDay(
+ new Date(_clamp(sd.getTime(), minAllowed.getTime(), Math.min(maxAllowed.getTime(), today.getTime()))),
+ )
+ commitRange(start, clamped)
+ return
+ }
+ commitRange(start, sd)
+ }
+
+ const inRange = (d: Date) => {
+ if (!start) return false
+ const sd = startOfDay(d)
+ const [lo, hi] = end
+ ? [start <= end ? start : end, start <= end ? end : start]
+ : hoverDate
+ ? [start <= hoverDate ? start : hoverDate, start <= hoverDate ? hoverDate : start]
+ : [null, null]
+ if (!lo || !hi) return false
+ return sd >= lo && sd <= hi
+ }
+
+ const label = useMemo(
+ () => formatRangeLabel(locale, start && end ? [start, end] : start ? [start] : []),
+ [locale, start, end],
+ )
+
+ const anchoredContainerClasses = 'relative inline-block h-0 align-top ' + (className || '')
+
+ return (
+ <div className={options ? undefined : anchoredContainerClasses}>
+ {/* Trigger input (optional visible) */}
+ {options ? (
+ <input
+ readOnly
+ onClick={() => setOpen(true)}
+ value={label || ''}
+ placeholder='Select a date range...'
+ className={options.altInputClass}
+ />
+ ) : null}
+
+ {/* Popover */}
+ {open ? (
+ options ? (
+ // Centered modal when used as input
+ <div className='fixed inset-0 z-50 flex items-start justify-center bg-black/20 p-4'>
+ <div
+ ref={popoverRef}
+ className='mt-10 w-[320px] rounded-xl border border-gray-200 bg-white p-3 shadow-xl dark:border-slate-800 dark:bg-slate-900'
+ >
+ <div className='flex items-center justify-between'>
+ <button
+ type='button'
+ className='rounded-md p-2 hover:bg-gray-100 dark:hover:bg-slate-800'
+ onClick={handlePrevMonth}
+ aria-label='Previous month'
+ >
+ <ChevronLeftIcon className='size-5' />
+ </button>
+ <div className='flex items-center gap-2'>
+ <div className='relative'>
+ <select
+ aria-label='Month'
+ className='appearance-none rounded-md border border-gray-200 bg-white px-2 py-1 pr-7 text-sm text-gray-900 hover:bg-gray-50 dark:border-slate-700 dark:bg-slate-800 dark:text-gray-50'
+ value={anchorMonth.getMonth()}
+ onChange={(e) => setAnchor(anchorMonth.getFullYear(), Number(e.target.value))}
+ >
+ {monthNames.map((m, idx) => (
+ <option
+ key={idx}
+ value={idx}
+ disabled={
+ (anchorMonth.getFullYear() === minYear && idx < minMonthOfMinYear) ||
+ (anchorMonth.getFullYear() === maxYear && idx > maxMonthOfMaxYear)
+ }
+ >
+ {m}
+ </option>
+ ))}
+ </select>
+ </div>
+ <div className='relative'>
+ <select
+ aria-label='Year'
+ className='appearance-none rounded-md border border-gray-200 bg-white px-2 py-1 pr-7 text-sm text-gray-900 hover:bg-gray-50 dark:border-slate-700 dark:bg-slate-800 dark:text-gray-50'
+ value={anchorMonth.getFullYear()}
+ onChange={(e) => setAnchor(Number(e.target.value), anchorMonth.getMonth())}
+ >
+ {Array.from({ length: maxYear - minYear + 1 }).map((_, i) => {
+ const y = minYear + i
+ return (
+ <option key={y} value={y}>
+ {y}
+ </option>
+ )
+ })}
+ </select>
+ </div>
+ </div>
+ <button
+ type='button'
+ className='rounded-md p-2 hover:bg-gray-100 dark:hover:bg-slate-800'
+ onClick={handleNextMonth}
+ aria-label='Next month'
+ >
+ <ChevronRightIcon className='size-5' />
+ </button>
+ </div>
+ <div className='mt-2 grid grid-cols-7 gap-1 text-center text-xs text-gray-500 dark:text-gray-300'>
+ {weekdays.map((wd, idx) => (
+ <div key={idx}>{wd}</div>
+ ))}
+ </div>
+ <div className='mt-1 grid grid-cols-7 gap-1'>
+ {days.map((d, idx) => {
+ const disabled = isDisabled(d)
+ const isStart = !!start && areSameDay(d, start)
+ const isEnd = !!end && areSameDay(d, end)
+ const isBetween = inRange(d)
+ const isCurrentMonth = isInCurrentMonth(d)
+ return (
+ <button
+ key={idx}
+ type='button'
+ disabled={disabled}
+ onMouseEnter={() => setHoverDate(start && !end ? startOfDay(d) : null)}
+ onMouseLeave={() => setHoverDate(null)}
+ onClick={() => !disabled && onDayClick(d)}
+ className={cx('relative h-9 w-9 rounded-md text-sm select-none', {
+ 'text-gray-900 dark:text-gray-100': isCurrentMonth && !disabled,
+ 'text-gray-400 dark:text-gray-500': !isCurrentMonth || disabled,
+ 'bg-indigo-600 text-white dark:bg-indigo-500': isStart || isEnd,
+ 'bg-gray-100 dark:bg-slate-800': isBetween && !isStart && !isEnd,
+ 'cursor-not-allowed opacity-50': disabled,
+ 'hover:bg-gray-200 dark:hover:bg-slate-700': !disabled && !isStart && !isEnd,
+ })}
+ >
+ {d.getDate()}
+ </button>
+ )
+ })}
+ </div>
+ <div className='mt-3 flex items-center justify-between'>
+ <div className='text-xs text-gray-600 dark:text-gray-300'>
+ {label || new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'short' }).format(anchorMonth)}
+ </div>
+ <div className='flex gap-2'>
+ <button
+ type='button'
+ className='rounded-md px-2 py-1 text-xs text-gray-700 hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-slate-800'
+ onClick={() => {
+ setStart(null)
+ setEnd(null)
+ setHoverDate(null)
+ }}
+ >
+ Clear
+ </button>
+ <button
+ type='button'
+ className='rounded-md bg-indigo-600 px-2 py-1 text-xs font-semibold text-white hover:bg-indigo-500'
+ disabled={!start}
+ onClick={() => {
+ if (!start) return
+ commitRange(start, end || start)
+ }}
+ >
+ Apply
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+ ) : (
+ // Anchored popover (toolbar usage)
+ <div className='absolute top-7 right-0 z-50'>
+ <div
+ ref={popoverRef}
+ className='w-[320px] rounded-xl border border-gray-200 bg-white p-3 shadow-xl dark:border-slate-800 dark:bg-slate-900'
+ >
+ <div className='flex items-center justify-between'>
+ <button
+ type='button'
+ className='rounded-md p-2 hover:bg-gray-100 dark:hover:bg-slate-800'
+ onClick={handlePrevMonth}
+ aria-label='Previous month'
+ >
+ <ChevronLeftIcon className='size-5' />
+ </button>
+ <div className='flex items-center gap-2'>
+ <div className='relative'>
+ <select
+ aria-label='Month'
+ className='appearance-none rounded-md border border-gray-200 bg-white px-2 py-1 pr-7 text-sm text-gray-900 hover:bg-gray-50 dark:border-slate-700 dark:bg-slate-800 dark:text-gray-50'
+ value={anchorMonth.getMonth()}
+ onChange={(e) => setAnchor(anchorMonth.getFullYear(), Number(e.target.value))}
+ >
+ {monthNames.map((m, idx) => (
+ <option
+ key={idx}
+ value={idx}
+ disabled={
+ (anchorMonth.getFullYear() === minYear && idx < minMonthOfMinYear) ||
+ (anchorMonth.getFullYear() === maxYear && idx > maxMonthOfMaxYear)
+ }
+ >
+ {m}
+ </option>
+ ))}
+ </select>
+ </div>
+ <div className='relative'>
+ <select
+ aria-label='Year'
+ className='appearance-none rounded-md border border-gray-200 bg-white px-2 py-1 pr-7 text-sm text-gray-900 hover:bg-gray-50 dark:border-slate-700 dark:bg-slate-800 dark:text-gray-50'
+ value={anchorMonth.getFullYear()}
+ onChange={(e) => setAnchor(Number(e.target.value), anchorMonth.getMonth())}
+ >
+ {Array.from({ length: maxYear - minYear + 1 }).map((_, i) => {
+ const y = minYear + i
+ return (
+ <option key={y} value={y}>
+ {y}
+ </option>
+ )
+ })}
+ </select>
+ </div>
+ </div>
+ <button
+ type='button'
+ className='rounded-md p-2 hover:bg-gray-100 dark:hover:bg-slate-800'
+ onClick={handleNextMonth}
+ aria-label='Next month'
+ >
+ <ChevronRightIcon className='size-5' />
+ </button>
+ </div>
+ <div className='mt-2 grid grid-cols-7 gap-1 text-center text-xs text-gray-500 dark:text-gray-300'>
+ {weekdays.map((wd, idx) => (
+ <div key={idx}>{wd}</div>
+ ))}
+ </div>
+ <div className='mt-1 grid grid-cols-7 gap-1'>
+ {days.map((d, idx) => {
+ const disabled = isDisabled(d)
+ const isStart = !!start && areSameDay(d, start)
+ const isEnd = !!end && areSameDay(d, end)
+ const isBetween = inRange(d)
+ const isCurrentMonth = isInCurrentMonth(d)
+ return (
+ <button
+ key={idx}
+ type='button'
+ disabled={disabled}
+ onMouseEnter={() => setHoverDate(start && !end ? startOfDay(d) : null)}
+ onMouseLeave={() => setHoverDate(null)}
+ onClick={() => !disabled && onDayClick(d)}
+ className={cx('relative h-9 w-9 rounded-md text-sm select-none', {
+ 'text-gray-900 dark:text-gray-100': isCurrentMonth && !disabled,
+ 'text-gray-400 dark:text-gray-500': !isCurrentMonth || disabled,
+ 'bg-indigo-600 text-white dark:bg-indigo-500': isStart || isEnd,
+ 'bg-gray-100 dark:bg-slate-800': isBetween && !isStart && !isEnd,
+ 'cursor-not-allowed opacity-50': disabled,
+ 'hover:bg-gray-200 dark:hover:bg-slate-700': !disabled && !isStart && !isEnd,
+ })}
+ >
+ {d.getDate()}
+ </button>
+ )
+ })}
+ </div>
+ <div className='mt-3 flex items-center justify-between'>
+ <div className='text-xs text-gray-600 dark:text-gray-300'>
+ {label || new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'short' }).format(anchorMonth)}
+ </div>
+ <div className='flex gap-2'>
+ <button
+ type='button'
+ className='rounded-md px-2 py-1 text-xs text-gray-700 hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-slate-800'
+ onClick={() => {
+ setStart(null)
+ setEnd(null)
+ setHoverDate(null)
+ }}
+ >
+ Clear
+ </button>
+ <button
+ type='button'
+ className='rounded-md bg-indigo-600 px-2 py-1 text-xs font-semibold text-white hover:bg-indigo-500'
+ disabled={!start}
+ onClick={() => {
+ if (!start) return
+ commitRange(start, end || start)
+ }}
+ >
+ Apply
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+ )
+ ) : null}
+ </div>
+ )
+})
+
+export default memo(DatePicker)
diff --git a/web/app/ui/Flatpicker.tsx b/web/app/ui/Flatpicker.tsx
deleted file mode 100644
index 6a40176f0..000000000
--- a/web/app/ui/Flatpicker.tsx
+++ /dev/null
@@ -1,128 +0,0 @@
-import cx from 'clsx'
-import _size from 'lodash/size'
-import _split from 'lodash/split'
-import React, { memo, createRef } from 'react'
-import Flatpickr from 'react-flatpickr'
-
-import { MAX_MONTHS_IN_PAST } from '~/lib/constants'
-
-interface FlatPickerProps {
- onChange?: (dates: Date[]) => void
- value?: Date[]
- maxDateMonths?: number
- options?: any
- maxRange?: number
- className?: string
-}
-
-class FlatPicker extends React.Component<
- FlatPickerProps,
- {
- maxDate: string
- minDate: Date | string
- }
-> {
- private calendar = createRef<Flatpickr>()
-
- constructor(props: FlatPickerProps) {
- super(props)
- this.setCustomDate = this.setCustomDate.bind(this)
- this.state = {
- maxDate: 'today',
- minDate: this.removeMonths(new Date(), props?.maxDateMonths || MAX_MONTHS_IN_PAST),
- }
- }
-
- private setCustomDate(dates: Date[]) {
- const { onChange, maxRange } = this.props
-
- if (maxRange && maxRange > 0 && _size(dates) === 1) {
- const maxDate = new Date(dates[0])
- const minDate = new Date(dates[0])
- maxDate.setDate(maxDate.getDate() + maxRange)
- minDate.setDate(minDate.getDate() - maxRange)
-
- this.setState({
- maxDate: maxDate > new Date() ? 'today' : _split(maxDate.toISOString(), 'T')[0],
- minDate: _split(minDate.toISOString(), 'T')[0],
- })
- }
-
- if (_size(dates) === 2) {
- onChange?.(dates)
- }
- }
-
- private openCalendar = () => {
- if (this.calendar.current) {
- this.setState({
- maxDate: 'today',
-
- minDate: this.removeMonths(new Date(), this.props?.maxDateMonths || MAX_MONTHS_IN_PAST),
- })
- this.calendar.current.flatpickr.open()
- }
- }
-
- private removeMonths(date: Date, months: number) {
- const d = date.getDate()
- date.setMonth(date.getMonth() - months)
- if (date.getDate() !== d) {
- date.setDate(0)
- }
- return date
- }
-
- public render() {
- const { value = [], maxDateMonths = MAX_MONTHS_IN_PAST, options, className } = this.props
- const { maxDate, minDate } = this.state
-
- if (options) {
- return (
- <div className={className}>
- <Flatpickr
- id='calendar'
- value={value}
- options={{
- mode: 'range',
- maxDate: 'today',
- minDate: this.removeMonths(new Date(), maxDateMonths),
- showMonths: 1,
- animate: true,
- altInput: true,
- position: 'auto',
- ...options,
- }}
- onChange={this.setCustomDate}
- placeholder='Select a date range...'
- />
- </div>
- )
- }
-
- return (
- <div className={cx('flatpicker-custom h-0', className)}>
- <Flatpickr
- id='calendar'
- value={value}
- options={{
- mode: 'range',
- maxDate,
- minDate,
- showMonths: 1,
- static: true,
- animate: true,
- altInput: true,
- position: 'auto right',
- altInputClass: 'hidden',
- }}
- ref={this.calendar}
- className='invisible'
- onChange={this.setCustomDate}
- />
- </div>
- )
- }
-}
-
-export default memo(FlatPicker)
diff --git a/web/package-lock.json b/web/package-lock.json
index 40f2ed759..ed81588cb 100644
--- a/web/package-lock.json
+++ b/web/package-lock.json
@@ -28,7 +28,6 @@
"dayjs": "^1.11.18",
"eslint-import-resolver-typescript": "^4.4.4",
"file-saver": "^2.0.5",
- "flatpickr": "^4.6.13",
"framer-motion": "^12.23.18",
"geojson": "^0.5.0",
"globals": "^16.4.0",
@@ -46,7 +45,6 @@
"prettier-plugin-tailwindcss": "^0.6.14",
"react": "^19.1.1",
"react-dom": "^19.1.1",
- "react-flatpickr": "^3.10.13",
"react-hotkeys-hook": "^4.6.1",
"react-i18next": "^15.7.3",
"react-leaflet": "^5.0.0",
@@ -73,7 +71,6 @@
"@types/node": "^24.5.2",
"@types/react": "^19.1.13",
"@types/react-dom": "^19.1.9",
- "@types/react-flatpickr": "^3.8.11",
"@types/sanitize-html": "^2.16.0",
"@typescript-eslint/eslint-plugin": "^8.44.1",
"@typescript-eslint/parser": "^8.44.1",
@@ -3744,16 +3741,6 @@
"@types/react": "^19.0.0"
}
},
- "node_modules/@types/react-flatpickr": {
- "version": "3.8.11",
- "resolved": "https://registry.npmjs.org/@types/react-flatpickr/-/react-flatpickr-3.8.11.tgz",
- "integrity": "sha512-wXGyGRpUjiGknioxWzWJdNvF2XxKw5lAI7H64Iv7w4iL+1iT7QvAzrigz5FkW4lTg9IJOww6t7g21FzsrmRV6A==",
- "dev": true,
- "dependencies": {
- "@types/react": "*",
- "flatpickr": "^4.0.6"
- }
- },
"node_modules/@types/sanitize-html": {
"version": "2.16.0",
"resolved": "https://registry.npmjs.org/@types/sanitize-html/-/sanitize-html-2.16.0.tgz",
@@ -7331,11 +7318,6 @@
"node": ">=16"
}
},
- "node_modules/flatpickr": {
- "version": "4.6.13",
- "resolved": "https://registry.npmjs.org/flatpickr/-/flatpickr-4.6.13.tgz",
- "integrity": "sha512-97PMG/aywoYpB4IvbvUJi0RQi8vearvU0oov1WW3k0WZPBMrTQVqekSX5CjSG/M4Q3i6A/0FKXC7RyAoAUUSPw=="
- },
"node_modules/flatted": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.3.tgz",
@@ -10002,18 +9984,6 @@
"react": "^19.1.1"
}
},
- "node_modules/react-flatpickr": {
- "version": "3.10.13",
- "resolved": "https://registry.npmjs.org/react-flatpickr/-/react-flatpickr-3.10.13.tgz",
- "integrity": "sha512-4m+K1K8jhvRFI8J/AHmQfA5hLALzhebEtEK8mLevXjX24MV3u502crzBn+EGFIBOfNUtrL5PId9FsGwgtuz/og==",
- "dependencies": {
- "flatpickr": "^4.6.2",
- "prop-types": "^15.5.10"
- },
- "peerDependencies": {
- "react": ">=16, <=18"
- }
- },
"node_modules/react-hotkeys-hook": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/react-hotkeys-hook/-/react-hotkeys-hook-4.6.2.tgz",
diff --git a/web/package.json b/web/package.json
index 2198e62c2..1f043eb27 100644
--- a/web/package.json
+++ b/web/package.json
@@ -42,7 +42,6 @@
"dayjs": "^1.11.18",
"eslint-import-resolver-typescript": "^4.4.4",
"file-saver": "^2.0.5",
- "flatpickr": "^4.6.13",
"framer-motion": "^12.23.18",
"geojson": "^0.5.0",
"globals": "^16.4.0",
@@ -60,7 +59,6 @@
"prettier-plugin-tailwindcss": "^0.6.14",
"react": "^19.1.1",
"react-dom": "^19.1.1",
- "react-flatpickr": "^3.10.13",
"react-hotkeys-hook": "^4.6.1",
"react-i18next": "^15.7.3",
"react-leaflet": "^5.0.0",
@@ -99,7 +97,6 @@
"@types/node": "^24.5.2",
"@types/react": "^19.1.13",
"@types/react-dom": "^19.1.9",
- "@types/react-flatpickr": "^3.8.11",
"@types/sanitize-html": "^2.16.0",
"@typescript-eslint/eslint-plugin": "^8.44.1",
"@typescript-eslint/parser": "^8.44.1",