ant-design-vue/components/vc-picker/interface.ts

123 lines
3.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import type { Ref } from 'vue';
import type { VueNode } from '../_util/type';
import type { GenerateConfig } from './generate';
export type Locale = {
locale: string;
// ===================== Date Panel =====================
/** Display month before year in date panel header */
monthBeforeYear?: boolean;
yearFormat: string;
monthFormat?: string;
quarterFormat?: string;
today: string;
now: string;
backToToday: string;
ok: string;
timeSelect: string;
dateSelect: string;
weekSelect?: string;
clear: string;
month: string;
year: string;
previousMonth: string;
nextMonth: string;
monthSelect: string;
yearSelect: string;
decadeSelect: string;
dayFormat: string;
dateFormat: string;
dateTimeFormat: string;
previousYear: string;
nextYear: string;
previousDecade: string;
nextDecade: string;
previousCentury: string;
nextCentury: string;
shortWeekDays?: string[];
shortMonths?: string[];
};
export type PanelMode = 'time' | 'date' | 'week' | 'month' | 'quarter' | 'year' | 'decade';
export type PickerMode = Exclude<PanelMode, 'datetime' | 'decade'>;
export type PanelRefProps = {
onKeydown?: (e: KeyboardEvent) => boolean;
onBlur?: (e: FocusEvent) => void;
onClose?: () => void;
};
export type NullableDateType<DateType> = DateType | null | undefined;
export type OnSelect<DateType> = (value: DateType, type: 'key' | 'mouse' | 'submit') => void;
export type PanelSharedProps<DateType> = {
prefixCls: string;
generateConfig: GenerateConfig<DateType>;
value?: NullableDateType<DateType>;
viewDate: DateType;
/** [Legacy] Set default display picker view date */
defaultPickerValue?: DateType;
locale: Locale;
disabledDate?: (date: DateType) => boolean;
prevIcon?: VueNode;
nextIcon?: VueNode;
superPrevIcon?: VueNode;
superNextIcon?: VueNode;
// /**
// * Typescript can not handle generic type so we can not use `forwardRef` here.
// * Thus, move ref into operationRef.
// * This is little hack which should refactor after typescript support.
// */
operationRef: Ref<PanelRefProps>;
onSelect: OnSelect<DateType>;
onViewDateChange: (value: DateType) => void;
onPanelChange: (mode: PanelMode | null, viewValue: DateType) => void;
};
export type DisabledTimes = {
disabledHours?: () => number[];
disabledMinutes?: (hour: number) => number[];
disabledSeconds?: (hour: number, minute: number) => number[];
};
export type DisabledTime<DateType> = (date: DateType | null) => DisabledTimes;
export type OnPanelChange<DateType> = (value: DateType, mode: PanelMode) => void;
export type EventValue<DateType> = DateType | null;
export type RangeValue<DateType> = [EventValue<DateType>, EventValue<DateType>] | null;
export type Components = {
button?: any;
};
export type RangeList = {
label: VueNode;
onClick: () => void;
onMouseenter: () => void;
onMouseleave: () => void;
}[];
export type CustomFormat<DateType> = (value: DateType) => string;
export interface PresetDate<T> {
label: VueNode;
value: T;
key: string; // 重要需要用key来高亮选中状态
}
// 扩展的 onChange 回调类型values 和 formatString 都包含第三个 preset 元素
export type RangePickerOnChange<DateType> = (
values: [DateType | null, DateType | null, PresetDate<RangeValue<DateType>> | null],
formatString: [string, string, string | null],
) => void;