@king-design/intact 3.6.0-beta.0 → 3.6.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 (188) hide show
  1. package/components/button/demos/basic.md +0 -1
  2. package/components/cascader/index.spec.ts +7 -6
  3. package/components/copy/index.spec.ts +9 -14
  4. package/components/datepicker/basepicker.ts +26 -314
  5. package/components/datepicker/calendar.ts +3 -1
  6. package/components/datepicker/calendar.vdt +5 -2
  7. package/components/datepicker/dayjs.ts +2 -16
  8. package/components/datepicker/demos/multiple.md +5 -0
  9. package/components/datepicker/demos/yearMonth.md +2 -8
  10. package/components/datepicker/helpers.ts +5 -7
  11. package/components/datepicker/index.md +1 -2
  12. package/components/datepicker/index.spec.ts +596 -157
  13. package/components/datepicker/index.ts +16 -33
  14. package/components/datepicker/index.vdt +41 -35
  15. package/components/datepicker/shortcuts.ts +1 -1
  16. package/components/datepicker/styles.ts +27 -18
  17. package/components/datepicker/useConfirm.ts +82 -0
  18. package/components/datepicker/useDisabled.ts +29 -31
  19. package/components/datepicker/useFormats.ts +8 -4
  20. package/components/datepicker/useHighlight.ts +81 -0
  21. package/components/datepicker/useKeyboards.ts +2 -1
  22. package/components/datepicker/useMergeRange.ts +12 -12
  23. package/components/datepicker/useMonths.ts +6 -3
  24. package/components/datepicker/usePanel.ts +19 -19
  25. package/components/datepicker/useShowDate.ts +21 -41
  26. package/components/datepicker/useStatus.ts +34 -15
  27. package/components/datepicker/useValue.ts +43 -72
  28. package/components/datepicker/useValueBase.ts +312 -0
  29. package/components/datepicker/useWeeks.ts +1 -1
  30. package/components/datepicker/useYears.ts +7 -3
  31. package/components/dropdown/dropdown.ts +5 -4
  32. package/components/dropdown/index.md +1 -0
  33. package/components/dropdown/item.ts +1 -1
  34. package/components/dropdown/useKeyboard.ts +0 -1
  35. package/components/form/form.ts +4 -0
  36. package/components/form/index.md +2 -1
  37. package/components/form/index.spec.ts +2 -0
  38. package/components/input/index.spec.ts +42 -0
  39. package/components/input/index.ts +8 -0
  40. package/components/input/index.vdt +3 -4
  41. package/components/input/useAutoWidth.ts +19 -1
  42. package/components/menu/demos/horizontal.md +7 -1
  43. package/components/menu/index.spec.ts +19 -0
  44. package/components/menu/styles.ts +2 -1
  45. package/components/scrollSelect/useMouseEvents.ts +5 -4
  46. package/components/select/base.ts +3 -2
  47. package/components/select/base.vdt +2 -1
  48. package/components/select/demos/creatable.md +2 -2
  49. package/components/select/index.md +1 -1
  50. package/components/select/index.spec.ts +142 -36
  51. package/components/select/menu.ts +1 -1
  52. package/components/select/option.ts +2 -1
  53. package/components/select/select.ts +1 -0
  54. package/components/select/styles.ts +3 -1
  55. package/components/select/useCard.ts +22 -4
  56. package/components/select/useInput.ts +5 -9
  57. package/components/spinner/index.spec.ts +18 -0
  58. package/components/spinner/useValue.ts +2 -1
  59. package/components/table/index.spec.ts +69 -1
  60. package/components/table/useStickyHeader.ts +1 -1
  61. package/components/timepicker/index.spec.ts +145 -27
  62. package/components/timepicker/panelPicker.ts +10 -4
  63. package/components/timepicker/panelPicker.vdt +3 -5
  64. package/components/timepicker/styles.ts +1 -0
  65. package/components/timepicker/useConfirm.ts +33 -0
  66. package/components/timepicker/useDefaultValue.ts +30 -0
  67. package/components/timepicker/useDisabled.ts +17 -4
  68. package/components/timepicker/useFormats.ts +1 -1
  69. package/components/timepicker/useValue.ts +22 -19
  70. package/components/tour/index.spec.ts +1 -1
  71. package/es/components/cascader/index.spec.js +18 -19
  72. package/es/components/copy/index.spec.js +14 -31
  73. package/es/components/datepicker/basepicker.d.ts +6 -27
  74. package/es/components/datepicker/basepicker.js +23 -268
  75. package/es/components/datepicker/calendar.d.ts +4 -2
  76. package/es/components/datepicker/dayjs.d.ts +2 -13
  77. package/es/components/datepicker/helpers.d.ts +3 -2
  78. package/es/components/datepicker/helpers.js +2 -3
  79. package/es/components/datepicker/index.d.ts +21 -29
  80. package/es/components/datepicker/index.js +22 -32
  81. package/es/components/datepicker/index.spec.js +1277 -484
  82. package/es/components/datepicker/index.vdt.js +39 -38
  83. package/es/components/datepicker/shortcuts.d.ts +1 -1
  84. package/es/components/datepicker/styles.d.ts +7 -2
  85. package/es/components/datepicker/styles.js +10 -15
  86. package/es/components/datepicker/useConfirm.d.ts +6 -0
  87. package/es/components/datepicker/useConfirm.js +65 -0
  88. package/es/components/datepicker/useDisabled.d.ts +5 -3
  89. package/es/components/datepicker/useDisabled.js +22 -27
  90. package/es/components/datepicker/useFormats.d.ts +2 -2
  91. package/es/components/datepicker/useFormats.js +6 -2
  92. package/es/components/datepicker/useHighlight.d.ts +14 -0
  93. package/es/components/datepicker/useHighlight.js +60 -0
  94. package/es/components/datepicker/useKeyboards.js +2 -1
  95. package/es/components/datepicker/useMergeRange.d.ts +1 -1
  96. package/es/components/datepicker/useMergeRange.js +11 -16
  97. package/es/components/datepicker/useMonths.js +5 -3
  98. package/es/components/datepicker/usePanel.d.ts +1 -10
  99. package/es/components/datepicker/usePanel.js +19 -32
  100. package/es/components/datepicker/useShowDate.d.ts +1 -1
  101. package/es/components/datepicker/useShowDate.js +15 -40
  102. package/es/components/datepicker/useStatus.js +33 -16
  103. package/es/components/datepicker/useValue.d.ts +11 -6
  104. package/es/components/datepicker/useValue.js +49 -69
  105. package/es/components/datepicker/useValueBase.d.ts +28 -0
  106. package/es/components/datepicker/useValueBase.js +280 -0
  107. package/es/components/datepicker/useYears.js +6 -3
  108. package/es/components/dropdown/dropdown.d.ts +1 -0
  109. package/es/components/dropdown/dropdown.js +7 -4
  110. package/es/components/form/form.d.ts +1 -0
  111. package/es/components/form/form.js +7 -0
  112. package/es/components/form/index.spec.js +10 -8
  113. package/es/components/input/index.d.ts +2 -0
  114. package/es/components/input/index.js +6 -0
  115. package/es/components/input/index.spec.js +45 -0
  116. package/es/components/input/index.vdt.js +4 -3
  117. package/es/components/input/useAutoWidth.d.ts +2 -0
  118. package/es/components/input/useAutoWidth.js +19 -1
  119. package/es/components/menu/index.spec.js +28 -0
  120. package/es/components/menu/styles.js +2 -2
  121. package/es/components/scrollSelect/useMouseEvents.js +5 -4
  122. package/es/components/select/base.d.ts +1 -1
  123. package/es/components/select/base.js +3 -2
  124. package/es/components/select/base.vdt.js +4 -3
  125. package/es/components/select/index.spec.js +346 -218
  126. package/es/components/select/menu.js +1 -1
  127. package/es/components/select/option.js +2 -1
  128. package/es/components/select/select.js +2 -1
  129. package/es/components/select/styles.d.ts +79 -0
  130. package/es/components/select/styles.js +1 -0
  131. package/es/components/select/useCard.d.ts +4 -3
  132. package/es/components/select/useCard.js +15 -4
  133. package/es/components/select/useInput.d.ts +1 -1
  134. package/es/components/select/useInput.js +4 -4
  135. package/es/components/spinner/index.spec.js +82 -44
  136. package/es/components/spinner/useValue.js +2 -1
  137. package/es/components/table/index.spec.js +84 -6
  138. package/es/components/table/useStickyHeader.js +1 -1
  139. package/es/components/timepicker/index.spec.js +298 -128
  140. package/es/components/timepicker/panelPicker.d.ts +21 -16
  141. package/es/components/timepicker/panelPicker.js +7 -4
  142. package/es/components/timepicker/panelPicker.vdt.js +5 -9
  143. package/es/components/timepicker/selectPicker.d.ts +4 -3
  144. package/es/components/timepicker/styles.js +1 -1
  145. package/es/components/timepicker/useConfirm.d.ts +6 -0
  146. package/es/components/timepicker/useConfirm.js +19 -0
  147. package/es/components/timepicker/useDefaultValue.d.ts +4 -0
  148. package/es/components/timepicker/useDefaultValue.js +27 -0
  149. package/es/components/timepicker/useDisabled.d.ts +6 -3
  150. package/es/components/timepicker/useDisabled.js +13 -4
  151. package/es/components/timepicker/useFormats.d.ts +1 -1
  152. package/es/components/timepicker/useValue.d.ts +13 -8
  153. package/es/components/timepicker/useValue.js +14 -15
  154. package/es/components/tour/index.spec.js +1 -1
  155. package/es/index.d.ts +2 -2
  156. package/es/index.js +2 -2
  157. package/es/site/data/components/button/demos/basic/react.js +0 -2
  158. package/es/site/data/components/datepicker/demos/multiple/index.d.ts +1 -0
  159. package/es/site/data/components/datepicker/demos/multiple/index.js +2 -1
  160. package/es/site/data/components/datepicker/demos/multiple/react.d.ts +1 -0
  161. package/es/site/data/components/datepicker/demos/multiple/react.js +13 -2
  162. package/es/site/data/components/datepicker/demos/yearMonth/index.d.ts +0 -2
  163. package/es/site/data/components/datepicker/demos/yearMonth/index.js +1 -3
  164. package/es/site/data/components/datepicker/demos/yearMonth/react.d.ts +0 -2
  165. package/es/site/data/components/datepicker/demos/yearMonth/react.js +1 -21
  166. package/es/site/data/components/menu/demos/horizontal/react.js +5 -1
  167. package/es/site/data/components/select/demos/creatable/react.js +2 -2
  168. package/es/site/data/components/select/demos/searchable/index.js +1 -1
  169. package/es/site/data/components/select/demos/searchable/react.js +1 -1
  170. package/es/site/data/components/tour/demos/customText/index.d.ts +19 -6
  171. package/es/site/data/components/tour/demos/customText/index.js +18 -17
  172. package/es/site/data/components/tour/demos/customText/react.d.ts +20 -6
  173. package/es/site/data/components/tour/demos/customText/react.js +31 -27
  174. package/es/test/demos.js +1 -1
  175. package/index.ts +2 -2
  176. package/package.json +2 -2
  177. package/components/datepicker/demos/nowrap.md +0 -35
  178. package/components/datepicker/usePosition.ts +0 -169
  179. package/es/components/datepicker/usePosition.d.ts +0 -10
  180. package/es/components/datepicker/usePosition.js +0 -166
  181. package/es/site/data/components/datepicker/demos/nowrap/index.d.ts +0 -10
  182. package/es/site/data/components/datepicker/demos/nowrap/index.js +0 -19
  183. package/es/site/data/components/datepicker/demos/nowrap/react.d.ts +0 -10
  184. package/es/site/data/components/datepicker/demos/nowrap/react.js +0 -49
  185. package/es/site/data/components/tour/demos/customButtons/index.d.ts +0 -33
  186. package/es/site/data/components/tour/demos/customButtons/index.js +0 -55
  187. package/es/site/data/components/tour/demos/customButtons/react.d.ts +0 -33
  188. package/es/site/data/components/tour/demos/customButtons/react.js +0 -99
@@ -1,29 +1,27 @@
1
1
  import {TypeDefs, provide} from 'intact';
2
2
  import template from './index.vdt';
3
- import {BaseSelect, BaseSelectProps} from '../select/base';
4
3
  import {DATEPICKER} from './constants';
5
4
  import dayjs, {Dayjs} from './dayjs';
6
5
  import {useValue} from './useValue';
7
6
  import {isNullOrUndefined} from 'intact-shared'
8
7
  import {_$} from '../../i18n';
9
8
  import {bind} from '../utils';
10
- import {State} from '../../hooks/useState';
11
9
  import {useDisabled} from './useDisabled';
12
10
  import {useFormats} from './useFormats';
13
11
  import {usePanel} from './usePanel';
14
12
  import {useFocusDate} from './useFocusDate';
15
13
  import {useKeyboards} from './useKeyboards';
16
14
  import {Shortcut} from './shortcuts';
17
- import {usePosition} from './usePosition';
18
- import {useMergeRange} from './useMergeRange';
19
-
15
+ import {useHighlight} from './useHighlight';
16
+ // import {useMergeRange} from './useMergeRange';
20
17
  import {
21
18
  BasePicker,
22
19
  BasePickerProps,
23
20
  BasePickerEvents,
24
21
  BasePickerBlocks,
25
- Value
26
22
  } from './basepicker';
23
+ import {Value} from './useValueBase';
24
+ import { useConfirm } from './useConfirm';
27
25
 
28
26
  export * as shortcuts from './shortcuts';
29
27
  export { dayjs };
@@ -35,7 +33,7 @@ export interface DatepickerProps<
35
33
  > extends BasePickerProps<V extends string ? V : V | string, M, R> {
36
34
  type?: 'date' | 'datetime' | 'year' | 'month' | 'week' | 'quarter'
37
35
  shortcuts?: Shortcut[],
38
- isMerge?: boolean
36
+ // isMerge?: boolean
39
37
  }
40
38
 
41
39
  export interface DatepickerEvents extends BasePickerEvents { }
@@ -49,13 +47,13 @@ const typeDefs: Required<TypeDefs<DatepickerProps>> = {
49
47
  ...BasePicker.typeDefs,
50
48
  type: ['date', 'datetime', 'year', 'month', 'week', 'quarter'],
51
49
  shortcuts: Array,
52
- isMerge: Boolean
50
+ // isMerge: Boolean
53
51
  };
54
52
 
55
53
  const defaults = (): Partial<DatepickerProps> => ({
56
54
  ...BasePicker.defaults(),
57
55
  type: 'date',
58
- isMerge: false
56
+ // isMerge: false
59
57
  });
60
58
 
61
59
  export class Datepicker<
@@ -68,18 +66,18 @@ export class Datepicker<
68
66
  static defaults = defaults;
69
67
 
70
68
  public formats = useFormats();
71
- public disabled = useDisabled(this.formats);
69
+ public disabled = useDisabled(this.formats, () => this.highlight.position);
72
70
  public panel = usePanel();
73
71
  public focusDate = useFocusDate();
74
- public value = useValue(this.formats, this.disabled, this.panel);
75
- public activePosition = usePosition();
76
- public mergeRange = useMergeRange(this.formats);
72
+ public value = useValue(this.formats, this.disabled, this.panel, () => this.highlight.position);
73
+ public highlight = useHighlight(this.value.value, this.formats.getShowString, this.input.keywords);
74
+ // public mergeRange = useMergeRange(this.formats);
75
+ private confirm = useConfirm(this.highlight, this.value, this.formats.getValueString);
77
76
 
78
77
  init() {
79
78
  super.init();
80
79
  provide(DATEPICKER, this);
81
80
  useKeyboards(this.panel.startRef, this.focusDate.focusDate);
82
- this.activePosition.setupEventListeners();
83
81
  }
84
82
 
85
83
  protected getPlaceholder() {
@@ -90,37 +88,22 @@ export class Datepicker<
90
88
  case 'datetime':
91
89
  return range ? _$('开始时间 ~ 结束时间') : _$('请选择日期和时间');
92
90
  case 'year':
93
- return _$('请选择年份');
91
+ return range ? _$('开始年份 ~ 结束年份') : _$('请选择年份');
94
92
  case 'month':
95
- return _$('请选择月份');
93
+ return range ? _$('开始月份 ~ 结束月份') : _$('请选择月份');
96
94
  case 'week':
97
- return _$('请选择周');
95
+ return range ? _$('开始周 ~ 结束周') : _$('请选择周');
98
96
  case 'quarter':
99
- return _$('请选择季度');
97
+ return range ? _$('开始季度 ~ 结束季度') : _$('请选择季度');
100
98
  default:
101
99
  return range ? _$('开始日期 ~ 结束日期') : _$('请选择日期');
102
100
  }
103
101
  }
104
102
 
105
103
  protected getLabel() {
106
- const {multiple} = this.get();
107
- if(multiple) {
108
- const results = this.value.format();
109
- const dayjsValue = this.value.getDayjsValue();
110
- return this.mergeRange.formatMultipleValues(dayjsValue, results as string[]);
111
- }
112
104
  return this.value.format();
113
105
  }
114
106
 
115
- @bind
116
- protected clear(e: MouseEvent) {
117
- super.clear(e);
118
- if (this.get('type') === 'datetime') {
119
- // reset the state to let user re-select
120
- this.panel.reset();
121
- }
122
- }
123
-
124
107
  @bind
125
108
  private setByShortcut(shortcut: Shortcut) {
126
109
  const {setValue, convertToDayjs} = this.value;
@@ -5,26 +5,26 @@ import {DatepickerTime} from './time';
5
5
  import {Icon} from '../icon';
6
6
  import {Button} from '../button';
7
7
  import {_$} from '../../i18n';
8
- import {makePanelStyles, makeDatePickRangeStyles} from './styles';
9
- import {PanelTypes, PanelFlags} from './usePanel';
8
+ import {makeStyles, makePanelStyles, makeHighlightStyles} from './styles';
9
+ import {PanelFlags} from './usePanel';
10
10
  import {isFunction} from 'intact-shared';
11
11
  import {Tabs, Tab} from '../tabs';
12
+ import {Position} from './useHighlight';
12
13
 
13
- const {className, type, range, multiple, shortcuts} = this.get();
14
+ const { k } = this.config;
15
+ const {className, type, range, multiple, shortcuts, size} = this.get();
14
16
  const {
15
17
  value: {value},
16
18
  onChangeDate,
17
- onConfirm,
19
+ /* onConfirm, */
18
20
  onChangeTime,
19
21
  onChangeDateForRange,
20
22
  getTimeValue,
21
23
  } = this.value;
22
- const { position, charLength, startTextLength, handleInputClick } = this.activePosition
23
- const { k } = this.config;
24
- const showPanel = range && position.value === 'end';
25
- const positionDisplay = !multiple && range && (type === 'datetime' || type === 'date');
24
+ const { onConfirm } = this.confirm;
25
+ const { position, handleInputClick, highlightWidth, highlightLeft } = this.highlight;
26
26
  // 判断是否显示双面板
27
- const showDualPanels = range && (type === 'date' || type === 'month' || type === 'year')
27
+ const showDualPanels = range && type !== 'datetime';
28
28
 
29
29
  const classNameObj = {
30
30
  [`${k}-datepicker-content`]: true,
@@ -33,22 +33,12 @@ const classNameObj = {
33
33
  };
34
34
  const classDatePickerObj = {
35
35
  [`${k}-datepicker`]: true,
36
- [makeDatePickRangeStyles(k, position.value, positionDisplay, charLength.value, startTextLength.value)]: true,
36
+ [makeHighlightStyles(k, size, highlightWidth.value, highlightLeft.value)]: range,
37
+ [makeStyles(k)]: true,
37
38
  }
38
39
  const {isDisabledTime, isDisabledConfirm} = this.disabled;
39
- const {startPanel, endPanel, getPanel, startRef, endRef} = this.panel;
40
+ const {startRef, endRef} = this.panel;
40
41
  const generatePanel = (flag) => {
41
- const panel = getPanel(flag);
42
- const timeValue = getTimeValue(flag);
43
- let dateString = '0000-00-00';
44
- let timeString = '00:00:00';
45
-
46
- if (type === 'datetime' && timeValue) {
47
- const valueString = this.formats.getShowString(timeValue).split(/\s+/);
48
- dateString = valueString[0];
49
- timeString = valueString[1];
50
- }
51
-
52
42
  return (
53
43
  <div class={`${k}-datepicker-calendar-time-wrapper`}>
54
44
  <DatepickerCalendar
@@ -57,22 +47,38 @@ const generatePanel = (flag) => {
57
47
  type={type === 'datetime' ? 'date' : type}
58
48
  flag={flag}
59
49
  ref={flag === PanelFlags.Start ? startRef : endRef}
50
+ highlightPosition={position.value}
60
51
  />
61
- <div class={`${k}-datepicker-time-wrapper`} v-if={type === 'datetime'}>
62
- <div class={`${k}-datepicker-time-time`}>{timeString}</div>
63
- <DatepickerTime
64
- value={timeValue}
65
- ev-$change:value={v => onChangeTime(v, flag)}
66
- format={this.formats.getValueFormat()}
67
- flag={flag}
68
- isDisabledTime={isDisabledTime}
69
- />
70
- </div>
52
+ <div class={`${k}-datepicker-time-wrapper`} v-if={type === 'datetime'}>{
53
+ (() => {
54
+ let timeValue = getTimeValue(flag);
55
+ if (flag === PanelFlags.End && !timeValue) {
56
+ timeValue = getTimeValue(PanelFlags.Start);
57
+ }
58
+ let timeString = '00:00:00';
59
+
60
+ if (timeValue) {
61
+ const valueString = this.formats.getShowString(timeValue).split(/\s+/);
62
+ timeString = valueString[1];
63
+ }
64
+
65
+ return <template>
66
+ <div class={`${k}-datepicker-time-time`}>{timeString}</div>
67
+ <DatepickerTime
68
+ value={timeValue}
69
+ ev-$change:value={v => onChangeTime(v, flag)}
70
+ format={this.formats.getValueFormat()}
71
+ flag={flag}
72
+ isDisabledTime={isDisabledTime}
73
+ />
74
+ </template>
75
+ })()
76
+ }</div>
71
77
  </div>
72
78
  );
73
79
  };
74
80
 
75
- <t:super class={classDatePickerObj} onClick={handleInputClick}>
81
+ <t:super class={classDatePickerObj} onClick={handleInputClick} alwaysShowOnClick={true}>
76
82
  <b:base-menu>
77
83
  <DropdownMenu class={classNameObj}>
78
84
  <div class={`${k}-datepicker-shortcuts`} v-if={shortcuts && shortcuts.length}>
@@ -86,8 +92,8 @@ const generatePanel = (flag) => {
86
92
  </div>
87
93
  <div class={`${k}-datepicker-wrapper`}>
88
94
  <div class={`${k}-datepicker-calendars`}>
89
- { showDualPanels ? generatePanel(PanelFlags.Start) : (showPanel ? null : generatePanel(PanelFlags.Start))}
90
- { showDualPanels ? generatePanel(PanelFlags.End) : (showPanel ? generatePanel(PanelFlags.End) : null)}
95
+ {generatePanel(!showDualPanels && position.value === Position.End ? PanelFlags.End : PanelFlags.Start)}
96
+ {showDualPanels ? generatePanel(PanelFlags.End) : null}
91
97
  </div>
92
98
  <div v-if={type === 'datetime'} class={`${k}-datepicker-footer`}>
93
99
  <Button type="primary" size="small"
@@ -1,6 +1,6 @@
1
1
  import {Children} from 'intact';
2
2
  import {_$} from '../../i18n';
3
- import {Value} from './basepicker';
3
+ import {Value} from './useValueBase';
4
4
 
5
5
  export type Shortcut = {
6
6
  label: (() => Children) | Children
@@ -3,6 +3,7 @@ import {theme, setDefault} from '../../styles/theme';
3
3
  import {deepDefaults, sizes, Sizes, getRight, getLeft, palette} from '../../styles/utils';
4
4
  import '../../styles/global';
5
5
  import { cache } from '../utils';
6
+ import { select } from '../select/styles';
6
7
 
7
8
  const defaults = {
8
9
  width: `300px`,
@@ -81,10 +82,21 @@ setDefault(() => {
81
82
  makePanelStyles?.clearCache();
82
83
  makeCalendarStyles?.clearCache();
83
84
  makeTimeStyles?.clearCache();
85
+ makeHighlightStyles?.clearCache();
84
86
  });
85
87
 
86
88
  export {datepicker};
87
89
 
90
+ export const makeStyles = cache((k: string) => {
91
+ return css`
92
+ &.${k}-dropdown-open {
93
+ .${k}-input-inner {
94
+ color: ${theme.color.placeholder};
95
+ }
96
+ }
97
+ `;
98
+ });
99
+
88
100
  export const makePanelStyles = cache(function makePanelStyles(k: string) {
89
101
  return css`
90
102
  display: flex;
@@ -298,29 +310,26 @@ export const makeTimeStyles = cache(function makeTimeStyles(k: string) {
298
310
  position: relative;
299
311
  .${k}-scroll-select {
300
312
  flex: 1;
301
- height: 305px;
313
+ height: 265px;
302
314
  }
303
315
  `;
304
316
  });
305
317
 
306
- export const makeDatePickRangeStyles = cache(function makeTimeStyles(k: string, activePositionValue: string, display: boolean, charLength: number = 10, startTextLength: number = 10) {
307
- const displayType = display ? 'block' : 'none';
308
- const charWidthPx = 8;
309
- const highlightWidthPx = charLength * charWidthPx;
310
-
311
- // 计算结束文本的起始位置 - 紧接着开始文本
312
- const endTextStartPos = startTextLength * charWidthPx;
313
-
318
+ export const makeHighlightStyles = cache(function makeHighlightStyles(k: string, size: Sizes, highlightWidth: number, highlightLeft: number) {
319
+ const paddingLeft = getLeft(select[size].padding);
314
320
  return css`
315
- &:hover:before, &:focus:before{
316
- content: '';
317
- display: ${displayType};
318
- width: ${highlightWidthPx}px;
319
- height: 1px;
320
- position: absolute;
321
- background-color: ${datepicker.item.active.bgColor};
322
- left: ${activePositionValue === 'start' ? '0' : endTextStartPos + 'px'};
323
- bottom: 0;
321
+ &.${k}-dropdown-open {
322
+ &:before {
323
+ content: '';
324
+ display: block;
325
+ width: ${highlightWidth ? highlightWidth + 'px' : '50%'};
326
+ height: 1px;
327
+ position: absolute;
328
+ background-color: ${datepicker.item.active.bgColor};
329
+ left: calc(${paddingLeft} + ${highlightLeft}px);
330
+ bottom: 0;
331
+ transition: left ${theme.transition.middle};
332
+ }
324
333
  }
325
334
  `;
326
335
  });
@@ -0,0 +1,82 @@
1
+ import {useInstance, Component, TypeDefs} from 'intact';
2
+ import {useState, watchState, State} from '../../hooks/useState';
3
+ import dayjs, {Dayjs, OpUnitType, QUnitType} from './dayjs';
4
+ import {findValueIndex} from './helpers';
5
+ import type {useFormats} from './useFormats';
6
+ import type {useDisabled} from './useDisabled';
7
+ import {isEqualArray, last, bind} from '../utils';
8
+ import {PanelFlags, usePanel} from './usePanel';
9
+ import type {BasePicker, BasePickerProps} from './basepicker';
10
+ import type { Datepicker } from '.';
11
+ import { Position, useHighlight } from './useHighlight';
12
+ import { useValue } from './useValue';
13
+ import { StateValueRange, StateValue, DayjsValueRange } from './useValueBase';
14
+
15
+ export function useConfirm(
16
+ highlight: ReturnType<typeof useHighlight>,
17
+ value: ReturnType<typeof useValue>,
18
+ getValueString: ReturnType<typeof useFormats>['getValueString'],
19
+ ) {
20
+ const instance = useInstance() as Datepicker;
21
+ let selectionState = [false, false];
22
+
23
+ /**
24
+ * can not use hide event to do it
25
+ * because value will be reset to dayjsValue on hide in useValue
26
+ */
27
+ instance.on('$change:show', (show) => {
28
+ if (!show) {
29
+ reset();
30
+ if (instance.get('range') && hasWholeRangeValue()) {
31
+ // to fix the order
32
+ value.updateValue();
33
+ }
34
+ }
35
+ });
36
+
37
+ instance.on('selecting', () => {
38
+ const { type } = instance.get();
39
+ if (type !== 'datetime') {
40
+ onConfirm();
41
+ }
42
+ });
43
+
44
+ function reset() {
45
+ selectionState = [false, false];
46
+ }
47
+
48
+ function onConfirm() {
49
+ const { multiple, range } = instance.get();
50
+ if (range) {
51
+ const position = highlight.position.value;
52
+ selectionState[position] = true;
53
+
54
+ if (selectionState.every(state => state)) {
55
+ if (!multiple) {
56
+ instance.hide();
57
+ } else {
58
+ // update value directly on multiple mode
59
+ reset();
60
+ value.unique();
61
+ value.updateValue();
62
+ }
63
+ }
64
+
65
+ highlight.togglePosition();
66
+ } else {
67
+ if (!multiple) {
68
+ instance.hide();
69
+ } else {
70
+ value.unique();
71
+ }
72
+ value.updateValue();
73
+ }
74
+ }
75
+
76
+ function hasWholeRangeValue() {
77
+ const lastValue = last(value.value.value) as StateValueRange;
78
+ return lastValue && lastValue.length === 2;
79
+ }
80
+
81
+ return { onConfirm }
82
+ }
@@ -5,10 +5,14 @@ import type {Datepicker} from './index';
5
5
  import {isNullOrUndefined} from 'intact-shared';
6
6
  import {isGT, isLT, last} from './helpers';
7
7
  import type {useFormats} from './useFormats';
8
- import {PanelFlags, PanelTypes} from './usePanel';
9
- import {Value} from './basepicker';
8
+ import {PanelFlags} from './usePanel';
9
+ import {Value, StateValueRange, StateValueItem} from './useValueBase';
10
+ import { Position } from './useHighlight';
10
11
 
11
- export function useDisabled({createDateByValueFormat}: ReturnType<typeof useFormats>) {
12
+ export function useDisabled(
13
+ {createDateByValueFormat}: ReturnType<typeof useFormats>,
14
+ getHighlightPosition?: () => State<Position>
15
+ ) {
12
16
  const instance = useInstance() as Datepicker;
13
17
  const maxDate = useState<Dayjs | null>(null);
14
18
  const minDate = useState<Dayjs | null>(null);
@@ -35,50 +39,44 @@ export function useDisabled({createDateByValueFormat}: ReturnType<typeof useForm
35
39
  !!disabledDate && disabledDate(value);
36
40
  }
37
41
 
38
- function isDisabledTime(value: Dayjs, flag: PanelFlags): boolean {
39
- if (!isDisabled(value, 'second')) {
40
- if (!instance.get('range')) return false;
41
-
42
- // compare the start and the end datetime
43
- const anotherDatetime = instance.value.getTimeValue(
44
- flag === PanelFlags.Start ? PanelFlags.End : PanelFlags.Start
45
- );
46
- if (!anotherDatetime) return false;
47
- if (flag === PanelFlags.Start) {
48
- return value.isAfter(anotherDatetime, 'second');
49
- } else {
50
- return value.isBefore(anotherDatetime, 'second');
51
- }
52
- }
53
- return true;
42
+ function isDisabledTime(value: Dayjs): boolean {
43
+ return isDisabled(value, 'second');
54
44
  }
55
45
 
56
46
  function isDisabledConfirm(): boolean {
57
47
  const lastValue = last(instance.value.value.value);
58
- if (!lastValue) return true;
48
+ const {range, multiple} = instance.get();
49
+ if (!lastValue || instance.value.allValuesUpdatedInMultipleMode()) return true;
59
50
 
60
- const {range} = instance.get();
61
- if (range && (lastValue as [Dayjs, Dayjs?]).length === 1) return false;
62
-
63
- const {startPanel, endPanel} = instance.panel;
64
- if (startPanel.value === PanelTypes.Date && endPanel.value === PanelTypes.Date) {
65
- return true;
51
+ if (range && getHighlightPosition) {
52
+ const position = getHighlightPosition();
53
+ // if the position is not selected, it should be disabled
54
+ if (!(lastValue as StateValueRange)[position.value]) {
55
+ return true;
56
+ }
66
57
  }
67
58
 
59
+ return isDisabledValue(lastValue);
60
+ }
61
+
62
+ function isDisabledValue(value: StateValueItem): boolean {
63
+ const { range } = instance.get();
68
64
  let start: Dayjs;
69
65
  let end: Dayjs | undefined;
66
+
70
67
  if (range) {
71
- start = (lastValue as [Dayjs, Dayjs])[0];
72
- end = (lastValue as [Dayjs, Dayjs])[1];
68
+ start = (value as [Dayjs, Dayjs])[0];
69
+ end = (value as [Dayjs, Dayjs])[1];
73
70
  } else {
74
- start = lastValue as Dayjs;
71
+ start = value as Dayjs;
75
72
  }
76
- if (isDisabledTime(start, PanelFlags.Start) || end && isDisabledTime(end, PanelFlags.End)) {
73
+
74
+ if (isDisabledTime(start) || end && isDisabledTime(end)) {
77
75
  return true;
78
76
  }
79
77
 
80
78
  return false;
81
79
  }
82
80
 
83
- return {isDisabled, isDisabledTime, isDisabledConfirm, maxDate, minDate};
81
+ return {isDisabled, isDisabledTime, isDisabledConfirm, isDisabledValue, maxDate, minDate};
84
82
  }
@@ -1,8 +1,8 @@
1
1
  import {useInstance} from 'intact';
2
- import dayjs, {Dayjs} from './dayjs';
2
+ import dayjs, {Dayjs} from 'dayjs';
3
3
  import {isString} from 'intact-shared';
4
4
  import type {Datepicker} from './index';
5
- import {Value} from './basepicker';
5
+ import type {Value} from './useValueBase';
6
6
 
7
7
  const FORMATS = {
8
8
  date: 'YYYY-MM-DD',
@@ -25,9 +25,13 @@ export function useFormats() {
25
25
  const {format, showFormat, type} = instance.get();
26
26
  return showFormat || format || FORMATS[type!];
27
27
  }
28
-
28
+
29
+ /**
30
+ * 根据日期字符串,按照格式创建日期对象
31
+ */
29
32
  function createDateByValueFormat(value: Value) {
30
- return dayjs(value, isString(value) ? getValueFormat() : undefined);
33
+ const format = isString(value) ? getValueFormat() : undefined;
34
+ return dayjs(value, format);
31
35
  }
32
36
 
33
37
  function createDateByShowFormat(value: string) {
@@ -0,0 +1,81 @@
1
+ import {useInstance, onMounted, nextTick} from 'intact';
2
+ import type {Datepicker} from '.';
3
+ import { useState, watchState, State } from '../../hooks/useState';
4
+ import {last} from '../utils';
5
+ import { StateValue, StateValueRange, Value } from './useValueBase';
6
+ import dayjs, {Dayjs} from 'dayjs';
7
+
8
+ type FullDatepickerType =
9
+ | Datepicker<Value, true, true>
10
+ | Datepicker<Value, true, false>
11
+ | Datepicker<Value, false, true>
12
+ | Datepicker<Value, false, false>;
13
+
14
+ export enum Position {
15
+ Start,
16
+ End
17
+ }
18
+
19
+ const DELIMITER_WIDTH = 14;
20
+ const fakeDate = dayjs();
21
+
22
+ export function useHighlight(
23
+ value: State<StateValue>,
24
+ getShowString: (value: Dayjs) => string,
25
+ keywords: State<string>,
26
+ ) {
27
+ const instance = useInstance() as FullDatepickerType;
28
+ const position = useState<Position>(Position.Start);
29
+ const highlightWidth = useState<number>(0);
30
+ const highlightLeft = useState<number>(0);
31
+
32
+ /**
33
+ * calculate the real width by rendering the showString to fake div
34
+ */
35
+ onMounted(() => {
36
+ const showString = getShowString(fakeDate);
37
+ instance.input.inputRef.value!.getStringWidth(showString).then((width) => {
38
+ highlightWidth.set(width);
39
+ });
40
+ });
41
+
42
+ /**
43
+ * change the left of style on position changed
44
+ */
45
+ watchState(position, (position) => {
46
+ highlightLeft.set(position === Position.Start ? 0 : highlightWidth.value + DELIMITER_WIDTH);
47
+ });
48
+
49
+ // if value is cleared reset the position to start
50
+ instance.watch('value', (v) => {
51
+ if (!v || Array.isArray(v) && !v.length) {
52
+ position.set(Position.Start);
53
+ }
54
+ });
55
+
56
+ function handleInputClick() {
57
+ const { range, type } = instance.get();
58
+ if (!range) return;
59
+
60
+ const cursorPosition = instance.input.inputRef.value!.getSelectionStart();
61
+
62
+ const showString = getShowString(fakeDate);
63
+ if (!cursorPosition || cursorPosition <= showString.length + 1 /* one whitespace */) {
64
+ position.set(Position.Start);
65
+ } else {
66
+ position.set(Position.End);
67
+ }
68
+ }
69
+
70
+ function togglePosition() {
71
+ position.set(position.value === Position.Start ? Position.End : Position.Start);
72
+ }
73
+
74
+ return {
75
+ position,
76
+ handleInputClick,
77
+ togglePosition,
78
+ highlightWidth,
79
+ highlightLeft,
80
+ };
81
+ }
@@ -92,7 +92,8 @@ export function useKeyboards(
92
92
  }
93
93
 
94
94
  let _focusDate = focusDate.value;
95
- _focusDate = _focusDate.add(offset, type === 'date' ? 'day' : type);
95
+ const unit = type === 'date' ? 'day' : type;
96
+ _focusDate = _focusDate.add(offset, unit as any);
96
97
  focusDate.set(_focusDate);
97
98
 
98
99
  // change panel show date
@@ -1,10 +1,10 @@
1
1
  import {useInstance} from 'intact';
2
2
  import {Dayjs} from './dayjs';
3
3
  import type {Datepicker} from './index';
4
- import {DayjsValueRange, DayjsValue} from './basepicker';
4
+ import {DayjsValueRange, DayjsValue} from './useValueBase';
5
5
  import type {useFormats} from './useFormats';
6
6
 
7
-
7
+ // TODO isMerge
8
8
  export function useMergeRange(formats: ReturnType<typeof useFormats>) {
9
9
  const instance = useInstance() as Datepicker;
10
10
 
@@ -33,17 +33,17 @@ export function useMergeRange(formats: ReturnType<typeof useFormats>) {
33
33
  }
34
34
 
35
35
  function formatMultipleValues(dayjsValue: DayjsValue, results: string[]): string[] {
36
- const {isMerge, nowrap} = instance.get();
36
+ // const {isMerge, nowrap} = instance.get();
37
37
 
38
- if (isMerge && nowrap) {
39
- const mergedResults = _mergeRanges(dayjsValue, (v: Dayjs) => v.format(formats.getShowFormat()));
40
- if (mergedResults.length > 0) {
41
- return [
42
- ...mergedResults,
43
- ...results.slice(1).map((result, index) => `${result}-${index}`)
44
- ];
45
- }
46
- }
38
+ // if (isMerge && nowrap) {
39
+ // const mergedResults = _mergeRanges(dayjsValue, (v: Dayjs) => v.format(formats.getShowFormat()));
40
+ // if (mergedResults.length > 0) {
41
+ // return [
42
+ // ...mergedResults,
43
+ // ...results.slice(1).map((result, index) => `${result}-${index}`)
44
+ // ];
45
+ // }
46
+ // }
47
47
 
48
48
  return results;
49
49
  }