From 9b74e0ad19f74879423a945c920eecd1580e8b82 Mon Sep 17 00:00:00 2001 From: sunhao Date: Mon, 29 Jan 2024 15:50:53 +0800 Subject: [PATCH] * datetime-picker: support for setting minDate and maxDate with callback. --- lib/datetime-picker/src/component/date-picker-menu.tsx | 6 ++++-- lib/datetime-picker/src/component/date-picker.tsx | 4 ++-- lib/datetime-picker/src/types/date-picker-menu-props.ts | 9 +++++---- lib/datetime-picker/src/types/date-picker-options.ts | 4 ++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/datetime-picker/src/component/date-picker-menu.tsx b/lib/datetime-picker/src/component/date-picker-menu.tsx index cb6353e776..d54354b112 100644 --- a/lib/datetime-picker/src/component/date-picker-menu.tsx +++ b/lib/datetime-picker/src/component/date-picker-menu.tsx @@ -112,6 +112,8 @@ export class DatePickerMenu extends Component {this.#renderMenu(props)} diff --git a/lib/datetime-picker/src/component/date-picker.tsx b/lib/datetime-picker/src/component/date-picker.tsx index d0a954159c..383d15f0a3 100644 --- a/lib/datetime-picker/src/component/date-picker.tsx +++ b/lib/datetime-picker/src/component/date-picker.tsx @@ -43,13 +43,13 @@ export class DatePicker extends } let date = createDate(value); if (minDate) { - const min = createDate(minDate); + const min = createDate(typeof minDate === 'function' ? minDate(date) : minDate); if (date < min) { date = min; } } if (maxDate) { - const max = createDate(maxDate); + const max = createDate(typeof maxDate === 'function' ? maxDate(date) : maxDate); if (date > max) { date = max; } diff --git a/lib/datetime-picker/src/types/date-picker-menu-props.ts b/lib/datetime-picker/src/types/date-picker-menu-props.ts index 9471c78fd3..b4378734de 100644 --- a/lib/datetime-picker/src/types/date-picker-menu-props.ts +++ b/lib/datetime-picker/src/types/date-picker-menu-props.ts @@ -1,5 +1,6 @@ import type {DateLike} from '@zui/helpers/src/date-helper'; -import type {NavItemOptions, NavOptions} from '@zui/nav'; +import type {ListitemProps} from '@zui/list'; +import type {NavOptions} from '@zui/nav'; import type {ToolbarItemOptions, ToolbarOptions} from '@zui/toolbar'; export type DatePickerMenuProps = { @@ -11,8 +12,8 @@ export type DatePickerMenuProps = { todayText?: string; clearText?: string; weekStart?: number; - menu?: NavItemOptions[] | NavOptions; + menu?: ListitemProps[] | NavOptions; actions?: ToolbarItemOptions[] | ToolbarOptions; - minDate?: DateLike; - maxDate?: DateLike; + minDate?: DateLike | ((date?: Date) => DateLike); + maxDate?: DateLike | ((date?: Date) => DateLike); }; diff --git a/lib/datetime-picker/src/types/date-picker-options.ts b/lib/datetime-picker/src/types/date-picker-options.ts index 18abb0bcc5..e1a0ce19da 100644 --- a/lib/datetime-picker/src/types/date-picker-options.ts +++ b/lib/datetime-picker/src/types/date-picker-options.ts @@ -17,8 +17,8 @@ export interface DatePickerOptions extends PickOptions { todayText?: string; clearText?: string; weekStart?: number; - minDate?: DateLike; - maxDate?: DateLike; + minDate?: DateLike | ((date?: Date) => DateLike); + maxDate?: DateLike | ((date?: Date) => DateLike); menu?: Item[] | NavOptions; actions?: ToolbarItemOptions[] | ToolbarOptions; onInvalid?: (value: string) => void;