@@ -66,6 +66,55 @@ export interface ComponentProps<DateType extends object> {
66
66
format ?: SharedPickerProps [ 'format' ] ;
67
67
}
68
68
69
+ /** Check if all the showXXX is `undefined` */
70
+ function existShowConfig (
71
+ showHour : boolean ,
72
+ showMinute : boolean ,
73
+ showSecond : boolean ,
74
+ showMillisecond : boolean ,
75
+ ) {
76
+ return [ showHour , showMinute , showSecond , showMillisecond ] . some ( ( show ) => show !== undefined ) ;
77
+ }
78
+
79
+ /** Fill the showXXX if needed */
80
+ function fillShowConfig (
81
+ hasShowConfig : boolean ,
82
+ showHour : boolean ,
83
+ showMinute : boolean ,
84
+ showSecond : boolean ,
85
+ showMillisecond : boolean ,
86
+ ) : [ showHour : boolean , showMinute : boolean , showSecond : boolean , showMillisecond : boolean ] {
87
+ let parsedShowHour = showHour ;
88
+ let parsedShowMinute = showMinute ;
89
+ let parsedShowSecond = showSecond ;
90
+
91
+ if (
92
+ ! hasShowConfig &&
93
+ ! parsedShowHour &&
94
+ ! parsedShowMinute &&
95
+ ! parsedShowSecond &&
96
+ ! showMillisecond
97
+ ) {
98
+ parsedShowHour = true ;
99
+ parsedShowMinute = true ;
100
+ parsedShowSecond = true ;
101
+ } else if ( hasShowConfig ) {
102
+ const existFalse = [ parsedShowHour , parsedShowMinute , parsedShowSecond ] . some (
103
+ ( show ) => show === false ,
104
+ ) ;
105
+ const existTrue = [ parsedShowHour , parsedShowMinute , parsedShowSecond ] . some (
106
+ ( show ) => show === true ,
107
+ ) ;
108
+ const defaultShow = existFalse ? true : ! existTrue ;
109
+
110
+ parsedShowHour = parsedShowHour ?? defaultShow ;
111
+ parsedShowMinute = parsedShowMinute ?? defaultShow ;
112
+ parsedShowSecond = parsedShowSecond ?? defaultShow ;
113
+ }
114
+
115
+ return [ parsedShowHour , parsedShowMinute , parsedShowSecond , showMillisecond ] ;
116
+ }
117
+
69
118
/**
70
119
* Get `showHour`, `showMinute`, `showSecond` or other from the props.
71
120
* This is pure function, will not get `showXXX` from the `format` prop.
@@ -91,12 +140,15 @@ export function getTimeProps<DateType extends object>(
91
140
92
141
const { showMillisecond } = timeConfig ;
93
142
let { showHour, showMinute, showSecond } = timeConfig ;
143
+ const hasShowConfig = existShowConfig ( showHour , showMinute , showSecond , showMillisecond ) ;
94
144
95
- if ( ! showHour && ! showMinute && ! showSecond && ! showMillisecond ) {
96
- showHour = true ;
97
- showMinute = true ;
98
- showSecond = true ;
99
- }
145
+ [ showHour , showMinute , showSecond ] = fillShowConfig (
146
+ hasShowConfig ,
147
+ showHour ,
148
+ showMinute ,
149
+ showSecond ,
150
+ showMillisecond ,
151
+ ) ;
100
152
101
153
return [
102
154
timeConfig ,
@@ -145,9 +197,7 @@ export function fillShowTimeConfig<DateType extends object>(
145
197
146
198
const showMeridiem = checkShow ( baselineFormat , [ 'a' , 'A' , 'LT' , 'LLL' , 'LTS' ] , use12Hours ) ;
147
199
148
- const hasShowConfig = [ showHour , showMinute , showSecond , showMillisecond ] . some (
149
- ( show ) => show !== undefined ,
150
- ) ;
200
+ const hasShowConfig = existShowConfig ( showHour , showMinute , showSecond , showMillisecond ) ;
151
201
152
202
// Fill with format, if needed
153
203
if ( ! hasShowConfig ) {
@@ -158,11 +208,13 @@ export function fillShowTimeConfig<DateType extends object>(
158
208
}
159
209
160
210
// Fallback if all can not see
161
- if ( ! hasShowConfig && ! showHour && ! showMinute && ! showSecond && ! showMillisecond ) {
162
- showHour = true ;
163
- showMinute = true ;
164
- showSecond = true ;
165
- }
211
+ [ showHour , showMinute , showSecond ] = fillShowConfig (
212
+ hasShowConfig ,
213
+ showHour ,
214
+ showMinute ,
215
+ showSecond ,
216
+ showMillisecond ,
217
+ ) ;
166
218
167
219
// ======================== Format ========================
168
220
const timeFormat =
0 commit comments