igniteui-webcomponents
Version:
Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.
103 lines (102 loc) • 3.52 kB
TypeScript
/**
* Date Part Classes Module
*
* This module provides structured classes for date/time parts used in date-time input.
* Each part type has its own class with specific validation and spin behavior.
*
* Classes are private to this module - only types and factory function are exported.
*/
export declare enum DatePart {
Month = "month",
Year = "year",
Date = "date",
Hours = "hours",
Minutes = "minutes",
Seconds = "seconds",
AmPm = "amPm"
}
/** Types of date/time parts that can appear in a format string */
export declare const DatePartType: {
readonly Month: "month";
readonly Year: "year";
readonly Date: "date";
readonly Hours: "hours";
readonly Minutes: "minutes";
readonly Seconds: "seconds";
readonly AmPm: "amPm";
readonly Literal: "literal";
};
export type DatePartType = (typeof DatePartType)[keyof typeof DatePartType];
export declare const DEFAULT_DATE_PARTS_SPIN_DELTAS: Readonly<DatePartDeltas>;
export interface DatePartDeltas {
date?: number;
month?: number;
year?: number;
hours?: number;
minutes?: number;
seconds?: number;
}
/** Options for creating a date part */
export interface DatePartOptions {
/** Start position in the masked string */
start: number;
/** End position in the masked string */
end: number;
/** The format string for this part (e.g., 'MM', 'yyyy') */
format: string;
}
/** Options for spin operations */
export interface SpinOptions {
/** The current date value */
date: Date;
/** Whether to loop values at boundaries */
spinLoop: boolean;
/** For AM/PM: the current masked value to determine AM or PM */
amPmValue?: string;
/** For AM/PM: the original date (for rollover prevention) */
originalDate?: Date;
}
/** Read-only interface for date part information */
export interface IDatePart {
/** The type of date part */
readonly type: DatePartType;
/** Start position in the masked string */
readonly start: number;
/** End position in the masked string */
readonly end: number;
/** The format string for this part */
readonly format: string;
/**
* Validates a numeric value for this part.
* @param value - The value to validate
* @param context - Optional context (year, month) for date-dependent validation
* @returns true if the value is valid for this part
*/
validate(value: number, context?: DateValidationContext): boolean;
/**
* Spins (increments/decrements) this part's value on the given date.
* @param delta - The amount to spin (positive = up, negative = down)
* @param options - Spin options including the date and loop behavior
*/
spin(delta: number, options: SpinOptions): void;
/**
* Extracts the value of this part from a Date object.
* @param date - The date to extract from
* @returns The formatted string value
*/
getValue(date: Date): string;
}
/** Context for date validation (needed for day-of-month validation) */
export interface DateValidationContext {
year?: number;
month?: number;
}
/**
* Creates a date part instance based on the type.
* This is the only way to create date part instances outside this module.
*
* @param type - The type of date part to create
* @param options - The options for the date part
* @returns A date part instance implementing IDatePart
*/
export declare function createDatePart(type: DatePartType, options: DatePartOptions): IDatePart;