import type { PickerMode } from 'rc-picker/lib/interface'; import type { DirectionType } from '../config-provider'; import type { SelectCommonPlacement } from '../_util/motion'; import type { PickerLocale } from './generatePicker'; export function getPlaceholder(picker: PickerMode | undefined, locale: PickerLocale, customizePlaceholder?: string): string { if (customizePlaceholder !== undefined) { return customizePlaceholder; } if (picker === 'year' && locale.lang.yearPlaceholder) { return locale.lang.yearPlaceholder; } if (picker === 'quarter' && locale.lang.quarterPlaceholder) { return locale.lang.quarterPlaceholder; } if (picker === 'month' && locale.lang.monthPlaceholder) { return locale.lang.monthPlaceholder; } if (picker === 'week' && locale.lang.weekPlaceholder) { return locale.lang.weekPlaceholder; } if (picker === 'time' && locale.timePickerLocale.placeholder) { return locale!.timePickerLocale.placeholder; } return locale.lang.placeholder; } export function getRangePlaceholder( picker: PickerMode | undefined, locale: PickerLocale, customizePlaceholder?: [string, string] ) { if (customizePlaceholder !== undefined) { return customizePlaceholder; } if (picker === 'year' && locale.lang.yearPlaceholder) { return locale.lang.rangeYearPlaceholder; } if (picker === 'quarter' && locale.lang.quarterPlaceholder) { return locale.lang.rangeQuarterPlaceholder; } if (picker === 'month' && locale.lang.monthPlaceholder) { return locale.lang.rangeMonthPlaceholder; } if (picker === 'week' && locale.lang.weekPlaceholder) { return locale.lang.rangeWeekPlaceholder; } if (picker === 'time' && locale.timePickerLocale.placeholder) { return locale!.timePickerLocale.rangePlaceholder; } return locale.lang.rangePlaceholder; } export function transPlacement2DropdownAlign(direction: DirectionType, placement?: SelectCommonPlacement) { const overflow = { adjustX: 1, adjustY: 1, }; switch (placement) { case 'bottomLeft': { return { points: ['tl', 'bl'], offset: [0, 4], overflow, }; } case 'bottomRight': { return { points: ['tr', 'br'], offset: [0, 4], overflow, }; } case 'topLeft': { return { points: ['bl', 'tl'], offset: [0, -4], overflow, }; } case 'topRight': { return { points: ['br', 'tr'], offset: [0, -4], overflow, }; } default: { return direction === 'rtl' ? { points: ['tr', 'br'], offset: [0, 4], overflow, } : { points: ['tl', 'bl'], offset: [0, 4], overflow, }; } } } export function getFormat(picker: PickerMode | undefined, locale: PickerLocale, customizeFormat?: string, showTime?: boolean | object , use12Hours: boolean = true): string { if (customizeFormat !== undefined) { return customizeFormat; } if (picker === 'year' && locale.yearFormat) { return locale.yearFormat; } if (picker === 'quarter' && locale.quarterFormat) { return locale.quarterFormat; } if (picker === 'month' && locale.monthFormat) { return locale.monthFormat; } if (picker === 'week' && locale.weekFormat) { return locale.weekFormat; } if (picker === 'time' && locale.timePickerLocale.format) { return use12Hours ? 'hh:mm A' : locale!.timePickerLocale.format; } if (showTime) { if (typeof showTime === 'object') { const { format, use12Hours } = showTime as any; const time = format ?? use12Hours !== false ? 'hh:mm A' : locale!.timePickerLocale.format; return `${locale!.dateFormat} ${time}`; } return `${locale!.dateFormat} hh:mm A`; } return locale!.dateFormat as string; } export function getRangeFormat(picker: PickerMode | undefined, locale: PickerLocale, customizeFormat?: [string, string], showTime?: boolean | object, use12Hours?: boolean): [string, string] { if (customizeFormat !== undefined) { return customizeFormat; } if (picker === 'year' && locale.yearFormat) { const format = locale.yearFormat; return [format, format]; } if (picker === 'quarter' && locale.quarterFormat) { const format = locale.quarterFormat return [format, format]; } if (picker === 'month' && locale.monthFormat) { const format = locale.monthFormat return [format, format]; } if (picker === 'week' && locale.weekFormat) { const format = locale.weekFormat; return [format, format]; } if (picker === 'time' && locale.timePickerLocale.format) { const format = use12Hours ? 'hh:mm A' : locale!.timePickerLocale.format; return [format, format]; } if (showTime) { if (typeof showTime === 'object') { const { format, use12Hours } = showTime as any; const time = format ?? use12Hours !== false ? 'hh:mm A' : locale!.timePickerLocale.format; const _format = `${locale!.dateFormat} ${time}`; return [_format, _format]; } const format = `${locale!.dateFormat} hh:mm A`; return [format, format]; } const format = locale!.dateFormat as string return [format, format]; }