2022-05-07 14:31:54 +08:00
|
|
|
import type {
|
2020-04-02 15:46:07 +08:00
|
|
|
PickerBaseProps as RCPickerBaseProps,
|
|
|
|
PickerDateProps as RCPickerDateProps,
|
|
|
|
PickerTimeProps as RCPickerTimeProps,
|
|
|
|
} from 'rc-picker/lib/Picker';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type {
|
2020-04-02 15:46:07 +08:00
|
|
|
RangePickerBaseProps as RCRangePickerBaseProps,
|
|
|
|
RangePickerDateProps as RCRangePickerDateProps,
|
|
|
|
RangePickerTimeProps as RCRangePickerTimeProps,
|
|
|
|
} from 'rc-picker/lib/RangePicker';
|
2023-05-19 18:57:35 +08:00
|
|
|
import type { GenerateConfig } from 'rc-picker/lib/generate/index';
|
2023-06-25 10:16:02 +08:00
|
|
|
import type { Locale as RcPickerLocale } from 'rc-picker/lib/interface';
|
2023-05-19 18:57:35 +08:00
|
|
|
import type { InputStatus } from '../../_util/statusUtils';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { SizeType } from '../../config-provider/SizeContext';
|
2022-06-22 14:57:09 +08:00
|
|
|
import type { TimePickerLocale } from '../../time-picker';
|
2020-04-02 15:46:07 +08:00
|
|
|
import generateRangePicker from './generateRangePicker';
|
2022-06-22 14:57:09 +08:00
|
|
|
import generateSinglePicker from './generateSinglePicker';
|
2020-04-02 15:46:07 +08:00
|
|
|
|
2022-12-13 14:57:40 +08:00
|
|
|
const DataPickerPlacements = ['bottomLeft', 'bottomRight', 'topLeft', 'topRight'] as const;
|
2023-07-17 23:43:32 +08:00
|
|
|
type DataPickerPlacement = typeof DataPickerPlacements[number];
|
2020-04-02 15:46:07 +08:00
|
|
|
|
|
|
|
type InjectDefaultProps<Props> = Omit<
|
|
|
|
Props,
|
2023-04-11 19:01:12 +08:00
|
|
|
'locale' | 'generateConfig' | 'hideHeader' | 'components'
|
2020-04-02 15:46:07 +08:00
|
|
|
> & {
|
|
|
|
locale?: PickerLocale;
|
|
|
|
size?: SizeType;
|
2022-01-20 16:54:47 +08:00
|
|
|
placement?: DataPickerPlacement;
|
2020-04-02 15:46:07 +08:00
|
|
|
bordered?: boolean;
|
2022-03-15 18:38:22 +08:00
|
|
|
status?: InputStatus;
|
2020-04-02 15:46:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export type PickerLocale = {
|
|
|
|
lang: RcPickerLocale & AdditionalPickerLocaleLangProps;
|
|
|
|
timePickerLocale: TimePickerLocale;
|
|
|
|
} & AdditionalPickerLocaleProps;
|
|
|
|
|
|
|
|
export type AdditionalPickerLocaleProps = {
|
|
|
|
dateFormat?: string;
|
|
|
|
dateTimeFormat?: string;
|
|
|
|
weekFormat?: string;
|
|
|
|
monthFormat?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type AdditionalPickerLocaleLangProps = {
|
|
|
|
placeholder: string;
|
|
|
|
yearPlaceholder?: string;
|
|
|
|
quarterPlaceholder?: string;
|
|
|
|
monthPlaceholder?: string;
|
|
|
|
weekPlaceholder?: string;
|
|
|
|
rangeYearPlaceholder?: [string, string];
|
2022-02-17 13:38:49 +08:00
|
|
|
rangeQuarterPlaceholder?: [string, string];
|
2020-04-02 15:46:07 +08:00
|
|
|
rangeMonthPlaceholder?: [string, string];
|
|
|
|
rangeWeekPlaceholder?: [string, string];
|
|
|
|
rangePlaceholder?: [string, string];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Picker Props
|
|
|
|
export type PickerBaseProps<DateType> = InjectDefaultProps<RCPickerBaseProps<DateType>>;
|
|
|
|
export type PickerDateProps<DateType> = InjectDefaultProps<RCPickerDateProps<DateType>>;
|
|
|
|
export type PickerTimeProps<DateType> = InjectDefaultProps<RCPickerTimeProps<DateType>>;
|
|
|
|
|
|
|
|
export type PickerProps<DateType> =
|
|
|
|
| PickerBaseProps<DateType>
|
|
|
|
| PickerDateProps<DateType>
|
|
|
|
| PickerTimeProps<DateType>;
|
|
|
|
|
|
|
|
// Range Picker Props
|
|
|
|
export type RangePickerBaseProps<DateType> = InjectDefaultProps<RCRangePickerBaseProps<DateType>>;
|
|
|
|
export type RangePickerDateProps<DateType> = InjectDefaultProps<RCRangePickerDateProps<DateType>>;
|
|
|
|
export type RangePickerTimeProps<DateType> = InjectDefaultProps<RCRangePickerTimeProps<DateType>>;
|
|
|
|
|
|
|
|
export type RangePickerProps<DateType> =
|
|
|
|
| RangePickerBaseProps<DateType>
|
|
|
|
| RangePickerDateProps<DateType>
|
|
|
|
| RangePickerTimeProps<DateType>;
|
|
|
|
|
|
|
|
function generatePicker<DateType>(generateConfig: GenerateConfig<DateType>) {
|
|
|
|
// =========================== Picker ===========================
|
2021-09-03 13:24:48 +08:00
|
|
|
const { DatePicker, WeekPicker, MonthPicker, YearPicker, TimePicker, QuarterPicker } =
|
|
|
|
generateSinglePicker(generateConfig);
|
2020-04-02 15:46:07 +08:00
|
|
|
|
|
|
|
// ======================== Range Picker ========================
|
|
|
|
const RangePicker = generateRangePicker(generateConfig);
|
|
|
|
|
|
|
|
// =========================== Export ===========================
|
2020-09-16 11:43:55 +08:00
|
|
|
type MergedDatePickerType = typeof DatePicker & {
|
2023-07-17 23:43:32 +08:00
|
|
|
displayName?: string;
|
2020-04-02 15:46:07 +08:00
|
|
|
WeekPicker: typeof WeekPicker;
|
|
|
|
MonthPicker: typeof MonthPicker;
|
|
|
|
YearPicker: typeof YearPicker;
|
2021-09-03 13:24:48 +08:00
|
|
|
RangePicker: typeof RangePicker;
|
2020-04-02 15:46:07 +08:00
|
|
|
TimePicker: typeof TimePicker;
|
2020-07-23 11:25:17 +08:00
|
|
|
QuarterPicker: typeof QuarterPicker;
|
2020-04-02 15:46:07 +08:00
|
|
|
};
|
|
|
|
|
2020-09-16 11:43:55 +08:00
|
|
|
const MergedDatePicker = DatePicker as MergedDatePickerType;
|
2020-04-02 15:46:07 +08:00
|
|
|
MergedDatePicker.WeekPicker = WeekPicker;
|
|
|
|
MergedDatePicker.MonthPicker = MonthPicker;
|
|
|
|
MergedDatePicker.YearPicker = YearPicker;
|
|
|
|
MergedDatePicker.RangePicker = RangePicker;
|
|
|
|
MergedDatePicker.TimePicker = TimePicker;
|
2020-07-23 11:25:17 +08:00
|
|
|
MergedDatePicker.QuarterPicker = QuarterPicker;
|
2020-04-02 15:46:07 +08:00
|
|
|
|
2023-07-17 23:43:32 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
MergedDatePicker.displayName = 'DatePicker';
|
|
|
|
}
|
|
|
|
|
2020-04-02 15:46:07 +08:00
|
|
|
return MergedDatePicker;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default generatePicker;
|