ant-design/components/date-picker/util.ts
二货机器人 34bf3fdb66
fix: DatePicker miss placeholder when it's undefined (#23818)
* fix placeholder

* add test case

* update snapshot
2020-05-02 21:55:23 +08:00

54 lines
1.6 KiB
TypeScript

import { PickerMode } from 'rc-picker/lib/interface';
import { 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 === '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;
}