// web/DateRangePicker.tsx import React, { useState } from 'react'; import { View } from 'react-native'; import type { DateRangePickerProps } from '../DatePicker'; import { ModalDialog } from './ModalDialog'; import { formatInputValue, isWithinInputBounds, parseInputValue, } from './dateInput'; import { BUTTON_BASE, eventValue, usePrimaryColor } from './shared'; /** The browser has start and end date inputs, so the range picker works on web. */ export const isDateRangePickerSupported: boolean = true; const INPUT_STYLE = { boxSizing: 'border-box', width: '100%', minHeight: 40, padding: '0 12px', border: '1px solid color-mix(in srgb, CanvasText 30%, transparent)', borderRadius: 8, fontFamily: 'inherit', fontSize: 16, color: 'inherit', backgroundColor: 'transparent', } as const; const startOfDay = (date: Date | null | undefined): Date | null => { if (!date || !Number.isFinite(date.getTime())) return null; const day = new Date(date.getTime()); day.setHours(0, 0, 0, 0); return day; }; /** * A `` with start and end date inputs and Cancel/Done buttons. Done * reports the range (the start of each day) once both are set and in order, * then calls `onClosed`, as the Android dialog does. */ export function DateRangePicker( props: DateRangePickerProps ): React.ReactElement { const { style, testID, visible } = props; return ( {visible ? : null} ); } function RangeDialog({ startDate, endDate, minDate, maxDate, locale, onConfirm, onClosed, }: DateRangePickerProps): React.ReactElement { const primary = usePrimaryColor(); const [start, setStart] = useState(startOfDay(startDate)); const [end, setEnd] = useState(startOfDay(endDate)); const valid = isWithinInputBounds(start, 'date', minDate, maxDate) && isWithinInputBounds(end, 'date', minDate, maxDate) && end >= start; const minimumEndDate = start && (!minDate || start >= minDate) ? start : minDate; const dismiss = () => onClosed?.(); const textButton = { ...BUTTON_BASE, height: 40, padding: '0 12px', border: 'none', borderRadius: 20, fontSize: 14, color: primary, backgroundColor: 'transparent', }; const renderInput = ( label: string, value: Date | null, onValue: (next: Date | null) => void, min: Date | null | undefined ) => ( onValue(parseInputValue(eventValue(event), 'date', null)) } style={{ ...INPUT_STYLE, accentColor: primary }} /> ); return (
{renderInput('Start date', start, setStart, minDate)} {renderInput('End date', end, setEnd, minimumEndDate)}
); }