@zenithui/day-picker
Version:
A ZenithUi Time Picker is React component enables users to select a date or date range from calendar.
69 lines (68 loc) • 3.17 kB
TypeScript
import { DateRange, Disabled, InternalRange } from "./types";
/**
* Gets the initial date from the selected date or range.
* If the selected date is a Date, it returns the date.
* If the selected date is an array, it returns the first element of the array.
* If the selected date is an object, it returns the from property of the object.
* @param selected
* @returns
*/
export declare function getInitialDate(selected: Date | DateRange): Date;
/**
* Gets the initial range from the selected date or range.
* If the selected date is a Date, it returns an object with the same date for both from and to.
* @param selected
* @returns
*/
export declare function getInitialRange(selected: Date | DateRange): InternalRange;
/**
* Checks if a given day is within a specified range, considering a focus date.
*
* @param day - The date to check if it falls within the range.
* @param range - An object containing the start (`from`) and end (`to`) dates of the range.
* Both `from` and `to` can be `null`.
* @param focus - A date that serves as a reference point to determine the interval.
* It can be `null`.
* @returns `true` if the day is within the range considering the focus date, otherwise `false`.
*
* The function works as follows:
* - If `range.from` or `focus` is `null`, it returns `false`.
* - If `focus` is after `range.from`, it checks if the day is within the interval from `range.from` to `focus`.
* - If `focus` is before `range.from`, it checks if the day is within the interval from `focus` to `range.from`.
* - If none of the above conditions are met, it returns `false`.
*/
export declare function isBetweenRange(day: Date, range: {
from: Date | null;
to: Date | null;
}, focus: Date | null): boolean;
/**
* Parses a given date input and returns a Date object.
*
* @param date - The date input which can be either a Date object or a string representing a date.
* @returns A Date object parsed from the input.
*
* @example
* ```typescript
* const date1 = parseDate("2023-10-05");
* const date2 = parseDate(new Date());
* ```
*/
export declare function parseDate(date: Date | string): Date;
/**
* Determines if a given date should be disabled based on various constraints.
*
* @param current - The date to check for disabling.
* @param disable - An object containing various disabling constraints.
* - `before` (Date | string): Disables dates before this date.
* - `after` (Date | string): Disables dates after this date.
* - `date` (Date | string): Disables a specific date.
* - `dates` (Array<Date | string>): Disables an array of specific dates.
* - `days` (Array<number | string>): Disables specific days of the week.
* Days can be specified as numbers (0 for Sunday, 1 for Monday, etc.) or
* as strings ("sunday", "monday", etc.).
* - `modifier` (function): A custom function that takes a date and returns
* a boolean indicating whether the date should be disabled.
*
* @returns `true` if the date should be disabled, `false` otherwise.
*/
export declare function getDisabled(current: Date, disable: Partial<Disabled> | undefined): boolean;