@douyinfe/semi-foundation 2.6.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/button/button.scss +14 -6
  2. package/datePicker/_utils/formatter.ts +2 -2
  3. package/datePicker/_utils/getInsetInputFormatToken.ts +42 -0
  4. package/datePicker/_utils/getInsetInputValueFromInsetInputStr.ts +60 -0
  5. package/datePicker/constants.ts +2 -0
  6. package/datePicker/datePicker.scss +136 -3
  7. package/datePicker/foundation.ts +92 -15
  8. package/datePicker/inputFoundation.ts +133 -4
  9. package/datePicker/monthsGridFoundation.ts +4 -0
  10. package/datePicker/rtl.scss +8 -0
  11. package/datePicker/variables.scss +30 -0
  12. package/lib/cjs/button/button.css +5 -5
  13. package/lib/cjs/button/button.scss +14 -6
  14. package/lib/cjs/datePicker/_utils/formatter.d.ts +2 -2
  15. package/lib/cjs/datePicker/_utils/getInsetInputFormatToken.d.ts +20 -0
  16. package/lib/cjs/datePicker/_utils/getInsetInputFormatToken.js +61 -0
  17. package/lib/cjs/datePicker/_utils/getInsetInputValueFromInsetInputStr.d.ts +31 -0
  18. package/lib/cjs/datePicker/_utils/getInsetInputValueFromInsetInputStr.js +76 -0
  19. package/lib/cjs/datePicker/constants.d.ts +2 -0
  20. package/lib/cjs/datePicker/constants.js +4 -3
  21. package/lib/cjs/datePicker/datePicker.css +104 -2
  22. package/lib/cjs/datePicker/datePicker.scss +136 -3
  23. package/lib/cjs/datePicker/foundation.d.ts +30 -7
  24. package/lib/cjs/datePicker/foundation.js +122 -9
  25. package/lib/cjs/datePicker/inputFoundation.d.ts +73 -3
  26. package/lib/cjs/datePicker/inputFoundation.js +196 -3
  27. package/lib/cjs/datePicker/monthsGridFoundation.d.ts +1 -0
  28. package/lib/cjs/datePicker/monthsGridFoundation.js +4 -2
  29. package/lib/cjs/datePicker/rtl.scss +8 -0
  30. package/lib/cjs/datePicker/variables.scss +30 -0
  31. package/lib/cjs/tooltip/foundation.js +8 -8
  32. package/lib/cjs/treeSelect/foundation.d.ts +3 -2
  33. package/lib/cjs/treeSelect/foundation.js +28 -15
  34. package/lib/es/button/button.css +5 -5
  35. package/lib/es/button/button.scss +14 -6
  36. package/lib/es/datePicker/_utils/formatter.d.ts +2 -2
  37. package/lib/es/datePicker/_utils/getInsetInputFormatToken.d.ts +20 -0
  38. package/lib/es/datePicker/_utils/getInsetInputFormatToken.js +48 -0
  39. package/lib/es/datePicker/_utils/getInsetInputValueFromInsetInputStr.d.ts +31 -0
  40. package/lib/es/datePicker/_utils/getInsetInputValueFromInsetInputStr.js +66 -0
  41. package/lib/es/datePicker/constants.d.ts +2 -0
  42. package/lib/es/datePicker/constants.js +4 -3
  43. package/lib/es/datePicker/datePicker.css +104 -2
  44. package/lib/es/datePicker/datePicker.scss +136 -3
  45. package/lib/es/datePicker/foundation.d.ts +30 -7
  46. package/lib/es/datePicker/foundation.js +120 -9
  47. package/lib/es/datePicker/inputFoundation.d.ts +73 -3
  48. package/lib/es/datePicker/inputFoundation.js +192 -4
  49. package/lib/es/datePicker/monthsGridFoundation.d.ts +1 -0
  50. package/lib/es/datePicker/monthsGridFoundation.js +4 -2
  51. package/lib/es/datePicker/rtl.scss +8 -0
  52. package/lib/es/datePicker/variables.scss +30 -0
  53. package/lib/es/tooltip/foundation.js +8 -8
  54. package/lib/es/treeSelect/foundation.d.ts +3 -2
  55. package/lib/es/treeSelect/foundation.js +27 -15
  56. package/package.json +3 -3
  57. package/tooltip/foundation.ts +8 -8
  58. package/treeSelect/foundation.ts +26 -19
@@ -24,8 +24,16 @@ $module: #{$prefix}-button;
24
24
  vertical-align: middle;
25
25
  white-space: nowrap;
26
26
 
27
- &:focus {
28
- outline: $width-button-outline solid $color-button_primary-outline-focus;
27
+ // the specificity of `.#{$module}:focus-visible` may lower than `reset.css` default `focus-visible` style
28
+ // so we add a class at the same level
29
+ &.#{$module}-primary,
30
+ &.#{$module}-secondary,
31
+ &.#{$module}-tertiary,
32
+ &.#{$module}-warning,
33
+ &.#{$module}-danger {
34
+ &:focus-visible {
35
+ outline: $width-button-outline solid $color-button_primary-outline-focus;
36
+ }
29
37
  }
30
38
 
31
39
  &-danger {
@@ -41,8 +49,8 @@ $module: #{$prefix}-button;
41
49
  &.#{$module}-borderless {
42
50
  color: $color-button_danger-bg-default;
43
51
  }
44
- &:not(.#{$module}-borderless):not(.#{$module}-light):focus {
45
- outline-color: $color-button_danger-outline-focus;
52
+ &:not(.#{$module}-borderless):not(.#{$module}-light):focus-visible {
53
+ outline: $width-button-outline solid $color-button_danger-outline-focus;
46
54
  }
47
55
  }
48
56
  &-warning {
@@ -58,8 +66,8 @@ $module: #{$prefix}-button;
58
66
  &.#{$module}-borderless {
59
67
  color: $color-button_warning-bg-default;
60
68
  }
61
- &:not(.#{$module}-borderless):not(.#{$module}-light):focus {
62
- outline-color: $color-button_warning-outline-focus;
69
+ &:not(.#{$module}-borderless):not(.#{$module}-light):focus-visible {
70
+ outline: $width-button-outline solid $color-button_warning-outline-focus;
63
71
  }
64
72
  }
65
73
  &-tertiary {
@@ -18,9 +18,9 @@ export function formatDateValues(
18
18
  values: BaseValueType[],
19
19
  formatToken: string,
20
20
  {
21
- groupInnerSeparator = strings.DEFAULT_SEPARATOR_RANGE,
21
+ groupInnerSeparator = strings.DEFAULT_SEPARATOR_RANGE as string,
22
22
  groupSize = 1,
23
- groupSeparator = strings.DEFAULT_SEPARATOR_MULTIPLE,
23
+ groupSeparator = strings.DEFAULT_SEPARATOR_MULTIPLE as string,
24
24
  } = {},
25
25
  locale: any
26
26
  ) {
@@ -0,0 +1,42 @@
1
+ import { strings } from '../constants';
2
+ import { getDefaultFormatTokenByType } from './getDefaultFormatToken';
3
+
4
+ /**
5
+ * 获取 insetInput 输入框的 placeholder
6
+ * Get the placeholder of the insetInput input
7
+ *
8
+ * If type is time related, we only recognize the format like `dateFormat timeFormat`
9
+ * - 'yyyy-MM-dd HH:mm:ss' // ok
10
+ * - 'yyyy-MM-dd HH:mm:ss' // bad format
11
+ *
12
+ * @example
13
+ * 'yyyy-MM-dd' => 'yyyy-MM-dd'
14
+ * 'yyyy-MM' => 'yyyy-MM'
15
+ * 'yyyy-MM-dd HH:mm:ss' => 'yyyy-MM-dd HH:mm:ss'
16
+ * 'yyyy-MM-dd HH:mm' => 'yyyy-MM-dd HH:mm'
17
+ * 'Pp' => 'yyyy-MM-dd'
18
+ */
19
+ export default function getInsetInputFormatToken(options: { format: string, type: typeof strings.TYPE_SET[number]; }) {
20
+ const { format, type } = options;
21
+ const dateReg = /([yMd]{0,4}[^a-z\s]*[yMd]{0,4}[^a-z\s]*[yMd]{0,4})/i;
22
+ const dateTimeReg = /([yMd]{0,4}[^a-z\s]*[yMd]{0,4}[^a-z\s]*[yMd]{0,4}) (H{0,2}[^a-z\s]*m{0,2}[^a-z\s]*s{0,2})/i;
23
+ const defaultToken = getDefaultFormatTokenByType(type);
24
+ let insetInputFormat: string;
25
+
26
+ switch (type) {
27
+ case 'dateTime':
28
+ case 'dateTimeRange':
29
+ const dateTimeResult = dateTimeReg.exec(format);
30
+ insetInputFormat = (dateTimeResult && dateTimeResult[1] && dateTimeResult[2]) ? `${dateTimeResult[1]} ${dateTimeResult[2]}` : defaultToken;
31
+ break;
32
+ case 'date':
33
+ case 'month':
34
+ case 'dateRange':
35
+ default:
36
+ const dateResult = dateReg.exec(format);
37
+ insetInputFormat = dateResult && dateResult[1] || defaultToken;
38
+ break;
39
+ }
40
+
41
+ return insetInputFormat;
42
+ }
@@ -0,0 +1,60 @@
1
+ import { strings } from '../constants';
2
+
3
+ /**
4
+ * 从 insetInputStr 字符串解析出 insetInputValue 对象
5
+ * Parse the insetInputValue object from the insetInputStr string
6
+ *
7
+ * @example
8
+ * ```
9
+ * '2022-02-01' => { monthLeft: { dateInput: '2022-02-01' } }
10
+ * '2022-02-01 00:00:00' => { monthLeft: { dateInput: '2022-02-01', timeInput: '00:00:00' } }
11
+ * '2022-02-01 00:00:00 ~ 2022-02-15 00:00:00' => { monthLeft: { dateInput: '2022-02-01', timeInput: '00:00:00'}, monthRight: { dateInput: '2022-02-15', timeInput: '00:00:00' } }
12
+ *
13
+ * '2022-0' => { monthLeft: { dateInput: '2022-0' } }
14
+ * '2022-02-01 00:00:' => { monthLeft: { dateInput: '2022-02-01', timeInput: '00:00:' } }
15
+ * '2022-02-01 00:00:00 ~ ' => { monthLeft: { dateInput: '2022-02-01', timeInput: '00:00:00'}, monthRight: { dateInput: '', timeInput: '' } }
16
+ * ' ~ 2022-02-15 00:00:00' => { monthLeft: { dateInput: '', timeInput: '' }, monthRight: { dateInput: '2022-02-15', timeInput: '00:00:00' } }
17
+ * ```
18
+ */
19
+ export default function getInsetInputValueFromInsetInputStr(options: { inputValue: string; rangeSeparator: string, type: typeof strings.TYPE_SET[number] }) {
20
+ const timeSeparator = ' ';
21
+ const { inputValue = '', rangeSeparator, type } = options;
22
+ let leftDateInput, leftTimeInput, rightDateInput, rightTimeInput;
23
+ const insetInputValue = {
24
+ monthLeft: {
25
+ dateInput: '',
26
+ timeInput: '',
27
+ },
28
+ monthRight: {
29
+ dateInput: '',
30
+ timeInput: '',
31
+ }
32
+ };
33
+
34
+ switch (type) {
35
+ case 'date':
36
+ case 'month':
37
+ insetInputValue.monthLeft.dateInput = inputValue;
38
+ break;
39
+ case 'dateRange':
40
+ [leftDateInput = '', rightDateInput = ''] = inputValue.split(rangeSeparator);
41
+ insetInputValue.monthLeft.dateInput = leftDateInput;
42
+ insetInputValue.monthRight.dateInput = rightDateInput;
43
+ break;
44
+ case 'dateTime':
45
+ [leftDateInput = '', leftTimeInput = ''] = inputValue.split(timeSeparator);
46
+ insetInputValue.monthLeft.dateInput = leftDateInput;
47
+ insetInputValue.monthLeft.timeInput = leftTimeInput;
48
+ break;
49
+ case 'dateTimeRange':
50
+ const [leftInput = '', rightInput = ''] = inputValue.split(rangeSeparator);
51
+ [leftDateInput = '', leftTimeInput = ''] = leftInput.split(timeSeparator);
52
+ [rightDateInput = '', rightTimeInput = ''] = rightInput.split(timeSeparator);
53
+ insetInputValue.monthLeft.dateInput = leftDateInput;
54
+ insetInputValue.monthLeft.timeInput = leftTimeInput;
55
+ insetInputValue.monthRight.dateInput = rightDateInput;
56
+ insetInputValue.monthRight.timeInput = rightTimeInput;
57
+ break;
58
+ }
59
+ return insetInputValue;
60
+ }
@@ -52,6 +52,7 @@ const strings = {
52
52
  PANEL_TYPE_RIGHT: 'right',
53
53
  STATUS: VALIDATE_STATUS,
54
54
  POSITION_SET: POPOVER_STRINGS.POSITION_SET,
55
+ POSITION_INLINE_INPUT: 'leftTopOver',
55
56
  ...formatToken,
56
57
  } as const;
57
58
 
@@ -59,6 +60,7 @@ const numbers = {
59
60
  WEEK_START_ON: 0, // Take the day of the week as the first day of the week, 0 for Sunday, 1 for Monday, and so on
60
61
  WEEK_HEIGHT: 36, // Date per line height 36px
61
62
  SPACING: popoverNumber.SPACING, // Floating distance trigger interval
63
+ SPACING_INSET_INPUT: 1,
62
64
  } as const;
63
65
 
64
66
  export { cssClasses, strings, numbers };
@@ -6,6 +6,7 @@ $module: #{$prefix}-datepicker;
6
6
  .#{$module} {
7
7
  box-sizing: border-box;
8
8
  display: inline-block;
9
+ vertical-align: top;
9
10
 
10
11
  // 双月网格
11
12
 
@@ -45,6 +46,34 @@ $module: #{$prefix}-datepicker;
45
46
  min-height: $height-datepicker_dateType_yamShowing_min;
46
47
  }
47
48
 
49
+ &[x-insetInput=true] {
50
+ .#{$module}-month-grid-left,
51
+ .#{$module}-month-grid-right {
52
+ &[x-open-type=year] {
53
+ min-height: $height-datepicker_month_grid_yearType_insetInput;
54
+ }
55
+ &[x-open-type=time] {
56
+ min-height: $height-datepicker_month_grid_timeType_insetInput;
57
+ }
58
+ }
59
+
60
+ .#{$module}-navigation {
61
+ padding-top: $spacing-datepicker_navigation_insetInput-paddingY;
62
+ padding-bottom: $spacing-datepicker_navigation_insetInput-paddingY;
63
+ }
64
+
65
+ .#{$module}-tpk {
66
+ min-height: $height-datepicker_timeType_insetInput_tpk;
67
+ }
68
+
69
+ &[x-type=dateTime],
70
+ &[x-type=dateTimeRange] {
71
+ .#{$module}-yam {
72
+ height: $height-datepicker_timeType_insetInput_yam;
73
+ }
74
+ }
75
+ }
76
+
48
77
  // 年月选择返回主面板
49
78
  .#{$module}-yearmonth-header {
50
79
  background: $color-datepicker_header-bg-default;
@@ -92,6 +121,7 @@ $module: #{$prefix}-datepicker;
92
121
 
93
122
  @include font-size-regular;
94
123
  min-height: $height-datepicker_timepicker_header_min;
124
+ line-height: $height-datepicker_timepicker_header_min;
95
125
  }
96
126
  }
97
127
 
@@ -581,6 +611,41 @@ $module: #{$prefix}-datepicker;
581
611
  cursor: pointer;
582
612
  }
583
613
 
614
+ &-inset-input {
615
+ &-wrapper {
616
+ display: flex;
617
+ flex-wrap: nowrap;
618
+ justify-content: space-between;
619
+ box-sizing: border-box;
620
+ column-gap: $spacing-datepicker_insetInput_wrapper-margin;
621
+ padding: $spacing-datepicker_insetInput_wrapper-paddingY $spacing-datepicker_insetInput_wrapper-paddingX;
622
+ padding-bottom: $spacing-datepicker_insetInput_wrapper-paddingBottom;
623
+
624
+ width: $width-datepicker_insetInput_date_type_wrapper;
625
+ &[x-type=dateRange],
626
+ &[x-type=dateTimeRange] {
627
+ width: $width-datepicker_insetInput_date_range_type_wrapper;
628
+ }
629
+ &[x-type=month] {
630
+ width: $width-datepicker_insetInput_month_type_wrapper;
631
+ }
632
+
633
+ .#{$prefix}-input-wrapper {
634
+ flex: 1;
635
+ flex-shrink: 0;
636
+ }
637
+ }
638
+
639
+ &-separator {
640
+ flex-grow: 0;
641
+ flex-shrink: 0;
642
+ height: $height-datepicker_insetInput_separator;
643
+ line-height: $height-datepicker_insetInput_separator;
644
+ padding: $spacing-datepicker_insetInput_separator-paddingY $spacing-datepicker_insetInput_separator-paddingX;
645
+ color: $color-datepicker_insetInput_separator;
646
+ }
647
+ }
648
+
584
649
  &-range {
585
650
 
586
651
  &-input {
@@ -862,6 +927,33 @@ $module: #{$prefix}-datepicker;
862
927
  min-height: 6 * $width-datepicker_day_compact;
863
928
  }
864
929
  }
930
+
931
+ &[x-insetInput=true] {
932
+ .#{$module}-month-grid-left,
933
+ .#{$module}-month-grid-right {
934
+ &[x-open-type=year] {
935
+ min-height: $height-datepicker_tpk_compact;
936
+ }
937
+ &[x-open-type=time] {
938
+ min-height: $height-datepicker_tpk_compact;
939
+ }
940
+ }
941
+
942
+ .#{$module}-yam-showing {
943
+ min-height: $height-datepicker_tpk_compact;
944
+ }
945
+
946
+ .#{$module}-tpk {
947
+ min-height: $height-datepicker_insetInput_tpk_compact;
948
+ }
949
+
950
+ &[x-type=dateTime],
951
+ &[x-type=dateTimeRange] {
952
+ .#{$module}-yam {
953
+ height: $height-datepicker_timeType_insetInput_yam_compact;
954
+ }
955
+ }
956
+ }
865
957
  }
866
958
 
867
959
  // 年月选择器
@@ -1039,6 +1131,46 @@ $module: #{$prefix}-datepicker;
1039
1131
  padding-right: $spacing-datepicker_footer_compact-paddintRight;
1040
1132
  padding-bottom: $spacing-datepicker_footer_compact-paddintBottom;
1041
1133
  }
1134
+
1135
+ .#{$module}-inset-input {
1136
+ &-wrapper {
1137
+ column-gap: $spacing-datepicker_insetInput_wrapper_compact-margin;
1138
+ padding: $spacing-datepicker_insetInput_wrapper_compact-paddingY $spacing-datepicker_insetInput_wrapper_compact-paddingX;
1139
+ padding-bottom: $spacing-datepicker_insetInput_wrapper_compact-paddingBottom;
1140
+
1141
+ width: $width-datepicker_insetInput_date_type_wrapper_compact;
1142
+ &[x-type=dateRange],
1143
+ &[x-type=dateTimeRange] {
1144
+ width: $width-datepicker_insetInput_date_range_type_wrapper_compact;
1145
+ padding-top: $spacing-datepicker_insetInput_wrapper_rangeType_compact-paddingTop;
1146
+
1147
+ .#{$prefix}-input-wrapper {
1148
+ margin-top: $spacing-datepicker_insetInput_wrapper_compact-paddingY;
1149
+ }
1150
+ }
1151
+ &[x-type=month] {
1152
+ width: $width-datepicker_insetInput_month_type_wrapper_compact;
1153
+ }
1154
+
1155
+ .#{$prefix}-input-wrapper {
1156
+ height: $height-datepicker_insetInput_wrapper_compact;
1157
+ box-sizing: border-box;
1158
+
1159
+ .#{$prefix}-input {
1160
+ font-size: $fontSize-datepicker_insetInput_compact-fontSize;
1161
+ line-height: $height-datepicker_insetInput_compact;
1162
+ height: $height-datepicker_insetInput_compact;
1163
+ vertical-align: top;
1164
+ }
1165
+ }
1166
+ }
1167
+
1168
+ &-separator {
1169
+ border-left: $width-datepicker-border solid $color-datepicker_border-bg-default;
1170
+ transform: translateX(50%);
1171
+ height: auto;
1172
+ }
1173
+ }
1042
1174
  }
1043
1175
 
1044
1176
  // 向上弹出时固定高度为6周 #1042
@@ -1046,8 +1178,10 @@ $module: #{$prefix}-datepicker;
1046
1178
 
1047
1179
  &-wrapper {
1048
1180
 
1049
- &[x-placement*="top"],
1050
- &[x-placement*="Top"] {
1181
+ &[x-placement^="top"],
1182
+ &[x-placement="leftTop"],
1183
+ &[x-placement="rightTop"],
1184
+ &[x-placement*="BottomOver"] {
1051
1185
  .#{$module} .#{$module}-weeks {
1052
1186
  min-height: 6 * $width-datepicker_day;
1053
1187
  }
@@ -1056,7 +1190,6 @@ $module: #{$prefix}-datepicker;
1056
1190
  min-height: 6 * $width-datepicker_day_compact;
1057
1191
  }
1058
1192
  }
1059
-
1060
1193
  }
1061
1194
  }
1062
1195
 
@@ -12,10 +12,12 @@ import { getDefaultFormatTokenByType } from './_utils/getDefaultFormatToken';
12
12
  import { strings } from './constants';
13
13
  import { strings as inputStrings } from '../input/constants';
14
14
 
15
- import { Type, DateInputFoundationProps } from './inputFoundation';
15
+ import { Type, DateInputFoundationProps, InsetInputValue } from './inputFoundation';
16
16
  import { MonthsGridFoundationProps } from './monthsGridFoundation';
17
17
  import { WeekStartNumber } from './_utils/getMonthTable';
18
18
  import { ArrayElement, Motion } from '../utils/type';
19
+ import getInsetInputFormatToken from './_utils/getInsetInputFormatToken';
20
+ import getInsetInputValueFromInsetInputStr from './_utils/getInsetInputValueFromInsetInputStr';
19
21
 
20
22
  export type ValidateStatus = ArrayElement<typeof strings.STATUS>;
21
23
  export type InputSize = ArrayElement<typeof strings.SIZE_SET>;
@@ -92,6 +94,8 @@ export interface RenderProps {
92
94
  triggerRender?: TriggerRenderType;
93
95
  }
94
96
 
97
+ export type RangeType = 'rangeStart' | 'rangeEnd' | false;
98
+
95
99
  export interface EventHandlerProps {
96
100
  onCancel?: OnCancelType;
97
101
  onChange?: OnChangeType;
@@ -104,7 +108,7 @@ export interface EventHandlerProps {
104
108
  // onClear?: React.MouseEventHandler<HTMLDivElement>;
105
109
  onClear?: (e: any) => void;
106
110
  // onFocus?: React.MouseEventHandler<HTMLInputElement>;
107
- onFocus?: (e: any, rangType: 'rangeStart' | 'rangeEnd') => void;
111
+ onFocus?: (e: any, rangType: RangeType) => void;
108
112
  onPresetClick?: OnPresetClickType;
109
113
  }
110
114
 
@@ -157,6 +161,7 @@ export interface DatePickerFoundationProps extends ElementProps, RenderProps, Ev
157
161
  dateFnsLocale?: any;
158
162
  localeCode?: string;
159
163
  rangeSeparator?: string;
164
+ insetInput?: boolean;
160
165
  }
161
166
 
162
167
  export interface DatePickerFoundationState {
@@ -167,8 +172,10 @@ export interface DatePickerFoundationState {
167
172
  cachedSelectedValue: Date[];
168
173
  prevTimeZone: string | number;
169
174
  motionEnd: boolean;
170
- rangeInputFocus: 'rangeStart' | 'rangeEnd' | boolean;
175
+ rangeInputFocus: RangeType;
171
176
  autofocus: boolean;
177
+ insetInputValue: InsetInputValue;
178
+ triggerDisabled: boolean;
172
179
  }
173
180
 
174
181
  export { Type, DateInputFoundationProps };
@@ -195,6 +202,9 @@ export interface DatePickerAdapter extends DefaultAdapter<DatePickerFoundationPr
195
202
  setRangeInputFocus: (rangeInputFocus: DatePickerFoundationState['rangeInputFocus']) => void;
196
203
  couldPanelClosed: () => boolean;
197
204
  isEventTarget: (e: any) => boolean;
205
+ updateInsetInputValue: (insetInputValue: InsetInputValue) => void;
206
+ setInsetInputFocus: () => void;
207
+ setTriggerDisabled: (disabled: boolean) => void;
198
208
  }
199
209
 
200
210
 
@@ -350,6 +360,16 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
350
360
  }
351
361
  }
352
362
 
363
+ /**
364
+ * clear inset input value when close panel
365
+ */
366
+ clearInsetInputValue() {
367
+ const { insetInput } = this._adapter.getProps();
368
+ if (insetInput) {
369
+ this._adapter.updateInsetInputValue(null);
370
+ }
371
+ }
372
+
353
373
  resetCachedSelectedValue(willUpdateDates?: Date[]) {
354
374
  const { value, cachedSelectedValue } = this._adapter.getStates();
355
375
  const newCachedSelectedValue = Array.isArray(willUpdateDates) ? willUpdateDates : value;
@@ -380,6 +400,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
380
400
  // range type picker, closing panel requires the following side effects
381
401
  this.rangeTypeSideEffectsWhenClosePanel(inputValue, willUpdateDates as Date[]);
382
402
  this.needConfirmSideEffectsWhenClosePanel(willUpdateDates as Date[]);
403
+ this.clearInsetInputValue();
383
404
  this._adapter.notifyOpenChange(false);
384
405
  this._adapter.notifyBlur(e);
385
406
  }
@@ -428,6 +449,37 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
428
449
  }
429
450
  }
430
451
 
452
+ /**
453
+ * inset input 变化时需要更新以下 state 状态
454
+ * - insetInputValue(总是)
455
+ * - inputValue(可以解析为合法日期时)
456
+ * - value(可以解析为合法日期时)
457
+ */
458
+ handleInsetInputChange(options: { insetInputStr: string, format: string, insetInputValue: InsetInputValue }) {
459
+ const { insetInputStr, format, insetInputValue } = options;
460
+ const _isMultiple = this._isMultiple();
461
+ const result = _isMultiple ? this.parseMultipleInput(insetInputStr, format) : this.parseInput(insetInputStr, format);
462
+ const { value: stateValue } = this.getStates();
463
+
464
+ if ((result && result.length)) {
465
+ const changedDates = this._getChangedDates(result);
466
+ if (!this._someDateDisabled(changedDates)) {
467
+ if (this._adapter.needConfirm()) {
468
+ this._adapter.updateCachedSelectedValue(result);
469
+ }
470
+ if (!isEqual(result, stateValue)) {
471
+ if (!this._isControlledComponent()) {
472
+ this._adapter.updateValue(result);
473
+ }
474
+ this._notifyChange(result);
475
+ }
476
+ const triggerInput = _isMultiple ? this.formatMultipleDates(result) : this.formatDates(result);
477
+ this._adapter.updateInputValue(triggerInput);
478
+ }
479
+ }
480
+ this._adapter.updateInsetInputValue(insetInputValue);
481
+ }
482
+
431
483
  /**
432
484
  * Input box blur
433
485
  * @param {String} input
@@ -479,7 +531,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
479
531
  }
480
532
  }
481
533
 
482
- handleSetRangeFocus(rangeInputFocus: boolean | 'rangeStart' | 'rangeEnd') {
534
+ handleSetRangeFocus(rangeInputFocus: RangeType) {
483
535
  this._adapter.setRangeInputFocus(rangeInputFocus);
484
536
  }
485
537
 
@@ -546,14 +598,14 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
546
598
  * @param {string} input
547
599
  * @returns {Date [] | '}
548
600
  */
549
- parseInput(input = '') {
601
+ parseInput(input = '', format?: string) {
550
602
  let result: Date[] = [];
551
603
  // console.log(input);
552
604
  const { dateFnsLocale, rangeSeparator } = this.getProps();
553
605
 
554
606
  if (input && input.length) {
555
607
  const type = this.getProp('type');
556
- const formatToken = this.getProp('format') || getDefaultFormatTokenByType(type);
608
+ const formatToken = format || this.getProp('format') || getDefaultFormatTokenByType(type);
557
609
  let parsedResult,
558
610
  formatedInput;
559
611
  const nowDate = new Date();
@@ -636,13 +688,13 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
636
688
  * @param {Date[]} dates
637
689
  * @returns {string}
638
690
  */
639
- formatDates(dates: Date[] = []) {
691
+ formatDates(dates: Date[] = [], customFormat?: string) {
640
692
  let str = '';
641
693
  const rangeSeparator = this.getProp('rangeSeparator');
642
694
 
643
695
  if (Array.isArray(dates) && dates.length) {
644
696
  const type = this.getProp('type');
645
- const formatToken = this.getProp('format') || getDefaultFormatTokenByType(type);
697
+ const formatToken = customFormat || this.getProp('format') || getDefaultFormatTokenByType(type);
646
698
 
647
699
  switch (type) {
648
700
  case 'date':
@@ -679,7 +731,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
679
731
  * @param {Date[]} dates
680
732
  * @returns {string}
681
733
  */
682
- formatMultipleDates(dates: Date[] = [], separator: string = strings.DEFAULT_SEPARATOR_MULTIPLE) {
734
+ formatMultipleDates(dates: Date[] = [], separator: string = strings.DEFAULT_SEPARATOR_MULTIPLE, customFormat?: string) {
683
735
  const strs = [];
684
736
  if (Array.isArray(dates) && dates.length) {
685
737
  const type = this.getProp('type');
@@ -688,12 +740,12 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
688
740
  case 'date':
689
741
  case 'dateTime':
690
742
  case 'month':
691
- dates.forEach(date => strs.push(this.formatDates([date])));
743
+ dates.forEach(date => strs.push(this.formatDates([date], customFormat)));
692
744
  break;
693
745
  case 'dateRange':
694
746
  case 'dateTimeRange':
695
747
  for (let i = 0; i < dates.length; i += 2) {
696
- strs.push(this.formatDates(dates.slice(i, i + 2)));
748
+ strs.push(this.formatDates(dates.slice(i, i + 2), customFormat));
697
749
  }
698
750
  break;
699
751
  default:
@@ -735,7 +787,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
735
787
  * @param {*} options
736
788
  */
737
789
  handleSelectedChange(value: Date[], options?: { fromPreset?: boolean; needCheckFocusRecord?: boolean }) {
738
- const type = this.getProp('type');
790
+ const { type, format, rangeSeparator, insetInput } = this._adapter.getProps();
739
791
  const { value: stateValue } = this.getStates();
740
792
  const controlled = this._isControlledComponent();
741
793
  const fromPreset = isObject(options) ? options.fromPreset : options;
@@ -754,9 +806,14 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
754
806
  const dates = Array.isArray(value) ? [...value] : value ? [value] : [];
755
807
  const changedDates = this._getChangedDates(dates);
756
808
 
757
- let inputValue;
809
+ let inputValue, insetInputValue;
758
810
  if (!this._someDateDisabled(changedDates)) {
759
811
  inputValue = this._isMultiple() ? this.formatMultipleDates(dates) : this.formatDates(dates);
812
+ if (insetInput) {
813
+ const insetInputFormatToken = getInsetInputFormatToken({ format, type });
814
+ const insetInputStr = this._isMultiple() ? this.formatMultipleDates(dates, undefined, insetInputFormatToken) : this.formatDates(dates, insetInputFormatToken);
815
+ insetInputValue = getInsetInputValueFromInsetInputStr({ inputValue: insetInputStr, type, rangeSeparator });
816
+ }
760
817
  const isRangeTypeAndInputIncomplete = this._isRangeType() && !this._isRangeValueComplete(dates);
761
818
  /**
762
819
  * If the input is incomplete when under control, the notifyChange is not triggered because
@@ -769,14 +826,19 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
769
826
  if (isRangeTypeAndInputIncomplete) {
770
827
  // do not change value when selected value is incomplete
771
828
  this._adapter.updateInputValue(inputValue);
829
+ this._adapter.updateInsetInputValue(insetInputValue);
772
830
  return;
773
831
  } else {
774
- (!controlled || fromPreset) && this._updateValueAndInput(dates, true, inputValue);
832
+ if (!controlled || fromPreset) {
833
+ this._updateValueAndInput(dates, true, inputValue);
834
+ this._adapter.updateInsetInputValue(insetInputValue);
835
+ }
775
836
  }
776
837
  }
777
838
  if (!controlled && this._adapter.needConfirm()) {
778
839
  // select date only change inputValue when needConfirm is true
779
840
  this._adapter.updateInputValue(inputValue);
841
+ this._adapter.updateInsetInputValue(insetInputValue);
780
842
  // if inputValue is not complete, don't notifyChange
781
843
  if (isRangeTypeAndInputIncomplete) {
782
844
  return;
@@ -810,7 +872,7 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
810
872
  }
811
873
 
812
874
  handleConfirm() {
813
- const { cachedSelectedValue, value } = this.getStates();
875
+ const { cachedSelectedValue, value } = this._adapter.getStates();
814
876
  const isRangeValueComplete = this._isRangeValueComplete(cachedSelectedValue);
815
877
  const newValue = isRangeValueComplete ? cachedSelectedValue : value;
816
878
  if (this._adapter.needConfirm() && !this._isControlledComponent()) {
@@ -1121,4 +1183,19 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
1121
1183
  this.openPanel();
1122
1184
  }
1123
1185
  }
1186
+
1187
+ handlePanelVisibleChange(visible: boolean) {
1188
+ if (visible) {
1189
+ this._adapter.setInsetInputFocus();
1190
+ /**
1191
+ * After the panel is closed, the trigger input is disabled
1192
+ * 面板关闭后,trigger input 禁用
1193
+ */
1194
+ setTimeout(() => {
1195
+ this._adapter.setTriggerDisabled(true);
1196
+ }, 0);
1197
+ } else {
1198
+ this._adapter.setTriggerDisabled(false);
1199
+ }
1200
+ }
1124
1201
  }