RangePicker.d.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import * as React from 'react';
  2. import type { BaseInfo, PanelMode, RangePickerRef, RangeTimeProps, SharedPickerProps, ValueDate } from '../interface';
  3. import { type SelectorIdType } from './Selector/RangeSelector';
  4. export type RangeValueType<DateType> = [
  5. start: DateType | null | undefined,
  6. end: DateType | null | undefined
  7. ];
  8. /** Used for change event, it should always be not undefined */
  9. export type NoUndefinedRangeValueType<DateType> = [start: DateType | null, end: DateType | null];
  10. export interface BaseRangePickerProps<DateType extends object> extends Omit<SharedPickerProps<DateType>, 'showTime' | 'id'> {
  11. id?: SelectorIdType;
  12. separator?: React.ReactNode;
  13. value?: RangeValueType<DateType> | null;
  14. defaultValue?: RangeValueType<DateType>;
  15. onChange?: (dates: NoUndefinedRangeValueType<DateType> | null, dateStrings: [string, string]) => void;
  16. onCalendarChange?: (dates: NoUndefinedRangeValueType<DateType>, dateStrings: [string, string], info: BaseInfo) => void;
  17. onOk?: (values: NoUndefinedRangeValueType<DateType>) => void;
  18. placeholder?: [string, string];
  19. /**
  20. * Config the popup panel date.
  21. * Every time active the input to open popup will reset with `defaultPickerValue`.
  22. *
  23. * Note: `defaultPickerValue` priority is higher than `value` for the first open.
  24. */
  25. defaultPickerValue?: [DateType, DateType] | DateType | null;
  26. /**
  27. * Config each start & end field popup panel date.
  28. * When config `pickerValue`, you must also provide `onPickerValueChange` to handle changes.
  29. */
  30. pickerValue?: [DateType, DateType] | DateType | null;
  31. /**
  32. * Each popup panel `pickerValue` includes `mode` change will trigger the callback.
  33. * @param date The changed picker value
  34. * @param info.source `panel` from the panel click. `reset` from popup open or field typing
  35. * @param info.mode Next `mode` panel
  36. */
  37. onPickerValueChange?: (date: [DateType, DateType], info: BaseInfo & {
  38. source: 'reset' | 'panel';
  39. mode: [PanelMode, PanelMode];
  40. }) => void;
  41. presets?: ValueDate<Exclude<RangeValueType<DateType>, null>>[];
  42. /** @deprecated Please use `presets` instead */
  43. ranges?: Record<string, Exclude<RangeValueType<DateType>, null> | (() => Exclude<RangeValueType<DateType>, null>)>;
  44. disabled?: boolean | [boolean, boolean];
  45. allowEmpty?: boolean | [boolean, boolean];
  46. showTime?: boolean | RangeTimeProps<DateType>;
  47. mode?: [startMode: PanelMode, endMode: PanelMode];
  48. /** Trigger on each `mode` or `pickerValue` changed. */
  49. onPanelChange?: (values: NoUndefinedRangeValueType<DateType>, modes: [startMode: PanelMode, endMode: PanelMode]) => void;
  50. }
  51. export interface RangePickerProps<DateType extends object> extends BaseRangePickerProps<DateType>, Omit<RangeTimeProps<DateType>, 'format' | 'defaultValue' | 'defaultOpenValue'> {
  52. }
  53. declare const RefRangePicker: <DateType extends object = any>(props: RangePickerProps<DateType> & React.RefAttributes<RangePickerRef>) => React.ReactElement;
  54. export default RefRangePicker;