2023-04-19 23:07:47 +08:00
|
|
|
import type { AlignType } from '@rc-component/trigger';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { PickerMode } from 'rc-picker/lib/interface';
|
|
|
|
import type { SelectCommonPlacement } from '../_util/motion';
|
2023-04-19 23:07:47 +08:00
|
|
|
import type { DirectionType } from '../config-provider';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { PickerLocale } from './generatePicker';
|
2019-12-11 23:32:19 +08:00
|
|
|
|
2020-05-02 21:55:23 +08:00
|
|
|
export function getPlaceholder(
|
|
|
|
locale: PickerLocale,
|
2023-01-16 16:39:35 +08:00
|
|
|
picker?: PickerMode,
|
2020-05-02 21:55:23 +08:00
|
|
|
customizePlaceholder?: string,
|
|
|
|
): string {
|
|
|
|
if (customizePlaceholder !== undefined) {
|
|
|
|
return customizePlaceholder;
|
|
|
|
}
|
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
if (picker === 'year' && locale.lang.yearPlaceholder) {
|
|
|
|
return locale.lang.yearPlaceholder;
|
|
|
|
}
|
2020-03-21 22:43:04 +08:00
|
|
|
if (picker === 'quarter' && locale.lang.quarterPlaceholder) {
|
|
|
|
return locale.lang.quarterPlaceholder;
|
|
|
|
}
|
2019-12-11 23:32:19 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-05-02 21:55:23 +08:00
|
|
|
export function getRangePlaceholder(
|
|
|
|
locale: PickerLocale,
|
2023-01-16 16:44:16 +08:00
|
|
|
picker?: PickerMode,
|
2020-05-02 21:55:23 +08:00
|
|
|
customizePlaceholder?: [string, string],
|
|
|
|
) {
|
|
|
|
if (customizePlaceholder !== undefined) {
|
|
|
|
return customizePlaceholder;
|
|
|
|
}
|
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
if (picker === 'year' && locale.lang.yearPlaceholder) {
|
|
|
|
return locale.lang.rangeYearPlaceholder;
|
|
|
|
}
|
2022-02-17 13:38:49 +08:00
|
|
|
if (picker === 'quarter' && locale.lang.quarterPlaceholder) {
|
|
|
|
return locale.lang.rangeQuarterPlaceholder;
|
|
|
|
}
|
2019-12-11 23:32:19 +08:00
|
|
|
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;
|
|
|
|
}
|
2022-01-20 16:54:47 +08:00
|
|
|
|
|
|
|
export function transPlacement2DropdownAlign(
|
|
|
|
direction: DirectionType,
|
|
|
|
placement?: SelectCommonPlacement,
|
2023-04-19 23:07:47 +08:00
|
|
|
): AlignType {
|
2022-01-20 16:54:47 +08:00
|
|
|
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: {
|
2022-08-18 17:40:47 +08:00
|
|
|
return {
|
|
|
|
points: direction === 'rtl' ? ['tr', 'br'] : ['tl', 'bl'],
|
|
|
|
offset: [0, 4],
|
|
|
|
overflow,
|
|
|
|
};
|
2022-01-20 16:54:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|