UNPKG

@rnwonder/react-date-picker

Version:

A lightweight, customizable, and accessible date picker component for React applications.

198 lines (196 loc) 7.48 kB
import { default as React, SetStateAction } from 'react'; export interface DateObjectUnits { year?: number; month?: number; day?: number; } export type MonthStatus = "prev" | "current" | "next"; export interface MonthDaysObject<T = string> { value: T; month: MonthStatus; } export type DatePickerType = "single" | "range" | "multiple"; export type DatePickerOnChange = { selectedDate?: DateObjectUnits; type: "single"; } | { startDate?: DateObjectUnits; endDate?: DateObjectUnits; type: "range"; } | { multipleDates?: DateObjectUnits[]; type: "multiple"; }; export interface PickerValue { value: PickerAloneValue; label: string; } export interface PickerAloneValue { start?: string; startDateObject?: DateObjectUnits; end?: string; endDateObject?: DateObjectUnits; selected?: string; selectedDateObject?: DateObjectUnits; multiple?: string[]; multipleDateObject?: DateObjectUnits[]; } export interface PickerInputJSXProps { value: PickerValue; showDate: () => void; } export interface TimeInputJSXProps { value: TimeValue; showTime: () => void; } export type PickerInputJSX = JSX.Element | ((props: PickerInputJSXProps) => JSX.Element); export type TimeInputJSX = JSX.Element | ((props: TimeInputJSXProps) => JSX.Element); export interface PickerRenderJSXProps { month: number; setMonth: React.Dispatch<SetStateAction<number>>; year: number; setYear: React.Dispatch<SetStateAction<number>>; selectedDate: DateObjectUnits | undefined; endDate: DateObjectUnits | undefined; multipleDates: DateObjectUnits[] | undefined; handleNextMonth: () => void; handlePrevMonth: () => void; close: () => void; handleDayClick: HandleDayClick; setRefToAllowOutsideClick: React.MutableRefObject<HTMLDivElement | undefined>; } export type HandleDayClick = (day: MonthDaysObject<number>, month: number, year: number, nextMonth: boolean) => void; export type PickerRenderJSX = JSX.Element | ((props: PickerRenderJSXProps) => JSX.Element); export type IMonthSelectorType = "short" | "long"; export type IMonthYearSelectorFlexDirection = "row" | "column"; export interface YearRange { start: number; end: number; } export type Locale = Intl.LocalesArgument; export type LocaleOptions = Intl.DateTimeFormatOptions; export interface RnColor { primaryColor?: string; primaryTextColor?: string; secondaryColor?: string; secondaryTextColor?: string; textColor?: string; arrowsColor?: string; weekEndDayBgColor?: string; weekEndDayTextColor?: string; weekDaysNameColor?: string; backgroundColor?: string; } export interface SelectorColorsAndClassNames extends Pick<RnColor, "primaryColor" | "primaryTextColor" | "textColor" | "backgroundColor" | "arrowsColor">, Pick<RnClassName, "monthYearTriggerBtnClass" | "monthYearTriggerBtnWrapperClass" | "monthYearSelectorWrapperClass" | "monthYearOptionBtnClass" | "monthYearOptionBtnActiveClass"> { } export type DateArray = MakeOptionalRequired<DateObjectUnits> | { start: MakeOptionalRequired<DateObjectUnits>; end: MakeOptionalRequired<DateObjectUnits>; }; export type MakeOptionalRequired<T> = { [K in keyof T]-?: T[K]; }; export interface ApplyDateRange { dayRangeEnd: boolean; dayRangeStartEnd: undefined | boolean; dayRangeStart: boolean; dayRangeBetween: boolean; daysCurrent: boolean; daysNotCurrentMonth: boolean; isWeekend: boolean; isSaturday: boolean; isSunday: boolean; customDayClass?: string; isMultipleSelected: boolean; hidden: boolean; disabled: boolean; dayRangeEndHover: boolean; date: string; dateValue: string; } export interface CustomDaysClassName extends MakeOptionalRequired<DateObjectUnits> { className: string; } export type WeekDaysType = "short" | "single" | "double"; export type SelectorType = "full-size" | "compact-dropdown"; export interface HoverRangeValue { start?: DateObjectUnits; end?: DateObjectUnits; } export interface RnClassName { inputClass?: string; inputWrapperClass?: string; datePickerWrapperClass?: string; datePickerTopAreaClass?: string; prevNextMonthBtnClass?: string; prevMonthBtnClass?: string; nextMonthBtnClass?: string; datePickerTopMonthYearAreaClass?: string; monthYearTriggerBtnClass?: string; monthYearTriggerBtnWrapperClass?: string; monthYearSelectorWrapperClass?: string; monthYearOptionBtnClass?: string; monthYearOptionBtnActiveClass?: string; datePickerBodyAreaClass?: string; calendarWrapperClass?: string; calendarOneAreaClass?: string; calendarTwoAreaClass?: string; calendarDividerClass?: string; weekNamesRowClass?: string; weekNamesClass?: string; daysRowClass?: string; daysWrapperClass?: string; daysBtnClass?: string; daysActiveRangeBetweenBtnClass?: string; daysActivePrimaryBtnClass?: string; currentDayBtnClass?: string; weekEndDaysBtnClass?: string; sundaysBtnClass?: string; saturdaysBtnClass?: string; daysNotInCurrentMonthBtnClass?: string; daysActiveRangeStartBtnClass?: string; daysActiveRangeEndBtnClass?: string; daysActiveRangeStartWrapperClass?: string; daysActiveRangeEndWrapperClass?: string; daysActivePrimaryWrapperClass?: string; daysActiveRangeBetweenWrapperClass?: string; datePickerCalendarDaysArea?: string; } export interface DatePickerDayClassNames extends Pick<RnClassName, "weekNamesClass" | "daysWrapperClass" | "daysActivePrimaryWrapperClass" | "datePickerBodyAreaClass" | "daysActivePrimaryBtnClass" | "daysActiveRangeBetweenBtnClass" | "daysActiveRangeEndBtnClass" | "daysActiveRangeStartBtnClass" | "daysActiveRangeStartWrapperClass" | "daysActiveRangeEndWrapperClass" | "daysActiveRangeBetweenWrapperClass" | "daysBtnClass" | "currentDayBtnClass" | "weekEndDaysBtnClass" | "sundaysBtnClass" | "saturdaysBtnClass" | "daysNotInCurrentMonthBtnClass"> { } export interface DatePickerDayColors extends Omit<RnColor, "arrowsColor" | "backgroundColor"> { } export interface DatePickerDayClassNamesAndColors extends DatePickerDayColors, DatePickerDayClassNames { } export interface CalendarDaysClassNamesAndColors extends DatePickerDayColors, DatePickerDayClassNames, Pick<RnClassName, "daysRowClass" | "datePickerCalendarDaysArea"> { } export type DateOption = Date | DateObjectUnits | string | number; export type DateMathDiffUnit = "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "quarters" | "years"; export interface DateMathDiff extends Partial<Record<DateMathDiffUnit, number>> { } export interface DateTimeObject extends DateObjectUnits, ITimePickerFormat { } export interface ITimePickerFormat { hour?: number; minute?: number; second?: number; } export type TimeView = "hour" | "minute" | "second"; export type TimeMeridiem = "AM" | "PM"; export interface TimeValue { value: ITimePickerFormat; label: string; } export interface TimeClassName { prevTimeViewBtnClass?: string; nextTimeViewBtnClass?: string; prevNextTimeViewBtnClass?: string; timeAnalogNumberClass?: string; timeAnalogWrapperClass?: string; timeAnalogClockHandClass?: string; timeAnalogClockCenterDotClass?: string; timePickerWrapperClass?: string; timePickerTopAreaClass?: string; timePickerBottomAreaClass?: string; timePickerMeridiemBtnClass?: string; }