UNPKG

@coreui/react-pro

Version:

UI Components Library for React.js

198 lines (197 loc) 8.99 kB
import type { DisabledDate, SelectionTypes, ViewTypes } from './types'; /** * Converts an ISO week string to a Date object representing the Monday of that week. * @param isoWeek - The ISO week string (e.g., "2023W05" or "2023w05"). * @returns The Date object for the Monday of the specified week, or null if invalid. */ export declare const convertIsoWeekToDate: (isoWeek: string) => Date; /** * Converts a date string or Date object to a Date object based on selection type. * @param date - The date to convert. * @param selectionType - The type of selection ('day', 'week', 'month', 'year'). * @returns The corresponding Date object or null if invalid. */ export declare const convertToDateObject: (date: Date | string, selectionType?: SelectionTypes) => Date; /** * Creates groups from an array. * @param arr - The array to group. * @param numberOfGroups - Number of groups to create. * @returns An array of grouped arrays. */ export declare const createGroupsInArray: <T>(arr: T[], numberOfGroups: number) => T[][]; /** * Adjusts the calendar date based on order and view type. * @param calendarDate - The current calendar date. * @param order - The order to adjust by. * @param view - The current view type. * @returns The adjusted Date object. */ export declare const getCalendarDate: (calendarDate: Date, order: number, view: ViewTypes) => Date; /** * Formats a date based on the selection type. * @param date - The date to format. * @param selectionType - The type of selection ('day', 'week', 'month', 'year'). * @returns A formatted date string or the original Date object. */ export declare const getDateBySelectionType: (date: Date | null, selectionType: SelectionTypes) => string | Date | null; /** * Retrieves the first available date within a range that is not disabled. * @param startDate - Start date of the range. * @param endDate - End date of the range. * @param min - Minimum allowed date. * @param max - Maximum allowed date. * @param disabledDates - Criteria for disabled dates. * @returns The first available Date object or null if none found. */ export declare const getFirstAvailableDateInRange: (startDate: Date, endDate: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => Date | null; /** * Retrieves an array of month names based on locale and format. * @param locale - The locale string (e.g., 'en-US'). * @param format - The format of the month names ('short' or 'long'). * @returns An array of month names. */ export declare const getMonthsNames: (locale: string, format?: "short" | "long") => string[]; /** * Retrieves an array of selectable dates from the given element. * @param element - The HTML element to search for selectable dates. * @param selector - The CSS selector used to identify selectable dates. Defaults to 'tr[tabindex="0"], td[tabindex="0"]'. * @returns An array of HTMLElements representing the selectable dates. */ export declare const getSelectableDates: (element: HTMLElement, selector?: string) => HTMLElement[]; /** * Generates an array of years centered around a given year. * @param year - The central year. * @param range - The number of years before and after the central year. * @returns An array of years. */ export declare const getYears: (year: number, range?: number) => number[]; /** * Calculates the ISO week number for a given date. * @param date - The date to calculate the week number for. * @returns The ISO week number. */ export declare const getWeekNumber: (date: Date) => number; /** * Retrieves detailed information about each week in a month for calendar rendering. * @param year - The year. * @param month - The month (0-11). * @param firstDayOfWeek - The first day of the week (0-6, where 0 is Sunday). * @returns An array of week objects containing week numbers and day details. */ export declare const getMonthDetails: (year: number, month: number, firstDayOfWeek: number) => { weekNumber?: number; days: { date: Date; month: string; }[]; }[]; /** * Checks if a date is disabled based on the 'date' period type. * @param date - The date to check. * @param min - Minimum allowed date. * @param max - Maximum allowed date. * @param disabledDates - Criteria for disabled dates. * @returns True if the date is disabled, false otherwise. */ export declare const isDateDisabled: (date: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean; /** * Checks if a date is within a specified range. * @param date - The date to check. * @param start - Start date of the range. * @param end - End date of the range. * @returns True if the date is within the range, false otherwise. */ export declare const isDateInRange: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Checks if a date is selected based on start and end dates. * @param date - The date to check. * @param start - Start date. * @param end - End date. * @returns True if the date is selected, false otherwise. */ export declare const isDateSelected: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Determines if any date within a range is disabled. * @param startDate - Start date of the range. * @param endDate - End date of the range. * @param disabledDates - Criteria for disabled dates. * @returns True if any date in the range is disabled, false otherwise. */ export declare const isDisableDateInRange: (startDate?: Date | null, endDate?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean; /** * Checks if a month is disabled based on the 'month' period type. * @param date - The date representing the month to check. * @param min - Minimum allowed date. * @param max - Maximum allowed date. * @param disabledDates - Criteria for disabled dates. * @returns True if the month is disabled, false otherwise. */ export declare const isMonthDisabled: (date: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean; /** * Checks if a month is selected based on start and end dates. * @param date - The date representing the month. * @param start - Start date. * @param end - End date. * @returns True if the month is selected, false otherwise. */ export declare const isMonthSelected: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Checks if a month is within a specified range. * @param date - The date representing the month. * @param start - Start date. * @param end - End date. * @returns True if the month is within the range, false otherwise. */ export declare const isMonthInRange: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Checks if two dates are the same calendar date. * @param date - First date. * @param date2 - Second date. * @returns True if both dates are the same, false otherwise. */ export declare const isSameDateAs: (date: Date | null, date2: Date | null) => boolean; /** * Checks if a date is today. * @param date - The date to check. * @returns True if the date is today, false otherwise. */ export declare const isToday: (date: Date) => boolean; /** * Checks if a year is disabled based on the 'year' period type. * @param date - The date representing the year to check. * @param min - Minimum allowed date. * @param max - Maximum allowed date. * @param disabledDates - Criteria for disabled dates. * @returns True if the year is disabled, false otherwise. */ export declare const isYearDisabled: (date: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean; /** * Checks if a year is selected based on start and end dates. * @param date - The date representing the year. * @param start - Start date. * @param end - End date. * @returns True if the year matches the start's or end's year, false otherwise. */ export declare const isYearSelected: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Checks if a year is within a specified range. * @param date - The date representing the year. * @param start - Start date. * @param end - End date. * @returns True if the year's value lies between start's year and end's year, false otherwise. */ export declare const isYearInRange: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Removes the time component from a Date object. * @param date - The original date. * @returns A new Date object with the time set to 00:00:00. */ export declare const removeTimeFromDate: (date: Date) => Date; /** * Copies the time (hours, minutes, seconds, milliseconds) from one Date to another. * * @param {Date} target - The date whose time will be updated. * @param {Date | null} source - The date to copy the time from. * @returns {Date} A new Date instance with the date from `target` and time from `source`. */ export declare const setTimeFromDate: (target: Date, source: Date | null) => Date;