UNPKG

@asadi/angular-date-components

Version:

`Angular Date Components` is a comprehensive angular library of date-related components designed to meet the needs of applications that require localization based on various calendar systems. While the package currently includes two powerful components (S

391 lines (390 loc) 11.4 kB
import { Observable } from "rxjs"; import { ADCDateSplitter } from "./enum"; import { ADCTableCell } from "./utils/table-cell.tools"; import { ADCTableRowTools } from "./utils/table-view-row.tools"; /** * Interface for a Date Adapter used to handle date-related functionalities in the ADC system. * This adapter provides methods to fetch and manipulate dates, allowing for consistent date handling * across different components of the application. */ export interface ADCIDateAdapter { /** * Specifies the starting day of the week (0 for Sunday, 1 for Monday, etc.). * This can be used to customize calendars to start on a specific day. * * @example * ```typescript * const adapter: ADCIDateAdapter = ...; * console.log(adapter.startDayOfweek); // 0 (for sunday) * ``` */ startDayOfweek: number; /** * Retrieves the names of all months of the year in order. * * @returns An array of month names, e.g., `['January', 'February', ...]`. * * @example * ```typescript * const months = adapter.getMonthsOfYear(); * console.log(months); // ['January', 'February', ...] * ``` */ getMonthsOfYear(): string[]; /** * Fetches the week number as string (e.g., week numbers) for a specific month of a given year. * * @param year - The target year. * @param monthId - The month index (0 for January, 11 for December). * @returns An array of week numbers, e.g., `['11', '12', ...]`. * * @example * ```typescript * const weeks = adapter.getWeeksOfMonth(2024, 0); * console.log(weeks); // ['0', '1', ...] * ``` */ getWeeksOfMonth(year: number, monthId: number): string[]; /** * Retrieves the date for a specific day of a given week in a specific year. * * @param year - The target year. * @param weekOfYear - The week number within the year. * @param dayOfWeek - The day of the week (0 for Sunday, 6 for Saturday). * @returns A string representing the date in `yyyy-MM-dd` or `yyyy/MM/dd` format. * * @example * ```typescript * const date = adapter.getDateOfDay(2024, 12, 2); * console.log(date); // '2024-03-19' (if it's Tuesday of week 12) * ``` */ getDateOfDay(year: number, weekOfYear: number, dayOfWeek: number): string; /** * Converts a given set of date components (year, month, day, and optional time) into a date string. * * @param year - The target year. * @param month - The target month (0 for January, 11 for December). * @param day - The target day of the month. * @param hour - (Optional) The hour in `hh` format. * @param minute - (Optional) The minute in `mm` format. * @returns A string representing the transformed date, e.g., `yyyy-MM-ddThh:mm`. * * @example * ```typescript * const date = adapter.transformDate(2024, 0, 1, '10', '30'); * console.log(date); // '2024-01-01T10:30' * ``` */ transformDate(year: number, month: number, day: number, hour?: string, minute?: string): string; /** * Gets the current date as a string in the format `yyyy-MM-dd`. * * @returns The current date string. * * @example * ```typescript * const today = adapter.today(); * console.log(today); // '2024-11-12' * ``` */ today(): string; /** * Retrieves the current month index (0 for January, 11 for December). * * @returns The current month index. * * @example * ```typescript * const currentMonth = adapter.getCurrentMonth(); * console.log(currentMonth); // 10 (for November) * ``` */ getCurrentMonth(): number; /** * Gets the current year as a four-digit number. * * @returns The current year. * * @example * ```typescript * const currentYear = adapter.getCurrentYear(); * console.log(currentYear); // 2024 * ``` */ getCurrentYear(): number; /** * Retrieves the current week of the year. * * @returns The current week number. * * @example * ```typescript * const currentWeek = adapter.getCurrentWeek(); * console.log(currentWeek); // 45 * ``` */ getCurrentWeek(): number; /** * Gets the current day of the month. * * @returns The current day as a number (1-31). * * @example * ```typescript * const currentDay = adapter.getCurrentDay(); * console.log(currentDay); // 12 * ``` */ getCurrentDay(): number; /** * Retrieves the total number of days in a given month of a specific year. * * @param year - The target year. * @param monthId - The month index (0 for January, 11 for December). * @returns The total number of days in the month. * * @example * ```typescript * const days = adapter.getDaysOfMonth(2024, 1); * console.log(days); // 29 (for February in a leap year) * ``` */ getDaysOfMonth(year: number, monthId: number): number; /** * Retrieves the total number of weeks in a specific year. * * @param year - The target year. * @returns The number of weeks in the year (usually 52 or 53). * * @example * ```typescript * const weeks = adapter.getWeeksOfYear(2024); * console.log(weeks); // 52 * ``` */ getWeeksOfYear(year: number): number; /** * Retrieves the day of the week for the given date. * The input is always in Gregorian format (`YYYY-MM-DD`). * * @param date - The Gregorian date string in `YYYY-MM-DD` format. * @returns The day index (0 for Sunday, 6 for Saturday). * * @example * ```typescript * const day = adapter.getDayOf('2024-11-28'); // Example Gregorian date * console.log(day); // 4 (Thursday in Persian calendar for this example) * ``` */ getDayIndexOf(date: string): number; /** * Retrieves the week of the year for the given date. * The input is always in Gregorian format (`YYYY-MM-DD`). * * @param date - The Gregorian date string in `YYYY-MM-DD` format. * @returns The week number. * * @example * ```typescript * const week = adapter.getWeekOf('2024-11-28'); // Example Gregorian date * console.log(week); // 39 * ``` */ getWeekOf(date: string): number; /** * Retrieves the month of the year for the given date. * The input is always in Gregorian format (`YYYY-MM-DD`). * * @param date - The Gregorian date string in `YYYY-MM-DD` format. * @returns The month index based on 1, for the first month should be 1. * * @example * ```typescript * const month = adapter.getMonthOf('2024-11-28'); * console.log(month); // 11 * ``` */ getMonthOf(date: string): number; /** * Retrieves the year for the given date. * The input is always in Gregorian format (`YYYY-MM-DD`). * * @param date - The Gregorian date string in `YYYY-MM-DD` format. * @returns The year for your calendar. * * @example * ```typescript * const year = adapter.getYearOf('2024-11-28'); // Example Gregorian date * console.log(year); // 1403 (Example year in Persian calendar) * ``` */ getYearOf(date: string): number; } export interface ADCIDateFormatter { get DateSplitter(): ADCDateSplitter; } export interface ADCILabels { week: string; year: string; day: string; today: string; month: string; daysOfWeek: string[]; /** * the key of record must be exact value as provided monthes in `ADCIDateAdapter` class */ monthsOfYear: Record<string, string>; } /** * Interface for configuration options used within the ADC system. * The `ADCIOptions` interface provides a set of getter properties * to control the behavior and appearance of components like calendars and schedulers. */ export interface ADCIOptions { /** * Specifies the direction for components. * * - `'ltr'`: Left-to-right direction (default). * - `'rtl'`: Right-to-left direction (useful for languages like Arabic or Hebrew). * * @returns The text direction (`'ltr'` or `'rtl'`). * * @example * ```typescript * const options: ADCIOptions = ...; * console.log(options.direction); // 'ltr' * ``` */ get direction(): 'ltr' | 'rtl'; /** * Determines the initial view to be displayed when the component is rendered. * * - `'month'`: Displays a monthly view. * - `'week'`: Displays a weekly view. * - `'day'`: Displays a daily view. * * @returns The initial view mode (`'month'`, `'week'`, or `'day'`). * * @example * ```typescript * const options: ADCIOptions = ...; * console.log(options.initialView); // 'week' * ``` */ get initialView(): 'month' | 'week' | 'day'; /** * Specifies the tolerance level for event overlap. * This value determines how closely events can be positioned before they are considered overlapping. * * @returns A number representing the overlap tolerance. * the value unit will calculated in each view (hour for scheduler month view, minute for scheduler week or day view and etc...) * * @example * ```typescript * const options: ADCIOptions = ...; * console.log(options.eventOverlapTolerance); // 5 * ``` */ get eventOverlapTolerance(): number; } export interface ADCITableRow { label: string; prefix: string; suffix: string; classList: string; value: string; verticalAlign: 'start' | 'center' | 'end'; horizontalAlign: 'start' | 'center' | 'end'; columns: ADCITableColumn[]; } export interface ADCITableColumn { label: string; prefix: string; suffix: string; classList: string; value: string; verticalAlign: 'start' | 'center' | 'end'; horizontalAlign: 'start' | 'center' | 'end'; selectable: boolean; } export interface ADCITableCell { rowIndex: number; rowValue: string; columnIndex: number; columnValue: string; } export interface ADCIBaseTableEvent { title: string; id: string; bgColor: string; tooltip?: string; isClickable?: boolean; } export interface ADCITableEvent { columnStart: number | null; columnEnd: number | null; rowStart: number; rowEnd: number; data: ADCIBaseTableEvent; offsetX: number; fractionX: number; overlapTolerance: number; } export interface ADCITableEventAttributes { width: string; left: string; right: string; backgroundColor: string; textAlign: string; classList: string[]; level: number; } export interface ADCIViewButton { id: string; name: string; } export interface ADCIDateRangeChangeEvent { startDate: string; endDate: string; } export interface ADCITableEventSelectEvent { event: ADCITableEvent; jsEvent: MouseEvent; dom: HTMLElement; } export interface ADCITableViewCTRL { /** * * @param rowIndex * * returns a utility class for manipulating table row * * @returns `ADCTableViewTools` */ row(rowIndex: number): ADCTableRowTools; /** * * with every change in view after rendering new cells, new cell will be availbale for watching with this observable * * @returns `Observable<ADCTableCell[]>` */ cellChanges(): Observable<ADCTableCell[]>; /** * * number of rows * * @returns `number` */ rowsCount(): number; get scrollableContainer(): HTMLElement; } export interface ADCIToolbar { disableNext: boolean; disableToday: boolean; disablePrevious: boolean; onViewChange(view: string): void; onPrevious(): void; onToday(): void; onNext(): void; }