@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.
- package/components/button/demos/basic.md +0 -1
- package/components/cascader/index.spec.ts +7 -6
- package/components/copy/index.spec.ts +9 -14
- package/components/datepicker/basepicker.ts +26 -314
- package/components/datepicker/calendar.ts +3 -1
- package/components/datepicker/calendar.vdt +5 -2
- package/components/datepicker/dayjs.ts +2 -16
- package/components/datepicker/demos/multiple.md +5 -0
- package/components/datepicker/demos/yearMonth.md +2 -8
- package/components/datepicker/helpers.ts +5 -7
- package/components/datepicker/index.md +1 -2
- package/components/datepicker/index.spec.ts +596 -157
- package/components/datepicker/index.ts +16 -33
- package/components/datepicker/index.vdt +41 -35
- package/components/datepicker/shortcuts.ts +1 -1
- package/components/datepicker/styles.ts +27 -18
- package/components/datepicker/useConfirm.ts +82 -0
- package/components/datepicker/useDisabled.ts +29 -31
- package/components/datepicker/useFormats.ts +8 -4
- package/components/datepicker/useHighlight.ts +81 -0
- package/components/datepicker/useKeyboards.ts +2 -1
- package/components/datepicker/useMergeRange.ts +12 -12
- package/components/datepicker/useMonths.ts +6 -3
- package/components/datepicker/usePanel.ts +19 -19
- package/components/datepicker/useShowDate.ts +21 -41
- package/components/datepicker/useStatus.ts +34 -15
- package/components/datepicker/useValue.ts +43 -72
- package/components/datepicker/useValueBase.ts +312 -0
- package/components/datepicker/useWeeks.ts +1 -1
- package/components/datepicker/useYears.ts +7 -3
- package/components/dropdown/dropdown.ts +5 -4
- package/components/dropdown/index.md +1 -0
- package/components/dropdown/item.ts +1 -1
- package/components/dropdown/useKeyboard.ts +0 -1
- package/components/form/form.ts +4 -0
- package/components/form/index.md +2 -1
- package/components/form/index.spec.ts +2 -0
- package/components/input/index.spec.ts +42 -0
- package/components/input/index.ts +8 -0
- package/components/input/index.vdt +3 -4
- package/components/input/useAutoWidth.ts +19 -1
- package/components/menu/demos/horizontal.md +7 -1
- package/components/menu/index.spec.ts +19 -0
- package/components/menu/styles.ts +2 -1
- package/components/scrollSelect/useMouseEvents.ts +5 -4
- package/components/select/base.ts +3 -2
- package/components/select/base.vdt +2 -1
- package/components/select/demos/creatable.md +2 -2
- package/components/select/index.md +1 -1
- package/components/select/index.spec.ts +142 -36
- package/components/select/menu.ts +1 -1
- package/components/select/option.ts +2 -1
- package/components/select/select.ts +1 -0
- package/components/select/styles.ts +3 -1
- package/components/select/useCard.ts +22 -4
- package/components/select/useInput.ts +5 -9
- package/components/spinner/index.spec.ts +18 -0
- package/components/spinner/useValue.ts +2 -1
- package/components/table/index.spec.ts +69 -1
- package/components/table/useStickyHeader.ts +1 -1
- package/components/timepicker/index.spec.ts +145 -27
- package/components/timepicker/panelPicker.ts +10 -4
- package/components/timepicker/panelPicker.vdt +3 -5
- package/components/timepicker/styles.ts +1 -0
- package/components/timepicker/useConfirm.ts +33 -0
- package/components/timepicker/useDefaultValue.ts +30 -0
- package/components/timepicker/useDisabled.ts +17 -4
- package/components/timepicker/useFormats.ts +1 -1
- package/components/timepicker/useValue.ts +22 -19
- package/components/tour/index.spec.ts +1 -1
- package/es/components/cascader/index.spec.js +18 -19
- package/es/components/copy/index.spec.js +14 -31
- package/es/components/datepicker/basepicker.d.ts +6 -27
- package/es/components/datepicker/basepicker.js +23 -268
- package/es/components/datepicker/calendar.d.ts +4 -2
- package/es/components/datepicker/dayjs.d.ts +2 -13
- package/es/components/datepicker/helpers.d.ts +3 -2
- package/es/components/datepicker/helpers.js +2 -3
- package/es/components/datepicker/index.d.ts +21 -29
- package/es/components/datepicker/index.js +22 -32
- package/es/components/datepicker/index.spec.js +1277 -484
- package/es/components/datepicker/index.vdt.js +39 -38
- package/es/components/datepicker/shortcuts.d.ts +1 -1
- package/es/components/datepicker/styles.d.ts +7 -2
- package/es/components/datepicker/styles.js +10 -15
- package/es/components/datepicker/useConfirm.d.ts +6 -0
- package/es/components/datepicker/useConfirm.js +65 -0
- package/es/components/datepicker/useDisabled.d.ts +5 -3
- package/es/components/datepicker/useDisabled.js +22 -27
- package/es/components/datepicker/useFormats.d.ts +2 -2
- package/es/components/datepicker/useFormats.js +6 -2
- package/es/components/datepicker/useHighlight.d.ts +14 -0
- package/es/components/datepicker/useHighlight.js +60 -0
- package/es/components/datepicker/useKeyboards.js +2 -1
- package/es/components/datepicker/useMergeRange.d.ts +1 -1
- package/es/components/datepicker/useMergeRange.js +11 -16
- package/es/components/datepicker/useMonths.js +5 -3
- package/es/components/datepicker/usePanel.d.ts +1 -10
- package/es/components/datepicker/usePanel.js +19 -32
- package/es/components/datepicker/useShowDate.d.ts +1 -1
- package/es/components/datepicker/useShowDate.js +15 -40
- package/es/components/datepicker/useStatus.js +33 -16
- package/es/components/datepicker/useValue.d.ts +11 -6
- package/es/components/datepicker/useValue.js +49 -69
- package/es/components/datepicker/useValueBase.d.ts +28 -0
- package/es/components/datepicker/useValueBase.js +280 -0
- package/es/components/datepicker/useYears.js +6 -3
- package/es/components/dropdown/dropdown.d.ts +1 -0
- package/es/components/dropdown/dropdown.js +7 -4
- package/es/components/form/form.d.ts +1 -0
- package/es/components/form/form.js +7 -0
- package/es/components/form/index.spec.js +10 -8
- package/es/components/input/index.d.ts +2 -0
- package/es/components/input/index.js +6 -0
- package/es/components/input/index.spec.js +45 -0
- package/es/components/input/index.vdt.js +4 -3
- package/es/components/input/useAutoWidth.d.ts +2 -0
- package/es/components/input/useAutoWidth.js +19 -1
- package/es/components/menu/index.spec.js +28 -0
- package/es/components/menu/styles.js +2 -2
- package/es/components/scrollSelect/useMouseEvents.js +5 -4
- package/es/components/select/base.d.ts +1 -1
- package/es/components/select/base.js +3 -2
- package/es/components/select/base.vdt.js +4 -3
- package/es/components/select/index.spec.js +346 -218
- package/es/components/select/menu.js +1 -1
- package/es/components/select/option.js +2 -1
- package/es/components/select/select.js +2 -1
- package/es/components/select/styles.d.ts +79 -0
- package/es/components/select/styles.js +1 -0
- package/es/components/select/useCard.d.ts +4 -3
- package/es/components/select/useCard.js +15 -4
- package/es/components/select/useInput.d.ts +1 -1
- package/es/components/select/useInput.js +4 -4
- package/es/components/spinner/index.spec.js +82 -44
- package/es/components/spinner/useValue.js +2 -1
- package/es/components/table/index.spec.js +84 -6
- package/es/components/table/useStickyHeader.js +1 -1
- package/es/components/timepicker/index.spec.js +298 -128
- package/es/components/timepicker/panelPicker.d.ts +21 -16
- package/es/components/timepicker/panelPicker.js +7 -4
- package/es/components/timepicker/panelPicker.vdt.js +5 -9
- package/es/components/timepicker/selectPicker.d.ts +4 -3
- package/es/components/timepicker/styles.js +1 -1
- package/es/components/timepicker/useConfirm.d.ts +6 -0
- package/es/components/timepicker/useConfirm.js +19 -0
- package/es/components/timepicker/useDefaultValue.d.ts +4 -0
- package/es/components/timepicker/useDefaultValue.js +27 -0
- package/es/components/timepicker/useDisabled.d.ts +6 -3
- package/es/components/timepicker/useDisabled.js +13 -4
- package/es/components/timepicker/useFormats.d.ts +1 -1
- package/es/components/timepicker/useValue.d.ts +13 -8
- package/es/components/timepicker/useValue.js +14 -15
- package/es/components/tour/index.spec.js +1 -1
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/es/site/data/components/button/demos/basic/react.js +0 -2
- package/es/site/data/components/datepicker/demos/multiple/index.d.ts +1 -0
- package/es/site/data/components/datepicker/demos/multiple/index.js +2 -1
- package/es/site/data/components/datepicker/demos/multiple/react.d.ts +1 -0
- package/es/site/data/components/datepicker/demos/multiple/react.js +13 -2
- package/es/site/data/components/datepicker/demos/yearMonth/index.d.ts +0 -2
- package/es/site/data/components/datepicker/demos/yearMonth/index.js +1 -3
- package/es/site/data/components/datepicker/demos/yearMonth/react.d.ts +0 -2
- package/es/site/data/components/datepicker/demos/yearMonth/react.js +1 -21
- package/es/site/data/components/menu/demos/horizontal/react.js +5 -1
- package/es/site/data/components/select/demos/creatable/react.js +2 -2
- package/es/site/data/components/select/demos/searchable/index.js +1 -1
- package/es/site/data/components/select/demos/searchable/react.js +1 -1
- package/es/site/data/components/tour/demos/customText/index.d.ts +19 -6
- package/es/site/data/components/tour/demos/customText/index.js +18 -17
- package/es/site/data/components/tour/demos/customText/react.d.ts +20 -6
- package/es/site/data/components/tour/demos/customText/react.js +31 -27
- package/es/test/demos.js +1 -1
- package/index.ts +2 -2
- package/package.json +2 -2
- package/components/datepicker/demos/nowrap.md +0 -35
- package/components/datepicker/usePosition.ts +0 -169
- package/es/components/datepicker/usePosition.d.ts +0 -10
- package/es/components/datepicker/usePosition.js +0 -166
- package/es/site/data/components/datepicker/demos/nowrap/index.d.ts +0 -10
- package/es/site/data/components/datepicker/demos/nowrap/index.js +0 -19
- package/es/site/data/components/datepicker/demos/nowrap/react.d.ts +0 -10
- package/es/site/data/components/datepicker/demos/nowrap/react.js +0 -49
- package/es/site/data/components/tour/demos/customButtons/index.d.ts +0 -33
- package/es/site/data/components/tour/demos/customButtons/index.js +0 -55
- package/es/site/data/components/tour/demos/customButtons/react.d.ts +0 -33
- 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 {
|
|
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
|
|
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,
|
|
9
|
-
import {
|
|
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 {
|
|
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 {
|
|
23
|
-
const {
|
|
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 &&
|
|
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
|
-
[
|
|
36
|
+
[makeHighlightStyles(k, size, highlightWidth.value, highlightLeft.value)]: range,
|
|
37
|
+
[makeStyles(k)]: true,
|
|
37
38
|
}
|
|
38
39
|
const {isDisabledTime, isDisabledConfirm} = this.disabled;
|
|
39
|
-
const {
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
{
|
|
90
|
-
{
|
|
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"
|
|
@@ -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:
|
|
313
|
+
height: 265px;
|
|
302
314
|
}
|
|
303
315
|
`;
|
|
304
316
|
});
|
|
305
317
|
|
|
306
|
-
export const
|
|
307
|
-
const
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
|
9
|
-
import {Value} from './
|
|
8
|
+
import {PanelFlags} from './usePanel';
|
|
9
|
+
import {Value, StateValueRange, StateValueItem} from './useValueBase';
|
|
10
|
+
import { Position } from './useHighlight';
|
|
10
11
|
|
|
11
|
-
export function useDisabled(
|
|
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
|
|
39
|
-
|
|
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
|
-
|
|
48
|
+
const {range, multiple} = instance.get();
|
|
49
|
+
if (!lastValue || instance.value.allValuesUpdatedInMultipleMode()) return true;
|
|
59
50
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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 = (
|
|
72
|
-
end = (
|
|
68
|
+
start = (value as [Dayjs, Dayjs])[0];
|
|
69
|
+
end = (value as [Dayjs, Dayjs])[1];
|
|
73
70
|
} else {
|
|
74
|
-
start =
|
|
71
|
+
start = value as Dayjs;
|
|
75
72
|
}
|
|
76
|
-
|
|
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 '
|
|
2
|
+
import dayjs, {Dayjs} from 'dayjs';
|
|
3
3
|
import {isString} from 'intact-shared';
|
|
4
4
|
import type {Datepicker} from './index';
|
|
5
|
-
import {Value} from './
|
|
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
|
-
|
|
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
|
-
|
|
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 './
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
}
|