@king-design/intact 3.5.2 → 3.6.0

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 (260) hide show
  1. package/components/.DS_Store +0 -0
  2. package/components/button/index.md +1 -0
  3. package/components/cascader/index.spec.ts +7 -6
  4. package/components/datepicker/basepicker.ts +26 -267
  5. package/components/datepicker/calendar.ts +8 -2
  6. package/components/datepicker/calendar.vdt +23 -6
  7. package/components/datepicker/dayjs.ts +8 -2
  8. package/components/datepicker/demos/multiple.md +1 -1
  9. package/components/datepicker/demos/yearMonth.md +1 -1
  10. package/components/datepicker/helpers.ts +10 -12
  11. package/components/datepicker/index.md +2 -2
  12. package/components/datepicker/index.spec.ts +619 -190
  13. package/components/datepicker/index.ts +22 -21
  14. package/components/datepicker/index.vdt +47 -42
  15. package/components/datepicker/shortcuts.ts +1 -1
  16. package/components/datepicker/styles.ts +112 -4
  17. package/components/datepicker/useConfirm.ts +82 -0
  18. package/components/datepicker/useDisabled.ts +31 -33
  19. package/components/datepicker/useFormats.ts +10 -4
  20. package/components/datepicker/useHighlight.ts +81 -0
  21. package/components/datepicker/useKeyboards.ts +2 -1
  22. package/components/datepicker/useMergeRange.ts +54 -0
  23. package/components/datepicker/useMonths.ts +6 -3
  24. package/components/datepicker/usePanel.ts +19 -19
  25. package/components/datepicker/useQuarters.ts +47 -0
  26. package/components/datepicker/useShowDate.ts +14 -3
  27. package/components/datepicker/useStatus.ts +34 -15
  28. package/components/datepicker/useValue.ts +41 -39
  29. package/components/datepicker/useValueBase.ts +309 -0
  30. package/components/datepicker/useWeeks.ts +58 -0
  31. package/components/datepicker/useYears.ts +7 -3
  32. package/components/descriptions/.DS_Store +0 -0
  33. package/components/dialog/useFixBody.ts +7 -64
  34. package/components/dropdown/dropdown.ts +5 -4
  35. package/components/dropdown/index.md +1 -0
  36. package/components/dropdown/item.ts +1 -1
  37. package/components/dropdown/useKeyboard.ts +0 -1
  38. package/components/ellipsis/styles.ts +4 -0
  39. package/components/form/styles.ts +1 -0
  40. package/components/input/index.spec.ts +42 -0
  41. package/components/input/index.ts +8 -0
  42. package/components/input/index.vdt +3 -4
  43. package/components/input/useAutoWidth.ts +19 -1
  44. package/components/menu/.DS_Store +0 -0
  45. package/components/menu/demos/.DS_Store +0 -0
  46. package/components/scrollSelect/index.spec.ts +3 -3
  47. package/components/scrollSelect/useMouseEvents.ts +24 -10
  48. package/components/select/base.ts +3 -2
  49. package/components/select/base.vdt +3 -1
  50. package/components/select/demos/creatable.md +13 -0
  51. package/components/select/index.md +1 -0
  52. package/components/select/index.spec.ts +225 -6
  53. package/components/select/option.ts +10 -1
  54. package/components/select/select.ts +3 -0
  55. package/components/select/styles.ts +3 -1
  56. package/components/select/useFilterable.ts +1 -1
  57. package/components/select/useInput.ts +7 -9
  58. package/components/select/useSearchable.ts +2 -2
  59. package/components/table/.DS_Store +0 -0
  60. package/components/table/index.spec.ts +69 -1
  61. package/components/table/useStickyHeader.ts +1 -1
  62. package/components/timepicker/demos/step.md +1 -1
  63. package/components/timepicker/index.spec.ts +145 -27
  64. package/components/timepicker/panelPicker.ts +10 -4
  65. package/components/timepicker/panelPicker.vdt +5 -3
  66. package/components/timepicker/useConfirm.ts +33 -0
  67. package/components/timepicker/useDefaultValue.ts +30 -0
  68. package/components/timepicker/useDisabled.ts +17 -4
  69. package/components/timepicker/useFormats.ts +1 -1
  70. package/components/timepicker/useValue.ts +22 -19
  71. package/components/tour/.DS_Store +0 -0
  72. package/components/tour/demos/basic.md +73 -0
  73. package/components/tour/demos/beforeChange.md +109 -0
  74. package/components/tour/demos/closable.md +70 -0
  75. package/components/tour/demos/custom.md +98 -0
  76. package/components/tour/demos/customText.md +94 -0
  77. package/components/tour/demos/declarative.md +72 -0
  78. package/components/tour/demos/events.md +101 -0
  79. package/components/tour/demos/maskClosable.md +76 -0
  80. package/components/tour/demos/notarget.md +59 -0
  81. package/components/tour/index.md +48 -0
  82. package/components/tour/index.spec.ts +259 -0
  83. package/components/tour/index.ts +2 -0
  84. package/components/tour/step.ts +55 -0
  85. package/components/tour/step.vdt +75 -0
  86. package/components/tour/styles.ts +283 -0
  87. package/components/tour/tour.ts +107 -0
  88. package/components/tour/tour.vdt +83 -0
  89. package/components/tour/useArrow.ts +46 -0
  90. package/components/tour/useFixBody.ts +22 -0
  91. package/components/tour/useHighlight.ts +36 -0
  92. package/components/tour/useMaskClosable.ts +26 -0
  93. package/components/tour/useNavigation.ts +46 -0
  94. package/components/tour/usePosition.ts +91 -0
  95. package/components/tour/useSteps.ts +80 -0
  96. package/components/virtualList/.DS_Store +0 -0
  97. package/components/virtualList/demos/.DS_Store +0 -0
  98. package/es/components/cascader/index.spec.js +18 -19
  99. package/es/components/datepicker/basepicker.d.ts +6 -25
  100. package/es/components/datepicker/basepicker.js +22 -234
  101. package/es/components/datepicker/calendar.d.ts +36 -6
  102. package/es/components/datepicker/calendar.js +4 -0
  103. package/es/components/datepicker/calendar.vdt.js +21 -5
  104. package/es/components/datepicker/dayjs.d.ts +2 -2
  105. package/es/components/datepicker/dayjs.js +6 -0
  106. package/es/components/datepicker/helpers.d.ts +8 -7
  107. package/es/components/datepicker/helpers.js +2 -3
  108. package/es/components/datepicker/index.d.ts +26 -19
  109. package/es/components/datepicker/index.js +21 -13
  110. package/es/components/datepicker/index.spec.js +1389 -633
  111. package/es/components/datepicker/index.vdt.js +43 -46
  112. package/es/components/datepicker/shortcuts.d.ts +1 -1
  113. package/es/components/datepicker/styles.d.ts +22 -0
  114. package/es/components/datepicker/styles.js +26 -4
  115. package/es/components/datepicker/useConfirm.d.ts +6 -0
  116. package/es/components/datepicker/useConfirm.js +65 -0
  117. package/es/components/datepicker/useDisabled.d.ts +7 -5
  118. package/es/components/datepicker/useDisabled.js +22 -27
  119. package/es/components/datepicker/useFormats.d.ts +2 -2
  120. package/es/components/datepicker/useFormats.js +9 -3
  121. package/es/components/datepicker/useHighlight.d.ts +14 -0
  122. package/es/components/datepicker/useHighlight.js +60 -0
  123. package/es/components/datepicker/useKeyboards.js +2 -1
  124. package/es/components/datepicker/useMergeRange.d.ts +5 -0
  125. package/es/components/datepicker/useMergeRange.js +45 -0
  126. package/es/components/datepicker/useMonths.js +5 -3
  127. package/es/components/datepicker/usePanel.d.ts +1 -10
  128. package/es/components/datepicker/usePanel.js +19 -32
  129. package/es/components/datepicker/useQuarters.d.ts +15 -0
  130. package/es/components/datepicker/useQuarters.js +36 -0
  131. package/es/components/datepicker/useShowDate.js +10 -2
  132. package/es/components/datepicker/useStatus.d.ts +1 -1
  133. package/es/components/datepicker/useStatus.js +33 -16
  134. package/es/components/datepicker/useValue.d.ts +12 -6
  135. package/es/components/datepicker/useValue.js +49 -45
  136. package/es/components/datepicker/useValueBase.d.ts +28 -0
  137. package/es/components/datepicker/useValueBase.js +277 -0
  138. package/es/components/datepicker/useWeeks.d.ts +19 -0
  139. package/es/components/datepicker/useWeeks.js +48 -0
  140. package/es/components/datepicker/useYears.js +6 -3
  141. package/es/components/dialog/useFixBody.js +6 -58
  142. package/es/components/dropdown/dropdown.d.ts +1 -0
  143. package/es/components/dropdown/dropdown.js +7 -4
  144. package/es/components/ellipsis/styles.js +1 -1
  145. package/es/components/form/styles.js +1 -1
  146. package/es/components/input/index.d.ts +2 -0
  147. package/es/components/input/index.js +6 -0
  148. package/es/components/input/index.spec.js +45 -0
  149. package/es/components/input/index.vdt.js +4 -3
  150. package/es/components/input/useAutoWidth.d.ts +2 -0
  151. package/es/components/input/useAutoWidth.js +19 -1
  152. package/es/components/scrollSelect/index.spec.js +4 -6
  153. package/es/components/scrollSelect/useMouseEvents.js +22 -9
  154. package/es/components/select/base.d.ts +1 -1
  155. package/es/components/select/base.js +3 -2
  156. package/es/components/select/base.vdt.js +5 -2
  157. package/es/components/select/index.spec.js +329 -82
  158. package/es/components/select/option.d.ts +1 -0
  159. package/es/components/select/option.js +10 -2
  160. package/es/components/select/select.d.ts +1 -0
  161. package/es/components/select/select.js +4 -2
  162. package/es/components/select/styles.d.ts +79 -0
  163. package/es/components/select/styles.js +1 -0
  164. package/es/components/select/useFilterable.js +2 -1
  165. package/es/components/select/useInput.d.ts +1 -1
  166. package/es/components/select/useInput.js +7 -4
  167. package/es/components/select/useSearchable.js +1 -0
  168. package/es/components/table/index.spec.js +84 -6
  169. package/es/components/table/useStickyHeader.js +1 -1
  170. package/es/components/timepicker/index.spec.js +298 -128
  171. package/es/components/timepicker/panelPicker.d.ts +23 -17
  172. package/es/components/timepicker/panelPicker.js +7 -4
  173. package/es/components/timepicker/panelPicker.vdt.js +8 -4
  174. package/es/components/timepicker/selectPicker.d.ts +5 -4
  175. package/es/components/timepicker/useConfirm.d.ts +6 -0
  176. package/es/components/timepicker/useConfirm.js +19 -0
  177. package/es/components/timepicker/useDefaultValue.d.ts +4 -0
  178. package/es/components/timepicker/useDefaultValue.js +27 -0
  179. package/es/components/timepicker/useDisabled.d.ts +7 -4
  180. package/es/components/timepicker/useDisabled.js +13 -4
  181. package/es/components/timepicker/useFormats.d.ts +1 -1
  182. package/es/components/timepicker/useValue.d.ts +14 -8
  183. package/es/components/timepicker/useValue.js +14 -15
  184. package/es/components/tour/index.d.ts +2 -0
  185. package/es/components/tour/index.js +2 -0
  186. package/es/components/tour/index.spec.d.ts +1 -0
  187. package/es/components/tour/index.spec.js +356 -0
  188. package/es/components/tour/step.d.ts +23 -0
  189. package/es/components/tour/step.js +46 -0
  190. package/es/components/tour/step.vdt.js +74 -0
  191. package/es/components/tour/styles.d.ts +7 -0
  192. package/es/components/tour/styles.js +84 -0
  193. package/es/components/tour/tour.d.ts +73 -0
  194. package/es/components/tour/tour.js +70 -0
  195. package/es/components/tour/tour.vdt.js +66 -0
  196. package/es/components/tour/useArrow.d.ts +4 -0
  197. package/es/components/tour/useArrow.js +40 -0
  198. package/es/components/tour/useFixBody.d.ts +4 -0
  199. package/es/components/tour/useFixBody.js +17 -0
  200. package/es/components/tour/useHighlight.d.ts +4 -0
  201. package/es/components/tour/useHighlight.js +31 -0
  202. package/es/components/tour/useMaskClosable.d.ts +1 -0
  203. package/es/components/tour/useMaskClosable.js +25 -0
  204. package/es/components/tour/useNavigation.d.ts +5 -0
  205. package/es/components/tour/useNavigation.js +103 -0
  206. package/es/components/tour/usePosition.d.ts +6 -0
  207. package/es/components/tour/usePosition.js +93 -0
  208. package/es/components/tour/useSteps.d.ts +6 -0
  209. package/es/components/tour/useSteps.js +68 -0
  210. package/es/hooks/useFixBody.d.ts +11 -0
  211. package/es/hooks/useFixBody.js +72 -0
  212. package/es/index.d.ts +3 -2
  213. package/es/index.js +3 -2
  214. package/es/site/data/components/datepicker/demos/multiple/react.js +2 -2
  215. package/es/site/data/components/select/demos/creatable/index.d.ts +1 -0
  216. package/es/site/data/components/select/demos/creatable/index.js +2 -1
  217. package/es/site/data/components/select/demos/creatable/react.d.ts +1 -0
  218. package/es/site/data/components/select/demos/creatable/react.js +31 -2
  219. package/es/site/data/components/tour/demos/basic/index.d.ts +17 -0
  220. package/es/site/data/components/tour/demos/basic/index.js +46 -0
  221. package/es/site/data/components/tour/demos/basic/react.d.ts +16 -0
  222. package/es/site/data/components/tour/demos/basic/react.js +82 -0
  223. package/es/site/data/components/tour/demos/beforeChange/index.d.ts +20 -0
  224. package/es/site/data/components/tour/demos/beforeChange/index.js +69 -0
  225. package/es/site/data/components/tour/demos/beforeChange/react.d.ts +19 -0
  226. package/es/site/data/components/tour/demos/beforeChange/react.js +129 -0
  227. package/es/site/data/components/tour/demos/closable/index.d.ts +18 -0
  228. package/es/site/data/components/tour/demos/closable/index.js +42 -0
  229. package/es/site/data/components/tour/demos/closable/react.d.ts +17 -0
  230. package/es/site/data/components/tour/demos/closable/react.js +85 -0
  231. package/es/site/data/components/tour/demos/custom/index.d.ts +11 -0
  232. package/es/site/data/components/tour/demos/custom/index.js +35 -0
  233. package/es/site/data/components/tour/demos/custom/react.d.ts +11 -0
  234. package/es/site/data/components/tour/demos/custom/react.js +108 -0
  235. package/es/site/data/components/tour/demos/customText/index.d.ts +33 -0
  236. package/es/site/data/components/tour/demos/customText/index.js +55 -0
  237. package/es/site/data/components/tour/demos/customText/react.d.ts +33 -0
  238. package/es/site/data/components/tour/demos/customText/react.js +99 -0
  239. package/es/site/data/components/tour/demos/declarative/index.d.ts +11 -0
  240. package/es/site/data/components/tour/demos/declarative/index.js +36 -0
  241. package/es/site/data/components/tour/demos/declarative/react.d.ts +10 -0
  242. package/es/site/data/components/tour/demos/declarative/react.js +80 -0
  243. package/es/site/data/components/tour/demos/events/index.d.ts +18 -0
  244. package/es/site/data/components/tour/demos/events/index.js +58 -0
  245. package/es/site/data/components/tour/demos/events/react.d.ts +18 -0
  246. package/es/site/data/components/tour/demos/events/react.js +101 -0
  247. package/es/site/data/components/tour/demos/maskClosable/index.d.ts +18 -0
  248. package/es/site/data/components/tour/demos/maskClosable/index.js +47 -0
  249. package/es/site/data/components/tour/demos/maskClosable/react.d.ts +17 -0
  250. package/es/site/data/components/tour/demos/maskClosable/react.js +95 -0
  251. package/es/site/data/components/tour/demos/notarget/index.d.ts +11 -0
  252. package/es/site/data/components/tour/demos/notarget/index.js +35 -0
  253. package/es/site/data/components/tour/demos/notarget/react.d.ts +10 -0
  254. package/es/site/data/components/tour/demos/notarget/react.js +61 -0
  255. package/es/site/data/components/tour/index.d.ts +57 -0
  256. package/es/site/data/components/tour/index.js +32 -0
  257. package/hooks/useFixBody.ts +87 -0
  258. package/index.ts +3 -2
  259. package/package.json +2 -2
  260. package/styles/.DS_Store +0 -0
@@ -1,26 +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';
15
+ import {useHighlight} from './useHighlight';
16
+ // import {useMergeRange} from './useMergeRange';
17
17
  import {
18
18
  BasePicker,
19
19
  BasePickerProps,
20
20
  BasePickerEvents,
21
21
  BasePickerBlocks,
22
- Value
23
22
  } from './basepicker';
23
+ import {Value} from './useValueBase';
24
+ import { useConfirm } from './useConfirm';
24
25
 
25
26
  export * as shortcuts from './shortcuts';
26
27
  export { dayjs };
@@ -30,8 +31,9 @@ export interface DatepickerProps<
30
31
  M extends boolean = boolean,
31
32
  R extends boolean = boolean,
32
33
  > extends BasePickerProps<V extends string ? V : V | string, M, R> {
33
- type?: 'date' | 'datetime' | 'year' | 'month'
34
- shortcuts?: Shortcut[]
34
+ type?: 'date' | 'datetime' | 'year' | 'month' | 'week' | 'quarter'
35
+ shortcuts?: Shortcut[],
36
+ // isMerge?: boolean
35
37
  }
36
38
 
37
39
  export interface DatepickerEvents extends BasePickerEvents { }
@@ -43,13 +45,15 @@ export interface DatepickerBlocks<
43
45
 
44
46
  const typeDefs: Required<TypeDefs<DatepickerProps>> = {
45
47
  ...BasePicker.typeDefs,
46
- type: ['date', 'datetime', 'year', 'month'],
48
+ type: ['date', 'datetime', 'year', 'month', 'week', 'quarter'],
47
49
  shortcuts: Array,
50
+ // isMerge: Boolean
48
51
  };
49
52
 
50
53
  const defaults = (): Partial<DatepickerProps> => ({
51
54
  ...BasePicker.defaults(),
52
55
  type: 'date',
56
+ // isMerge: false
53
57
  });
54
58
 
55
59
  export class Datepicker<
@@ -62,11 +66,14 @@ export class Datepicker<
62
66
  static defaults = defaults;
63
67
 
64
68
  public formats = useFormats();
65
- public disabled = useDisabled(this.formats);
69
+ public disabled = useDisabled(this.formats, () => this.highlight.position);
66
70
  public panel = usePanel();
67
71
  public focusDate = useFocusDate();
68
- public value = useValue(this.formats, this.disabled, this.panel);
69
-
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);
76
+
70
77
  init() {
71
78
  super.init();
72
79
  provide(DATEPICKER, this);
@@ -75,16 +82,19 @@ export class Datepicker<
75
82
 
76
83
  protected getPlaceholder() {
77
84
  const {placeholder, type, range} = this.get();
78
-
79
85
  if (!isNullOrUndefined(placeholder)) return placeholder;
80
86
 
81
87
  switch (type) {
82
88
  case 'datetime':
83
89
  return range ? _$('开始时间 ~ 结束时间') : _$('请选择日期和时间');
84
90
  case 'year':
85
- return _$('请选择年份');
91
+ return range ? _$('开始年份 ~ 结束年份') : _$('请选择年份');
86
92
  case 'month':
87
- return _$('请选择月份');
93
+ return range ? _$('开始月份 ~ 结束月份') : _$('请选择月份');
94
+ case 'week':
95
+ return range ? _$('开始周 ~ 结束周') : _$('请选择周');
96
+ case 'quarter':
97
+ return range ? _$('开始季度 ~ 结束季度') : _$('请选择季度');
88
98
  default:
89
99
  return range ? _$('开始日期 ~ 结束日期') : _$('请选择日期');
90
100
  }
@@ -94,15 +104,6 @@ export class Datepicker<
94
104
  return this.value.format();
95
105
  }
96
106
 
97
- @bind
98
- protected clear(e: MouseEvent) {
99
- super.clear(e);
100
- if (this.get('type') === 'datetime') {
101
- // reset the state to let user re-select
102
- this.panel.reset();
103
- }
104
- }
105
-
106
107
  @bind
107
108
  private setByShortcut(shortcut: Shortcut) {
108
109
  const {setValue, convertToDayjs} = this.value;
@@ -5,75 +5,80 @@ import {DatepickerTime} from './time';
5
5
  import {Icon} from '../icon';
6
6
  import {Button} from '../button';
7
7
  import {_$} from '../../i18n';
8
- import {makePanelStyles} 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 { k } = this.config;
24
+ const { onConfirm } = this.confirm;
25
+ const { position, handleInputClick, highlightWidth, highlightLeft } = this.highlight;
26
+ // 判断是否显示双面板
27
+ const showDualPanels = range && type !== 'datetime';
28
+
23
29
  const classNameObj = {
24
30
  [`${k}-datepicker-content`]: true,
25
31
  [className]: className,
26
32
  [makePanelStyles(k)]: true,
27
33
  };
28
-
34
+ const classDatePickerObj = {
35
+ [`${k}-datepicker`]: true,
36
+ [makeHighlightStyles(k, size, highlightWidth.value, highlightLeft.value)]: range,
37
+ [makeStyles(k)]: true,
38
+ }
29
39
  const {isDisabledTime, isDisabledConfirm} = this.disabled;
30
- const {startPanel, endPanel, getPanel, startRef, endRef} = this.panel;
40
+ const {startRef, endRef} = this.panel;
31
41
  const generatePanel = (flag) => {
32
- const panel = getPanel(flag);
33
- const timeValue = getTimeValue(flag);
34
42
  return (
35
- <div class={`${k}-datepicker-calendar-wrapper`}>
36
- {(() => {
37
- if (type === 'datetime') {
38
- let dateString = '0000-00-00';
39
- let timeString = '00:00:00';
40
- if (timeValue) {
41
- const valueString = this.formats.getShowString(timeValue).split(/\s+/);
42
- dateString = valueString[0];
43
- timeString = valueString[1];
44
- }
45
- return (
46
- <Tabs type="card"
47
- value={panel.value}
48
- ev-$change:value={panel.set}
49
- >
50
- <Tab value={PanelTypes.Date}>{dateString}</Tab>
51
- <Tab value={PanelTypes.Time} disabled={!timeValue} >{timeString}</Tab>
52
- </Tabs>
53
- );
54
- }
55
- })()}
43
+ <div class={`${k}-datepicker-calendar-time-wrapper`}>
56
44
  <DatepickerCalendar
57
- v-if={panel.value === PanelTypes.Date}
58
45
  value={value}
59
46
  ev-change={onChangeDate}
60
47
  type={type === 'datetime' ? 'date' : type}
61
48
  flag={flag}
62
49
  ref={flag === PanelFlags.Start ? startRef : endRef}
50
+ highlightPosition={position.value}
63
51
  />
64
- <DatepickerTime
65
- v-else
66
- value={timeValue}
67
- ev-$change:value={v => onChangeTime(v, flag)}
68
- format={this.formats.getValueFormat()}
69
- flag={flag}
70
- isDisabledTime={isDisabledTime}
71
- />
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>
72
77
  </div>
73
78
  );
74
79
  };
75
80
 
76
- <t:super class={`${k}-datepicker`}>
81
+ <t:super class={classDatePickerObj} onClick={handleInputClick} alwaysShowOnClick={true}>
77
82
  <b:base-menu>
78
83
  <DropdownMenu class={classNameObj}>
79
84
  <div class={`${k}-datepicker-shortcuts`} v-if={shortcuts && shortcuts.length}>
@@ -87,8 +92,8 @@ const generatePanel = (flag) => {
87
92
  </div>
88
93
  <div class={`${k}-datepicker-wrapper`}>
89
94
  <div class={`${k}-datepicker-calendars`}>
90
- {generatePanel(PanelFlags.Start)}
91
- {range ? generatePanel(PanelFlags.End) : null}
95
+ {generatePanel(!showDualPanels && position.value === Position.End ? PanelFlags.End : PanelFlags.Start)}
96
+ {showDualPanels ? generatePanel(PanelFlags.End) : null}
92
97
  </div>
93
98
  <div v-if={type === 'datetime'} class={`${k}-datepicker-footer`}>
94
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`,
@@ -11,7 +12,9 @@ const defaults = {
11
12
 
12
13
  item: {
13
14
  gutter: `7px`,
15
+ yearGutter: '36px',
14
16
  height: `24px`,
17
+ rangeGutter: `17px`,
15
18
  get hoverBgColor() { return theme.color.bg },
16
19
  get exceedColor() { return theme.color.disabled },
17
20
  get todayBorder() { return `1px solid ${theme.color.border}` },
@@ -49,6 +52,19 @@ const defaults = {
49
52
  padding: `8px 16px`,
50
53
  },
51
54
 
55
+ week: {
56
+ height: `20px`,
57
+ width: `40px`,
58
+ margin: `0 0 0 10px`,
59
+ padding: `0 2px`,
60
+ currentWeek: '#eee'
61
+ },
62
+
63
+ calendarTime: {
64
+ height: `44px`,
65
+ fontSize: `14px`,
66
+ },
67
+
52
68
  shortcuts: {
53
69
  width: '100px',
54
70
  padding: '12px 0',
@@ -57,7 +73,7 @@ const defaults = {
57
73
  height: '32px',
58
74
  padding: '0 16px',
59
75
  }
60
- }
76
+ },
61
77
  };
62
78
 
63
79
  let datepicker: typeof defaults;
@@ -66,10 +82,21 @@ setDefault(() => {
66
82
  makePanelStyles?.clearCache();
67
83
  makeCalendarStyles?.clearCache();
68
84
  makeTimeStyles?.clearCache();
85
+ makeHighlightStyles?.clearCache();
69
86
  });
70
87
 
71
88
  export {datepicker};
72
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
+
73
100
  export const makePanelStyles = cache(function makePanelStyles(k: string) {
74
101
  return css`
75
102
  display: flex;
@@ -103,12 +130,26 @@ export const makePanelStyles = cache(function makePanelStyles(k: string) {
103
130
  width: 50%;
104
131
  }
105
132
  }
133
+
134
+ }
135
+ .${k}-datepicker-calendar-time-wrapper {
136
+ display: flex;
137
+ .${k}-datepicker-time-time {
138
+ height: ${datepicker.calendarTime.height};
139
+ line-height: ${datepicker.calendarTime.height};
140
+ text-align: center;
141
+ font-size: ${datepicker.calendarTime.fontSize};
142
+ }
143
+ .${k}-datepicker-time-wrapper {
144
+ overflow: hidden;
145
+ height: 320px;
146
+ }
106
147
  }
107
148
  .${k}-datepicker-footer {
108
149
  border-top: ${datepicker.border};
109
150
  padding: ${datepicker.footer.padding};
110
151
  text-align: right;
111
- }
152
+ }
112
153
  `
113
154
  });
114
155
 
@@ -207,8 +248,56 @@ export const makeCalendarStyles = cache(function makeCalendarStyles(k: string) {
207
248
  grid-template-columns: repeat(7, 1fr);
208
249
  }
209
250
  .${k}-years {
251
+ .${k}-calendar-item {
252
+ height: 20px;
253
+ width: 40px;
254
+
255
+ &.${k}-in-range:after {
256
+ width: calc(100% + 14px);
257
+ left: calc(-${datepicker.item.yearGutter} / 2);
258
+ padding: 0 calc(${datepicker.item.yearGutter} / 2);
259
+ }
260
+ }
261
+ display: grid;
262
+ justify-items: center;
263
+ grid-template-columns: repeat(3, 1fr);
264
+ gap: 0;
265
+ }
266
+ .${k}-weeks {
210
267
  display: grid;
211
- grid-template-columns: repeat(4, 1fr);
268
+ .week-row {
269
+ display: flex;
270
+ align-items: center;
271
+ width: ${datepicker.week.width};
272
+ margin: ${datepicker.week.margin};
273
+
274
+ .${k}-week-number {
275
+ padding: ${datepicker.week.padding};
276
+ cursor: pointer;
277
+ }
278
+ }
279
+ .${k}-calendar-item {
280
+ height: ${datepicker.week.height};
281
+ &.${k}-today:not(:last-child) .${k}-value {
282
+ background: ${datepicker.week.currentWeek};
283
+ border: 0;
284
+ &:after {
285
+ content: '';
286
+ display: block;
287
+ position: absolute;
288
+ box-sizing: content-box;
289
+ background: ${datepicker.week.currentWeek};
290
+ width: 100%;
291
+ height: 100%;
292
+ left: 0;
293
+ padding: 0 ${datepicker.item.rangeGutter};
294
+ z-index: -1;
295
+ }
296
+ }
297
+ &.${k}-today:last-child .${k}-value {
298
+ border: 0;
299
+ }
300
+ }
212
301
  }
213
302
  `
214
303
  });
@@ -221,7 +310,26 @@ export const makeTimeStyles = cache(function makeTimeStyles(k: string) {
221
310
  position: relative;
222
311
  .${k}-scroll-select {
223
312
  flex: 1;
224
- height: 305px;
313
+ height: 265px;
225
314
  }
226
315
  `;
227
316
  });
317
+
318
+ export const makeHighlightStyles = cache(function makeHighlightStyles(k: string, size: Sizes, highlightWidth: number, highlightLeft: number) {
319
+ const paddingLeft = getLeft(select[size].padding);
320
+ return css`
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
+ }
333
+ }
334
+ `;
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
+ }
@@ -1,14 +1,18 @@
1
1
  import {useInstance} from 'intact';
2
2
  import {useState, State} from '../../hooks/useState';
3
- import {Dayjs, OpUnitType} from 'dayjs';
3
+ import {Dayjs, OpUnitType, QUnitType} from './dayjs';
4
4
  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);
@@ -28,57 +32,51 @@ export function useDisabled({createDateByValueFormat}: ReturnType<typeof useForm
28
32
  convertToDayjs(minDate, v);
29
33
  });
30
34
 
31
- function isDisabled(value: Dayjs, type: OpUnitType = 'date') {
35
+ function isDisabled(value: Dayjs, type: OpUnitType | QUnitType = 'date') {
32
36
  const {disabledDate} = instance.get();
33
37
  return isGT(value, maxDate.value, type) ||
34
38
  isLT(value, minDate.value, type) ||
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 < 2) return true;
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,14 +1,16 @@
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',
9
9
  datetime: 'YYYY-MM-DD HH:mm:ss',
10
10
  year: 'YYYY',
11
11
  month: 'YYYY-MM',
12
+ quarter: 'YYYY-[Q]Q',
13
+ week: 'YYYY-w[周]',
12
14
  };
13
15
 
14
16
  export function useFormats() {
@@ -23,9 +25,13 @@ export function useFormats() {
23
25
  const {format, showFormat, type} = instance.get();
24
26
  return showFormat || format || FORMATS[type!];
25
27
  }
26
-
28
+
29
+ /**
30
+ * 根据日期字符串,按照格式创建日期对象
31
+ */
27
32
  function createDateByValueFormat(value: Value) {
28
- return dayjs(value, isString(value) ? getValueFormat() : undefined);
33
+ const format = isString(value) ? getValueFormat() : undefined;
34
+ return dayjs(value, format);
29
35
  }
30
36
 
31
37
  function createDateByShowFormat(value: string) {