-
-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathRangePicker.tsx
More file actions
847 lines (732 loc) Β· 23.7 KB
/
RangePicker.tsx
File metadata and controls
847 lines (732 loc) Β· 23.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
import { useEvent, useMergedState } from '@rc-component/util';
import cls from 'classnames';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
import omit from '@rc-component/util/lib/omit';
import pickAttrs from '@rc-component/util/lib/pickAttrs';
import warning from '@rc-component/util/lib/warning';
import * as React from 'react';
import type {
BaseInfo,
InternalMode,
OnOpenChange,
OpenConfig,
PanelMode,
RangePickerRef,
RangeTimeProps,
SelectorProps,
SharedHTMLAttrs,
SharedPickerProps,
ValueDate,
} from '../interface';
import type { PickerPanelProps } from '../PickerPanel';
import PickerTrigger from '../PickerTrigger';
import { pickTriggerProps } from '../PickerTrigger/util';
import { fillIndex, getFromDate, toArray } from '../utils/miscUtil';
import PickerContext from './context';
import useCellRender from './hooks/useCellRender';
import useFieldsInvalidate from './hooks/useFieldsInvalidate';
import useFilledProps from './hooks/useFilledProps';
import useOpen from './hooks/useOpen';
import usePickerRef from './hooks/usePickerRef';
import usePresets from './hooks/usePresets';
import useRangeActive from './hooks/useRangeActive';
import useRangeDisabledDate from './hooks/useRangeDisabledDate';
import useRangePickerValue from './hooks/useRangePickerValue';
import useRangeValue, { useInnerValue } from './hooks/useRangeValue';
import useShowNow from './hooks/useShowNow';
import Popup, { type PopupShowTimeConfig } from './Popup';
import RangeSelector, { type SelectorIdType } from './Selector/RangeSelector';
import useSemantic from '../hooks/useSemantic';
function separateConfig<T>(config: T | [T, T] | null | undefined, defaultConfig: T): [T, T] {
const singleConfig = config ?? defaultConfig;
if (Array.isArray(singleConfig)) {
return singleConfig;
}
return [singleConfig, singleConfig];
}
export type RangeValueType<DateType> = [
start: DateType | null | undefined,
end: DateType | null | undefined,
];
/** Used for change event, it should always be not undefined */
export type NoUndefinedRangeValueType<DateType> = [start: DateType | null, end: DateType | null];
export interface BaseRangePickerProps<DateType extends object>
extends Omit<SharedPickerProps<DateType>, 'showTime' | 'id'> {
// Structure
id?: SelectorIdType;
separator?: React.ReactNode;
// Value
value?: RangeValueType<DateType> | null;
defaultValue?: RangeValueType<DateType>;
onChange?: (
dates: NoUndefinedRangeValueType<DateType> | null,
dateStrings: [string, string],
) => void;
onCalendarChange?: (
dates: NoUndefinedRangeValueType<DateType>,
dateStrings: [string, string],
info: BaseInfo,
) => void;
onOk?: (values: NoUndefinedRangeValueType<DateType>) => void;
// Placeholder
placeholder?: [string, string];
// Picker Value
/**
* Config the popup panel date.
* Every time active the input to open popup will reset with `defaultPickerValue`.
*
* Note: `defaultPickerValue` priority is higher than `value` for the first open.
*/
defaultPickerValue?: [DateType, DateType] | DateType | null;
/**
* Config each start & end field popup panel date.
* When config `pickerValue`, you must also provide `onPickerValueChange` to handle changes.
*/
pickerValue?: [DateType, DateType] | DateType | null;
/**
* Each popup panel `pickerValue` includes `mode` change will trigger the callback.
* @param date The changed picker value
* @param info.source `panel` from the panel click. `reset` from popup open or field typing
* @param info.mode Next `mode` panel
*/
onPickerValueChange?: (
date: [DateType, DateType],
info: BaseInfo & {
source: 'reset' | 'panel';
mode: [PanelMode, PanelMode];
},
) => void;
// Preset
presets?: ValueDate<Exclude<RangeValueType<DateType>, null>>[];
/** @deprecated Please use `presets` instead */
ranges?: Record<
string,
Exclude<RangeValueType<DateType>, null> | (() => Exclude<RangeValueType<DateType>, null>)
>;
// Control
disabled?: boolean | [boolean, boolean];
allowEmpty?: boolean | [boolean, boolean];
// Time
showTime?: boolean | RangeTimeProps<DateType>;
// Mode
mode?: [startMode: PanelMode, endMode: PanelMode];
/** Trigger on each `mode` or `pickerValue` changed. */
onPanelChange?: (
values: NoUndefinedRangeValueType<DateType>,
modes: [startMode: PanelMode, endMode: PanelMode],
) => void;
}
export interface RangePickerProps<DateType extends object>
extends BaseRangePickerProps<DateType>,
Omit<RangeTimeProps<DateType>, 'format' | 'defaultValue' | 'defaultOpenValue'> {}
function getActiveRange(activeIndex: number) {
return activeIndex === 1 ? 'end' : 'start';
}
function RangePicker<DateType extends object = any>(
props: RangePickerProps<DateType>,
ref: React.Ref<RangePickerRef>,
) {
// ========================= Prop =========================
const [filledProps, internalPicker, complexPicker, formatList, maskFormat, isInvalidateDate] =
useFilledProps(props, () => {
const { disabled, allowEmpty } = props;
const mergedDisabled = separateConfig(disabled, false);
const mergedAllowEmpty = separateConfig(allowEmpty, false);
return {
disabled: mergedDisabled,
allowEmpty: mergedAllowEmpty,
};
});
const {
// Style
prefixCls,
rootClassName,
styles: propStyles,
classNames: propClassNames,
previewValue,
// Value
defaultValue,
value,
needConfirm,
onKeyDown,
// Disabled
disabled,
allowEmpty,
disabledDate,
minDate,
maxDate,
// Open
defaultOpen,
open,
onOpenChange,
// Picker
locale,
generateConfig,
picker,
showNow,
showToday,
showTime,
// Mode
mode,
onPanelChange,
onCalendarChange,
onOk,
// Picker Value
defaultPickerValue,
pickerValue,
onPickerValueChange,
// Format
inputReadOnly,
suffixIcon,
// Focus
onFocus,
onBlur,
// Presets
presets,
ranges,
// Render
components,
cellRender,
dateRender,
monthCellRender,
// Native
onClick,
} = filledProps;
// ========================= Refs =========================
const selectorRef = usePickerRef(ref);
// ======================= Semantic =======================
const [mergedClassNames, mergedStyles] = useSemantic(propClassNames, propStyles);
// ========================= Open =========================
const [mergedOpen, setMergeOpen] = useOpen(open, defaultOpen, disabled, onOpenChange);
const triggerOpen: OnOpenChange = (nextOpen, config?: OpenConfig) => {
// No need to open if all disabled
if (disabled.some((fieldDisabled) => !fieldDisabled) || !nextOpen) {
setMergeOpen(nextOpen, config);
}
};
// ======================== Values ========================
const [mergedValue, setInnerValue, getCalendarValue, triggerCalendarChange, triggerOk] =
useInnerValue(
generateConfig,
locale,
formatList,
true,
false,
defaultValue,
value,
onCalendarChange,
onOk,
);
const calendarValue = getCalendarValue();
// ======================== Active ========================
const [
focused,
triggerFocus,
lastOperation,
activeIndex,
setActiveIndex,
nextActiveIndex,
activeIndexList,
updateSubmitIndex,
hasActiveSubmitValue,
] = useRangeActive(disabled, allowEmpty, mergedOpen);
const onSharedFocus = (event: React.FocusEvent<HTMLElement>, index?: number) => {
triggerFocus(true);
onFocus?.(event, {
range: getActiveRange(index ?? activeIndex),
});
};
const onSharedBlur = (event: React.FocusEvent<HTMLElement>, index?: number) => {
triggerFocus(false);
onBlur?.(event, {
range: getActiveRange(index ?? activeIndex),
});
};
// ======================= ShowTime =======================
/** Used for Popup panel */
const mergedShowTime = React.useMemo<
PopupShowTimeConfig<DateType> & Pick<RangeTimeProps<DateType>, 'defaultOpenValue'>
>(() => {
if (!showTime) {
return null;
}
const { disabledTime } = showTime;
const proxyDisabledTime = disabledTime
? (date: DateType) => {
const range = getActiveRange(activeIndex);
const fromDate = getFromDate(calendarValue, activeIndexList, activeIndex);
return disabledTime(date, range, {
from: fromDate,
});
}
: undefined;
return { ...showTime, disabledTime: proxyDisabledTime };
}, [showTime, activeIndex, calendarValue, activeIndexList]);
// ========================= Mode =========================
const [modes, setModes] = useMergedState<[PanelMode, PanelMode]>([picker, picker], {
value: mode,
});
const mergedMode = modes[activeIndex] || picker;
/** Extends from `mergedMode` to patch `datetime` mode */
const internalMode: InternalMode =
mergedMode === 'date' && mergedShowTime ? 'datetime' : mergedMode;
// ====================== PanelCount ======================
const multiplePanel = internalMode === picker && internalMode !== 'time';
// ======================= Show Now =======================
const mergedShowNow = useShowNow(picker, mergedMode, showNow, showToday, true);
// ======================== Value =========================
const [
/** Trigger `onChange` by check `disabledDate` */
flushSubmit,
/** Trigger `onChange` directly without check `disabledDate` */
triggerSubmitChange,
] = useRangeValue<RangeValueType<DateType>, DateType>(
filledProps,
mergedValue,
setInnerValue,
getCalendarValue,
triggerCalendarChange,
disabled,
formatList,
focused,
mergedOpen,
isInvalidateDate,
);
// ===================== DisabledDate =====================
const mergedDisabledDate = useRangeDisabledDate(
calendarValue,
disabled,
activeIndexList,
generateConfig,
locale,
disabledDate,
);
// ======================= Validate =======================
const [submitInvalidates, onSelectorInvalid] = useFieldsInvalidate(
calendarValue,
isInvalidateDate,
allowEmpty,
);
// ===================== Picker Value =====================
const [currentPickerValue, setCurrentPickerValue] = useRangePickerValue(
generateConfig,
locale,
calendarValue,
modes,
mergedOpen,
activeIndex,
internalPicker,
multiplePanel,
defaultPickerValue,
pickerValue,
mergedShowTime?.defaultOpenValue,
onPickerValueChange,
minDate,
maxDate,
);
// >>> Mode need wait for `pickerValue`
const triggerModeChange = useEvent(
(nextPickerValue: DateType, nextMode: PanelMode, triggerEvent?: boolean) => {
const clone = fillIndex(modes, activeIndex, nextMode);
if (clone[0] !== modes[0] || clone[1] !== modes[1]) {
setModes(clone);
}
// Compatible with `onPanelChange`
if (onPanelChange && triggerEvent !== false) {
const clonePickerValue: RangeValueType<DateType> = [...calendarValue];
if (nextPickerValue) {
clonePickerValue[activeIndex] = nextPickerValue;
}
onPanelChange(clonePickerValue, clone);
}
},
);
// ======================== Change ========================
const fillCalendarValue = (date: DateType, index: number) =>
// Trigger change only when date changed
fillIndex(calendarValue, index, date);
// ======================== Submit ========================
/**
* Trigger by confirm operation.
* This function has already handle the `needConfirm` check logic.
* - Selector: enter key
* - Panel: OK button
*/
const triggerPartConfirm = (date?: DateType, skipFocus?: boolean) => {
let nextValue = calendarValue;
if (date) {
nextValue = fillCalendarValue(date, activeIndex);
}
updateSubmitIndex(activeIndex);
// Get next focus index
const nextIndex = nextActiveIndex(nextValue);
// Change calendar value and tell flush it
triggerCalendarChange(nextValue);
flushSubmit(activeIndex, nextIndex === null);
if (nextIndex === null) {
triggerOpen(false, { force: true });
} else if (!skipFocus) {
selectorRef.current.focus({ index: nextIndex });
}
};
// ======================== Click =========================
const onSelectorClick: React.MouseEventHandler<HTMLDivElement> = (event) => {
const rootNode = (event.target as HTMLElement).getRootNode();
if (
!selectorRef.current.nativeElement.contains(
(rootNode as Document | ShadowRoot).activeElement ?? document.activeElement,
)
) {
// Click to focus the enabled input
const enabledIndex = disabled.findIndex((d) => !d);
if (enabledIndex >= 0) {
selectorRef.current.focus({ index: enabledIndex });
}
}
triggerOpen(true);
onClick?.(event);
};
const onSelectorClear = () => {
triggerSubmitChange(null);
triggerOpen(false, { force: true });
};
// ======================== Hover =========================
const [hoverSource, setHoverSource] = React.useState<'cell' | 'preset'>(null);
const [internalHoverValues, setInternalHoverValues] =
React.useState<RangeValueType<DateType>>(null);
const hoverValues = React.useMemo(() => {
return internalHoverValues || calendarValue;
}, [calendarValue, internalHoverValues]);
// Clean up `internalHoverValues` when closed
React.useEffect(() => {
if (!mergedOpen) {
setInternalHoverValues(null);
}
}, [mergedOpen]);
// ========================================================
// == Panels ==
// ========================================================
// Save the offset with active bar position
// const [activeOffset, setActiveOffset] = React.useState(0);
const [activeInfo, setActiveInfo] = React.useState<
[activeInputLeft: number, activeInputRight: number, selectorWidth: number]
>([0, 0, 0]);
const onSetHover = (date: RangeValueType<DateType> | null, source: 'cell' | 'preset') => {
if (previewValue !== 'hover') {
return;
}
setInternalHoverValues(date);
setHoverSource(source);
};
// ======================= Presets ========================
const presetList = usePresets(presets, ranges);
const onPresetHover = (nextValues: RangeValueType<DateType> | null) => {
onSetHover(nextValues, 'preset');
};
const onPresetSubmit = (nextValues: RangeValueType<DateType>) => {
const passed = triggerSubmitChange(nextValues);
if (passed) {
triggerOpen(false, { force: true });
}
};
const onNow = (now: DateType) => {
triggerPartConfirm(now);
};
// ======================== Panel =========================
const onPanelHover = (date: DateType) => {
onSetHover(date ? fillCalendarValue(date, activeIndex) : null, 'cell');
};
// >>> Focus
const onPanelFocus: React.FocusEventHandler<HTMLElement> = (event) => {
triggerOpen(true);
onSharedFocus(event);
};
// >>> MouseDown
const onPanelMouseDown: React.MouseEventHandler<HTMLDivElement> = () => {
lastOperation('panel');
};
// >>> Calendar
const onPanelSelect: PickerPanelProps<DateType>['onChange'] = (date: DateType) => {
const clone: RangeValueType<DateType> = fillIndex(calendarValue, activeIndex, date);
// Only trigger calendar event but not update internal `calendarValue` state
triggerCalendarChange(clone);
// >>> Trigger next active if !needConfirm
// Fully logic check `useRangeValue` hook
if (!needConfirm && !complexPicker && internalPicker === internalMode) {
triggerPartConfirm(date);
}
};
// >>> Close
const onPopupClose = () => {
// Close popup
triggerOpen(false);
};
// >>> cellRender
const onInternalCellRender = useCellRender(
cellRender,
dateRender,
monthCellRender,
getActiveRange(activeIndex),
);
// >>> Value
const panelValue = calendarValue[activeIndex] || null;
// >>> invalid
const isPopupInvalidateDate = useEvent((date: DateType) => {
return isInvalidateDate(date, {
activeIndex,
});
});
const panelProps = React.useMemo(() => {
const domProps = pickAttrs(filledProps, false);
const restProps = omit(filledProps, [
...(Object.keys(domProps) as (keyof SharedHTMLAttrs)[]),
'onChange',
'onCalendarChange',
'style',
'className',
'onPanelChange',
'disabledTime',
'classNames',
'styles',
]);
return restProps;
}, [filledProps]);
// >>> Render
const panel = (
<Popup<any>
// MISC
{...panelProps}
showNow={mergedShowNow}
showTime={mergedShowTime}
// Range
range
multiplePanel={multiplePanel}
activeInfo={activeInfo}
index={activeIndex}
// Disabled
disabledDate={mergedDisabledDate}
// Focus
onFocus={onPanelFocus}
onBlur={onSharedBlur}
onPanelMouseDown={onPanelMouseDown}
// Mode
picker={picker}
mode={mergedMode}
internalMode={internalMode}
onPanelChange={triggerModeChange}
// Value
format={maskFormat}
value={panelValue}
isInvalid={isPopupInvalidateDate}
onChange={null}
onSelect={onPanelSelect}
// PickerValue
pickerValue={currentPickerValue}
defaultOpenValue={toArray(showTime?.defaultOpenValue)[activeIndex]}
onPickerValueChange={setCurrentPickerValue}
// Hover
hoverValue={hoverValues}
onHover={onPanelHover}
// Submit
needConfirm={needConfirm}
onSubmit={triggerPartConfirm}
onOk={triggerOk}
// Preset
presets={presetList}
onPresetHover={onPresetHover}
onPresetSubmit={onPresetSubmit}
// Now
onNow={onNow}
// Render
cellRender={onInternalCellRender}
/>
);
// ========================================================
// == Selector ==
// ========================================================
// ======================== Change ========================
const onSelectorChange = (date: DateType, index: number) => {
const clone = fillCalendarValue(date, index);
triggerCalendarChange(clone);
};
const onSelectorInputChange = () => {
lastOperation('input');
};
// ======================= Selector =======================
const onSelectorFocus: SelectorProps['onFocus'] = (event, index) => {
// Check if `needConfirm` but user not submit yet
const activeListLen = activeIndexList.length;
const lastActiveIndex = activeIndexList[activeListLen - 1];
if (
activeListLen &&
lastActiveIndex !== index &&
needConfirm &&
// Not change index if is not filled
!allowEmpty[lastActiveIndex] &&
!hasActiveSubmitValue(lastActiveIndex) &&
calendarValue[lastActiveIndex]
) {
selectorRef.current.focus({ index: lastActiveIndex });
return;
}
lastOperation('input');
triggerOpen(true, {
inherit: true,
});
// When click input to switch the field, it will not trigger close.
// Which means it will lose the part confirm and we need fill back.
// ref: https://github.com/ant-design/ant-design/issues/49512
if (activeIndex !== index && mergedOpen && !needConfirm && complexPicker) {
triggerPartConfirm(null, true);
}
setActiveIndex(index);
onSharedFocus(event, index);
};
const onSelectorBlur: SelectorProps['onBlur'] = (event, index) => {
triggerOpen(false);
if (!needConfirm && lastOperation() === 'input') {
const nextIndex = nextActiveIndex(calendarValue);
flushSubmit(activeIndex, nextIndex === null);
}
onSharedBlur(event, index);
};
const onSelectorKeyDown: SelectorProps['onKeyDown'] = (event, preventDefault) => {
if (event.key === 'Tab') {
triggerPartConfirm(null, true);
}
onKeyDown?.(event, preventDefault);
};
// ======================= Context ========================
const context = React.useMemo(
() => ({
prefixCls,
locale,
generateConfig,
button: components.button,
input: components.input,
classNames: mergedClassNames,
styles: mergedStyles,
}),
[
prefixCls,
locale,
generateConfig,
components.button,
components.input,
mergedClassNames,
mergedStyles,
],
);
// ======================== Effect ========================
// >>> Mode
// Reset for every active
useLayoutEffect(() => {
if (mergedOpen && activeIndex !== undefined) {
// Legacy compatible. This effect update should not trigger `onPanelChange`
triggerModeChange(null, picker, false);
}
}, [mergedOpen, activeIndex, picker]);
// >>> For complex picker, we need check if need to focus next one
useLayoutEffect(() => {
const lastOp = lastOperation();
// Trade as confirm on field leave
if (!mergedOpen && lastOp === 'input') {
triggerOpen(false);
triggerPartConfirm(null, true);
}
// Submit with complex picker
if (!mergedOpen && complexPicker && !needConfirm && lastOp === 'panel') {
triggerOpen(true);
triggerPartConfirm();
}
}, [mergedOpen]);
// ====================== DevWarning ======================
if (process.env.NODE_ENV !== 'production') {
const isIndexEmpty = (index: number) => {
return (
// Value is empty
!value?.[index] &&
// DefaultValue is empty
!defaultValue?.[index]
);
};
if (
disabled.some(
(fieldDisabled, index) => fieldDisabled && isIndexEmpty(index) && !allowEmpty[index],
)
) {
warning(
false,
'`disabled` should not set with empty `value`. You should set `allowEmpty` or `value` instead.',
);
}
}
// ======================== Render ========================
return (
<PickerContext.Provider value={context}>
<PickerTrigger
{...pickTriggerProps(filledProps)}
popupElement={panel}
popupStyle={mergedStyles.popup.root}
popupClassName={cls(rootClassName, mergedClassNames.popup.root)}
// Visible
visible={mergedOpen}
onClose={onPopupClose}
// Range
range
>
<RangeSelector
// Shared
{...filledProps}
// Ref
ref={selectorRef}
// Style
className={cls(filledProps.className, rootClassName, mergedClassNames.root)}
style={{
...mergedStyles.root,
...filledProps.style,
}}
// Icon
suffixIcon={suffixIcon}
// Active
activeIndex={focused || mergedOpen ? activeIndex : null}
activeHelp={!!internalHoverValues}
allHelp={!!internalHoverValues && hoverSource === 'preset'}
focused={focused}
onFocus={onSelectorFocus}
onBlur={onSelectorBlur}
onKeyDown={onSelectorKeyDown}
onSubmit={triggerPartConfirm}
// Change
value={hoverValues}
maskFormat={maskFormat}
onChange={onSelectorChange}
onInputChange={onSelectorInputChange}
// Format
format={formatList}
inputReadOnly={inputReadOnly}
// Disabled
disabled={disabled}
// Open
open={mergedOpen}
onOpenChange={triggerOpen}
// Click
onClick={onSelectorClick}
onClear={onSelectorClear}
// Invalid
invalid={submitInvalidates}
onInvalid={onSelectorInvalid}
// Offset
onActiveInfo={setActiveInfo}
/>
</PickerTrigger>
</PickerContext.Provider>
);
}
const RefRangePicker = React.forwardRef(RangePicker) as <DateType extends object = any>(
props: RangePickerProps<DateType> & React.RefAttributes<RangePickerRef>,
) => React.ReactElement;
if (process.env.NODE_ENV !== 'production') {
(RefRangePicker as any).displayName = 'RefRangePicker';
}
export default RefRangePicker;