From 4fad1caa3a2929974e38b918f212f95a047c26b0 Mon Sep 17 00:00:00 2001 From: Kyrylo Hrishchenko Date: Fri, 3 Jan 2025 19:18:48 +0200 Subject: [PATCH] fix(Calendart): improve type declaration using generic types with default params to dynamically manage the `selectionMode` (fixes #7555) (#7556) --- components/lib/calendar/calendar.d.ts | 76 ++++++--------------------- 1 file changed, 15 insertions(+), 61 deletions(-) diff --git a/components/lib/calendar/calendar.d.ts b/components/lib/calendar/calendar.d.ts index b2debf0f9f..cc73366df5 100644 --- a/components/lib/calendar/calendar.d.ts +++ b/components/lib/calendar/calendar.d.ts @@ -965,77 +965,31 @@ interface CalendarBaseProps { */ unstyled?: boolean; } -/** - * Defines valid properties in single Calendar component. - * @group Properties - */ -interface CalendarPropsSingle extends CalendarBaseProps { - /** - * Specifies the selection mode either "single", "range", or "multiple"; - * @defaultValue single - */ - selectionMode?: 'single' | undefined; - /** - * Value of the component. - * @defaultValue null - */ - value?: Nullable; - /** - * Callback to invoke when value changes. - * @param { FormEvent} event - Custom change event - */ - onChange?(event: FormEvent): void; -} -/** - * Defines valid properties in range Calendar component. - * @group Properties - */ -interface CalendarPropsRange extends CalendarBaseProps { - /** - * Specifies the selection mode either "single", "range", or "multiple"; - * @defaultValue single - */ - selectionMode: 'range'; - /** - * Value of the component. - * @defaultValue null - */ - value?: Nullable<(Date | null)[]>; - /** - * Callback to invoke when value changes. - * @param { FormEvent<(Date | null)[]>} event - Custom change event - */ - onChange?(event: FormEvent<(Date | null)[]>): void; -} + +export type CalendarSelectionMode = 'single' | 'range' | 'multiple'; /** - * Defines valid properties in multiple Calendar component. + * Defines valid properties in Calendar component. * @group Properties */ -interface CalendarPropsMultiple extends CalendarBaseProps { +export interface CalendarProps extends CalendarBaseProps { /** * Specifies the selection mode either "single", "range", or "multiple"; * @defaultValue single */ - selectionMode: 'multiple'; + selectionMode?: TMode; /** * Value of the component. * @defaultValue null */ - value?: Nullable; + value?: Nullable; /** * Callback to invoke when value changes. - * @param {FormEvent} event - Custom change event + * @param {FormEvent} event - Custom change event */ - onChange?(event: FormEvent): void; + onChange?(event: FormEvent): void; } -/** - * Defines valid properties in Calendar component. - * @group Properties - */ -export type CalendarProps = CalendarPropsRange | CalendarPropsMultiple | CalendarPropsSingle; - /** * **PrimeReact - Calendar** * @@ -1047,7 +1001,7 @@ export type CalendarProps = CalendarPropsRange | CalendarPropsMultiple | Calenda * * @group Component */ -export declare class Calendar extends React.Component { +export declare class Calendar extends React.Component, any> { /** * Used to show the overlay. */ @@ -1062,14 +1016,14 @@ export declare class Calendar extends React.Component { public focus(): void; /** * Used to get the current date. - * @return {Date | Date[]} Current Date + * @return {TValue} Current Date */ - public getCurrentDateTime(): Date | Date[]; + public getCurrentDateTime(): TValue; /** * Used to get the view date. - * @return {Date | Date[]} View Date + * @return {TValue} View Date */ - public getViewDate(): Date | Date[]; + public getViewDate(): TValue; /** * Used to get container element. * @return {HTMLSpanElement} Container element @@ -1088,7 +1042,7 @@ export declare class Calendar extends React.Component { /** * Used to update the current view date. * @param {React.SyntheticEvent | null} event - Browser event. - * @param {Date | Date[] | null} value - New date. + * @param {TValue | null} value - New date. */ - public updateViewDate(event: React.SyntheticEvent | null, value: Nullable): void; + public updateViewDate(event: React.SyntheticEvent | null, value: Nullable): void; }