1
1
import * as React from 'react' ;
2
2
import { fillLocale } from '../../hooks/useLocale' ;
3
3
import { getTimeConfig } from '../../hooks/useTimeConfig' ;
4
+ import type { InternalMode } from '../../interface' ;
4
5
import type { RangePickerProps } from '../RangePicker' ;
5
6
import { fillClearIcon } from '../Selector/hooks/useClearIcon' ;
6
7
@@ -15,16 +16,17 @@ type PickedProps<DateType extends object = any> = Pick<
15
16
| 'components'
16
17
| 'clearIcon'
17
18
| 'allowClear'
19
+ | 'needConfirm'
18
20
> & {
19
21
// RangePicker showTime definition is different with Picker
20
22
showTime ?: any ;
21
23
} ;
22
24
23
25
type ExcludeBooleanType < T > = T extends boolean ? never : T ;
24
26
25
- /** Align the outer props with unique typed and fill undefined props */
26
27
/**
27
28
* Align the outer props with unique typed and fill undefined props.
29
+ * This is shared with both RangePicker and Picker.
28
30
* This will auto handle the legacy props fill like `clearIcon` + `allowClear` = `clearIcon`
29
31
*/
30
32
export default function useFilledProps <
@@ -34,10 +36,14 @@ export default function useFilledProps<
34
36
> (
35
37
props : InProps ,
36
38
updater ?: ( ) => UpdaterProps ,
37
- ) : Omit < InProps , keyof UpdaterProps | 'showTime' > &
38
- UpdaterProps & {
39
- showTime ?: ExcludeBooleanType < InProps [ 'showTime' ] > ;
40
- } {
39
+ ) : [
40
+ filledProps : Omit < InProps , keyof UpdaterProps | 'showTime' > &
41
+ UpdaterProps & {
42
+ showTime ?: ExcludeBooleanType < InProps [ 'showTime' ] > ;
43
+ } ,
44
+ internalPicker : InternalMode ,
45
+ complexPicker : boolean ,
46
+ ] {
41
47
const {
42
48
locale,
43
49
picker = 'date' ,
@@ -48,6 +54,7 @@ export default function useFilledProps<
48
54
components = { } ,
49
55
allowClear,
50
56
clearIcon,
57
+ needConfirm,
51
58
} = props ;
52
59
53
60
const filledProps = React . useMemo (
@@ -67,5 +74,23 @@ export default function useFilledProps<
67
74
[ props ] ,
68
75
) ;
69
76
70
- return filledProps ;
77
+ // ======================== Picker ========================
78
+ /** Almost same as `picker`, but add `datetime` for `date` with `showTime` */
79
+ const internalPicker : InternalMode =
80
+ picker === 'date' && filledProps . showTime ? 'datetime' : picker ;
81
+
82
+ /** The picker is `datetime` or `time` */
83
+ const complexPicker = internalPicker === 'time' || internalPicker === 'datetime' ;
84
+ const mergedNeedConfirm = needConfirm ?? complexPicker ;
85
+
86
+ // ======================== Merged ========================
87
+ const mergedProps = React . useMemo (
88
+ ( ) => ( {
89
+ ...filledProps ,
90
+ needConfirm : mergedNeedConfirm ,
91
+ } ) ,
92
+ [ filledProps , mergedNeedConfirm ] ,
93
+ ) ;
94
+
95
+ return [ mergedProps , internalPicker , complexPicker ] ;
71
96
}
0 commit comments